Use statistics endpoint for paperless-ngx

pull/556/head
Michael Shamoon 1 year ago
parent a677a507b8
commit a488cc0115

@ -118,7 +118,6 @@ export function cleanServiceGroups(groups) {
container,
currency, // coinmarketcap widget
symbols,
inboxTag, // paperlessngx widget
} = cleanedService.widget;
cleanedService.widget = {
@ -130,8 +129,6 @@ export function cleanServiceGroups(groups) {
if (currency) cleanedService.widget.currency = currency;
if (symbols) cleanedService.widget.symbols = symbols;
if (inboxTag) cleanedService.widget.inboxTag = inboxTag;
if (type === "docker") {
if (server) cleanedService.widget.server = server;

@ -5,26 +5,13 @@ import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { widget } = service;
const { data: inboxData, error: inboxError } = useWidgetAPI(widget, "inbox",
{
query: `tag:${widget.inboxTag}`,
format: "json",
fields: "count"
});
const { data: statisticsData, error: statisticsError } = useWidgetAPI(widget, "statistics");
const { data: documentData, error: documentError } = useWidgetAPI(widget, "documents",
{
fields: "count",
format: "json",
});
if (inboxError || documentError) {
const finalError = inboxError ?? documentError;
return <Container error={finalError} />;
if (statisticsError) {
return <Container error={statisticsError} />;
}
if (!inboxData || !documentData) {
if (!statisticsData) {
return (
<Container service={service}>
<Block label="paperlessngx.inbox" />
@ -35,8 +22,8 @@ export default function Component({ service }) {
return (
<Container service={service}>
<Block label="paperlessngx.inbox" value={inboxData.count} />
<Block label="paperlessngx.total" value={documentData.count} />
{statisticsData.documents_inbox !== undefined && <Block label="paperlessngx.inbox" value={statisticsData.documents_inbox} />}
<Block label="paperlessngx.total" value={statisticsData.documents_total} />
</Container>
);
}

@ -5,18 +5,10 @@ const widget = {
proxyHandler: genericProxyHandler,
mappings: {
"inbox": {
endpoint: "documents/",
params: ["format", "query", "fields"],
"statistics": {
endpoint: "statistics/?format=json",
validate: [
"count"
]
},
"documents": {
endpoint: "documents/",
params: ["format", "fields"],
validate: [
"count"
"documents_total"
]
},
},

Loading…
Cancel
Save