web: migrate System Task list to web
This commit is contained in:
33
web/src/api/SystemTask.ts
Normal file
33
web/src/api/SystemTask.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { DefaultClient, QueryArguments } from "./Client";
|
||||
|
||||
export enum TaskStatus {
|
||||
SUCCESSFUL = 1,
|
||||
WARNING = 2,
|
||||
ERROR = 4,
|
||||
}
|
||||
|
||||
export class SystemTask {
|
||||
|
||||
task_name: string;
|
||||
task_description: string;
|
||||
task_finish_timestamp: number;
|
||||
status: TaskStatus;
|
||||
messages: string[];
|
||||
|
||||
constructor() {
|
||||
throw Error();
|
||||
}
|
||||
|
||||
static get(task_name: string): Promise<SystemTask> {
|
||||
return DefaultClient.fetch<SystemTask>(["admin", "system_tasks", task_name]);
|
||||
}
|
||||
|
||||
static list(filter?: QueryArguments): Promise<SystemTask[]> {
|
||||
return DefaultClient.fetch<SystemTask[]>(["admin", "system_tasks"], filter);
|
||||
}
|
||||
|
||||
static retry(task_name: string): string {
|
||||
return DefaultClient.makeUrl(["admin", "system_tasks", task_name, "retry"]);
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ export const SIDEBAR_ITEMS: SidebarItem[] = [
|
||||
new SidebarItem("Library", "/library"),
|
||||
new SidebarItem("Monitor").children(
|
||||
new SidebarItem("Overview", "/administration/overview"),
|
||||
new SidebarItem("System Tasks", "/administration/tasks/"),
|
||||
new SidebarItem("System Tasks", "/administration/system-tasks"),
|
||||
).when((): Promise<boolean> => {
|
||||
return User.me().then(u => u.is_superuser);
|
||||
}),
|
||||
|
87
web/src/pages/system-tasks/SystemTaskListPage.ts
Normal file
87
web/src/pages/system-tasks/SystemTaskListPage.ts
Normal file
@ -0,0 +1,87 @@
|
||||
import { gettext } from "django";
|
||||
import { customElement, html, property, TemplateResult } from "lit-element";
|
||||
import { AKResponse } from "../../api/Client";
|
||||
import { TablePage } from "../../elements/table/TablePage";
|
||||
|
||||
import "../../elements/buttons/ModalButton";
|
||||
import "../../elements/buttons/SpinnerButton";
|
||||
import "../../elements/buttons/ActionButton";
|
||||
import { TableColumn } from "../../elements/table/Table";
|
||||
import { SystemTask, TaskStatus } from "../../api/SystemTask";
|
||||
|
||||
@customElement("ak-system-task-list")
|
||||
export class SystemTaskListPage extends TablePage<SystemTask> {
|
||||
searchEnabled(): boolean {
|
||||
return false;
|
||||
}
|
||||
pageTitle(): string {
|
||||
return gettext("System Tasks");
|
||||
}
|
||||
pageDescription(): string {
|
||||
return gettext("Long-running operations which authentik executes in the background.");
|
||||
}
|
||||
pageIcon(): string {
|
||||
return gettext("pf-icon pf-icon-automation");
|
||||
}
|
||||
|
||||
@property()
|
||||
order = "slug";
|
||||
|
||||
apiEndpoint(page: number): Promise<AKResponse<SystemTask>> {
|
||||
return SystemTask.list({
|
||||
ordering: this.order,
|
||||
page: page,
|
||||
}).then((tasks) => {
|
||||
return {
|
||||
pagination: {
|
||||
count: tasks.length,
|
||||
total_pages: 1,
|
||||
start_index: 0,
|
||||
end_index: tasks.length,
|
||||
current: 1,
|
||||
},
|
||||
results: tasks,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
columns(): TableColumn[] {
|
||||
return [
|
||||
new TableColumn("Identifier", "task_name"),
|
||||
new TableColumn("Description"),
|
||||
new TableColumn("Last run"),
|
||||
new TableColumn("Status"),
|
||||
new TableColumn("Messages"),
|
||||
new TableColumn(""),
|
||||
];
|
||||
}
|
||||
|
||||
taskStatus(task: SystemTask): TemplateResult {
|
||||
switch (task.status) {
|
||||
case TaskStatus.SUCCESSFUL:
|
||||
return html`<i class="fas fa-check pf-m-success" > </i> ${gettext("Successful")}`;
|
||||
case TaskStatus.WARNING:
|
||||
return html`<i class="fas fa-exclamation-triangle pf-m-warning" > </i> ${gettext("Warning")}`;
|
||||
case TaskStatus.ERROR:
|
||||
return html`<i class="fas fa-times pf-m-danger" > </i> ${gettext("Error")}`;
|
||||
default:
|
||||
return html`<i class="fas fa-question-circle" > </i> ${gettext("Unknown")}`;
|
||||
}
|
||||
}
|
||||
|
||||
row(item: SystemTask): TemplateResult[] {
|
||||
return [
|
||||
html`${item.task_name}`,
|
||||
html`${item.task_description}`,
|
||||
html`${new Date(item.task_finish_timestamp * 1000).toLocaleString()}`,
|
||||
this.taskStatus(item),
|
||||
html`${item.messages.map(m => {
|
||||
return html`<li>${m}</li>`;
|
||||
})}`,
|
||||
html`<ak-action-button url=${SystemTask.retry(item.task_name)}>
|
||||
${gettext("Retry Task")}
|
||||
</ak-action-button>`,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,7 @@ import "./pages/providers/ProviderViewPage";
|
||||
import "./pages/sources/SourcesListPage";
|
||||
import "./pages/sources/SourceViewPage";
|
||||
import "./pages/groups/GroupListPage";
|
||||
import "./pages/system-tasks/SystemTaskListPage";
|
||||
|
||||
export const ROUTES: Route[] = [
|
||||
// Prevent infinite Shell loops
|
||||
@ -28,6 +29,7 @@ export const ROUTES: Route[] = [
|
||||
new Route(new RegExp("^#.*")).redirect("/library"),
|
||||
new Route(new RegExp("^/library$"), html`<ak-library></ak-library>`),
|
||||
new Route(new RegExp("^/administration/overview$"), html`<ak-admin-overview></ak-admin-overview>`),
|
||||
new Route(new RegExp("^/administration/system-tasks$"), html`<ak-system-task-list></ak-system-task-list>`),
|
||||
new Route(new RegExp("^/providers$"), html`<ak-provider-list></ak-provider-list>`),
|
||||
new Route(new RegExp(`^/providers/(?<id>${ID_REGEX})$`)).then((args) => {
|
||||
return html`<ak-provider-view .providerID=${parseInt(args.id, 10)}></ak-provider-view>`;
|
||||
|
Reference in New Issue
Block a user