2021-12-24 19:04:21 +00:00
|
|
|
import { t } from "@lingui/macro";
|
|
|
|
|
2021-10-28 07:48:51 +00:00
|
|
|
import { CSSResult, LitElement, TemplateResult, css, html } from "lit";
|
2021-11-04 21:34:48 +00:00
|
|
|
import { customElement, property } from "lit/decorators.js";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-04-10 15:06:54 +00:00
|
|
|
import AKGlobal from "../authentik.css";
|
2021-04-10 15:30:23 +00:00
|
|
|
import PFButton from "@patternfly/patternfly/components/Button/button.css";
|
2021-09-21 09:31:37 +00:00
|
|
|
import PFContent from "@patternfly/patternfly/components/Content/content.css";
|
|
|
|
import PFPage from "@patternfly/patternfly/components/Page/page.css";
|
|
|
|
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
|
|
|
|
|
|
|
import { EventsApi } from "@goauthentik/api";
|
|
|
|
|
|
|
|
import { DEFAULT_CONFIG, tenant } from "../api/Config";
|
2021-12-24 19:04:21 +00:00
|
|
|
import { currentInterface } from "../api/Sentry";
|
2021-08-05 22:11:24 +00:00
|
|
|
import {
|
|
|
|
EVENT_API_DRAWER_TOGGLE,
|
|
|
|
EVENT_NOTIFICATION_DRAWER_TOGGLE,
|
2021-09-19 19:58:59 +00:00
|
|
|
EVENT_REFRESH,
|
2021-08-05 22:11:24 +00:00
|
|
|
EVENT_SIDEBAR_TOGGLE,
|
|
|
|
TITLE_DEFAULT,
|
|
|
|
} from "../constants";
|
2021-04-10 15:06:54 +00:00
|
|
|
|
|
|
|
@customElement("ak-page-header")
|
|
|
|
export class PageHeader extends LitElement {
|
|
|
|
@property()
|
|
|
|
icon?: string;
|
|
|
|
|
2021-08-03 15:52:21 +00:00
|
|
|
@property({ type: Boolean })
|
|
|
|
iconImage = false;
|
2021-04-10 15:06:54 +00:00
|
|
|
|
2021-08-03 15:52:21 +00:00
|
|
|
@property({ type: Boolean })
|
2021-07-23 18:57:06 +00:00
|
|
|
hasNotifications = false;
|
|
|
|
|
2021-04-10 15:06:54 +00:00
|
|
|
@property()
|
|
|
|
set header(value: string) {
|
2021-08-03 15:52:21 +00:00
|
|
|
tenant().then((tenant) => {
|
2021-12-24 19:04:21 +00:00
|
|
|
const currentIf = currentInterface();
|
|
|
|
let title = tenant.brandingTitle || TITLE_DEFAULT;
|
|
|
|
if (currentIf === "admin") {
|
|
|
|
title = `${t`Admin`} - ${title}`;
|
|
|
|
}
|
2021-04-22 21:49:30 +00:00
|
|
|
if (value !== "") {
|
2021-12-24 19:04:21 +00:00
|
|
|
title = `${value} - ${title}`;
|
2021-04-22 21:49:30 +00:00
|
|
|
}
|
2021-12-24 19:04:21 +00:00
|
|
|
document.title = title;
|
2021-04-22 21:49:30 +00:00
|
|
|
});
|
2021-04-10 15:06:54 +00:00
|
|
|
this._header = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
get header(): string {
|
|
|
|
return this._header;
|
|
|
|
}
|
|
|
|
|
|
|
|
@property()
|
|
|
|
description?: string;
|
|
|
|
|
|
|
|
_header = "";
|
|
|
|
|
|
|
|
static get styles(): CSSResult[] {
|
2021-08-03 15:52:21 +00:00
|
|
|
return [
|
|
|
|
PFBase,
|
|
|
|
PFButton,
|
|
|
|
PFPage,
|
|
|
|
PFContent,
|
|
|
|
AKGlobal,
|
|
|
|
css`
|
|
|
|
:host {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
min-height: 114px;
|
|
|
|
}
|
|
|
|
.pf-c-button.pf-m-plain {
|
|
|
|
background-color: var(--pf-c-page__main-section--m-light--BackgroundColor);
|
|
|
|
border-radius: 0px;
|
|
|
|
}
|
|
|
|
.pf-c-page__main-section {
|
|
|
|
flex-grow: 1;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
img.pf-icon {
|
|
|
|
max-height: 24px;
|
|
|
|
}
|
|
|
|
.sidebar-trigger,
|
|
|
|
.notification-trigger {
|
|
|
|
font-size: 24px;
|
|
|
|
}
|
|
|
|
.notification-trigger.has-notifications {
|
2021-12-16 09:17:17 +00:00
|
|
|
color: var(--pf-global--active-color--100);
|
2021-08-03 15:52:21 +00:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
];
|
2021-04-10 15:06:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-19 19:58:59 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
window.addEventListener(EVENT_REFRESH, () => {
|
|
|
|
this.firstUpdated();
|
|
|
|
});
|
2021-04-10 15:06:54 +00:00
|
|
|
}
|
|
|
|
|
2021-07-23 18:57:06 +00:00
|
|
|
firstUpdated(): void {
|
2021-08-03 15:52:21 +00:00
|
|
|
new EventsApi(DEFAULT_CONFIG)
|
|
|
|
.eventsNotificationsList({
|
|
|
|
seen: false,
|
|
|
|
ordering: "-created",
|
|
|
|
pageSize: 1,
|
|
|
|
})
|
|
|
|
.then((r) => {
|
|
|
|
this.hasNotifications = r.pagination.count > 0;
|
|
|
|
});
|
2021-07-23 18:57:06 +00:00
|
|
|
}
|
|
|
|
|
2021-09-19 19:58:59 +00:00
|
|
|
renderIcon(): TemplateResult {
|
|
|
|
if (this.icon) {
|
2021-12-13 14:27:28 +00:00
|
|
|
if (this.iconImage && !this.icon.startsWith("fa://")) {
|
2021-09-19 19:58:59 +00:00
|
|
|
return html`<img class="pf-icon" src="${this.icon}" /> `;
|
|
|
|
}
|
2021-12-13 14:27:28 +00:00
|
|
|
const icon = this.icon.replaceAll("fa://", "fa ");
|
|
|
|
return html`<i class=${icon}></i> `;
|
2021-09-19 19:58:59 +00:00
|
|
|
}
|
|
|
|
return html``;
|
|
|
|
}
|
|
|
|
|
2021-04-10 15:06:54 +00:00
|
|
|
render(): TemplateResult {
|
2021-04-10 15:30:23 +00:00
|
|
|
return html`<button
|
2021-08-03 15:52:21 +00:00
|
|
|
class="sidebar-trigger pf-c-button pf-m-plain"
|
|
|
|
@click=${() => {
|
|
|
|
this.dispatchEvent(
|
|
|
|
new CustomEvent(EVENT_SIDEBAR_TOGGLE, {
|
|
|
|
bubbles: true,
|
|
|
|
composed: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<i class="fas fa-bars"></i>
|
|
|
|
</button>
|
|
|
|
<section class="pf-c-page__main-section pf-m-light">
|
|
|
|
<div class="pf-c-content">
|
2021-12-14 14:23:20 +00:00
|
|
|
<h1>
|
|
|
|
${this.renderIcon()}
|
|
|
|
<slot name="header"> ${this.header} </slot>
|
|
|
|
</h1>
|
2021-08-03 15:52:21 +00:00
|
|
|
${this.description ? html`<p>${this.description}</p>` : html``}
|
|
|
|
</div>
|
|
|
|
</section>
|
2021-08-05 20:04:31 +00:00
|
|
|
<button
|
|
|
|
class="notification-trigger pf-c-button pf-m-plain"
|
|
|
|
@click=${() => {
|
|
|
|
this.dispatchEvent(
|
|
|
|
new CustomEvent(EVENT_API_DRAWER_TOGGLE, {
|
|
|
|
bubbles: true,
|
|
|
|
composed: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<i class="fas fa-code"></i>
|
|
|
|
</button>
|
2021-08-03 15:52:21 +00:00
|
|
|
<button
|
|
|
|
class="notification-trigger pf-c-button pf-m-plain ${this.hasNotifications
|
|
|
|
? "has-notifications"
|
|
|
|
: ""}"
|
|
|
|
@click=${() => {
|
|
|
|
this.dispatchEvent(
|
2021-08-05 20:04:31 +00:00
|
|
|
new CustomEvent(EVENT_NOTIFICATION_DRAWER_TOGGLE, {
|
2021-08-03 15:52:21 +00:00
|
|
|
bubbles: true,
|
|
|
|
composed: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<i class="fas fa-bell"></i>
|
2021-08-05 22:11:24 +00:00
|
|
|
</button> `;
|
2021-04-10 15:06:54 +00:00
|
|
|
}
|
|
|
|
}
|