Add ALL containers start & stop operation

This commit is contained in:
bergware
2018-03-06 12:02:37 +01:00
parent 1f8f164001
commit a297e1033c
4 changed files with 40 additions and 7 deletions
@@ -42,10 +42,20 @@ img.stopped{opacity:0.3}
</table>
<input type="button" onclick="addContainer()" value="Add Container"/>
<input type="button" onclick="reloadUpdate()" value="Check for Updates"/>
<input type="button" onclick="startAll()" value="Start all Containers"/>
<input type="button" onclick="stopAll()" value="Stop all Containers"/>
<script src="<?autov('/webGui/javascript/jquery.switchbutton.js')?>"></script>
<script src="<?autov('/plugins/dynamix.docker.manager/javascript/docker.js')?>"></script>
<script>
function startAll() {
for (var i=0,ct; ct=docker[i]; i++) if (ct.state=='false') $('#'+ct.id).addClass('fa-spin');
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'start'}, function(){loadlist();});
}
function stopAll() {
for (var i=0,ct; ct=docker[i]; i++) if (ct.state=='true') $('#'+ct.id).addClass('fa-spin');
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'stop'}, function(){loadlist();});
}
<?if ($display['resize']):?>
function resize(bind) {
var width = [];
@@ -0,0 +1,27 @@
<?PHP
/* Copyright 2005-2018, Lime Technology
* Copyright 2014-2018, Guilherme Jardim, Eric Schultz, Jon Panozzo.
* Copyright 2012-2018, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
exec("docker ps -a --format='{{.Names}}'",$container);
$action = $_POST['action'];
switch ($action) {
case 'stop' : $state = 'true'; break;
case 'start': $state = 'false'; break;
}
foreach ($container as $ct) {
if (exec("docker inspect --format='{{.State.Running}}' $ct")==$state) exec("docker $action $ct >/dev/null");
}
?>
@@ -32,6 +32,7 @@ extract(parse_ini_file('state/network.ini',true));
// Read container info
$all = $DockerTemplates->getAllInfo();
$menu = [];
$docker = ['var docker=[];'];
foreach ($all_containers as $ct) {
$name = $ct['Name'];
@@ -47,6 +48,7 @@ foreach ($all_containers as $ct) {
$support = html_entity_decode($info['Support']);
$project = html_entity_decode($info['Project']);
$menu[] = sprintf("addDockerContainerContext('%s','%s','%s',%s,%s,%s,'%s','%s','%s','%s');",addslashes($name),addslashes($imageID),addslashes($template),$running,$updateStatus,$is_autostart,addslashes($webGui),$id,addslashes($support),addslashes($project));
$docker[] = "docker.push({id:'$id',state:'$running'});";
$shape = $ct['Running'] ? 'play':'square';
$status = $ct['Running'] ? 'started':'stopped';
$icon = $info['icon'] ?: '/plugins/dynamix.docker.manager/images/question.png';
@@ -122,5 +124,5 @@ foreach ($DockerClient->getDockerImages() as $image) {
echo "</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
echo "<td><div class='advanced' style='width:124px'>Created ".htmlspecialchars($image['Created'])."</div></td></tr>";
}
echo "\0".implode($menu);
echo "\0".implode($menu).implode($docker);
?>
@@ -49,7 +49,6 @@ function execUpContainer(container) {
function popupWithIframe(title, cmd, reload) {
pauseEvents();
$("#iframe-popup").html('<iframe id="myIframe" frameborder="0" scrolling="yes" width="100%" height="99%"></iframe>');
$("#iframe-popup").dialog({
autoOpen:true,
@@ -82,7 +81,6 @@ function addContainer() {
var path = location.pathname;
var x = path.indexOf("?");
if (x!=-1) path = path.substring(0,x);
location = path+"/AddContainer";
}
@@ -90,13 +88,11 @@ function editContainer(container, template) {
var path = location.pathname;
var x = path.indexOf("?");
if (x!=-1) path = path.substring(0, x);
location = path+"/UpdateContainer?xmlTemplate=edit:"+template;
}
function updateContainer(container) {
var body = "Update container: "+container;
swal({
title:"Are you sure?",
text:body,
@@ -111,7 +107,6 @@ function updateContainer(container) {
function rmContainer(container, image, id) {
var body = "Remove container: "+container+"<br><br><label><input id=\"removeimagechk\" type=\"checkbox\" checked style=\"display:inline; width:unset; height:unset; margin-top:unset; margin-bottom:unset\">also remove image</label>";
swal({
title:"Are you sure?",
text:body,
@@ -133,7 +128,6 @@ function rmContainer(container, image, id) {
function rmImage(image, imageName) {
var body = "Remove image: "+$('<textarea />').html(imageName).text();
swal({
title:"Are you sure?",
text:body,