import { EVENT_REFRESH } from "@goauthentik/common/constants"; import { getRelativeTime } from "@goauthentik/common/utils"; import "@goauthentik/components/ak-status-label"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/EmptyState"; import "@goauthentik/elements/events/LogViewer"; import { msg, str } from "@lit/localize"; import { CSSResult, TemplateResult, html, nothing } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import PFCard from "@patternfly/patternfly/components/Card/card.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import { SyncStatus, SystemTask, SystemTaskStatusEnum } from "@goauthentik/api"; @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, PFCard]; } firstUpdated() { this.loading = true; this.fetch().then((status) => { this.syncState = status; this.loading = false; }); } renderSyncTask(task: SystemTask): TemplateResult { return html`
  • ${(this.syncState?.tasks || []).length > 1 ? html`${task.name}` : nothing} ${msg( str`Finished ${getRelativeTime(task.finishTimestamp)} (${task.finishTimestamp.toLocaleString()})`, )}
  • `; } 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()}
    `; } }