Code optimizations

This commit is contained in:
bergware
2016-04-07 21:31:40 +02:00
parent 926354ab59
commit e586bd63ce
9 changed files with 33 additions and 36 deletions

View File

@@ -2,8 +2,8 @@ Menu="Main:1"
Title="Array Devices"
---
<?PHP
/* Copyright 2015, Lime Technology
* Copyright 2015, Bergware International.
/* Copyright 2015-2016, Lime Technology
* Copyright 2015-2016, 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,
@@ -19,7 +19,7 @@ var timer = null;
function array_status() {
$.post('/webGui/include/DeviceList.php',{path:'<?=$path?>',device:'array'},function(data) {
if (data) $('#array_devices').html(data);
<?if (($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)) && $var['fsState']=='Started'):?>
<?if ($update && $var['fsState']=='Started'):?>
<?if ($tabbed):?>
if ($('#tab1').is(':checked')) timer = setTimeout(array_status,<?=abs($display['refresh'])?>);
<?else:?>
@@ -28,7 +28,7 @@ function array_status() {
<?endif;?>
});
}
<?if (($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)) && $var['fsState']=='Started' && $display['tabs']==0):?>
<?if ($update && $var['fsState']=='Started' && $tabbed):?>
$('#tab1').bind({click:function() {clearTimeout(timer); array_status();}});
<?endif;?>

View File

@@ -2,8 +2,8 @@ Menu="Main:5"
Title="Array Operation"
---
<?PHP
/* Copyright 2015, Lime Technology
* Copyright 2015, Bergware International.
/* Copyright 2015-2016, Lime Technology
* Copyright 2015-2016, 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,
@@ -13,7 +13,6 @@ Title="Array Operation"
* all copies or substantial portions of the Software.
*/
?>
<?
function maintenance_mode() {
echo "<tr>";
@@ -42,7 +41,7 @@ function tab0() {
function parity_status() {
$.post('/webGui/include/DeviceList.php',{path:'<?=$path?>',device:'parity'},function(data) {
if (data) {$.each(data.split(';'),function(k,v) {if ($('#line'+k).length>0) $('#line'+k).html(v);});}
<?if ($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)):?>
<?if ($update):?>
<?if ($tabbed):?>
if ($('#tab'+$('input[name$="tabs"]').length).is(':checked')) timer = setTimeout(parity_status,<?=abs($display['refresh'])?>);
<?else:?>
@@ -58,7 +57,7 @@ function parity_status() {
}
parity_status();
<?if ($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)):?>
<?if ($update):?>
<?if ($tabbed):?>
$('#tab'+$('input[name$="tabs"]').length).bind({click:function() {clearTimeout(timer); parity_status(); tab0();}});
<?endif;?>

View File

@@ -2,8 +2,8 @@ Menu="Main:3"
Title="Boot Device"
---
<?PHP
/* Copyright 2015, Lime Technology
* Copyright 2015, Bergware International.
/* Copyright 2015-2016, Lime Technology
* Copyright 2015-2016, 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,
@@ -17,7 +17,7 @@ Title="Boot Device"
function boot_status() {
$.post('/webGui/include/DeviceList.php',{path:'<?=$path?>',device:'flash'},function(data) {
if (data) $('#boot_device').html(data);
<?if (($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)) && $var['fsState']=='Started'):?>
<?if ($update && $var['fsState']=='Started'):?>
<?if ($tabbed):?>
if ($('#tab3').is(':checked')) timer = setTimeout(boot_status,<?=abs($display['refresh'])?>);
<?else:?>
@@ -26,7 +26,7 @@ function boot_status() {
<?endif;?>
});
}
<?if (($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)) && $var['fsState']=='Started' && $display['tabs']==0):?>
<?if ($update && $var['fsState']=='Started' && $tabbed):?>
$('#tab3').bind({click:function() {clearTimeout(timer); boot_status();}});
<?endif;?>

View File

@@ -3,8 +3,8 @@ Title="Cache Devices"
Cond="($var['fsState']=='Stopped' || $var['cacheSbNumDisks'])"
---
<?PHP
/* Copyright 2015, Lime Technology
* Copyright 2015, Bergware International.
/* Copyright 2015-2016, Lime Technology
* Copyright 2015-2016, 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,
@@ -18,7 +18,7 @@ Cond="($var['fsState']=='Stopped' || $var['cacheSbNumDisks'])"
function cache_status() {
$.post('/webGui/include/DeviceList.php',{path:'<?=$path?>',device:'cache'},function(data) {
if (data) $('#cache_device').html(data);
<?if (($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)) && $var['fsState']=='Started'):?>
<?if ($update && $var['fsState']=='Started'):?>
<?if ($tabbed):?>
if ($('#tab2').is(':checked')) timer = setTimeout(cache_status,<?=abs($display['refresh'])?>);
<?else:?>
@@ -27,7 +27,7 @@ function cache_status() {
<?endif;?>
});
}
<?if (($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)) && $var['fsState']=='Started' && $display['tabs']==0):?>
<?if ($update && $var['fsState']=='Started' && $tabbed):?>
$('#tab2').bind({click:function() {clearTimeout(timer); cache_status();}});
<?endif;?>

View File

@@ -13,7 +13,6 @@ Title="Statistics"
* all copies or substantial portions of the Software.
*/
?>
<?
exec('cat /sys/devices/system/cpu/*/topology/thread_siblings_list|sort -nu', $cores);
$fans = exec("sensors -uA 2>/dev/null|grep -c 'fan[0-9]_input'");
@@ -391,7 +390,7 @@ function update3() {
<?endif;?>
$.post('<?=$url?>',{cmd:'cpu'},function(data) {
if (data) $.each(data.split('#'),function(k,v) {$('#cpu'+k).html(v);});
<?if ($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)):?>
<?if ($update):?>
setTimeout(update3,<?=max(abs($display['refresh']),3000)?>);
<?endif;?>
});
@@ -417,7 +416,7 @@ function update30() {
if (view == 'alert') opts.push({text:'Acknowledge',icon:'fa-check-square-o',action:function(e){e.preventDefault();acknowledge(disk);}});
context.attach(id,opts);
});
<?if ($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)):?>
<?if ($update):?>
timer30 = setTimeout(update30,<?=max(abs($display['refresh']),30000)?>);
<?endif;?>
});
@@ -426,7 +425,7 @@ function update60() {
<?if ($var['mdNumInvalid']==0 && $var['mdResync']>0):?>
$.post('<?=$url?>',{cmd:'parity'},function(data) {
if (data) $('#parity').html(data);
<?if ($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)):?>
<?if ($update):?>
setTimeout(update60,<?=max(abs($display['refresh']),60000)?>);
<?endif;?>
});

View File

@@ -3,8 +3,8 @@ Title="Archived Notifications"
---
<?PHP
/* Copyright 2012, Andrew Hamer-Adams, http://www.pixeleyes.co.nz.
* Copyright 2015, Lime Technology
* Copyright 2015, Bergware International.
* Copyright 2015-2016, Lime Technology
* Copyright 2015-2016, 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,
@@ -14,7 +14,6 @@ Title="Archived Notifications"
* all copies or substantial portions of the Software.
*/
?>
<?
$files = count(glob("{$notify['path']}/archive/*.notify", GLOB_NOSORT));
?>
@@ -54,7 +53,7 @@ function archiveList(init) {
}
$('#archive_list .expand-child td').hide();
for (var i = 0; i < rows.length; i++) $('#archive_list .expand-child.row'+rows[i]+' td').show();
<?if ($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)):?>
<?if ($update):?>
setTimeout(archiveList,<?=max(abs($display['refresh']),30000)?>);
<?endif;?>
});

View File

@@ -3,8 +3,8 @@ Title="Unassigned Devices"
Cond="((count($devs)>0)&&($var['fsState']=='Started'))"
---
<?PHP
/* Copyright 2015, Bergware International.
* Copyright 2015, Lime Technology
/* Copyright 2015-2016, Bergware International.
* Copyright 2015-2016, Lime Technology
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
@@ -14,7 +14,6 @@ Cond="((count($devs)>0)&&($var['fsState']=='Started'))"
* all copies or substantial portions of the Software.
*/
?>
<?
$tabX = '#tab'.($var['fsState']=='Stopped'||is_dir('/mnt/cache') ? '4' : '3');
?>
@@ -22,7 +21,7 @@ $tabX = '#tab'.($var['fsState']=='Stopped'||is_dir('/mnt/cache') ? '4' : '3');
function open_status() {
$.post('/webGui/include/DeviceList.php',{path:'<?=$path?>',device:'open'},function(data) {
if (data) $('#open_devices').html(data);
<?if (($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)) && $var['fsState']=='Started'):?>
<?if ($update && $var['fsState']=='Started'):?>
<?if ($tabbed):?>
if ($('<?=$tabX?>').is(':checked')) timer = setTimeout(open_status,<?=abs($display['refresh'])?>);
<?else:?>
@@ -31,7 +30,7 @@ function open_status() {
<?endif;?>
});
}
<?if (($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)) && $var['fsState']=='Started' && $display['tabs']==0):?>
<?if ($update && $var['fsState']=='Started' && $tabbed):?>
$('<?=$tabX?>').bind({click:function() {clearTimeout(timer); open_status();}});
<?endif;?>

