Skip to content

Commit

Permalink
enumerateUpgraded method
Browse files Browse the repository at this point in the history
  • Loading branch information
userXinos committed Aug 17, 2023
1 parent 0ec6393 commit 6bb80ea
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
5 changes: 4 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@
"running": "Running",
"stopped": "Stopped",
"passed": "Passed",
"failed": "Failed"
"failed": "Failed",
"yes": "Yes",
"no": "No",
"updatesAvailable": "updates available"
}
}
3 changes: 3 additions & 0 deletions src/widgets/openmediavault/component.jsx
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -10,6 +11,8 @@ export default function Component({ service }) {
return <SmartGetList service={service} />;
case "downloader.getDownloadList":
return <DownloaderGetDownloadList service={service} />;
case "apt.enumerateUpgraded":
return <AptEnumerateUpgraded service={service} />;
default:
return null;
}
Expand Down
37 changes: 37 additions & 0 deletions src/widgets/openmediavault/methods/apt_enumerateUpgraded.jsx
Original file line number Diff line number Diff line change
@@ -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 <Container service={service} error={error} />;
}

const itemsWithData = items.map((item) => ({
...item,
number: data?.response ? item.getValue(data.response, t) : null,
}));

return (
<Container service={service}>
{itemsWithData.map((e) => (
<Block key={e.label} label={e.label} value={e.number} />
))}
</Container>
);
}

0 comments on commit 6bb80ea

Please sign in to comment.