import { CoreApi, Application, ProvidersApi, Provider, ApplicationPolicyEngineModeEnum } from "authentik-api"; import { t } from "@lingui/macro"; import { customElement, property } from "lit-element"; import { html, TemplateResult } from "lit-html"; import { DEFAULT_CONFIG } from "../../api/Config"; import { Form } from "../../elements/forms/Form"; import { until } from "lit-html/directives/until"; import { ifDefined } from "lit-html/directives/if-defined"; import "../../elements/forms/HorizontalFormElement"; import "../../elements/forms/FormGroup"; @customElement("ak-application-form") export class ApplicationForm extends Form { @property({ attribute: false }) application?: Application; @property({ attribute: false }) provider?: number; getSuccessMessage(): string { if (this.application) { return t`Successfully updated application.`; } else { return t`Successfully created application.`; } } send = (data: Application): Promise => { let writeOp: Promise; if (this.application) { writeOp = new CoreApi(DEFAULT_CONFIG).coreApplicationsUpdate({ slug: this.application.slug, data: data }); } else { writeOp = new CoreApi(DEFAULT_CONFIG).coreApplicationsCreate({ data: data }); } const icon = this.getFormFile(); if (icon) { return writeOp.then(app => { return new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIcon({ slug: app.slug, file: icon }); }); } return writeOp; }; groupProviders(providers: Provider[]): TemplateResult { const m = new Map(); providers.forEach(p => { if (!m.has(p.verboseName || "")) { m.set(p.verboseName || "", []); } const tProviders = m.get(p.verboseName || "") || []; tProviders.push(p); }); return html` ${Array.from(m).map(([group, providers]) => { return html` ${providers.map(p => { const selected = (this.application?.provider?.pk === p.pk) || (this.provider === p.pk); return html``; })} `; })} `; } renderForm(): TemplateResult { return html`

${t`Application's display Name.`}

${t`Internal application name, used in URLs.`}

${t`UI settings`}

${t`If left empty, authentik will try to extract the launch URL based on the selected provider.`}

`; } }