2020-12-01 16:27:19 +00:00
|
|
|
import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
|
2020-11-30 22:49:33 +00:00
|
|
|
import { Application } from "../api/application";
|
2020-12-01 08:15:41 +00:00
|
|
|
import { PBResponse } from "../api/client";
|
2020-11-30 22:49:33 +00:00
|
|
|
import { COMMON_STYLES } from "../common/styles";
|
|
|
|
import { truncate } from "../utils";
|
2020-11-30 11:33:09 +00:00
|
|
|
|
|
|
|
@customElement("pb-library")
|
|
|
|
export class ApplicationViewPage extends LitElement {
|
|
|
|
@property()
|
|
|
|
apps?: PBResponse<Application>;
|
|
|
|
|
2020-12-01 16:27:19 +00:00
|
|
|
static get styles(): CSSResult[] {
|
2020-11-30 11:33:09 +00:00
|
|
|
return COMMON_STYLES.concat(
|
|
|
|
css`
|
|
|
|
img.pf-icon {
|
|
|
|
max-height: 24px;
|
|
|
|
}
|
2020-12-01 16:41:27 +00:00
|
|
|
.pf-c-avatar {
|
|
|
|
--pf-c-avatar--BorderRadius: 0;
|
|
|
|
}
|
2020-11-30 11:33:09 +00:00
|
|
|
`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-01 08:15:41 +00:00
|
|
|
firstUpdated(): void {
|
2020-11-30 11:33:09 +00:00
|
|
|
Application.list().then((r) => (this.apps = r));
|
|
|
|
}
|
|
|
|
|
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>
|
2020-12-01 08:15:41 +00:00
|
|
|
<h1 class="pf-c-title pf-m-lg">No Applications available.</h1>
|
2020-11-30 11:33:09 +00:00
|
|
|
<div class="pf-c-empty-state__body">
|
2020-12-01 08:15:41 +00:00
|
|
|
Either no applications are defined, or you don't have access to any.
|
2020-11-30 11:33:09 +00:00
|
|
|
</div>
|
|
|
|
{% if perms.passbook_core.add_application %}
|
|
|
|
<a
|
|
|
|
href="{% url 'passbook_admin:application-create' %}"
|
|
|
|
class="pf-c-button pf-m-primary"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
{% trans 'Create Application' %}
|
|
|
|
</a>
|
|
|
|
{% endif %}
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderApp(app: Application): TemplateResult {
|
|
|
|
return html` <a href="${app.launch_url}" class="pf-c-card pf-m-hoverable pf-m-compact">
|
|
|
|
<div class="pf-c-card__header">
|
|
|
|
${app.meta_icon
|
2020-12-01 08:15:41 +00:00
|
|
|
? html`<img
|
2020-11-30 11:33:09 +00:00
|
|
|
class="app-icon pf-c-avatar"
|
|
|
|
src="${app.meta_icon}"
|
|
|
|
alt="Application Icon"
|
|
|
|
/>`
|
2020-12-01 08:15:41 +00:00
|
|
|
: html`<i class="pf-icon pf-icon-arrow"></i>`}
|
2020-11-30 11:33:09 +00:00
|
|
|
</div>
|
|
|
|
<div class="pf-c-card__title">
|
|
|
|
<p id="card-1-check-label">${app.name}</p>
|
|
|
|
<div class="pf-c-content">
|
|
|
|
<small>${app.meta_publisher}</small>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="pf-c-card__body">${truncate(app.meta_description, 35)}</div>
|
|
|
|
</a>`;
|
|
|
|
}
|
|
|
|
|
2020-12-01 08:15:41 +00:00
|
|
|
renderLoading(): 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">
|
|
|
|
<div class="pf-l-bullseye">
|
|
|
|
<div class="pf-l-bullseye__item">
|
|
|
|
<span
|
|
|
|
class="pf-c-spinner pf-m-xl"
|
|
|
|
role="progressbar"
|
|
|
|
aria-valuetext="Loading..."
|
|
|
|
>
|
|
|
|
<span class="pf-c-spinner__clipper"></span>
|
|
|
|
<span class="pf-c-spinner__lead-ball"></span>
|
|
|
|
<span class="pf-c-spinner__tail-ball"></span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</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">
|
|
|
|
<section class="pf-c-page__main-section pf-m-light">
|
|
|
|
<div class="pf-c-content">
|
|
|
|
<h1>
|
|
|
|
<i class="pf-icon pf-icon-applications"></i>
|
|
|
|
Applications
|
|
|
|
</h1>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
${this.apps
|
2020-12-01 08:15:41 +00:00
|
|
|
? html`<section class="pf-c-page__main-section">
|
2020-11-30 11:33:09 +00:00
|
|
|
<div class="pf-l-gallery pf-m-gutter">
|
|
|
|
${this.apps.results.map((app) => this.renderApp(app))}
|
|
|
|
</div>
|
|
|
|
</section>`
|
2020-12-01 08:15:41 +00:00
|
|
|
: this.renderLoading()}
|
2020-11-30 11:33:09 +00:00
|
|
|
</main>`;
|
|
|
|
}
|
|
|
|
}
|