View File

@@ -68,9 +68,9 @@ function plus(value, label, last) {
}
function updateTime() {
var now = new Date();
days = parseInt(uptime/86400);
hour = parseInt(uptime/3600%24);
mins = parseInt(uptime/60%60);
var days = parseInt(uptime/86400);
var hour = parseInt(uptime/3600%24);
var mins = parseInt(uptime/60%60);
$('#uptime').html(((days|hour|mins)?plus(days,'day',(hour|mins)==0)+plus(hour,'hour',mins==0)+plus(mins,'minute',true):'less than a minute'));
uptime += Math.round((now.getTime() - before.getTime())/1000);
before = now;
@@ -172,7 +172,7 @@ function notifier() {
close: function(e,m,o) {$.post('/webGui/include/Notify.php',{cmd:'archive',file:notify.file}); return(false);}
});
});
<?if ($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)):?>
<?if ($update):?>
timers.notifier = setTimeout(notifier,<?=max(5000,abs($display['refresh']))?>);
<?endif;?>
}
@@ -182,7 +182,7 @@ function watchdog() {
$.post('/webGui/include/Watchdog.php',{mode:<?=$display['refresh']?>,dot:'<?=$display['number'][0]?>'},function(data) {
if (data) {
$.each(data.split('#'),function(k,v) {
<?if ($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)):?>
<?if ($update):?>
if (v!='stop') $('#statusbar').html(v); else setTimeout(refresh,0);
});
timers.watchdog = setTimeout(watchdog,<?=abs($display['refresh'])?>);
@@ -204,7 +204,7 @@ $(function() {
if (tab=='tab0') tab = 'tab'+$('input[name$="tabs"]').length; else if ($('#'+tab).length==0) {initab(); tab = 'tab1';}
if ($.cookie('help')=='help') {$('.inline_help').show(); $('#nav-item.HelpButton').addClass('active');}
$('#'+tab).attr('checked', true);
<?if ($display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0)):?>
<?if ($update):?>
if (update>1) timers.countDown = setTimeout(countDown,1000);
<?endif;?>
updateTime();

View File

@@ -52,6 +52,7 @@ foreach (glob('plugins/*', GLOB_ONLYDIR) as $plugin) {
// Here's the page we're rendering
$myPage = $site[basename($path)];
$pageroot = "{$docroot}/".dirname($myPage['file']);
$update = $display['refresh']>0 || ($display['refresh']<0 && $var['mdResync']==0);
// Giddyup
require_once 'include/DefaultPageLayout.php';