web/admin: improve UI for notification toggle
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
cbeb6e58ac
commit
ff64814f40
|
@ -27,6 +27,7 @@ class ChannelsStorage(BaseStorage):
|
||||||
uid,
|
uid,
|
||||||
{
|
{
|
||||||
"type": "event.update",
|
"type": "event.update",
|
||||||
|
"message_type": "message",
|
||||||
"level": message.level_tag,
|
"level": message.level_tag,
|
||||||
"tags": message.tags,
|
"tags": message.tags,
|
||||||
"message": message.message,
|
"message": message.message,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { MessageLevel } from "../elements/messages/Message";
|
||||||
import { showMessage } from "../elements/messages/MessageContainer";
|
import { showMessage } from "../elements/messages/MessageContainer";
|
||||||
|
|
||||||
export interface WSMessage {
|
export interface WSMessage {
|
||||||
type: string;
|
message_type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WebsocketClient {
|
export class WebsocketClient {
|
||||||
|
|
|
@ -4,8 +4,10 @@ import PFContent from "@patternfly/patternfly/components/Content/content.css";
|
||||||
import AKGlobal from "../authentik.css";
|
import AKGlobal from "../authentik.css";
|
||||||
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
||||||
import PFButton from "@patternfly/patternfly/components/Button/button.css";
|
import PFButton from "@patternfly/patternfly/components/Button/button.css";
|
||||||
import { EVENT_SIDEBAR_TOGGLE, TITLE_DEFAULT } from "../constants";
|
import { EVENT_NOTIFICATION_TOGGLE, EVENT_SIDEBAR_TOGGLE, TITLE_DEFAULT } from "../constants";
|
||||||
import { tenant } from "../api/Config";
|
import { DEFAULT_CONFIG, tenant } from "../api/Config";
|
||||||
|
import { until } from "lit-html/directives/until";
|
||||||
|
import { EventsApi } from "../../api/dist";
|
||||||
|
|
||||||
@customElement("ak-page-header")
|
@customElement("ak-page-header")
|
||||||
export class PageHeader extends LitElement {
|
export class PageHeader extends LitElement {
|
||||||
|
@ -44,12 +46,12 @@ export class PageHeader extends LitElement {
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
min-height: 114px;
|
min-height: 114px;
|
||||||
}
|
}
|
||||||
button.pf-c-button.pf-m-plain.sidebar-trigger {
|
.pf-c-button.pf-m-plain {
|
||||||
background-color: var(--pf-c-page__main-section--m-light--BackgroundColor);
|
background-color: var(--pf-c-page__main-section--m-light--BackgroundColor);
|
||||||
border-radius: 0px;
|
border-radius: 0px;
|
||||||
}
|
}
|
||||||
.pf-c-page__main-section {
|
.pf-c-page__main-section {
|
||||||
width: 100%;
|
flex-grow: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
@ -57,6 +59,13 @@ export class PageHeader extends LitElement {
|
||||||
img.pf-icon {
|
img.pf-icon {
|
||||||
max-height: 24px;
|
max-height: 24px;
|
||||||
}
|
}
|
||||||
|
.sidebar-trigger,
|
||||||
|
.notification-trigger {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
.notification-trigger.has-notifications {
|
||||||
|
color: #2B9AF3;
|
||||||
|
}
|
||||||
`];
|
`];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +101,26 @@ export class PageHeader extends LitElement {
|
||||||
${this.description ?
|
${this.description ?
|
||||||
html`<p>${this.description}</p>` : html``}
|
html`<p>${this.description}</p>` : html``}
|
||||||
</div>
|
</div>
|
||||||
</section>`;
|
</section>
|
||||||
|
${until(new EventsApi(DEFAULT_CONFIG).eventsNotificationsList({
|
||||||
|
seen: false,
|
||||||
|
ordering: "-created",
|
||||||
|
pageSize: 1,
|
||||||
|
}).then(r => {
|
||||||
|
return html`
|
||||||
|
<button
|
||||||
|
class="notification-trigger pf-c-button pf-m-plain ${r.pagination.count > 0 ? "has-notifications" : ""}"
|
||||||
|
@click=${() => {
|
||||||
|
this.dispatchEvent(
|
||||||
|
new CustomEvent(EVENT_NOTIFICATION_TOGGLE, {
|
||||||
|
bubbles: true,
|
||||||
|
composed: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}}>
|
||||||
|
<i class="fas fa-bell"></i>
|
||||||
|
</button>`;
|
||||||
|
}))}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ export class MessageContainer extends LitElement {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.addEventListener(EVENT_WS_MESSAGE, ((e: CustomEvent<WSMessage>) => {
|
this.addEventListener(EVENT_WS_MESSAGE, ((e: CustomEvent<WSMessage>) => {
|
||||||
if (e.detail.type !== WS_MSG_TYPE_MESSAGE) return;
|
if (e.detail.message_type !== WS_MSG_TYPE_MESSAGE) return;
|
||||||
this.addMessage(e.detail as unknown as APIMessage);
|
this.addMessage(e.detail as unknown as APIMessage);
|
||||||
}) as EventListener);
|
}) as EventListener);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,15 @@ export class NotificationDrawer extends LitElement {
|
||||||
static get styles(): CSSResult[] {
|
static get styles(): CSSResult[] {
|
||||||
return [PFBase, PFButton, PFNotificationDrawer, PFContent, PFDropdown, AKGlobal].concat(
|
return [PFBase, PFButton, PFNotificationDrawer, PFContent, PFDropdown, AKGlobal].concat(
|
||||||
css`
|
css`
|
||||||
|
.pf-c-notification-drawer__header {
|
||||||
|
height: 114px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.pf-c-notification-drawer__header-action,
|
||||||
|
.pf-c-notification-drawer__header-action-close,
|
||||||
|
.pf-c-notification-drawer__header-action-close > .pf-c-button.pf-m-plain {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
.pf-c-notification-drawer__list-item-description {
|
.pf-c-notification-drawer__list-item-description {
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
@ -95,12 +104,14 @@ export class NotificationDrawer extends LitElement {
|
||||||
return html`<div class="pf-c-drawer__body pf-m-no-padding">
|
return html`<div class="pf-c-drawer__body pf-m-no-padding">
|
||||||
<div class="pf-c-notification-drawer">
|
<div class="pf-c-notification-drawer">
|
||||||
<div class="pf-c-notification-drawer__header">
|
<div class="pf-c-notification-drawer__header">
|
||||||
<h1 class="pf-c-notification-drawer__header-title">
|
<div class="text">
|
||||||
${t`Notifications`}
|
<h1 class="pf-c-notification-drawer__header-title">
|
||||||
</h1>
|
${t`Notifications`}
|
||||||
<span class="pf-c-notification-drawer__header-status">
|
</h1>
|
||||||
${t`${this.unread} unread`}
|
<span>
|
||||||
</span>
|
${t`${this.unread} unread`}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
<div class="pf-c-notification-drawer__header-action">
|
<div class="pf-c-notification-drawer__header-action">
|
||||||
<div class="pf-c-notification-drawer__header-action-close">
|
<div class="pf-c-notification-drawer__header-action-close">
|
||||||
<button
|
<button
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
import { CSSResult, customElement, html, LitElement, TemplateResult } from "lit-element";
|
|
||||||
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
|
||||||
import PFDropdown from "@patternfly/patternfly/components/Dropdown/dropdown.css";
|
|
||||||
import FA from "@fortawesome/fontawesome-free/css/fontawesome.css";
|
|
||||||
import { EVENT_NOTIFICATION_TOGGLE } from "../../constants";
|
|
||||||
|
|
||||||
@customElement("ak-notification-trigger")
|
|
||||||
export class NotificationRule extends LitElement {
|
|
||||||
|
|
||||||
static get styles(): CSSResult[] {
|
|
||||||
return [PFBase, PFDropdown, FA];
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.addEventListener("click", () => {
|
|
||||||
this.dispatchEvent(
|
|
||||||
new CustomEvent(EVENT_NOTIFICATION_TOGGLE, {
|
|
||||||
bubbles: true,
|
|
||||||
composed: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render(): TemplateResult {
|
|
||||||
// TODO: Show icon with red dot when unread notifications exist
|
|
||||||
return html`<i class="fas fa-bell pf-c-dropdown__toggle-icon" aria-hidden="true"></i>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -5,7 +5,6 @@ import { me } from "../../api/Users";
|
||||||
import { until } from "lit-html/directives/until";
|
import { until } from "lit-html/directives/until";
|
||||||
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
||||||
|
|
||||||
import "../notifications/NotificationTrigger";
|
|
||||||
import { ifDefined } from "lit-html/directives/if-defined";
|
import { ifDefined } from "lit-html/directives/if-defined";
|
||||||
|
|
||||||
@customElement("ak-sidebar-user")
|
@customElement("ak-sidebar-user")
|
||||||
|
@ -39,8 +38,6 @@ export class SidebarUser extends LitElement {
|
||||||
return html`<img class="pf-c-avatar" src="${ifDefined(u.user.avatar)}" alt="" />`;
|
return html`<img class="pf-c-avatar" src="${ifDefined(u.user.avatar)}" alt="" />`;
|
||||||
}), html``)}
|
}), html``)}
|
||||||
</a>
|
</a>
|
||||||
<ak-notification-trigger class="pf-c-nav__link user-notifications">
|
|
||||||
</ak-notification-trigger>
|
|
||||||
<a href="/flows/-/default/invalidation/" class="pf-c-nav__link user-logout" id="logout">
|
<a href="/flows/-/default/invalidation/" class="pf-c-nav__link user-logout" id="logout">
|
||||||
<i class="fas fa-sign-out-alt" aria-hidden="true"></i>
|
<i class="fas fa-sign-out-alt" aria-hidden="true"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -735,7 +735,7 @@ msgstr "Connect"
|
||||||
msgid "Connected."
|
msgid "Connected."
|
||||||
msgstr "Connected."
|
msgstr "Connected."
|
||||||
|
|
||||||
#: src/elements/messages/MessageContainer.ts
|
#: src/common/ws.ts
|
||||||
msgid "Connection error, reconnecting..."
|
msgid "Connection error, reconnecting..."
|
||||||
msgstr "Connection error, reconnecting..."
|
msgstr "Connection error, reconnecting..."
|
||||||
|
|
||||||
|
|
|
@ -729,7 +729,7 @@ msgstr ""
|
||||||
msgid "Connected."
|
msgid "Connected."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/elements/messages/MessageContainer.ts
|
#: src/common/ws.ts
|
||||||
msgid "Connection error, reconnecting..."
|
msgid "Connection error, reconnecting..."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
Reference in New Issue