import { gettext } from "django"; import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element"; import { EventsApi, Notification } from "authentik-api"; import { AKResponse } from "../../api/Client"; import { DEFAULT_CONFIG } from "../../api/Config"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import PFNotificationDrawer from "@patternfly/patternfly/components/NotificationDrawer/notification-drawer.css"; import PFDropdown from "@patternfly/patternfly/components/Dropdown/dropdown.css"; @customElement("ak-notification-drawer") export class NotificationDrawer extends LitElement { @property({attribute: false}) notifications?: AKResponse; @property({type: Number}) unread = 0; static get styles(): CSSResult[] { return [PFBase, PFNotificationDrawer, PFDropdown].concat( css` .pf-c-notification-drawer__header { height: 114px; padding: var(--pf-c-page__main-section--PaddingTop) var(--pf-c-page__main-section--PaddingRight) var(--pf-c-page__main-section--PaddingBottom) var(--pf-c-page__main-section--PaddingLeft); display: flex; flex-direction: column; } .pf-c-notification-drawer__list-item-description { white-space: pre-wrap; } ` ); } firstUpdated(): void { new EventsApi(DEFAULT_CONFIG).eventsNotificationsList({ seen: "false", ordering: "-created", }).then(r => { this.notifications = r; this.unread = r.results.length; }); } renderItem(item: Notification): TemplateResult { let level = ""; switch (item.severity) { case "notice": level = "pf-m-info"; break; case "warning": level = "pf-m-warning"; break; case "alert": level = "pf-m-danger"; break; default: break; } return html`
  • ${item.event?.action}

    ${item.body}

    ${item.created?.toLocaleString()}
  • `; } render(): TemplateResult { if (!this.notifications) { return html``; } return html`

    ${gettext("Notifications")}

    ${gettext(`${this.unread} unread`)}

      ${this.notifications.results.map(n => this.renderItem(n))}
    `; } }