import { gettext } from "django"; import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element"; import { ifDefined } from "lit-html/directives/if-defined"; import { until } from "lit-html/directives/until"; import { Application, CoreApi } from "authentik-api"; import { AKResponse } from "../api/Client"; import { DEFAULT_CONFIG } from "../api/Config"; import { me } from "../api/Users"; import { loading, truncate } from "../utils"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import PFCard from "@patternfly/patternfly/components/Card/card.css"; import PFTitle from "@patternfly/patternfly/components/Title/title.css"; import PFEmptyState from "@patternfly/patternfly/components/EmptyState/empty-state.css"; import PFPage from "@patternfly/patternfly/components/Page/page.css"; import PFContent from "@patternfly/patternfly/components/Content/content.css"; import AKGlobal from "../authentik.css"; import PFAvatar from "@patternfly/patternfly/components/Avatar/avatar.css"; import PFGallery from "@patternfly/patternfly/layouts/Gallery/gallery.css"; @customElement("ak-library-app") export class LibraryApplication extends LitElement { @property({attribute: false}) application?: Application; static get styles(): CSSResult[] { return [PFBase, PFCard, PFAvatar, AKGlobal, css` a { height: 100%; } i.pf-icon { height: 36px; display: flex; flex-direction: column; justify-content: center; } .pf-c-avatar { --pf-c-avatar--BorderRadius: 0; } .pf-c-card__header { min-height: 60px; justify-content: space-between; } .pf-c-card__header a { display: flex; flex-direction: column; justify-content: center; margin-right: 0.25em; } ` ]; } render(): TemplateResult { if (!this.application) { return html``; } return html` ${this.application.metaIcon ? html`` : html``} ${until(me().then((u) => { if (!u.user.isSuperuser) return html``; return html` `; }))} ${this.application.name} ${this.application.metaPublisher} ${truncate(this.application.metaDescription, 35)} `; } } @customElement("ak-library") export class LibraryPage extends LitElement { @property({attribute: false}) apps?: AKResponse; pageTitle(): string { return gettext("Applications"); } static get styles(): CSSResult[] { return [PFBase, PFEmptyState, PFTitle, PFPage, PFContent, PFGallery, AKGlobal].concat(css` :host, main { height: 100%; } `); } firstUpdated(): void { new CoreApi(DEFAULT_CONFIG).coreApplicationsList({}).then((apps) => { this.apps = apps; }); } renderEmptyState(): TemplateResult { return html` ${gettext("No Applications available.")} ${gettext("Either no applications are defined, or you don't have access to any.")} `; } renderApps(): TemplateResult { return html` ${this.apps?.results.map((app) => html``)} `; } render(): TemplateResult { return html` ${gettext("Applications")} ${loading(this.apps, html`${(this.apps?.results.length || 0) > 0 ? this.renderApps() : this.renderEmptyState()}`)} `; } }
${this.application.name}