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/sources/SourcesListPage.ts

136 lines
5 KiB
TypeScript
Raw Normal View History

2021-02-09 09:22:49 +00:00
import { gettext } from "django";
2021-02-09 16:04:55 +00:00
import { customElement, html, property, TemplateResult } from "lit-element";
import { AKResponse } from "../../api/Client";
2021-02-09 09:22:49 +00:00
import { TableColumn } from "../../elements/table/Table";
import { TablePage } from "../../elements/table/TablePage";
2021-02-09 16:04:55 +00:00
import "../../elements/buttons/SpinnerButton";
2021-02-10 19:12:15 +00:00
import "../../elements/buttons/Dropdown";
import "../../elements/forms/DeleteForm";
import "../../elements/forms/ModalForm";
import "../../elements/forms/ProxyForm";
2021-02-10 19:12:15 +00:00
import { until } from "lit-html/directives/until";
2021-03-02 14:12:26 +00:00
import { PAGE_SIZE } from "../../constants";
import { Source, SourcesApi } from "authentik-api";
import { DEFAULT_CONFIG } from "../../api/Config";
import { ifDefined } from "lit-html/directives/if-defined";
import "./ldap/LDAPSourceForm";
import "./saml/SAMLSourceForm";
2021-02-09 16:04:55 +00:00
2021-02-09 09:22:49 +00:00
@customElement("ak-source-list")
export class SourceListPage extends TablePage<Source> {
pageTitle(): string {
return "Sources";
}
pageDescription(): string | undefined {
return "External Sources which can be used to get Identities into authentik, for example Social Providers like Twiter and GitHub or Enterprise Providers like ADFS and LDAP.";
}
pageIcon(): string {
return "pf-icon pf-icon-middleware";
}
searchEnabled(): boolean {
return true;
}
@property()
order = "name";
2021-02-09 16:04:55 +00:00
apiEndpoint(page: number): Promise<AKResponse<Source>> {
return new SourcesApi(DEFAULT_CONFIG).sourcesAllList({
2021-02-09 09:22:49 +00:00
ordering: this.order,
page: page,
pageSize: PAGE_SIZE,
2021-02-09 09:22:49 +00:00
search: this.search || "",
});
}
columns(): TableColumn[] {
return [
new TableColumn("Name", "name"),
new TableColumn("Type", "verboseName"),
2021-02-09 09:22:49 +00:00
new TableColumn(""),
];
}
row(item: Source): TemplateResult[] {
return [
2021-02-19 18:29:17 +00:00
html`<a href="#/core/sources/${item.slug}">
2021-02-09 09:22:49 +00:00
<div>${item.name}</div>
${item.enabled ? html`` : html`<small>${gettext("Disabled")}</small>`}
</a>`,
html`${item.verboseName}`,
2021-02-09 09:22:49 +00:00
html`
<ak-forms-modal>
<span slot="submit">
${gettext("Update")}
</span>
<span slot="header">
${gettext(`Update ${item.verboseName}`)}
</span>
<ak-proxy-form
slot="form"
.args=${{
"sourceSlug": item.slug
}}
type=${ifDefined(item.objectType)}
.typeMap=${{
"ldap": "ak-source-ldap-form",
"saml": "ak-source-saml-form",
}}>
</ak-proxy-form>
<button slot="trigger" class="pf-c-button pf-m-secondary">
2021-02-10 19:12:15 +00:00
${gettext("Edit")}
</button>
</ak-forms-modal>
<ak-forms-delete
.obj=${item}
objectLabel=${gettext("Source")}
.delete=${() => {
return new SourcesApi(DEFAULT_CONFIG).sourcesAllDelete({
slug: item.slug || ""
});
}}>
<button slot="trigger" class="pf-c-button pf-m-danger">
2021-02-10 19:12:15 +00:00
${gettext("Delete")}
</button>
</ak-forms-delete>`,
2021-02-09 09:22:49 +00:00
];
}
2021-02-10 19:12:15 +00:00
renderToolbar(): TemplateResult {
return html`
<ak-dropdown class="pf-c-dropdown">
<button class="pf-m-primary pf-c-dropdown__toggle" type="button">
<span class="pf-c-dropdown__toggle-text">${gettext("Create")}</span>
<i class="fas fa-caret-down pf-c-dropdown__toggle-icon" aria-hidden="true"></i>
</button>
<ul class="pf-c-dropdown__menu" hidden>
${until(new SourcesApi(DEFAULT_CONFIG).sourcesAllTypes().then((types) => {
2021-02-10 19:12:15 +00:00
return types.map((type) => {
return html`<li>
<ak-forms-modal>
<span slot="submit">
${gettext("Create")}
</span>
<span slot="header">
${gettext(`Create ${type.name}`)}
</span>
<ak-proxy-form
slot="form"
type=${type.link}>
</ak-proxy-form>
<button slot="trigger" class="pf-c-dropdown__menu-item">
${type.name}<br>
2021-02-10 19:12:15 +00:00
<small>${type.description}</small>
</button>
</ak-forms-modal>
2021-02-10 19:12:15 +00:00
</li>`;
});
}), html`<ak-spinner></ak-spinner>`)}
</ul>
</ak-dropdown>
${super.renderToolbar()}`;
}
2021-02-09 09:22:49 +00:00
}