Add list to auth home page.
This commit is contained in:
parent
b66da7bd9d
commit
a6e26c6d72
11
src/api/auth/listAuth.ts
Normal file
11
src/api/auth/listAuth.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { appendAPIURL, getHeaders } from "../apiUtils";
|
||||||
|
import { AuthListAPIType, AuthListType } from "../types/auth";
|
||||||
|
|
||||||
|
export async function listAuth(): Promise<AuthListType> {
|
||||||
|
const request = new Request(appendAPIURL(`/v1/sys/auth`), {
|
||||||
|
headers: getHeaders(),
|
||||||
|
});
|
||||||
|
const resp = await fetch(request);
|
||||||
|
const data = (await resp.json()) as AuthListAPIType;
|
||||||
|
return data.data;
|
||||||
|
}
|
19
src/api/types/auth.ts
Normal file
19
src/api/types/auth.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
export type AuthMethod = {
|
||||||
|
type: string;
|
||||||
|
accessor: string;
|
||||||
|
config: Record<string, unknown>;
|
||||||
|
description: string;
|
||||||
|
external_entropy_access: Boolean;
|
||||||
|
local: Boolean;
|
||||||
|
options: Record<string, unknown>;
|
||||||
|
seal_wrap: Boolean;
|
||||||
|
uuid: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AuthListAPIType = {
|
||||||
|
data: AuthListType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AuthListType = {
|
||||||
|
[path: string]: AuthMethod;
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
import { makeElement } from "z-makeelement";
|
import { makeElement } from "z-makeelement";
|
||||||
|
|
||||||
type TileParams = {
|
export type TileParams = {
|
||||||
condition?: boolean;
|
condition?: boolean;
|
||||||
|
color?: string;
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
|
@ -17,7 +18,7 @@ export function Tile(params: TileParams): HTMLElement {
|
||||||
onclick: params.onclick,
|
onclick: params.onclick,
|
||||||
children: makeElement({
|
children: makeElement({
|
||||||
tag: "div",
|
tag: "div",
|
||||||
class: ["uk-padding-small", "uk-background-primary"],
|
class: ["uk-padding-small", "uk-background-" + (params.color || "primary")],
|
||||||
children: [
|
children: [
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "p",
|
tag: "p",
|
||||||
|
|
|
@ -1,6 +1,49 @@
|
||||||
import { Page } from "../../../types/Page";
|
import { Page } from "../../../types/Page";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
import { setErrorText } from "../../../pageUtils";
|
import { setErrorText } from "../../../pageUtils";
|
||||||
|
import { listAuth } from "../../../api/auth/listAuth";
|
||||||
|
import { objectToMap } from "../../../utils";
|
||||||
|
import { AuthMethod } from "../../../api/types/auth";
|
||||||
|
import { makeElement } from "z-makeelement";
|
||||||
|
|
||||||
|
|
||||||
|
export function AuthListElement(path: string, method: AuthMethod): HTMLElement {
|
||||||
|
const isClickable = method.type != "token";
|
||||||
|
|
||||||
|
return makeElement({
|
||||||
|
tag: "div",
|
||||||
|
class: ["uk-padding-small", "uk-background-secondary"],
|
||||||
|
children: [
|
||||||
|
makeElement({
|
||||||
|
tag: isClickable ? "a" : "span",
|
||||||
|
class: "uk-h4 uk-margin-bottom",
|
||||||
|
text: path,
|
||||||
|
}),
|
||||||
|
makeElement({
|
||||||
|
tag: "span",
|
||||||
|
class: "uk-text-muted",
|
||||||
|
text: ` (${method.accessor})`
|
||||||
|
}),
|
||||||
|
makeElement({
|
||||||
|
tag: "div",
|
||||||
|
class: "uk-margin-top",
|
||||||
|
children: [
|
||||||
|
makeElement({
|
||||||
|
tag: "button",
|
||||||
|
class: "uk-button uk-button-small uk-button-primary",
|
||||||
|
text: "View Config",
|
||||||
|
}),
|
||||||
|
makeElement({
|
||||||
|
tag: "button",
|
||||||
|
class: "uk-button uk-button-small uk-button-primary",
|
||||||
|
text: "Edit Config",
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export class AuthHomePage extends Page {
|
export class AuthHomePage extends Page {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -10,7 +53,12 @@ export class AuthHomePage extends Page {
|
||||||
await this.router.changePage("ACCESS_HOME");
|
await this.router.changePage("ACCESS_HOME");
|
||||||
}
|
}
|
||||||
async render(): Promise<void> {
|
async render(): Promise<void> {
|
||||||
setErrorText(i18next.t("not_implemented"));
|
let authList = objectToMap(await listAuth()) as Map<string, AuthMethod>;
|
||||||
|
const contentElement = makeElement({ tag: "div" });
|
||||||
|
this.router.setPageContent(contentElement);
|
||||||
|
for (const [path, details] of authList) {
|
||||||
|
contentElement.appendChild(AuthListElement(path, details))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
get name(): string {
|
get name(): string {
|
||||||
return i18next.t("auth_home_title");
|
return i18next.t("auth_home_title");
|
||||||
|
|
2
src/translations/en.js
vendored
2
src/translations/en.js
vendored
|
@ -220,4 +220,6 @@ module.exports = {
|
||||||
|
|
||||||
// Auth Home Page
|
// Auth Home Page
|
||||||
auth_home_title: "Auth",
|
auth_home_title: "Auth",
|
||||||
|
auth_home_view_config: "View Config",
|
||||||
|
auth_home_edit_config: "Edit Config",
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue