import { AKResponse } from "@goauthentik/web/api/Client"; import { DEFAULT_CONFIG } from "@goauthentik/web/api/Config"; import { uiConfig } from "@goauthentik/web/common/config"; import { EVENT_REFRESH } from "@goauthentik/web/constants"; import { PFColor } from "@goauthentik/web/elements/Label"; import "@goauthentik/web/elements/buttons/ActionButton"; import "@goauthentik/web/elements/buttons/SpinnerButton"; import "@goauthentik/web/elements/forms/DeleteBulkForm"; import "@goauthentik/web/elements/forms/ModalForm"; import { TableColumn } from "@goauthentik/web/elements/table/Table"; import { TablePage } from "@goauthentik/web/elements/table/TablePage"; import "@goauthentik/web/pages/blueprints/BlueprintForm"; import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { BlueprintInstance, BlueprintInstanceStatusEnum, ManagedApi } from "@goauthentik/api"; export function BlueprintStatus(blueprint?: BlueprintInstance): string { if (!blueprint) return ""; switch (blueprint.status) { case BlueprintInstanceStatusEnum.Successful: return t`Successful`; case BlueprintInstanceStatusEnum.Orphaned: return t`Orphaned`; case BlueprintInstanceStatusEnum.Unknown: return t`Unknown`; case BlueprintInstanceStatusEnum.Warning: return t`Warning`; case BlueprintInstanceStatusEnum.Error: return t`Error`; } } @customElement("ak-blueprint-list") export class BlueprintListPage extends TablePage { searchEnabled(): boolean { return true; } pageTitle(): string { return t`Blueprints`; } pageDescription(): string { return t`Automate and template configuration within authentik.`; } pageIcon(): string { return "pf-icon pf-icon-blueprint"; } checkbox = true; @property() order = "name"; async apiEndpoint(page: number): Promise> { return new ManagedApi(DEFAULT_CONFIG).managedBlueprintsList({ ordering: this.order, page: page, pageSize: (await uiConfig()).pagination.perPage, search: this.search || "", }); } columns(): TableColumn[] { return [ new TableColumn(t`Name`, "name"), new TableColumn(t`Status`, "status"), new TableColumn(t`Last applied`, "last_applied"), new TableColumn(t`Enabled`, "enabled"), new TableColumn(t`Actions`), ]; } renderToolbarSelected(): TemplateResult { const disabled = this.selectedElements.length < 1; return html` { return [{ key: t`Name`, value: item.name }]; }} .usedBy=${(item: BlueprintInstance) => { return new ManagedApi(DEFAULT_CONFIG).managedBlueprintsUsedByList({ instanceUuid: item.pk, }); }} .delete=${(item: BlueprintInstance) => { return new ManagedApi(DEFAULT_CONFIG).managedBlueprintsDestroy({ instanceUuid: item.pk, }); }} > `; } row(item: BlueprintInstance): TemplateResult[] { return [ html`${item.name}`, html`${BlueprintStatus(item)}`, html`${item.lastApplied.toLocaleString()}`, html` ${item.enabled ? t`Yes` : t`No`} `, html` { return new ManagedApi(DEFAULT_CONFIG) .managedBlueprintsApplyCreate({ instanceUuid: item.pk, }) .then(() => { this.dispatchEvent( new CustomEvent(EVENT_REFRESH, { bubbles: true, composed: true, }), ); }); }} > ${t`Update`} ${t`Update Blueprint`} `, ]; } renderObjectCreate(): TemplateResult { return html` ${t`Create`} ${t`Create Blueprint Instance`} `; } }