Update plugins table inline instead of rebuilding the complete list

This commit is contained in:
bergware
2018-03-08 16:45:57 +01:00
parent 8821c1d302
commit 9279720b03
6 changed files with 71 additions and 48 deletions
@@ -17,7 +17,8 @@ Tag="download"
<script>
function installPlugin(name) {
var file = name.trim();
if (file) {noAudit();openBox('/plugins/dynamix.plugin.manager/scripts/plugin&arg1=install&arg2='+file,'Install Plugin',600,900,true);}
var plugin = file.replace(/^.*(\\|\/|\:)/,'').replace('.plg','')+':install';
if (file) openBox('/plugins/dynamix.plugin.manager/scripts/plugin&arg1=install&arg2='+file,'Install Plugin',600,900,true,'loadlist',plugin);
}
</script>
**Enter URL of remote plugin file or local plugin file**
+20 -19
View File
@@ -17,17 +17,14 @@ Code="f1e6"
* all copies or substantial portions of the Software.
*/
?>
<?
$empty = "<tr><td colspan='6' style='text-align:center;padding-top:12px'><i class='fa fa-spinner fa-spin icon'></i><em>Please wait, retrieving and updating plugin information ...</em></td><tr>";
// Remove stale /tmp/plugin/*.plg entries
foreach (glob("/tmp/plugins/*.{plg,txt}", GLOB_NOSORT+GLOB_BRACE) as $entry) if (!file_exists("/var/log/plugins/".basename($entry))) @unlink($entry);
$audit = $notify['version'] ? 1 : 0;
?>
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.filetree.css">
<style>
#plugin_tree{width:33%;height:200px;overflow-y:scroll;}
</style>
<style>#plugin_tree{width:33%;height:200px;overflow-y:scroll;}</style>
<script src="/webGui/javascript/jquery.filetree.js"></script>
<script>
<?if ($display['resize']):?>
@@ -43,29 +40,33 @@ function resize(bind) {
}
}
<?endif;?>
function noAudit() {
hideUpgrade();
$.cookie('noAudit','true',{path:'/'});
}
$(function() {
var audit = <?=$audit?>;
if ($.cookie('noAudit') != null) {
$.removeCookie('noAudit',{path:'/'});
audit = 0;
}
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{audit:audit},function(data) {
if (data) $('#plugin_list').html(data);
function loadlist(id) {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{audit:id},function(data) {
if (id) {
var tmp = id.split(':');
var tr = 'tr#'+tmp[0].replace(/[\. _]/g,'');
switch (tmp[1]) {
case 'remove' : $('#plugin_list').find(tr).remove(); break;
case 'update' : $('#plugin_list').find(tr).remove();
case 'install': $('#plugin_list').append(data).trigger('update'); break;
}
} else {
$('#plugin_list').html(data);
}
<?if ($display['resize']):?>
resize();
$(window).bind('resize',function(){resize(true);});
<?endif;?>
$('#plugin_table').tablesorter({sortList:[[4,0],[1,0]],sortAppend:[[1,0]],headers:{0:{sorter:false},5:{sorter:false}},textAttribute:'data'});
$('.desc_readmore').readmore({maxHeight:58});
$('.desc_readmore').readmore({maxHeight:66,moreLink:"<a href='#'><i class='fa fa-chevron-down'></i></a>",lessLink:"<a href='#'><i class='fa fa-chevron-up'></i></a>"});
});
$('#plugin_tree').fileTree({root:'/boot/',filter:'plg'}, function(file) {$('#plugin_file').val(file);});
<?if (!$audit):?>
<?if (!$notify['version']):?>
$('.tabs').append("<span class='status vhshift'><input type='button' value='Check for Updates' onclick='openBox(\"/plugins/dynamix.plugin.manager/scripts/plugin&arg1=checkall\",\"Plugin Update Check\",490,430,true)'></span>");
<?endif;?>
}
$(function() {
loadlist();
});
</script>
<table class='tablesorter plugins shift' id='plugin_table'>
+20 -15
View File
@@ -16,7 +16,6 @@ Tag="thumbs-up"
?>
<?
$empty = "<tr><td colspan='6' style='text-align:center;padding-top:12px'><i class='fa fa-spinner fa-spin icon'></i><em>Please wait, retrieving and updating system information ...</em></td><tr>";
$audit = $notify['unraidos'] ? 1 : 0;
$version = $date = 'unknown';
if (file_exists('/boot/previous/changes.txt')) {
@@ -48,26 +47,32 @@ function update_table(branch) {
function downgrade() {
$.get('/plugins/dynamix.plugin.manager/include/Downgrade.php',{version:'<?=$version?>'},function(){refresh();});
}
function noAudit() {
hideUpgrade();
$.cookie('noAudit','true',{path:'/'});
}
$(function() {
var audit = <?=$audit?>;
if ($.cookie('noAudit') != null) {
$.removeCookie('noAudit',{path:'/'});
audit = 0;
}
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{system:'true',audit:audit},function(data) {
$('#os_list').html(data);
function loadlist(id) {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{system:'true',audit:id},function(data) {
if (id) {
var tmp = id.split(':');
var tr = 'tr#'+tmp[0].replace(/[\. _]/g,'');
switch (tmp[1]) {
case 'update':
case 'install': $('#os_list').find(tr).remove(); $('#os_list').append(data).trigger('update'); break;
}
} else {
$('#os_list').html(data);
}
$('#os_table').tablesorter({sortList:[[4,0],[1,0]],sortAppend:[[1,0]],headers:{0:{sorter:false},5:{sorter:false}},textAttribute:'data'});
<?if (preg_match("/^\*\*(REBOOT REQUIRED|DOWNGRADE)/",@file_get_contents("$docroot/plugins/unRAIDServer/README.md",false,null,0,20))):?>
$('#change_branch').prop('disabled',true);
<?endif;?>
<?if (file_exists('/boot/previous/bzroot')):?>
$('#previous').show();
<?endif;?>
});
<?if (!$audit):?>
<?if (!$notify['unraidos']):?>
$('.tabs').append("<span class='status vhshift'><input type='button' value='Check for Updates' onclick='openBox(\"/plugins/dynamix.plugin.manager/scripts/plugin&arg1=checkos\",\"Plugin Update Check\",490,430,true)'></span>");
<?endif;?>
}
$(function() {
loadlist();
});
</script>
@@ -75,6 +80,6 @@ $(function() {
<thead><tr><th></th><th>Component</th><th>Author</th><th>Version</th><th>Status</th><th>Branch</th></tr></thead>
<tbody id="os_list"><?=$empty?></tbody>
<?if (file_exists('/boot/previous/bzroot')):?>
<tbody><tr><td><img src="/plugins/unRAIDServer/images/unRAIDServer.png"></td><td><b>unRAID Server OS (previous)</b></td><td>LimeTech</td><td><?=$version?></td><td><?=$date?></td><td><input type="button" value="Downgrade" onclick="downgrade()"></td></tbody>
<tbody id="previous" style="display:none"><tr><td><img src="/plugins/unRAIDServer/images/unRAIDServer.png"></td><td><b>unRAID Server OS (previous)</b></td><td>LimeTech</td><td><?=$version?></td><td><?=$date?></td><td><input type="button" value="Downgrade" onclick="downgrade()"></td></tbody>
<?endif;?>
</table>
@@ -20,19 +20,24 @@ function plugin($method, $arg = '') {
return $retval==0 ? implode("\n", $output) : false;
}
function check_plugin($arg, $google='8.8.8.8') {
// ping google DNS server first to ensure internet is present
$inet = exec("ping -qnl2 -c2 -W3 $google|awk '/received/{print $4}'");
return $inet ? plugin('check',$arg) : false;
function check_plugin($arg, $dns='8.8.8.8') {
// ping DNS server first to ensure internet is present
return exec("ping -qnl2 -c2 -W3 $dns 2>/dev/null|awk '/received/{print $4}'") ? plugin('check',$arg) : false;
}
function make_link($method, $arg, $extra='') {
$id = basename($arg, '.plg').$method;
$plg = basename($arg,'.plg').':'.$method;
$id = str_replace(['.',' ','_'],'',$plg);
$check = $method=='remove' ? "<input type='checkbox' onClick='document.getElementById(\"$id\").disabled=!this.checked'>" : "";
$disabled = $check ? ' disabled' : '';
$cmd = $method == 'delete' ? "/plugins/dynamix.plugin.manager/scripts/plugin_rm&arg1=$arg" : "/plugins/dynamix.plugin.manager/scripts/plugin&arg1=$method&arg2=$arg".($extra?"&arg3=$extra":"");
$clr = $method == 'delete' ? "" : "noAudit();";
return "{$check}<input type='button' id='$id' value='".ucfirst($method)."' onclick='{$clr}openBox(\"{$cmd}\",\"".ucwords($method)." Plugin\",600,900,true)'{$disabled}>";
if ($method == 'delete') {
$cmd = "/plugins/dynamix.plugin.manager/scripts/plugin_rm&arg1=$arg";
$exec = $plg = "";
} else {
$cmd = "/plugins/dynamix.plugin.manager/scripts/plugin&arg1=$method&arg2=$arg".($extra?"&arg3=$extra":"");
$exec = "loadlist";
}
return "$check<input type='button' id='$id' value='".ucfirst($method)."' onclick='openBox(\"$cmd\",\"".ucwords($method)." Plugin\",600,900,true,\"$exec\",\"$plg\");'$disabled>";
}
// trying our best to find an icon
@@ -20,8 +20,18 @@ $branch = $_GET['branch'] ?? false;
$audit = $_GET['audit'] ?? false;
$empty = true;
$builtin = ['unRAIDServer'];
$plugins = "/var/log/plugins/*.plg";
foreach (glob("/var/log/plugins/*.plg",GLOB_NOSORT) as $plugin_link) {
if ($audit) {
list($plg,$action) = explode(':',$audit);
switch ($action) {
case 'remove' : return;
case 'install':
case 'update' : $plugins = "/var/log/plugins/$plg.plg"; break;
}
}
foreach (glob($plugins,GLOB_NOSORT) as $plugin_link) {
//only consider symlinks
$plugin_file = @readlink($plugin_link);
if ($plugin_file === false) continue;
@@ -31,7 +41,7 @@ foreach (glob("/var/log/plugins/*.plg",GLOB_NOSORT) as $plugin_link) {
//switch between system and custom plugins
if (($system && !$custom) || (!$system && $custom)) continue;
//forced plugin check?
$checked = $audit ? check_plugin(basename($plugin_file)) : true;
$checked = check_plugin(basename($plugin_file));
//OS update?
$os = $system && $name==$builtin[0];
$toggle = false;
@@ -102,7 +112,7 @@ foreach (glob("/var/log/plugins/*.plg",GLOB_NOSORT) as $plugin_link) {
}
//write plugin information
$empty = false;
echo "<tr>";
echo "<tr id=\"".str_replace(['.',' ','_'],'',basename($plugin_file,'.plg'))."\">";
echo "<td style='vertical-align:top;width:64px'><p style='text-align:center'>$link</p></td>";
echo "<td><span class='desc_readmore' style='display:block'>$desc</span></td>";
echo "<td>$author</td>";
@@ -134,10 +134,11 @@ function chkDelete(form, button) {
button.value = form.confirmDelete.checked ? 'Delete' : 'Apply';
button.disabled = false;
}
function openBox(cmd,title,height,width,load) {
function openBox(cmd,title,height,width,load,func,id) {
// open shadowbox window (run in foreground)
if (id === undefined) id = '';
var run = cmd.split('?')[0].substr(-4)=='.php' ? cmd : '/logging.htm?cmd='+cmd+'&csrf_token=<?=$var['csrf_token']?>';
var options = load ? {modal:true,onClose:function(){location=location;}} : {modal:true};
var options = load ? (func ? {modal:true,onClose:function(){setTimeout(func+'('+'"'+id+'")',0);}} : {modal:true,onClose:function(){location=location;}}) : {modal:true};
Shadowbox.open({content:run, player:'iframe', title:title, height:height, width:width, options:options});
}
function openWindow(cmd,title,height,width) {