mirror of
https://github.com/unraid/webgui.git
synced 2026-01-15 22:19:58 -06:00
Code cleanup
This commit is contained in:
@@ -557,35 +557,20 @@ function toggle_net(init) {
|
||||
$('.net_closed').show();
|
||||
}
|
||||
}
|
||||
function parseINI(data){
|
||||
var regex = {
|
||||
section: /^\s*\[\s*\"*([^\]]*)\s*\"*\]\s*$/,
|
||||
param: /^\s*([^=]+?)\s*=\s*\"*(.*?)\s*\"*$/,
|
||||
comment: /^\s*;.*$/
|
||||
};
|
||||
var value = {};
|
||||
var lines = data.split(/[\r\n]+/);
|
||||
var section = null;
|
||||
lines.forEach(function(line){
|
||||
if(regex.comment.test(line)){
|
||||
return;
|
||||
}else if(regex.param.test(line)){
|
||||
var match = line.match(regex.param);
|
||||
if(section){
|
||||
value[section][match[1]] = match[2];
|
||||
}else{
|
||||
value[match[1]] = match[2];
|
||||
}
|
||||
}else if(regex.section.test(line)){
|
||||
var match = line.match(regex.section);
|
||||
value[match[1]] = {};
|
||||
section = match[1];
|
||||
}else if(line.length == 0 && section){
|
||||
section = null;
|
||||
};
|
||||
});
|
||||
return value;
|
||||
}
|
||||
var cpuload = new NchanSubscriber('/sub/cpuload');
|
||||
cpuload.on('message',function(message) {
|
||||
// message should be something like: {"cpuload": {"cpu":[0,0],"cpu0":[0,0],"cpu1":[0,0],"cpu2":[0,0],"cpu3":[0,0]}}
|
||||
// The array values are [<load-percentage>,<guest-percentage>]. guest-percentage is that part of load-percentage that is being consumed by VM guests
|
||||
// var json = $.parseJSON(message);
|
||||
// $.each(json["cpuload"],function(k,v) {
|
||||
// $('#'+k).animate({width:v[0]+'%'},{step:function(){$('#'+k).css('overflow','visible');}}).text(v[0]+'%');
|
||||
// });
|
||||
// message is the cpuload.ini file contents
|
||||
var ini = parseINI(message);
|
||||
$.each(ini,function(k,v) {
|
||||
$('#'+k).animate({width:v['host']+'%'},{step:function(){$('#'+k).css('overflow','visible');}}).text(v['host']+'%');
|
||||
});
|
||||
});
|
||||
$(function() {
|
||||
dropdown('enter_share');
|
||||
dropdown('enter_view');
|
||||
@@ -596,21 +581,6 @@ $(function() {
|
||||
update30();
|
||||
update15();
|
||||
context.init({preventDoubleContext:false});
|
||||
|
||||
var cpuload_sub = new NchanSubscriber('/sub/cpuload');
|
||||
cpuload_sub.on("message", function(message, message_metadata) {
|
||||
// message should be something like: {"cpuload": {"cpu":[0,0],"cpu0":[0,0],"cpu1":[0,0],"cpu2":[0,0],"cpu3":[0,0]}}
|
||||
// The array values are [<load-percentage>,<guest-percentage>]. guest-percentage is that part of load-percentage that is being consumed by VM guests
|
||||
// var json = $.parseJSON(message);
|
||||
// $.each(json["cpuload"],function(k,v) {
|
||||
// $('#'+k).animate({width:v[0]+'%'},{step:function(){$('#'+k).css('overflow','visible');}}).text(v[0]+'%');
|
||||
// });
|
||||
// message is the cpuload.ini file contents
|
||||
var ini = parseINI(message);
|
||||
$.each(ini,function(k,v) {
|
||||
$('#'+k).animate({width:v['host']+'%'},{step:function(){$('#'+k).css('overflow','visible');}}).text(v['host']+'%');
|
||||
});
|
||||
});
|
||||
cpuload_sub.start();
|
||||
cpuload.start();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -188,9 +188,6 @@ case 'sys':
|
||||
$mem = max(round((1-$memory[1]/$memory[0])*100),0);
|
||||
echo "{$mem}%#".implode('#',$sys);
|
||||
break;
|
||||
case 'cpu':
|
||||
echo @file_get_contents('state/cpuload.ini');
|
||||
break;
|
||||
case 'fan':
|
||||
exec("sensors -uA 2>/dev/null|grep -Po 'fan\d_input: \K\d+'",$rpms);
|
||||
if ($rpms) echo implode(' RPM#',$rpms).' RPM';
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
.upgrade_notice{position:fixed;top:1px;left:0;width:100%;height:40px;line-height:40px;color:#E68A00;background:#FEEFB3;border-bottom:#E68A00 1px solid;text-align:center;font-size:15px;z-index:999}
|
||||
.upgrade_notice i{margin:14px;float:right;cursor:pointer}
|
||||
.dynamix_back-to-top {background: none;margin: 0;position: fixed;bottom: 30px;right: 0;width: 30px;height: 30px;z-index: 100;display: none;text-decoration: none;color: #ffffff;}
|
||||
|
||||
<?
|
||||
$banner = '/boot/config/plugins/dynamix/banner.png';
|
||||
echo "#header.image{background-image:url(";
|
||||
@@ -374,10 +373,7 @@ foreach ($pages as $page) {
|
||||
echo "<div class=\"Panel\"><a href=\"$link\" onclick=\"$.cookie('one','tab1',{path:'/'})\">$icon<div class=\"PanelText\">$title</div></a></div>";
|
||||
}
|
||||
}
|
||||
$text = $page['text'];
|
||||
if (!isset($page['Markdown']) || $page['Markdown'] == 'true') {
|
||||
$text = Markdown($text);
|
||||
}
|
||||
$text = empty($page['Markdown']) || $page['Markdown']=='true' ? Markdown($page['text']) : $page['text'];
|
||||
eval("?>$text");
|
||||
if ($close) echo "</div></div>";
|
||||
}
|
||||
@@ -399,10 +395,6 @@ default:
|
||||
}
|
||||
echo "</span></span><span id='countdown'></span><span id='user-notice' class='red-text'></span>";
|
||||
echo "<span id='copyright'>unRAID® webGui ©2017, Lime Technology, Inc.";
|
||||
if (isset($myPage['Author'])) {
|
||||
echo " | Page author: {$myPage['Author']}";
|
||||
if (isset($myPage['Version'])) echo ", version: {$myPage['Version']}";
|
||||
}
|
||||
echo " <a href='http://lime-technology.com/wiki/index.php/Official_Documentation' target='_blank' title='Online manual'><i class='fa fa-book'></i> manual</a>";
|
||||
echo "</span></div>";
|
||||
?>
|
||||
@@ -411,34 +403,75 @@ echo "</span></div>";
|
||||
if (typeof InstallTrigger!=='undefined') $('#nav-block').addClass('mozilla');
|
||||
|
||||
function parseINI(data){
|
||||
var regex = {
|
||||
section: /^\s*\[\s*\"*([^\]]*)\s*\"*\]\s*$/,
|
||||
param: /^\s*([^=]+?)\s*=\s*\"*(.*?)\s*\"*$/,
|
||||
comment: /^\s*;.*$/
|
||||
var regex = {
|
||||
section: /^\s*\[\s*\"*([^\]]*)\s*\"*\]\s*$/,
|
||||
param: /^\s*([^=]+?)\s*=\s*\"*(.*?)\s*\"*$/,
|
||||
comment: /^\s*;.*$/
|
||||
};
|
||||
var value = {};
|
||||
var lines = data.split(/[\r\n]+/);
|
||||
var section = null;
|
||||
lines.forEach(function(line) {
|
||||
if (regex.comment.test(line)) {
|
||||
return;
|
||||
} else if (regex.param.test(line)) {
|
||||
var match = line.match(regex.param);
|
||||
if (section) {
|
||||
value[section][match[1]] = match[2];
|
||||
} else {
|
||||
value[match[1]] = match[2];
|
||||
}
|
||||
} else if (regex.section.test(line)) {
|
||||
var match = line.match(regex.section);
|
||||
value[match[1]] = {};
|
||||
section = match[1];
|
||||
} else if (line.length==0 && section) {
|
||||
section = null;
|
||||
};
|
||||
var value = {};
|
||||
var lines = data.split(/[\r\n]+/);
|
||||
var section = null;
|
||||
lines.forEach(function(line){
|
||||
if(regex.comment.test(line)){
|
||||
return;
|
||||
}else if(regex.param.test(line)){
|
||||
var match = line.match(regex.param);
|
||||
if(section){
|
||||
value[section][match[1]] = match[2];
|
||||
}else{
|
||||
value[match[1]] = match[2];
|
||||
}
|
||||
}else if(regex.section.test(line)){
|
||||
var match = line.match(regex.section);
|
||||
value[match[1]] = {};
|
||||
section = match[1];
|
||||
}else if(line.length == 0 && section){
|
||||
section = null;
|
||||
};
|
||||
});
|
||||
return value;
|
||||
});
|
||||
return value;
|
||||
}
|
||||
var watchdog = new NchanSubscriber('/sub/var');
|
||||
watchdog.on('message', function(data) {
|
||||
var ini = parseINI(data);
|
||||
var state = ini['fsState'];
|
||||
var progress = ini['fsProgress'];
|
||||
var status;
|
||||
if (state=='Stopped') {
|
||||
status = "<span class='red strong'>Array Stopped</span>";
|
||||
} else if (state=='Started') {
|
||||
status = "<span class='green strong'>Array Started</span>";
|
||||
} else if (state=='Formatting') {
|
||||
status = "<span class='green strong'>Array Started</span>•<span class='orange strong'>Formatting device(s)</span>";
|
||||
} else {
|
||||
status = "<span class='orange strong'>Array "+state+"</span>";
|
||||
}
|
||||
if (ini['mdResync']>0) {
|
||||
var action;
|
||||
if (ini['mdResyncAction'].indexOf("recon")>=0) action = "Parity-Sync / Data-Rebuild";
|
||||
else if (ini['mdResyncAction'].indexOf("clear")>=0) action = "Clearing";
|
||||
else if (ini['mdResyncAction']=="check") action = "Read-Check";
|
||||
else if (ini['mdResyncAction'].indexOf("check")>=0) action = "Parity-Check";
|
||||
action += " "+(ini['mdResyncPos']/(ini['mdResync']/100+1)).toFixed(1)+" %";
|
||||
status += "•<span class='orange strong'>"+action.replace('.','<?=$display['number'][0]?>')+"</span>";
|
||||
}
|
||||
if (progress) status += "•<span class='blue strong'>"+progress+"</span>";
|
||||
$('#statusbar').html(status);
|
||||
});
|
||||
var backtotopoffset = 250;
|
||||
var backtotopduration = 500;
|
||||
$(window).scroll(function() {
|
||||
if ($(this).scrollTop() > backtotopoffset) {
|
||||
$('.dynamix_back-to-top').fadeIn(backtotopduration);
|
||||
} else {
|
||||
$('.dynamix_back-to-top').fadeOut(backtotopduration);
|
||||
}
|
||||
});
|
||||
$('.dynamix_back-to-top').click(function(event) {
|
||||
event.preventDefault();
|
||||
$('html,body').animate({scrollTop:0},backtotopduration);
|
||||
return false;
|
||||
});
|
||||
$(function() {
|
||||
<?if ($notify['entity'] & 1 == 1):?>
|
||||
$.post('/webGui/include/Notify.php',{cmd:'init'},function(){timers.notifier = setTimeout(notifier,0);});
|
||||
@@ -512,56 +545,9 @@ $(function() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$('form').append($('<input>').attr({type:'hidden', name:'csrf_token', value:'<?=$var['csrf_token']?>'}));
|
||||
|
||||
var watchdog = new NchanSubscriber('/sub/var');
|
||||
watchdog.on('message', function(data){
|
||||
var ini=parseINI(data);
|
||||
var state=ini['fsState'];
|
||||
var progress=ini['fsProgress'];
|
||||
var status;
|
||||
|
||||
if (state=="Stopped") {
|
||||
status="<span class='red strong'>Array Stopped</span>";
|
||||
} else if (state=="Started") {
|
||||
status="<span class='green strong'>Array Started</span>";
|
||||
} else if (state=="Formatting") {
|
||||
status="<span class='green strong'>Array Started</span>•<span class='orange strong'>Formatting device(s)</span>";
|
||||
} else {
|
||||
status="<span class='orange strong'>Array "+state+"</span>";
|
||||
}
|
||||
if (ini['mdResync'] > 0) {
|
||||
var action;
|
||||
if (ini['mdResyncAction'].indexOf("recon")>=0) action="Parity-Sync / Data-Rebuild";
|
||||
else if (ini['mdResyncAction'].indexOf("clear")>=0) action="Clearing";
|
||||
else if (ini['mdResyncAction'] == "check") action="Read-Check";
|
||||
else if (ini['mdResyncAction'].indexOf("check")>=0) action="Parity-Check";
|
||||
action+=" "+(ini['mdResyncPos']/(ini['mdResync']/100+1)).toFixed(1)+" %";
|
||||
status+="•<span class='orange strong'>"+action.replace('.','<?=$display['number'][0]?>')+"</span>";
|
||||
}
|
||||
if (progress)
|
||||
status+="•<span class='blue strong'>"+progress+"</span>";
|
||||
$('#statusbar').html(status);
|
||||
});
|
||||
watchdog.start();
|
||||
});
|
||||
|
||||
var backtotopoffset = 250;
|
||||
var backtotopduration = 500;
|
||||
$(window).scroll(function() {
|
||||
if ($(this).scrollTop() > backtotopoffset) {
|
||||
$('.dynamix_back-to-top').fadeIn(backtotopduration);
|
||||
} else {
|
||||
$('.dynamix_back-to-top').fadeOut(backtotopduration);
|
||||
}
|
||||
});
|
||||
|
||||
$('.dynamix_back-to-top').click(function(event) {
|
||||
event.preventDefault();
|
||||
$('html, body').animate({scrollTop: 0},backtotopduration);
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user