Skip to content

Commit

Permalink
Include truenas in uptime refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shamoon committed Dec 15, 2023
1 parent e768b1c commit 30e4a2a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 31 deletions.
3 changes: 1 addition & 2 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,7 @@
"truenas": {
"load": "System Load",
"uptime": "Uptime",
"alerts": "Alerts",
"time": "{{value, number(style: unit; unitDisplay: long;)}}"
"alerts": "Alerts"
},
"pyload": {
"speed": "Speed",
Expand Down
30 changes: 1 addition & 29 deletions src/widgets/truenas/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,6 @@ import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";

const processUptime = (uptime) => {
const seconds = uptime.toFixed(0);

const levels = [
[Math.floor(seconds / 31536000), "year"],
[Math.floor((seconds % 31536000) / 2592000), "month"],
[Math.floor(((seconds % 31536000) % 2592000) / 86400), "day"],
[Math.floor(((seconds % 31536000) % 86400) / 3600), "hour"],
[Math.floor((((seconds % 31536000) % 86400) % 3600) / 60), "minute"],
[(((seconds % 31536000) % 86400) % 3600) % 60, "second"],
];

for (let i = 0; i < levels.length; i += 1) {
const level = levels[i];
if (level[0] > 0) {
return {
value: level[0],
unit: level[1],
};
}
}

return {
value: 0,
unit: "second",
};
};

export default function Component({ service }) {
const { t } = useTranslation();

Expand All @@ -58,7 +30,7 @@ export default function Component({ service }) {
return (
<Container service={service}>
<Block label="truenas.load" value={t("common.number", { value: statusData.loadavg[0] })} />
<Block label="truenas.uptime" value={t("truenas.time", processUptime(statusData.uptime_seconds))} />
<Block label="truenas.uptime" value={t("common.uptime", { value: statusData.uptime_seconds })} />
<Block label="truenas.alerts" value={t("common.number", { value: alertData.pending })} />
</Container>
);
Expand Down

0 comments on commit 30e4a2a

Please sign in to comment.