[TASK] Refactor showBar in node infobox

This commit is contained in:
Xaver Maierhofer 2017-02-12 22:18:23 +01:00 committed by Geno
parent 65318fb4aa
commit 5fce84cb5c

View File

@ -18,17 +18,10 @@ define(['sorttable', 'virtual-dom', 'chroma-js', 'moment', 'helper'],
function showStatus(d) {
return function (el) {
el.classList.add(d.flags.unseen ? 'unseen' : (d.flags.online ? 'online' : 'offline'));
if (d.flags.online) {
el.textContent = _.t('node.lastOnline', {
el.textContent = _.t((d.flags.online ? 'node.lastOnline' : 'node.lastOffline'), {
time: d.lastseen.fromNow(),
date: d.lastseen.format('DD.MM.YYYY, H:mm:ss')
});
} else {
el.textContent = _.t('node.lastOffline', {
time: d.lastseen.fromNow(),
date: d.lastseen.format('DD.MM.YYYY, H:mm:ss')
});
}
};
}
@ -116,34 +109,19 @@ define(['sorttable', 'virtual-dom', 'chroma-js', 'moment', 'helper'],
};
}
function showBar(v) {
function showBar(v, width, warning) {
var span = document.createElement('span');
span.classList.add('bar');
var bar = document.createElement('span');
bar.style.width = (v * 100) + '%';
span.appendChild(bar);
var label = document.createElement('label');
label.textContent = (Math.round(v * 100)) + ' %';
span.appendChild(label);
return span;
}
function showLoadBar(v, p) {
var span = document.createElement('span');
span.classList.add('bar');
var bar = document.createElement('span');
bar.style.width = ((v * 100) % 100) + '%';
if (v >= p) {
bar.style.width = (width * 100) + '%';
if (warning) {
span.classList.add('warning');
}
span.appendChild(bar);
var label = document.createElement('label');
label.textContent = (v);
label.textContent = v;
span.appendChild(label);
return span;
@ -155,7 +133,13 @@ define(['sorttable', 'virtual-dom', 'chroma-js', 'moment', 'helper'],
}
return function (el) {
el.appendChild(showLoadBar(d.statistics.loadavg.toFixed(2), d.nodeinfo.hardware.nproc));
var value = d.statistics.loadavg.toFixed(2);
var width = d.statistics.loadavg % 1;
var warning = false;
if (d.statistics.loadavg >= d.nodeinfo.hardware.nproc) {
warning = true;
}
el.appendChild(showBar(value, width, warning));
};
}
@ -165,7 +149,13 @@ define(['sorttable', 'virtual-dom', 'chroma-js', 'moment', 'helper'],
}
return function (el) {
el.appendChild(showBar(d.statistics.memory_usage));
var value = Math.round(d.statistics.memory_usage * 100) + ' %';
var width = d.statistics.memory_usage;
var warning = false;
if (d.statistics.memory_usage >= 0.8) {
warning = true;
}
el.appendChild(showBar(value, width, warning));
};
}