This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/web/src/pages/LibraryPage.ts

128 lines
4.5 KiB
TypeScript
Raw Normal View History

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 "../api";
2021-02-09 16:04:55 +00:00
import { AKResponse } from "../api/Client";
import { DEFAULT_CONFIG } from "../api/Config";
import { me } from "../api/Users";
2020-11-30 22:49:33 +00:00
import { COMMON_STYLES } from "../common/styles";
import { loading, truncate } from "../utils";
2020-12-05 21:08:42 +00:00
@customElement("ak-library-app")
export class LibraryApplication extends LitElement {
2020-12-02 14:44:40 +00:00
@property({attribute: false})
application?: Application;
static get styles(): CSSResult[] {
return COMMON_STYLES.concat(
css`
2020-12-05 21:08:42 +00:00
a {
height: 100%;
}
i.pf-icon {
height: 36px;
}
.pf-c-avatar {
--pf-c-avatar--BorderRadius: 0;
}
.pf-c-card__header {
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) {
2020-12-05 21:08:42 +00:00
return html`<ak-spinner></ak-spinner>`;
}
return html` <a href="${ifDefined(this.application.launchUrl)}" class="pf-c-card pf-m-hoverable pf-m-compact">
<div class="pf-c-card__header">
${this.application.metaIcon
? html`<img class="app-icon pf-c-avatar" src="${ifDefined(this.application.metaIcon)}" alt="Application Icon"/>`
: html`<i class="pf-icon pf-icon-arrow"></i>`}
${until(me().then((u) => {
if (!u.isSuperuser) return html``;
return html`
<a href="#/core/applications/${this.application?.slug}">
<i class="fas fa-pencil-alt"></i>
</a>
`;
}))}
</div>
<div class="pf-c-card__title">
<p id="card-1-check-label">${this.application.name}</p>
<div class="pf-c-content">
<small>${this.application.metaPublisher}</small>
</div>
</div>
<div class="pf-c-card__body">${truncate(this.application.metaDescription, 35)}</div>
</a>`;
}
}
2020-12-05 21:08:42 +00:00
@customElement("ak-library")
export class LibraryPage extends LitElement {
@property({attribute: false})
2021-02-09 16:04:55 +00:00
apps?: AKResponse<Application>;
static get styles(): CSSResult[] {
return COMMON_STYLES.concat(css`
:host,
main {
height: 100%;
}
`);
}
2020-12-01 08:15:41 +00:00
firstUpdated(): void {
new CoreApi(DEFAULT_CONFIG).coreApplicationsList({}).then((apps) => {
this.apps = apps;
});
}
2020-12-01 08:15:41 +00:00
renderEmptyState(): TemplateResult {
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>
<h1 class="pf-c-title pf-m-lg">${gettext("No Applications available.")}</h1>
<div class="pf-c-empty-state__body">
${gettext("Either no applications are defined, or you don't have access to any.")}
</div>
</div>
</div>`;
}
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>`)}
</div>`;
}
2020-12-01 08:15:41 +00:00
render(): TemplateResult {
return html`<main role="main" class="pf-c-page__main" tabindex="-1" id="main-content">
<section class="pf-c-page__main-section pf-m-light">
<div class="pf-c-content">
<h1>
<i class="pf-icon pf-icon-applications"></i>
${gettext("Applications")}
</h1>
</div>
</section>
<section class="pf-c-page__main-section">
${loading(this.apps, html`${(this.apps?.results.length || 0) > 0 ?
this.renderApps() :
this.renderEmptyState()}`)}
</section>
</main>`;
}
}