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/admin-overview/TopApplicationsTable.ts

60 lines
2 KiB
TypeScript
Raw Normal View History

import { t } from "@lingui/macro";
2020-12-01 21:17:07 +00:00
import { CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
import { EventsApi, EventTopPerUser } from "authentik-api";
import PFTable from "@patternfly/patternfly/components/Table/table.css";
import AKGlobal from "../../authentik.css";
2020-12-01 21:17:07 +00:00
2020-12-02 14:44:40 +00:00
import "../../elements/Spinner";
import { DEFAULT_CONFIG } from "../../api/Config";
2020-12-02 14:44:40 +00:00
2020-12-05 21:08:42 +00:00
@customElement("ak-top-applications-table")
2020-12-01 21:17:07 +00:00
export class TopApplicationsTable extends LitElement {
@property({ attribute: false })
topN?: EventTopPerUser[];
2020-12-01 21:17:07 +00:00
static get styles(): CSSResult[] {
return [PFTable, AKGlobal];
2020-12-01 21:17:07 +00:00
}
firstUpdated(): void {
new EventsApi(DEFAULT_CONFIG)
.eventsEventsTopPerUserList({
action: "authorize_application",
topN: 11,
})
.then((events) => {
this.topN = events;
});
2020-12-01 21:17:07 +00:00
}
renderRow(event: EventTopPerUser): TemplateResult {
2020-12-01 21:17:07 +00:00
return html`<tr role="row">
<td role="cell">${event.application.name}</td>
<td role="cell">${event.countedEvents}</td>
2020-12-01 21:17:07 +00:00
<td role="cell">
<progress
value="${event.countedEvents}"
max="${this.topN ? this.topN[0].countedEvents : 0}"
></progress>
2020-12-01 21:17:07 +00:00
</td>
</tr>`;
}
render(): TemplateResult {
return html`<table class="pf-c-table pf-m-compact" role="grid">
<thead>
<tr role="row">
<th role="columnheader" scope="col">${t`Application`}</th>
<th role="columnheader" scope="col">${t`Logins`}</th>
<th role="columnheader" scope="col"></th>
</tr>
</thead>
<tbody role="rowgroup">
${this.topN
? this.topN.map((e) => this.renderRow(e))
: html`<ak-spinner></ak-spinner>`}
</tbody>
</table>`;
2020-12-01 21:17:07 +00:00
}
}