Docker list: do all updating inline + new button "Update all Containers"

This commit is contained in:
bergware
2018-03-09 13:05:39 +01:00
parent b90fa7da4a
commit 8bc44e77e1
4 changed files with 56 additions and 29 deletions
@@ -19,7 +19,6 @@ Markdown="false"
?>
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.ui.css">
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.switchbutton.css">
<style>
.basic{display:block}
.advanced{display:none;white-space:nowrap}
@@ -37,16 +36,6 @@ img.stopped{opacity:0.3}
.switch-button-label.off{color:inherit}
th.three{width:3%}
</style>
<form id="formAutostart" method="POST" action="/plugins/dynamix.docker.manager/include/UpdateConfig.php" target="progressFrame">
<input type="hidden" name="action" value="autostart" />
<input type="hidden" name="container" value="none" />
</form>
<form id="formStartStop" method="POST" action="/update.php" target="progressFrame">
<input type="hidden" id="cmdStartStop" name="#command" value="">
<input type="hidden" id="cmdArg1" name="#arg[1]" value="">
<input type="hidden" id="cmdArg2" name="#arg[2]" value="">
</form>
<div id="dialog-confirm" style="display:none;" title="Dialog Title"></div>
<div id="iframe-popup" style="display:none;-webkit-overflow-scrolling:touch;"></div>
<span class="status" style="margin-top:-44px"><span><input type="checkbox" class="advancedview"></span></span>
@@ -54,10 +43,11 @@ th.three{width:3%}
<thead><tr><th></th><th>Application</th><th>Version</th><th>Network</th><th>Port Mappings <small>(App to Host)</small></th><th>Volume Mappings <small>(App to Host)</small></th><th width="80px" style="text-align:center">Autostart</th><th class="three">Log</th></tr></thead>
<tbody id="docker_list"><tr><td colspan='8' style='text-align:center;padding-top:12px'><i class='fa fa-spinner fa-spin icon'></i>Please wait... retrieving container information</td></tr></tbody>
</table>
<input type="button" onclick="addContainer()" value="Add Container"/>
<input type="button" onclick="startAll()" value="Start all Containers"/>
<input type="button" onclick="stopAll()" value="Stop all Containers"/>
<input type="button" onclick="reloadUpdate()" value="Check for Updates"/>
<input type="button" onclick="addContainer()" value="Add Container">
<input type="button" onclick="startAll()" value="Start all Containers">
<input type="button" onclick="stopAll()" value="Stop all Containers">
<input type="button" onclick="checkAll()" value="Check for Updates" id="checkAll">
<input type="button" onclick="updateAll()" value="Update all Containers" id="updateAll" style="display:none">
<script src="<?autov('/webGui/javascript/jquery.switchbutton.js')?>"></script>
<script src="<?autov('/plugins/dynamix.docker.manager/javascript/docker.js')?>"></script>
@@ -82,7 +72,7 @@ function listview() {
$('.docker_readmore').readmore('destroy');
}
}
function loadlist() {
function loadlist(update) {
$.get('/plugins/dynamix.docker.manager/include/DockerContainers.php',function(d) {
var data = d.split(/\0/);
$('#docker_list').html(data[0]);
@@ -103,6 +93,11 @@ function loadlist() {
listview();
context.init({preventDoubleContext:false});
$('input[type=button]').prop('disabled',false);
if (update) {
$('input#checkAll').hide(); $('input#updateAll').show();
} else {
$('input#checkAll').show(); $('input#updateAll').hide();
}
});
}
$(function() {
@@ -113,6 +108,6 @@ $(function() {
$.cookie('docker_listview_mode',$('.advancedview').is(':checked')?'advanced':'basic',{expires:3650});
listview();
});
loadlist();
$.post('/plugins/dynamix.docker.manager/include/DockerUpdate.php',{},function(u){loadlist(u);});
});
</script>
@@ -48,7 +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'});";
$docker[] = "docker.push({name:'$name',id:'$id',state:'$running',update:'$updateStatus'});";
$shape = $ct['Running'] ? 'play':'square';
$status = $ct['Running'] ? 'started':'stopped';
$icon = $info['icon'] ?: '/plugins/dynamix.docker.manager/images/question.png';
@@ -0,0 +1,31 @@
<?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';
require_once "$docroot/plugins/dynamix.docker.manager/include/DockerClient.php";
$DockerClient = new DockerClient();
$DockerTemplates = new DockerTemplates();
if ($_POST['check']) {
$DockerTemplates->downloadTemplates();
$DockerTemplates->getAllInfo(true);
}
$all_containers = $DockerClient->getDockerContainers();
$all_info = $DockerTemplates->getAllInfo();
foreach ($all_containers as $ct) {
$info = &$all_info[$ct['Name']];
if ($info['updated']=='false'&&$info['updated']!='undef') {echo 'true'; break;}
}
?>
@@ -42,9 +42,9 @@ function addDockerImageContext(image, imageTag) {
function execUpContainer(container) {
var title = "Updating the container: "+container;
var address = "/plugins/dynamix.docker.manager/include/CreateDocker.php?updateContainer=true&ct[]="+encodeURIComponent(container);
popupWithIframe(title, address, true);
popupWithIframe(title, address, true, 'loadlist');
}
function popupWithIframe(title, cmd, reload) {
function popupWithIframe(title, cmd, reload, func) {
pauseEvents();
$("#iframe-popup").html('<iframe id="myIframe" frameborder="0" scrolling="yes" width="100%" height="99%"></iframe>');
$("#iframe-popup").dialog({
@@ -62,7 +62,7 @@ function popupWithIframe(title, cmd, reload) {
},
close:function(event, ui) {
if (reload && !$("#myIframe").contents().find("#canvas").length) {
location = window.location.href;
if (func) setTimeout(func+'()',0); else location = window.location.href;
} else {
resumeEvents();
}
@@ -154,16 +154,17 @@ function stopAll() {
for (var i=0,ct; ct=docker[i]; i++) if (ct.state=='true') $('#'+ct.id).find('i').addClass('fa-spin');
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'stop'}, function(){loadlist();});
}
function reloadUpdate() {
function checkAll() {
$('input[type=button]').prop('disabled',true);
$(".updatecolumn").html("<span style=\"color:#267CA8;white-space:nowrap;\"><i class=\"fa fa-spin fa-refresh\"></i> checking...</span>");
$("#cmdStartStop").val("/plugins/dynamix.docker.manager/scripts/dockerupdate.php");
$("#cmdArg1").remove();
$("#cmdArg2").remove();
$("#formStartStop").submit();
$.post('/plugins/dynamix.docker.manager/include/DockerUpdate.php',{check:true},function(u){loadlist(u);});
}
function autoStart(container, event) {
document.getElementsByName("container")[0].value = container;
$("#formStartStop").submit();
function updateAll() {
$('input[type=button]').prop('disabled',true);
var list = '';
for (var i=0,ct; ct=docker[i]; i++) if (ct.update=='false') list += '&ct[]='+ct.name;
var address = "/plugins/dynamix.docker.manager/include/CreateDocker.php?updateContainer=true"+list;
popupWithIframe('Updating all Containers', address, true, 'loadlist');
}
function containerLogs(container, id) {
var height = 600;