import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; import { getRelativeTime } from "@goauthentik/common/utils"; import { PFColor } from "@goauthentik/elements/Label"; import "@goauthentik/elements/buttons/ActionButton"; import "@goauthentik/elements/buttons/SpinnerButton"; import "@goauthentik/elements/events/LogViewer"; import { PaginatedResponse } from "@goauthentik/elements/table/Table"; import { TableColumn } from "@goauthentik/elements/table/Table"; import { TablePage } from "@goauthentik/elements/table/TablePage"; import "@patternfly/elements/pf-tooltip/pf-tooltip.js"; import { msg, str } from "@lit/localize"; import { CSSResult, TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css"; import { EventsApi, SystemTask, SystemTaskStatusEnum } from "@goauthentik/api"; @customElement("ak-system-task-list") export class SystemTaskListPage extends TablePage { pageTitle(): string { return msg("System Tasks"); } pageDescription(): string { return msg("Long-running operations which authentik executes in the background."); } pageIcon(): string { return "pf-icon pf-icon-automation"; } expandable = true; searchEnabled(): boolean { return true; } @property() order = "name"; static get styles(): CSSResult[] { return super.styles.concat(PFDescriptionList); } async apiEndpoint(): Promise> { return new EventsApi(DEFAULT_CONFIG).eventsSystemTasksList( await this.defaultEndpointConfig(), ); } columns(): TableColumn[] { return [ new TableColumn(msg("Identifier"), "name"), new TableColumn(msg("Description")), new TableColumn(msg("Last run")), new TableColumn(msg("Status"), "status"), new TableColumn(msg("Actions")), ]; } taskStatus(task: SystemTask): TemplateResult { switch (task.status) { case SystemTaskStatusEnum.Successful: return html`${msg("Successful")}`; case SystemTaskStatusEnum.Warning: return html`${msg("Warning")}`; case SystemTaskStatusEnum.Error: return html`${msg("Error")}`; default: return html`${msg("Unknown")}`; } } renderExpanded(item: SystemTask): TemplateResult { return html`
${msg("Duration")}
${msg(str`${item.duration.toFixed(2)} seconds`)}
${msg("Expiry")}
${item.expiring ? html` ${getRelativeTime(item.expires || new Date())} ` : msg("-")}
${msg("Messages")}
`; } row(item: SystemTask): TemplateResult[] { return [ html`
${item.name}${item.uid ? `:${item.uid}` : ""}
`, html`${item.description}`, html`
${getRelativeTime(item.finishTimestamp)}
${item.finishTimestamp.toLocaleString()}`, this.taskStatus(item), html` { return new EventsApi(DEFAULT_CONFIG) .eventsSystemTasksRunCreate({ uuid: item.uuid, }) .then(() => { this.dispatchEvent( new CustomEvent(EVENT_REFRESH, { bubbles: true, composed: true, }), ); }); }} > `, ]; } } declare global { interface HTMLElementTagNameMap { "ak-system-task-list": SystemTaskListPage; } }