mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-09 14:58:47 +00:00
Enhancement: support different bytes multipliers for disk space for resources / glances and metrics widgets (#2966)
This commit is contained in:
parent
3fae59c2bd
commit
291bf422f9
8 changed files with 22 additions and 12 deletions
|
@ -21,6 +21,7 @@ function convertToFahrenheit(t) {
|
|||
export default function Widget({ options }) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const { settings } = useContext(SettingsContext);
|
||||
const diskUnits = options.diskUnits === "bbytes" ? "common.bbytes" : "common.bytes";
|
||||
|
||||
const { data, error } = useSWR(
|
||||
`/api/widgets/glances?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`,
|
||||
|
@ -132,9 +133,9 @@ export default function Widget({ options }) {
|
|||
<Resource
|
||||
key={`disk_${disk.mnt_point ?? disk.device_name}`}
|
||||
icon={FiHardDrive}
|
||||
value={t("common.bytes", { value: disk.free })}
|
||||
value={t(diskUnits, { value: disk.free })}
|
||||
label={t("glances.free")}
|
||||
expandedValue={t("common.bytes", { value: disk.size })}
|
||||
expandedValue={t(diskUnits, { value: disk.size })}
|
||||
expandedLabel={t("glances.total")}
|
||||
percentage={disk.percent}
|
||||
expanded={options.expanded}
|
||||
|
|
|
@ -5,8 +5,9 @@ import { useTranslation } from "next-i18next";
|
|||
import Resource from "../widget/resource";
|
||||
import Error from "../widget/error";
|
||||
|
||||
export default function Disk({ options, expanded, refresh = 1500 }) {
|
||||
export default function Disk({ options, expanded, diskUnits, refresh = 1500 }) {
|
||||
const { t } = useTranslation();
|
||||
const diskUnitsName = diskUnits === "bbytes" ? "common.bbytes" : "common.bytes";
|
||||
|
||||
const { data, error } = useSWR(`/api/widgets/resources?type=disk&target=${options.disk}`, {
|
||||
refreshInterval: refresh,
|
||||
|
@ -36,9 +37,9 @@ export default function Disk({ options, expanded, refresh = 1500 }) {
|
|||
return (
|
||||
<Resource
|
||||
icon={FiHardDrive}
|
||||
value={t("common.bytes", { value: data.drive.available })}
|
||||
value={t(diskUnitsName, { value: data.drive.available })}
|
||||
label={t("resources.free")}
|
||||
expandedValue={t("common.bytes", { value: data.drive.size })}
|
||||
expandedValue={t(diskUnitsName, { value: data.drive.size })}
|
||||
expandedLabel={t("resources.total")}
|
||||
percentage={percent}
|
||||
expanded={expanded}
|
||||
|
|
|
@ -8,7 +8,7 @@ import CpuTemp from "./cputemp";
|
|||
import Uptime from "./uptime";
|
||||
|
||||
export default function Resources({ options }) {
|
||||
const { expanded, units } = options;
|
||||
const { expanded, units, diskUnits } = options;
|
||||
let { refresh } = options;
|
||||
if (!refresh) refresh = 1500;
|
||||
refresh = Math.max(refresh, 1000);
|
||||
|
@ -19,8 +19,10 @@ export default function Resources({ options }) {
|
|||
{options.cpu && <Cpu expanded={expanded} refresh={refresh} />}
|
||||
{options.memory && <Memory expanded={expanded} refresh={refresh} />}
|
||||
{Array.isArray(options.disk)
|
||||
? options.disk.map((disk) => <Disk key={disk} options={{ disk }} expanded={expanded} refresh={refresh} />)
|
||||
: options.disk && <Disk options={options} expanded={expanded} refresh={refresh} />}
|
||||
? options.disk.map((disk) => (
|
||||
<Disk key={disk} options={{ disk }} expanded={expanded} diskUnits={diskUnits} refresh={refresh} />
|
||||
))
|
||||
: options.disk && <Disk options={options} expanded={expanded} diskUnits={diskUnits} refresh={refresh} />}
|
||||
{options.cputemp && <CpuTemp expanded={expanded} units={units} refresh={refresh} />}
|
||||
{options.uptime && <Uptime refresh={refresh} />}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue