import { t } from "@lingui/macro"; import { CSSResult, LitElement, TemplateResult, css, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { until } from "lit/directives/until.js"; import AKGlobal from "../authentik.css"; import PFAvatar from "@patternfly/patternfly/components/Avatar/avatar.css"; import PFBrand from "@patternfly/patternfly/components/Brand/brand.css"; import PFButton from "@patternfly/patternfly/components/Button/button.css"; import PFDrawer from "@patternfly/patternfly/components/Drawer/drawer.css"; import PFDropdown from "@patternfly/patternfly/components/Dropdown/dropdown.css"; import PFNotificationBadge from "@patternfly/patternfly/components/NotificationBadge/notification-badge.css"; import PFPage from "@patternfly/patternfly/components/Page/page.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import PFDisplay from "@patternfly/patternfly/utilities/Display/display.css"; import { CurrentTenant, EventsApi } from "@goauthentik/api"; import { DEFAULT_CONFIG, tenant } from "../api/Config"; import { configureSentry } from "../api/Sentry"; import { me } from "../api/Users"; import { UserDisplay, uiConfig } from "../common/config"; import { WebsocketClient } from "../common/ws"; import { EVENT_API_DRAWER_TOGGLE, EVENT_NOTIFICATION_DRAWER_TOGGLE, EVENT_REFRESH, } from "../constants"; import "../elements/messages/MessageContainer"; import "../elements/messages/MessageContainer"; import "../elements/notifications/NotificationDrawer"; import { getURLParam, updateURLParams } from "../elements/router/RouteMatch"; import "../elements/router/RouterOutlet"; import "../elements/sidebar/Sidebar"; import { DefaultTenant } from "../elements/sidebar/SidebarBrand"; import "../elements/sidebar/SidebarItem"; import { ROUTES } from "../routesUser"; import { first } from "../utils"; import "./locale"; @customElement("ak-interface-user") export class UserInterface extends LitElement { @property({ type: Boolean }) notificationDrawerOpen = getURLParam("notificationDrawerOpen", false); @property({ type: Boolean }) apiDrawerOpen = getURLParam("apiDrawerOpen", false); ws: WebsocketClient; @property({ attribute: false }) tenant: CurrentTenant = DefaultTenant; @property({ type: Number }) notificationsCount = -1; static get styles(): CSSResult[] { return [ PFBase, PFDisplay, PFBrand, PFPage, PFAvatar, PFButton, PFDrawer, PFDropdown, PFNotificationBadge, AKGlobal, css` .pf-c-page__main, .pf-c-drawer__content, .pf-c-page__drawer { z-index: auto !important; background-color: transparent !important; } .pf-c-page { background-color: var(--pf-c-page--BackgroundColor) !important; } .display-none { display: none; } .pf-c-brand { min-height: 48px; height: 48px; } .has-notifications { color: #2b9af3; } `, ]; } constructor() { super(); this.ws = new WebsocketClient(); window.addEventListener(EVENT_NOTIFICATION_DRAWER_TOGGLE, () => { this.notificationDrawerOpen = !this.notificationDrawerOpen; updateURLParams({ notificationDrawerOpen: this.notificationDrawerOpen, }); }); window.addEventListener(EVENT_API_DRAWER_TOGGLE, () => { this.apiDrawerOpen = !this.apiDrawerOpen; updateURLParams({ apiDrawerOpen: this.apiDrawerOpen, }); }); window.addEventListener(EVENT_REFRESH, () => { this.firstUpdated(); }); tenant().then((tenant) => (this.tenant = tenant)); configureSentry(true); } firstUpdated(): void { new EventsApi(DEFAULT_CONFIG) .eventsNotificationsList({ seen: false, ordering: "-created", pageSize: 1, }) .then((r) => { this.notificationsCount = r.pagination.count; }); } render(): TemplateResult { return html`${until( uiConfig().then((config) => { return html`