Do Clear Statistics inline without complete page refresh

This commit is contained in:
bergware
2018-03-18 22:19:13 +01:00
parent 93ab98844f
commit b0f991841a
3 changed files with 17 additions and 9 deletions

View File

@@ -29,7 +29,11 @@ function toggle_state(device,name,action) {
var button = '[id^=button-]';
}
pauseEvents(event);
$.post('/webGui/include/ToggleState.php',{device:device,name:name,action:action,csrf:'<?=$var['csrf_token']?>'},function(){resumeEvents(event);if (button) $(button).prop('disabled',false);});
$.post('/webGui/include/ToggleState.php',{device:device,name:name,action:action,state:'<?=$var['mdState']?>',csrf:'<?=$var['csrf_token']?>'},function(){resumeEvents(event);if (button) $(button).prop('disabled',false);});
}
function clear_stats() {
pauseEvents();
$.post('/webGui/include/ToggleState.php',{device:'Clear',name:'',action:'',state:'<?=$var['mdState']?>',csrf:'<?=$var['csrf_token']?>'},function(){resumeEvents();});
}
function display_diskio() {
if ($.cookie('diskio')===undefined) {

View File

@@ -432,15 +432,12 @@ $(function(){
</table>
</form>
<?if ($var['fsState']=="Started"):?>
<form name="otherOps" method="POST" action="/update.htm" target="progressFrame">
<input type="hidden" name="startState" value="<?=$var['mdState']?>">
<table class="array_status">
<tr><td></td><td><input type="button" id="button-down" onclick="$('[id^=button-]').prop('disabled',true);toggle_state('down')" value="Spin Down"<?=$parity?' disabled':''?>><input type="button" id="button-up" onclick="$('[id^=button-]').prop('disabled',true);toggle_state('up')" value="Spin Up"<?=$parity?' disabled':''?>></td>
<td><strong>Spin Down</strong> will immediately spin down all disks.<br><strong>Spin Up</strong> will immediately spin up all disks.</td></tr>
<tr><td></td><td><input type="submit" name="clearStatistics" value="Clear Statistics"></td><td><strong>Clear Statistics</strong> will immediately clear all disk statistics.</td></tr>
<tr><td></td><td><input type="button" value="Clear Statistics" onclick="clear_stats()"></td><td><strong>Clear Statistics</strong> will immediately clear all disk statistics.</td></tr>
<tr><td></td><td class="line" colspan="2"></td></tr>
</table>
</form>
<?if ($var['shareCacheEnabled']=="yes" && is_dir("/mnt/cache")):?>
<form name="mover_schedule" method="POST" action="/update.htm" target="progressFrame">
<table class="array_status">

View File

@@ -14,20 +14,27 @@
$device = $_POST['device'];
$name = $_POST['name'];
$action = $_POST['action'];
$state = $_POST['state'];
$csrf = $_POST['csrf'];
function emhttpd($cmd) {
global $csrf;
$ch = curl_init("http://127.0.0.1/update.htm?$cmd&csrf_token=$csrf");
global $state, $csrf;
$ch = curl_init("http://127.0.0.1/update.htm?$cmd&startState=$state&csrf_token=$csrf");
curl_setopt_array($ch, [CURLOPT_UNIX_SOCKET_PATH => '/var/run/emhttpd.socket', CURLOPT_RETURNTRANSFER => true]);
curl_exec($ch);
curl_close($ch);
}
if ($device=='New') {
switch ($device) {
case 'New':
$cmd = $action=='up' ? 'S0' : ($action=='down' ? 'y' : false);
if ($cmd && $name) exec("/usr/sbin/hdparm -$cmd /dev/$name >/dev/null 2>&1");
} else {
break;
case 'Clear':
emhttpd("clearStatistics=true");
break;
default:
if ($name) emhttpd("cmdSpin$action=$name"); else emhttpd("cmdSpin{$device}All=true");
break;
}
?>