2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2020-12-01 16:27:19 +00:00
|
|
|
import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
|
2020-12-02 21:14:28 +00:00
|
|
|
import { ifDefined } from "lit-html/directives/if-defined";
|
2021-03-08 20:51:25 +00:00
|
|
|
import { until } from "lit-html/directives/until";
|
2021-03-16 20:32:39 +00:00
|
|
|
import { Application, CoreApi } from "authentik-api";
|
2021-02-09 16:04:55 +00:00
|
|
|
import { AKResponse } from "../api/Client";
|
2021-03-08 10:14:00 +00:00
|
|
|
import { DEFAULT_CONFIG } from "../api/Config";
|
2021-03-08 20:51:25 +00:00
|
|
|
import { me } from "../api/Users";
|
2020-12-02 21:14:28 +00:00
|
|
|
import { loading, truncate } from "../utils";
|
2021-04-10 15:06:54 +00:00
|
|
|
import "../elements/PageHeader";
|
2021-03-17 16:11:39 +00:00
|
|
|
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";
|
2021-03-17 17:00:17 +00:00
|
|
|
import PFGallery from "@patternfly/patternfly/layouts/Gallery/gallery.css";
|
2020-11-30 11:33:09 +00:00
|
|
|
|
2020-12-05 21:08:42 +00:00
|
|
|
@customElement("ak-library-app")
|
2020-12-02 21:14:28 +00:00
|
|
|
export class LibraryApplication extends LitElement {
|
2020-12-02 14:44:40 +00:00
|
|
|
@property({attribute: false})
|
2020-12-02 21:14:28 +00:00
|
|
|
application?: Application;
|
2020-11-30 11:33:09 +00:00
|
|
|
|
2020-12-01 16:27:19 +00:00
|
|
|
static get styles(): CSSResult[] {
|
2021-03-17 17:00:17 +00:00
|
|
|
return [PFBase, PFCard, PFAvatar, AKGlobal,
|
2020-11-30 11:33:09 +00:00
|
|
|
css`
|
2020-12-05 21:08:42 +00:00
|
|
|
a {
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
i.pf-icon {
|
|
|
|
height: 36px;
|
2021-03-17 17:00:17 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: center;
|
2020-11-30 11:33:09 +00:00
|
|
|
}
|
2020-12-01 16:41:27 +00:00
|
|
|
.pf-c-avatar {
|
|
|
|
--pf-c-avatar--BorderRadius: 0;
|
|
|
|
}
|
2021-03-08 20:51:25 +00:00
|
|
|
.pf-c-card__header {
|
2021-03-17 21:25:11 +00:00
|
|
|
min-height: 60px;
|
2021-03-08 20:51:25 +00:00
|
|
|
justify-content: space-between;
|
|
|
|
}
|
|
|
|
.pf-c-card__header a {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: center;
|
|
|
|
margin-right: 0.25em;
|
|
|
|
}
|
2020-11-30 11:33:09 +00:00
|
|
|
`
|
2021-03-17 16:11:39 +00:00
|
|
|
];
|
2020-11-30 11:33:09 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 21:14:28 +00:00
|
|
|
render(): TemplateResult {
|
|
|
|
if (!this.application) {
|
2020-12-05 21:08:42 +00:00
|
|
|
return html`<ak-spinner></ak-spinner>`;
|
2020-12-02 21:14:28 +00:00
|
|
|
}
|
2021-03-08 10:14:00 +00:00
|
|
|
return html` <a href="${ifDefined(this.application.launchUrl)}" class="pf-c-card pf-m-hoverable pf-m-compact">
|
2020-12-02 21:14:28 +00:00
|
|
|
<div class="pf-c-card__header">
|
2021-03-08 10:14:00 +00:00
|
|
|
${this.application.metaIcon
|
|
|
|
? html`<img class="app-icon pf-c-avatar" src="${ifDefined(this.application.metaIcon)}" alt="Application Icon"/>`
|
2021-03-17 18:51:52 +00:00
|
|
|
: html`<i class="fas fas fa-share-square"></i>`}
|
2021-03-08 20:51:25 +00:00
|
|
|
${until(me().then((u) => {
|
2021-03-22 12:44:17 +00:00
|
|
|
if (!u.user.isSuperuser) return html``;
|
2021-03-08 20:51:25 +00:00
|
|
|
return html`
|
|
|
|
<a href="#/core/applications/${this.application?.slug}">
|
|
|
|
<i class="fas fa-pencil-alt"></i>
|
|
|
|
</a>
|
|
|
|
`;
|
|
|
|
}))}
|
2020-12-02 21:14:28 +00:00
|
|
|
</div>
|
|
|
|
<div class="pf-c-card__title">
|
|
|
|
<p id="card-1-check-label">${this.application.name}</p>
|
|
|
|
<div class="pf-c-content">
|
2021-03-08 10:14:00 +00:00
|
|
|
<small>${this.application.metaPublisher}</small>
|
2020-12-02 21:14:28 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-08 10:14:00 +00:00
|
|
|
<div class="pf-c-card__body">${truncate(this.application.metaDescription, 35)}</div>
|
2020-12-02 21:14:28 +00:00
|
|
|
</a>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-12-05 21:08:42 +00:00
|
|
|
@customElement("ak-library")
|
2020-12-02 21:14:28 +00:00
|
|
|
export class LibraryPage extends LitElement {
|
|
|
|
@property({attribute: false})
|
2021-02-09 16:04:55 +00:00
|
|
|
apps?: AKResponse<Application>;
|
2020-12-02 21:14:28 +00:00
|
|
|
|
2021-03-18 13:47:13 +00:00
|
|
|
pageTitle(): string {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Applications`;
|
2021-03-18 13:47:13 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 21:14:28 +00:00
|
|
|
static get styles(): CSSResult[] {
|
2021-03-17 17:00:17 +00:00
|
|
|
return [PFBase, PFEmptyState, PFTitle, PFPage, PFContent, PFGallery, AKGlobal].concat(css`
|
2021-02-24 08:21:16 +00:00
|
|
|
:host,
|
|
|
|
main {
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
`);
|
2020-12-02 21:14:28 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 08:15:41 +00:00
|
|
|
firstUpdated(): void {
|
2021-03-08 10:14:00 +00:00
|
|
|
new CoreApi(DEFAULT_CONFIG).coreApplicationsList({}).then((apps) => {
|
|
|
|
this.apps = apps;
|
|
|
|
});
|
2020-11-30 11:33:09 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 08:15:41 +00:00
|
|
|
renderEmptyState(): TemplateResult {
|
2020-11-30 11:33:09 +00:00
|
|
|
return html` <div class="pf-c-empty-state pf-m-full-height">
|
|
|
|
<div class="pf-c-empty-state__content">
|
|
|
|
<i class="fas fa-cubes pf-c-empty-state__icon" aria-hidden="true"></i>
|
2021-04-03 17:26:43 +00:00
|
|
|
<h1 class="pf-c-title pf-m-lg">${t`No Applications available.`}</h1>
|
2020-11-30 11:33:09 +00:00
|
|
|
<div class="pf-c-empty-state__body">
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Either no applications are defined, or you don't have access to any.`}
|
2020-11-30 11:33:09 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
|
2020-12-02 21:14:28 +00:00
|
|
|
renderApps(): TemplateResult {
|
|
|
|
return html`<div class="pf-l-gallery pf-m-gutter">
|
2020-12-05 21:08:42 +00:00
|
|
|
${this.apps?.results.map((app) => html`<ak-library-app .application=${app}></ak-library-app>`)}
|
2020-11-30 11:33:09 +00:00
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
|
2020-12-01 08:15:41 +00:00
|
|
|
render(): TemplateResult {
|
2020-11-30 11:33:09 +00:00
|
|
|
return html`<main role="main" class="pf-c-page__main" tabindex="-1" id="main-content">
|
2021-04-10 15:06:54 +00:00
|
|
|
<ak-page-header
|
|
|
|
icon="pf-icon pf-icon-applications"
|
|
|
|
header=${t`Applications`}>
|
|
|
|
</ak-page-header>
|
2020-12-02 21:14:28 +00:00
|
|
|
<section class="pf-c-page__main-section">
|
|
|
|
${loading(this.apps, html`${(this.apps?.results.length || 0) > 0 ?
|
2021-01-16 22:04:08 +00:00
|
|
|
this.renderApps() :
|
|
|
|
this.renderEmptyState()}`)}
|
2020-12-02 21:14:28 +00:00
|
|
|
</section>
|
2020-11-30 11:33:09 +00:00
|
|
|
</main>`;
|
|
|
|
}
|
|
|
|
}
|