import { EVENT_REFRESH } from "@goauthentik/common/constants"; import { formatElapsedTime } from "@goauthentik/common/temporal"; import "@goauthentik/components/ak-status-label"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/EmptyState"; import "@goauthentik/elements/buttons/ActionButton"; import "@goauthentik/elements/events/LogViewer"; import { PaginatedResponse, Table, TableColumn } from "@goauthentik/elements/table/Table"; import { msg } from "@lit/localize"; import { CSSResult, TemplateResult, css, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import PFButton from "@patternfly/patternfly/components/Button/button.css"; import PFCard from "@patternfly/patternfly/components/Card/card.css"; import PFTable from "@patternfly/patternfly/components/Table/table.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import { SyncStatus, SystemTask, SystemTaskStatusEnum } from "@goauthentik/api"; @customElement("ak-sync-status-table") export class SyncStatusTable extends Table { @property({ attribute: false }) tasks: SystemTask[] = []; expandable = true; static get styles() { return super.styles.concat(css` code:not(:last-of-type)::after { content: "-"; margin: 0 0.25rem; } `); } async apiEndpoint(): Promise> { if (this.tasks.length === 1) { this.expandedElements = this.tasks; } return { pagination: { next: 0, previous: 0, count: this.tasks.length, current: 1, totalPages: 1, startIndex: 0, endIndex: this.tasks.length, }, results: this.tasks, }; } columns(): TableColumn[] { return [ new TableColumn(msg("Task")), new TableColumn(msg("Status")), new TableColumn(msg("Finished")), ]; } row(item: SystemTask): TemplateResult[] { const nameParts = item.fullName.split(":"); nameParts.shift(); return [ html`
${item.name}
${nameParts.map((part) => html`${part}`)}`, html``, html`
${formatElapsedTime(item.finishTimestamp)}
${item.finishTimestamp.toLocaleString()}`, ]; } renderExpanded(item: SystemTask): TemplateResult { return html`
`; } renderToolbarContainer() { return html``; } renderTablePagination() { return html``; } } @customElement("ak-sync-status-card") export class SyncStatusCard extends AKElement { @state() syncState?: SyncStatus; @state() loading = false; @property({ attribute: false }) fetch!: () => Promise; @property({ attribute: false }) triggerSync!: () => Promise; static get styles(): CSSResult[] { return [PFBase, PFButton, PFCard, PFTable]; } firstUpdated() { this.loading = true; this.fetch().then((status) => { this.syncState = status; this.loading = false; }); } renderSyncStatus(): TemplateResult { if (this.loading) { return html``; } if (!this.syncState) { return html`${msg("No sync status.")}`; } if (this.syncState.isRunning) { return html`${msg("Sync currently running.")}`; } if (this.syncState.tasks.length < 1) { return html`${msg("Not synced yet.")}`; } return html``; } render(): TemplateResult { return html`
${msg("Sync status")}
${this.renderSyncStatus()}
`; } } declare global { interface HTMLElementTagNameMap { "ak-sync-status-table": SyncStatusTable; "ak-sync-status-card": SyncStatusCard; } }