import { PFSize } from "@goauthentik/common/enums.js"; import { globalAK } from "@goauthentik/common/global"; import { rootInterface } from "@goauthentik/common/theme"; import { truncateWords } from "@goauthentik/common/utils"; import "@goauthentik/elements/AppIcon"; import { AKElement } from "@goauthentik/elements/Base"; import "@goauthentik/elements/Expand"; import "@goauthentik/user/LibraryApplication/RACLaunchEndpointModal"; import type { RACLaunchEndpointModal } from "@goauthentik/user/LibraryApplication/RACLaunchEndpointModal"; import type { UserInterface } from "@goauthentik/user/index.entrypoint.js"; import { msg } from "@lit/localize"; import { CSSResult, TemplateResult, css, html, nothing } from "lit"; import { customElement, property, query } from "lit/decorators.js"; import { classMap } from "lit/directives/class-map.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { styleMap } from "lit/directives/style-map.js"; import PFButton from "@patternfly/patternfly/components/Button/button.css"; import PFCard from "@patternfly/patternfly/components/Card/card.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import { Application } from "@goauthentik/api"; @customElement("ak-library-app") export class LibraryApplication extends AKElement { @property({ attribute: false }) application?: Application; @property({ type: Boolean }) selected = false; @property() background = ""; @query("ak-library-rac-endpoint-launch") racEndpointLaunch?: RACLaunchEndpointModal; static get styles(): CSSResult[] { return [ PFBase, PFCard, PFButton, css` .pf-c-card { --pf-c-card--BoxShadow: var(--pf-global--BoxShadow--md); } .pf-c-card__header { justify-content: space-between; flex-direction: column; } .pf-c-card__header a { display: flex; flex-direction: column; justify-content: center; } a:hover { text-decoration: none; } .expander { flex-grow: 1; } .pf-c-card__title { text-align: center; /* This is not ideal as it hard limits us to 2 lines of text for the title of the application. In theory that should be fine for most cases, but ideally we don't do this */ height: 48px; } `, ]; } renderExpansion(application: Application) { const { me, uiConfig } = rootInterface(); return html`
${application.metaPublisher}
${truncateWords(application.metaDescription || "", 10)} ${uiConfig?.enabledFeatures.applicationEdit && me?.user.isSuperuser ? html`  ${msg("Edit")} ` : html``}
`; } renderLaunch(): TemplateResult { if (!this.application) { return html``; } if (this.application?.launchUrl === "goauthentik.io://providers/rac/launch") { return html`
{ this.racEndpointLaunch?.onClick(); }} >
{ this.racEndpointLaunch?.onClick(); }} > ${this.application.name}
`; } return html`
${this.application.name}
`; } render(): TemplateResult { if (!this.application) { return html``; } const { me, uiConfig } = rootInterface(); const expandable = (uiConfig?.enabledFeatures.applicationEdit && me?.user.isSuperuser) || this.application.metaPublisher !== "" || this.application.metaDescription !== ""; const classes = { "pf-m-selectable": this.selected, "pf-m-selected": this.selected }; const styles = this.background ? { background: this.background } : {}; return html`
${this.renderLaunch()}
${expandable ? this.renderExpansion(this.application) : nothing}
`; } } declare global { interface HTMLElementTagNameMap { "ak-library-app": LibraryApplication; } }