2021-04-10 18:19:23 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-08-15 19:32:28 +00:00
|
|
|
import { CoreApi, User } from "@goauthentik/api";
|
2021-04-10 18:19:23 +00:00
|
|
|
import { customElement, property } from "lit-element";
|
|
|
|
import { TemplateResult, html } from "lit-html";
|
|
|
|
import { AKResponse } from "../../api/Client";
|
|
|
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
|
|
|
import { PAGE_SIZE } from "../../constants";
|
|
|
|
import { TableColumn } from "../../elements/table/Table";
|
|
|
|
import { TableModal } from "../../elements/table/TableModal";
|
|
|
|
import "../../elements/buttons/SpinnerButton";
|
|
|
|
import { first } from "../../utils";
|
|
|
|
|
|
|
|
@customElement("ak-group-member-select-table")
|
|
|
|
export class MemberSelectTable extends TableModal<User> {
|
|
|
|
checkbox = true;
|
2021-08-05 08:15:31 +00:00
|
|
|
checkboxChip = true;
|
2021-04-10 18:19:23 +00:00
|
|
|
|
|
|
|
searchEnabled(): boolean {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@property()
|
|
|
|
confirm!: (selectedItems: User[]) => Promise<unknown>;
|
|
|
|
|
2021-04-17 17:36:55 +00:00
|
|
|
order = "username";
|
|
|
|
|
2021-04-10 18:19:23 +00:00
|
|
|
apiEndpoint(page: number): Promise<AKResponse<User>> {
|
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreUsersList({
|
|
|
|
ordering: this.order,
|
|
|
|
page: page,
|
2021-08-03 15:52:21 +00:00
|
|
|
pageSize: PAGE_SIZE / 2,
|
2021-04-10 18:19:23 +00:00
|
|
|
search: this.search || "",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
columns(): TableColumn[] {
|
|
|
|
return [
|
|
|
|
new TableColumn(t`Name`, "username"),
|
|
|
|
new TableColumn(t`Active`, "active"),
|
|
|
|
new TableColumn(t`Last login`, "last_login"),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
row(item: User): TemplateResult[] {
|
|
|
|
return [
|
2021-04-17 17:56:49 +00:00
|
|
|
html`<div>
|
2021-04-10 18:19:23 +00:00
|
|
|
<div>${item.username}</div>
|
|
|
|
<small>${item.name}</small>
|
2021-04-17 17:56:49 +00:00
|
|
|
</div>`,
|
2021-04-10 18:19:23 +00:00
|
|
|
html`${item.isActive ? t`Yes` : t`No`}`,
|
2021-09-19 14:08:30 +00:00
|
|
|
html`${first(item.lastLogin?.toLocaleString(), t`-`)}`,
|
2021-04-10 18:19:23 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
renderSelectedChip(item: User): TemplateResult {
|
|
|
|
return html`${item.username}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderModalInner(): TemplateResult {
|
|
|
|
return html`<section class="pf-c-page__main-section pf-m-light">
|
2021-08-03 15:52:21 +00:00
|
|
|
<div class="pf-c-content">
|
|
|
|
<h1 class="pf-c-title pf-m-2xl">${t`Select users to add`}</h1>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<section class="pf-c-page__main-section pf-m-light">${this.renderTable()}</section>
|
|
|
|
<footer class="pf-c-modal-box__footer">
|
|
|
|
<ak-spinner-button
|
|
|
|
.callAction=${() => {
|
|
|
|
return this.confirm(this.selectedElements).then(() => {
|
|
|
|
this.open = false;
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
class="pf-m-primary"
|
|
|
|
>
|
|
|
|
${t`Add`} </ak-spinner-button
|
|
|
|
>
|
|
|
|
<ak-spinner-button
|
|
|
|
.callAction=${async () => {
|
2021-04-10 18:19:23 +00:00
|
|
|
this.open = false;
|
2021-08-03 15:52:21 +00:00
|
|
|
}}
|
|
|
|
class="pf-m-secondary"
|
|
|
|
>
|
|
|
|
${t`Cancel`}
|
|
|
|
</ak-spinner-button>
|
|
|
|
</footer>`;
|
2021-04-10 18:19:23 +00:00
|
|
|
}
|
|
|
|
}
|