0.1.3: copertina con CPU, RAM e disco in percentuale
This commit is contained in:
1 parent
c73af11575
commit
887d3a6888
4 files changed
+93
-23
No files matched your search
+85
-19
@@ -6,39 +6,105 @@ CoverBackground {
|
||||
|
||||
// Guardie: quando lo snapshot non è ancora arrivato i campi mancano e in
|
||||
// JS leggere una proprietà di undefined solleva un'eccezione.
|
||||
function num(v, fallback) {
|
||||
return (v === undefined || v === null) ? fallback : v
|
||||
function cpuPct() {
|
||||
var d = statusClient.data
|
||||
return (d && d.cpu && d.cpu.percent !== undefined) ? d.cpu.percent : -1
|
||||
}
|
||||
function memPct() {
|
||||
var d = statusClient.data
|
||||
return (d && d.memory && d.memory.percent !== undefined) ? d.memory.percent : -1
|
||||
}
|
||||
function diskPct() {
|
||||
var d = statusClient.data
|
||||
if (d && d.disks && d.disks.length > 0 && d.disks[0].percent !== undefined)
|
||||
return d.disks[0].percent
|
||||
return -1
|
||||
}
|
||||
|
||||
// Stesse soglie delle card: verde, giallo da 85%, rosso da 95%.
|
||||
function levelColor(p) {
|
||||
if (p < 0) return Theme.secondaryColor
|
||||
if (p >= 95) return "#e53935"
|
||||
if (p >= 85) return "#ffb300"
|
||||
return "#43a047"
|
||||
}
|
||||
function pctText(p) {
|
||||
return p < 0 ? "—" : statusClient.fmtNum(p, 0) + "%"
|
||||
}
|
||||
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
width: parent.width - 2 * Theme.paddingLarge
|
||||
width: parent.width - 2 * Theme.paddingMedium
|
||||
spacing: Theme.paddingSmall
|
||||
|
||||
Label {
|
||||
text: "Server"
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.secondaryColor
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
Label {
|
||||
text: statusClient.error !== "" ? "—" : statusClient.fmtNum(num(statusClient.data.cpu ? statusClient.data.cpu.percent : undefined, -1), 0) + " %"
|
||||
font.pixelSize: Theme.fontSizeExtraLarge
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
Label {
|
||||
text: "CPU"
|
||||
text: qsTr("Server")
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
color: Theme.secondaryColor
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
// CPU · RAM · disco: etichetta a sinistra, percentuale a destra.
|
||||
Column {
|
||||
width: parent.width
|
||||
spacing: Theme.paddingSmall / 2
|
||||
|
||||
Row {
|
||||
width: parent.width
|
||||
Label {
|
||||
text: qsTr("CPU")
|
||||
width: parent.width * 0.5
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.primaryColor
|
||||
}
|
||||
Label {
|
||||
text: pctText(cpuPct())
|
||||
width: parent.width * 0.5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: levelColor(cpuPct())
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
width: parent.width
|
||||
Label {
|
||||
text: qsTr("RAM")
|
||||
width: parent.width * 0.5
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.primaryColor
|
||||
}
|
||||
Label {
|
||||
text: pctText(memPct())
|
||||
width: parent.width * 0.5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: levelColor(memPct())
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
width: parent.width
|
||||
Label {
|
||||
text: qsTr("Disco")
|
||||
width: parent.width * 0.5
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.primaryColor
|
||||
}
|
||||
Label {
|
||||
text: pctText(diskPct())
|
||||
width: parent.width * 0.5
|
||||
horizontalAlignment: Text.AlignRight
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: levelColor(diskPct())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
text: statusClient.fetchedAt !== "" ? statusClient.fetchedAt : ""
|
||||
text: statusClient.error !== "" ? qsTr("errore") : statusClient.fetchedAt
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
color: Theme.secondaryColor
|
||||
color: statusClient.error !== "" ? "#e53935" : Theme.secondaryColor
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user