From 885a2f0a583241763c28680636857289ed4a1c15 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 16 Dec 2020 22:25:44 +0100 Subject: [PATCH] web: add flow and policy cache card --- .../templates/administration/overview.html | 50 -------------- web/src/api/flow.ts | 6 ++ web/src/api/policy.ts | 14 ++-- web/src/elements/cards/AggregateCard.ts | 10 ++- .../pages/admin-overview/AdminOverviewPage.ts | 25 ++++--- web/src/pages/admin-overview/OverviewCards.ts | 67 ++++++++++++++++++- 6 files changed, 103 insertions(+), 69 deletions(-) diff --git a/authentik/admin/templates/administration/overview.html b/authentik/admin/templates/administration/overview.html index a386bb2d2..421619c2b 100644 --- a/authentik/admin/templates/administration/overview.html +++ b/authentik/admin/templates/administration/overview.html @@ -11,57 +11,7 @@
{% endblock %} diff --git a/web/src/api/flow.ts b/web/src/api/flow.ts index f9c009675..2a376fc07 100644 --- a/web/src/api/flow.ts +++ b/web/src/api/flow.ts @@ -33,6 +33,12 @@ export class Flow { static list(filter?: QueryArguments): Promise> { return DefaultClient.fetch>(["flows", "instances"], filter); } + + static cached(): Promise { + return DefaultClient.fetch>(["flows", "cached"]).then(r => { + return r.pagination.count; + }); + } } export class Stage { diff --git a/web/src/api/policy.ts b/web/src/api/policy.ts index 3344e361d..16c7f7215 100644 --- a/web/src/api/policy.ts +++ b/web/src/api/policy.ts @@ -8,12 +8,18 @@ export class Policy { throw Error(); } - static get(pk: string): Promise { - return DefaultClient.fetch(["policies", "all", pk]); + static get(pk: string): Promise { + return DefaultClient.fetch(["policies", "all", pk]); } - static list(filter?: QueryArguments): Promise> { - return DefaultClient.fetch>(["policies", "all"], filter); + static list(filter?: QueryArguments): Promise> { + return DefaultClient.fetch>(["policies", "all"], filter); + } + + static cached(): Promise { + return DefaultClient.fetch>(["policies", "cached"]).then(r => { + return r.pagination.count; + }); } } diff --git a/web/src/elements/cards/AggregateCard.ts b/web/src/elements/cards/AggregateCard.ts index 8fb70c70f..101114df0 100644 --- a/web/src/elements/cards/AggregateCard.ts +++ b/web/src/elements/cards/AggregateCard.ts @@ -31,15 +31,19 @@ export class AggregateCard extends LitElement { return html``; } + renderHeaderLink(): TemplateResult { + return html`${this.headerLink ? html` + + ` : ""}`; + } + render(): TemplateResult { return html`
${this.header ? gettext(this.header) : ""}
- ${this.headerLink ? html` - - ` : ""} + ${this.renderHeaderLink()}
${this.renderInner()} diff --git a/web/src/pages/admin-overview/AdminOverviewPage.ts b/web/src/pages/admin-overview/AdminOverviewPage.ts index c4bd1ce08..8ea91f457 100644 --- a/web/src/pages/admin-overview/AdminOverviewPage.ts +++ b/web/src/pages/admin-overview/AdminOverviewPage.ts @@ -41,6 +41,17 @@ export class AdminOverviewPage extends LitElement { + + + + + + + ${this.data ? this.data?.worker_count < 1 ? @@ -53,16 +64,10 @@ export class AdminOverviewPage extends LitElement {

` : html``}
- - - - - - + + + +
`; } diff --git a/web/src/pages/admin-overview/OverviewCards.ts b/web/src/pages/admin-overview/OverviewCards.ts index 90b92d892..c35bd98c6 100644 --- a/web/src/pages/admin-overview/OverviewCards.ts +++ b/web/src/pages/admin-overview/OverviewCards.ts @@ -2,6 +2,7 @@ import { gettext } from "django"; import { customElement, property } from "lit-element"; import { html, TemplateResult } from "lit-html"; import { until } from "lit-html/directives/until"; +import { Flow } from "../../api/flow"; import { Policy } from "../../api/policy"; import { Provider } from "../../api/provider"; import { AggregateCard } from "../../elements/cards/AggregateCard"; @@ -62,8 +63,8 @@ export class ProviderStatusCard extends AdminStatusCard { } -@customElement("ak-admin-status-card-policy") -export class PolicyStatusCard extends AdminStatusCard { +@customElement("ak-admin-status-card-policy-unbound") +export class PolicyUnboundStatusCard extends AdminStatusCard { getPrimaryCounter(): Promise { return Policy.list({ @@ -88,3 +89,65 @@ export class PolicyStatusCard extends AdminStatusCard { } } + +@customElement("ak-admin-status-card-policy-cache") +export class PolicyCacheStatusCard extends AdminStatusCard { + + getPrimaryCounter(): Promise { + return Policy.cached(); + } + + getStatus(counter: number): Promise { + if (counter < 1) { + return Promise.resolve({ + icon: "fa fa-exclamation-triangle", + message: gettext("No policies cached. Users may experience slow response times."), + }); + } else { + return Promise.resolve({ + icon: "fa fa-check-circle" + }); + } + } + + renderHeaderLink(): TemplateResult { + return html` + + + +
+
`; + } + +} + +@customElement("ak-admin-status-card-flow-cache") +export class FlowCacheStatusCard extends AdminStatusCard { + + getPrimaryCounter(): Promise { + return Flow.cached(); + } + + getStatus(counter: number): Promise { + if (counter < 1) { + return Promise.resolve({ + icon: "fa fa-exclamation-triangle", + message: gettext("No flows cached."), + }); + } else { + return Promise.resolve({ + icon: "fa fa-check-circle" + }); + } + } + + renderHeaderLink(): TemplateResult { + return html` + + + +
+
`; + } + +}