Skip to content

Commit

Permalink
Do the auto compose for all containers selected at once and not in a …
Browse files Browse the repository at this point in the history
…loop
  • Loading branch information
austinwbest committed Nov 22, 2023
1 parent f819a12 commit f5a198d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 65 deletions.
52 changes: 30 additions & 22 deletions root/app/www/public/ajax/containers.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@
$pulls = getFile(PULL_FILE);
$pulls = is_array($pulls) ? $pulls : json_decode($pulls, true);
$container = findContainerFromHash($_POST['hash']);
$version = '';

switch ($_POST['trigger']) {
case '1': //-- Start
Expand Down Expand Up @@ -214,31 +213,41 @@
$result = 'docker run ' . $container['Names'] . '<br><pre>' . $run . '</pre>';
break;
case '6': //-- GENERATE COMPOSE
$run = dockerAutoCompose($container['Names']);
$lines = explode("\n", $run);
$version = $lines[count($lines) - 1];
$run = str_replace($version, '', $run);
$result = trim($run);
break;
}
$containerList = '';
$containers = explode(',', $_POST['hash']);

$processList = dockerProcessList(false);
$processList = json_decode($processList, true);
$containerProcess = [];
foreach ($processList as $process) {
if ($process['Names'] == $container['Names']) {
$containerProcess = $process;
foreach ($containers as $selectedContainer) {
$thisContainer = findContainerFromHash($selectedContainer);
$containerList .= $thisContainer['Names'] . ' ';
}

$result = '<pre>' . dockerAutoCompose(trim($containerList)) . '</pre>';
break;
}
}

$processList = dockerProcessList(false);
$processList = json_decode($processList, true);
$dockerStats = dockerStats(false);
$dockerStats = json_decode($dockerStats, true);
$containerStats = [];
foreach ($dockerStats as $dockerStat) {
if ($dockerStat['Name'] == $container['Names']) {
$containerStats = $dockerStat;
break;
$containerProcess = $containerStats = [];

if (is_array($container)) {
foreach ($processList as $process) {
if (!is_array($process)) {
continue;
}

if ($process['Names'] == $container['Names']) {
$containerProcess = $process;
break;
}
}

foreach ($dockerStats as $dockerStat) {
if ($dockerStat['Name'] == $container['Names']) {
$containerStats = $dockerStat;
break;
}
}
}

Expand All @@ -258,8 +267,7 @@
'status' => $containerProcess['Status'],
'cpu' => $containerStats['CPUPerc'],
'mem' => $containerStats['MemPerc'],
'result' => $result,
'version' => $version
'result' => $result
];

echo json_encode($return);
Expand Down
99 changes: 56 additions & 43 deletions root/app/www/public/js/containers.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,54 +78,67 @@ function massApplyContainerTrigger()
let counter = 1;
let firstCompose = '';

if (parseInt($('#massContainerTrigger').val()) == 5 || parseInt($('#massContainerTrigger').val()) == 6) {
$('#massTrigger-results').html('<pre></pre>');
}

$.each($('[id^=massTrigger-]'), function () {
if ($(this).prop('checked')) {
const containerHash = $(this).attr('id').replace('massTrigger-', '');
if (!firstCompose) {
firstCompose = containerHash;
//-- DO COMPOSE ALL AT ONCE
if (parseInt($('#massContainerTrigger').val()) == 6) {
let hashes = '';
$.each($('[id^=massTrigger-]'), function () {
if ($(this).prop('checked')) {
const containerHash = $(this).attr('id').replace('massTrigger-', '');
hashes += (hashes ? ',' : '') + containerHash;
}
});

$.ajax({
type: 'POST',
url: '../ajax/containers.php',
data: '&m=massApplyContainerTrigger&trigger=' + $('#massContainerTrigger').val() + '&hash=' + containerHash,
dataType: 'json',
async: 'global',
success: function (resultData) {
if (parseInt($('#massContainerTrigger').val()) == 5 || parseInt($('#massContainerTrigger').val()) == 6) {
$('#massTrigger-results pre').append(resultData.result + "\n");

if (counter == selected) {
$('#massTrigger-results pre').prepend(resultData.version + "\n");
$.ajax({
type: 'POST',
url: '../ajax/containers.php',
data: '&m=massApplyContainerTrigger&trigger=' + $('#massContainerTrigger').val() + '&hash=' + hashes,
dataType: 'json',
async: 'global',
success: function (resultData) {
$('#massTrigger-results').append(resultData.result);
$('#massContainerTrigger').val('0');
$('.containers-check').prop('checked', false);
$('#massTrigger-close-btn').show();
$('#massTrigger-spinner').hide();
}
});
} else {
$.each($('[id^=massTrigger-]'), function () {
if ($(this).prop('checked')) {
const containerHash = $(this).attr('id').replace('massTrigger-', '');

$.ajax({
type: 'POST',
url: '../ajax/containers.php',
data: '&m=massApplyContainerTrigger&trigger=' + $('#massContainerTrigger').val() + '&hash=' + containerHash,
dataType: 'json',
async: 'global',
success: function (resultData) {
if (parseInt($('#massContainerTrigger').val()) == 5) {
$('#massTrigger-results').append(resultData.result + "\n");
} else {
$('#massTrigger-results pre').append("\n");
$('#' + containerHash + '-control').html(resultData.control);
$('#' + containerHash + '-update').html(resultData.update);
$('#' + containerHash + '-state').html(resultData.state);
$('#' + containerHash + '-running').html(resultData.running);
$('#' + containerHash + '-status').html(resultData.status);
$('#' + containerHash + '-cpu').html(resultData.cpu);
$('#' + containerHash + '-mem').html(resultData.mem);

$('#massTrigger-results').prepend(counter + ': ' + resultData.result);
}
} else {
$('#' + containerHash + '-control').html(resultData.control);
$('#' + containerHash + '-update').html(resultData.update);
$('#' + containerHash + '-state').html(resultData.state);
$('#' + containerHash + '-running').html(resultData.running);
$('#' + containerHash + '-status').html(resultData.status);
$('#' + containerHash + '-cpu').html(resultData.cpu);
$('#' + containerHash + '-mem').html(resultData.mem);

$('#massTrigger-results').prepend(counter + ': ' + resultData.result);
}

if (counter == selected) {
$('#massContainerTrigger').val('0');
$('.containers-check').prop('checked', false);
$('#massTrigger-close-btn').show();
$('#massTrigger-spinner').hide();
if (counter == selected) {
$('#massContainerTrigger').val('0');
$('.containers-check').prop('checked', false);
$('#massTrigger-close-btn').show();
$('#massTrigger-spinner').hide();
}
counter++;
}
counter++;
}
});
}
});
});
}
});
}
}
// ---------------------------------------------------------------------------------------------

0 comments on commit f5a198d

Please sign in to comment.