diff --git a/public/locales/en/common.json b/public/locales/en/common.json index dc4fcd00d15..e6cce3adf94 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -708,6 +708,9 @@ "running": "Running", "stopped": "Stopped", "passed": "Passed", - "failed": "Failed" + "failed": "Failed", + "yes": "Yes", + "no": "No", + "updatesAvailable": "updates available" } } diff --git a/src/widgets/openmediavault/component.jsx b/src/widgets/openmediavault/component.jsx index bd34a7502f1..ebf1bbb23ac 100644 --- a/src/widgets/openmediavault/component.jsx +++ b/src/widgets/openmediavault/component.jsx @@ -1,6 +1,7 @@ import ServicesGetStatus from "./methods/services_get_status"; import SmartGetList from "./methods/smart_get_list"; import DownloaderGetDownloadList from "./methods/downloader_get_downloadlist"; +import AptEnumerateUpgraded from "./methods/apt_enumerateUpgraded"; export default function Component({ service }) { switch (service.widget.method) { @@ -10,6 +11,8 @@ export default function Component({ service }) { return ; case "downloader.getDownloadList": return ; + case "apt.enumerateUpgraded": + return ; default: return null; } diff --git a/src/widgets/openmediavault/methods/apt_enumerateUpgraded.jsx b/src/widgets/openmediavault/methods/apt_enumerateUpgraded.jsx new file mode 100644 index 00000000000..d75503bfac5 --- /dev/null +++ b/src/widgets/openmediavault/methods/apt_enumerateUpgraded.jsx @@ -0,0 +1,37 @@ +// noinspection JSUnresolvedVariable + +import { useTranslation } from "next-i18next"; + +import useWidgetAPI from "utils/proxy/use-widget-api"; +import Container from "components/services/widget/container"; +import Block from "components/services/widget/block"; + +const items = [ + { + label: "openmediavault.updatesAvailable", + getValue: (data, t) => (data.length > 0 ? t("openmediavault.yes") : t("openmediavault.no")), + }, +]; + +// noinspection DuplicatedCode +export default function Component({ service }) { + const { t } = useTranslation(); + const { data, error } = useWidgetAPI(service.widget); + + if (error) { + return ; + } + + const itemsWithData = items.map((item) => ({ + ...item, + number: data?.response ? item.getValue(data.response, t) : null, + })); + + return ( + + {itemsWithData.map((e) => ( + + ))} + + ); +} diff --git a/src/widgets/openmediavault/methods/downloader_get_downloadlist.jsx b/src/widgets/openmediavault/methods/downloader_get_downloadlist.jsx index ed776db0f81..f19b2f4742a 100644 --- a/src/widgets/openmediavault/methods/downloader_get_downloadlist.jsx +++ b/src/widgets/openmediavault/methods/downloader_get_downloadlist.jsx @@ -1,3 +1,5 @@ +// noinspection JSUnresolvedVariable + import useWidgetAPI from "utils/proxy/use-widget-api"; import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; @@ -10,10 +12,11 @@ const downloadReduce = (acc, e) => { }; const items = [ - { label: "openmediavault.downloading", getNumber: (data) => (!data ? null : data.reduce(downloadReduce, 0)) }, - { label: "openmediavault.total", getNumber: (data) => (!data ? null : data?.length) }, + { label: "openmediavault.downloading", getNumber: (data) => data.reduce(downloadReduce, 0) }, + { label: "openmediavault.total", getNumber: (data) => data?.length }, ]; +// noinspection DuplicatedCode export default function Component({ service }) { const { data, error } = useWidgetAPI(service.widget); @@ -23,7 +26,7 @@ export default function Component({ service }) { const itemsWithData = items.map((item) => ({ ...item, - number: item.getNumber(data?.response?.data), + number: data?.response?.data ? item.getNumber(data?.response?.data) : null, })); return ( diff --git a/src/widgets/openmediavault/methods/services_get_status.jsx b/src/widgets/openmediavault/methods/services_get_status.jsx index 3ec66a45c73..b808f60e2d7 100644 --- a/src/widgets/openmediavault/methods/services_get_status.jsx +++ b/src/widgets/openmediavault/methods/services_get_status.jsx @@ -16,11 +16,12 @@ const notRunningReduce = (acc, e) => { }; const items = [ - { label: "openmediavault.running", getNumber: (data) => (!data ? null : data.reduce(isRunningReduce, 0)) }, - { label: "openmediavault.stopped", getNumber: (data) => (!data ? null : data.reduce(notRunningReduce, 0)) }, - { label: "openmediavault.total", getNumber: (data) => (!data ? null : data?.length) }, + { label: "openmediavault.running", getNumber: (data) => data.reduce(isRunningReduce, 0) }, + { label: "openmediavault.stopped", getNumber: (data) => data.reduce(notRunningReduce, 0) }, + { label: "openmediavault.total", getNumber: (data) => data?.length }, ]; +// noinspection DuplicatedCode export default function Component({ service }) { const { data, error } = useWidgetAPI(service.widget); @@ -30,7 +31,7 @@ export default function Component({ service }) { const itemsWithData = items.map((item) => ({ ...item, - number: item.getNumber(data?.response?.data), + number: data?.response?.data ? item.getNumber(data?.response?.data) : null, })); return ( diff --git a/src/widgets/openmediavault/methods/smart_get_list.jsx b/src/widgets/openmediavault/methods/smart_get_list.jsx index 55a76db6718..1a105a367e4 100644 --- a/src/widgets/openmediavault/methods/smart_get_list.jsx +++ b/src/widgets/openmediavault/methods/smart_get_list.jsx @@ -1,3 +1,5 @@ +// noinspection JSUnresolvedVariable + import useWidgetAPI from "utils/proxy/use-widget-api"; import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; @@ -16,8 +18,8 @@ const failedReduce = (acc, e) => { }; const items = [ - { label: "openmediavault.passed", getNumber: (data) => (!data ? null : data.reduce(passedReduce, 0)) }, - { label: "openmediavault.failed", getNumber: (data) => (!data ? null : data.reduce(failedReduce, 0)) }, + { label: "openmediavault.passed", getNumber: (data) => data.reduce(passedReduce, 0) }, + { label: "openmediavault.failed", getNumber: (data) => data.reduce(failedReduce, 0) }, ]; export default function Component({ service }) { @@ -29,7 +31,7 @@ export default function Component({ service }) { const itemsWithData = items.map((item) => ({ ...item, - number: item.getNumber(JSON.parse(data?.response?.output || "{}")?.data), + number: data?.response?.output ? item.getNumber(JSON.parse(data?.response?.output || "{}")?.data) : null, })); return ( diff --git a/src/widgets/openmediavault/proxy.js b/src/widgets/openmediavault/proxy.js index a9099d24468..06380b13c3b 100644 --- a/src/widgets/openmediavault/proxy.js +++ b/src/widgets/openmediavault/proxy.js @@ -1,3 +1,5 @@ +// noinspection JSUnresolvedVariable + import { formatApiCall } from "utils/proxy/api-helpers"; import { httpProxy } from "utils/proxy/http"; import getServiceWidget from "utils/config/service-helpers"; @@ -11,6 +13,7 @@ const BG_POLL_PERIOD = 500; const logger = createLogger(PROXY_NAME); +// noinspection DuplicatedCode async function getWidget(req) { const { group, service } = req.query;