Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenMediaVault widget: Part 2 #1817

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Comment on lines +1 to +2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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>
);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// noinspection JSUnresolvedVariable

Comment on lines +1 to +2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// noinspection JSUnresolvedVariable

import useWidgetAPI from "utils/proxy/use-widget-api";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// noinspection DuplicatedCode

export default function Component({ service }) {
const { data, error } = useWidgetAPI(service.widget);

Expand All @@ -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 (
Expand Down
9 changes: 5 additions & 4 deletions src/widgets/openmediavault/methods/services_get_status.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// noinspection DuplicatedCode

export default function Component({ service }) {
const { data, error } = useWidgetAPI(service.widget);

Expand All @@ -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 (
Expand Down
8 changes: 5 additions & 3 deletions src/widgets/openmediavault/methods/smart_get_list.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// noinspection JSUnresolvedVariable

Comment on lines +1 to +2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// noinspection JSUnresolvedVariable

import useWidgetAPI from "utils/proxy/use-widget-api";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
Expand All @@ -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 }) {
Expand All @@ -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 (
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/openmediavault/proxy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// noinspection JSUnresolvedVariable

Comment on lines +1 to +2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// noinspection JSUnresolvedVariable

import { formatApiCall } from "utils/proxy/api-helpers";
import { httpProxy } from "utils/proxy/http";
import getServiceWidget from "utils/config/service-helpers";
Expand All @@ -11,6 +13,7 @@ const BG_POLL_PERIOD = 500;

const logger = createLogger(PROXY_NAME);

// noinspection DuplicatedCode
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// noinspection DuplicatedCode

async function getWidget(req) {
const { group, service } = req.query;

Expand Down