web/admin: migrate api calls to async (#4335)
migrate api calls to async Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
@ -18,7 +18,7 @@ import YAML from "yaml";
|
||||
import { customElement, property } from "lit/decorators.js";
|
||||
|
||||
@customElement("ak-codemirror")
|
||||
export class CodeMirrorTextarea extends AKElement {
|
||||
export class CodeMirrorTextarea<T> extends AKElement {
|
||||
@property({ type: Boolean })
|
||||
readOnly = false;
|
||||
|
||||
@ -39,7 +39,7 @@ export class CodeMirrorTextarea extends AKElement {
|
||||
|
||||
@property()
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
|
||||
set value(v: any) {
|
||||
set value(v: T | string) {
|
||||
if (v === null || v === undefined) return;
|
||||
// Value might be an object if within an iron-form, as that calls the getter of value
|
||||
// in the beginning and the calls this setter on reset
|
||||
@ -59,15 +59,14 @@ export class CodeMirrorTextarea extends AKElement {
|
||||
}
|
||||
if (this.editor) {
|
||||
this.editor.dispatch({
|
||||
changes: { from: 0, to: this.editor.state.doc.length, insert: textValue },
|
||||
changes: { from: 0, to: this.editor.state.doc.length, insert: textValue as string },
|
||||
});
|
||||
} else {
|
||||
this._value = textValue;
|
||||
this._value = textValue as string;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
get value(): any {
|
||||
get value(): T | string {
|
||||
try {
|
||||
switch (this.mode.toLowerCase()) {
|
||||
case "yaml":
|
||||
|
||||
@ -16,7 +16,7 @@ export class AdminModelPerDay extends AKChart<Coordinate[]> {
|
||||
@property({ attribute: false })
|
||||
query?: { [key: string]: unknown } | undefined;
|
||||
|
||||
apiRequest(): Promise<Coordinate[]> {
|
||||
async apiRequest(): Promise<Coordinate[]> {
|
||||
return new EventsApi(DEFAULT_CONFIG).eventsEventsPerMonthList({
|
||||
action: this.action,
|
||||
query: JSON.stringify(this.query || {}),
|
||||
|
||||
@ -13,7 +13,7 @@ export class ApplicationAuthorizeChart extends AKChart<Coordinate[]> {
|
||||
@property()
|
||||
applicationSlug!: string;
|
||||
|
||||
apiRequest(): Promise<Coordinate[]> {
|
||||
async apiRequest(): Promise<Coordinate[]> {
|
||||
return new CoreApi(DEFAULT_CONFIG).coreApplicationsMetricsList({
|
||||
slug: this.applicationSlug,
|
||||
});
|
||||
|
||||
@ -13,7 +13,7 @@ export class UserChart extends AKChart<UserMetrics> {
|
||||
@property({ type: Number })
|
||||
userId?: number;
|
||||
|
||||
apiRequest(): Promise<UserMetrics> {
|
||||
async apiRequest(): Promise<UserMetrics> {
|
||||
return new CoreApi(DEFAULT_CONFIG).coreUsersMetricsRetrieve({
|
||||
id: this.userId || 0,
|
||||
});
|
||||
|
||||
@ -40,8 +40,7 @@ export class DeleteObjectsTable<T> extends Table<T> {
|
||||
return super.styles.concat(PFList);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async apiEndpoint(page: number): Promise<PaginatedResponse<T>> {
|
||||
async apiEndpoint(): Promise<PaginatedResponse<T>> {
|
||||
return Promise.resolve({
|
||||
pagination: {
|
||||
count: this.objects.length,
|
||||
@ -114,10 +113,9 @@ export class DeleteObjectsTable<T> extends Table<T> {
|
||||
}
|
||||
|
||||
@customElement("ak-forms-delete-bulk")
|
||||
export class DeleteBulkForm extends ModalButton {
|
||||
export class DeleteBulkForm<T> extends ModalButton {
|
||||
@property({ attribute: false })
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
objects: any[] = [];
|
||||
objects: T[] = [];
|
||||
|
||||
@property()
|
||||
objectLabel?: string;
|
||||
@ -129,8 +127,7 @@ export class DeleteBulkForm extends ModalButton {
|
||||
actionSubtext?: string;
|
||||
|
||||
@property({ attribute: false })
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
metadata: (item: any) => BulkDeleteMetadata = (item: any) => {
|
||||
metadata: (item: T) => BulkDeleteMetadata = (item: T) => {
|
||||
const rec = item as Record<string, unknown>;
|
||||
const meta = [];
|
||||
if (Object.prototype.hasOwnProperty.call(rec, "name")) {
|
||||
@ -143,33 +140,30 @@ export class DeleteBulkForm extends ModalButton {
|
||||
};
|
||||
|
||||
@property({ attribute: false })
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
usedBy?: (item: any) => Promise<UsedBy[]>;
|
||||
usedBy?: (item: T) => Promise<UsedBy[]>;
|
||||
|
||||
@property({ attribute: false })
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
delete!: (item: any) => Promise<any>;
|
||||
delete!: (item: T) => Promise<T>;
|
||||
|
||||
confirm(): Promise<void> {
|
||||
return Promise.all(
|
||||
this.objects.map((item) => {
|
||||
return this.delete(item);
|
||||
}),
|
||||
)
|
||||
.then(() => {
|
||||
this.onSuccess();
|
||||
this.open = false;
|
||||
this.dispatchEvent(
|
||||
new CustomEvent(EVENT_REFRESH, {
|
||||
bubbles: true,
|
||||
composed: true,
|
||||
}),
|
||||
);
|
||||
})
|
||||
.catch((e) => {
|
||||
this.onError(e);
|
||||
throw e;
|
||||
});
|
||||
async confirm(): Promise<void> {
|
||||
try {
|
||||
await Promise.all(
|
||||
this.objects.map((item) => {
|
||||
return this.delete(item);
|
||||
}),
|
||||
);
|
||||
this.onSuccess();
|
||||
this.open = false;
|
||||
this.dispatchEvent(
|
||||
new CustomEvent(EVENT_REFRESH, {
|
||||
bubbles: true,
|
||||
composed: true,
|
||||
}),
|
||||
);
|
||||
} catch (e) {
|
||||
this.onError(e as Error);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
onSuccess(): void {
|
||||
|
||||
@ -27,8 +27,7 @@ export class Radio<T> extends AKElement {
|
||||
value?: T;
|
||||
|
||||
@property({ attribute: false })
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
onChange: (value: T) => void = (value: T) => {
|
||||
onChange: (value: T) => void = () => {
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
@ -28,8 +28,9 @@ export class TablePagination extends AKElement {
|
||||
pages?: Pagination;
|
||||
|
||||
@property({ attribute: false })
|
||||
// eslint-disable-next-line
|
||||
pageChangeHandler: (page: number) => void = (page: number) => {};
|
||||
pageChangeHandler: (page: number) => void = () => {
|
||||
return;
|
||||
};
|
||||
|
||||
static get styles(): CSSResult[] {
|
||||
return [PFBase, PFButton, PFPagination, AKGlobal];
|
||||
|
||||
@ -16,8 +16,7 @@ export class UserDeviceList extends MFADevicesPage {
|
||||
@property({ type: Number })
|
||||
userId?: number;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async apiEndpoint(page: number): Promise<PaginatedResponse<Device>> {
|
||||
async apiEndpoint(): Promise<PaginatedResponse<Device>> {
|
||||
return new AuthenticatorsApi(DEFAULT_CONFIG)
|
||||
.authenticatorsAdminAllList({
|
||||
user: this.userId,
|
||||
|
||||
@ -58,8 +58,7 @@ export class WizardFormPage extends WizardPage {
|
||||
return response;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
nextDataCallback: (data: KeyUnknown) => Promise<boolean> = async (data): Promise<boolean> => {
|
||||
nextDataCallback: (data: KeyUnknown) => Promise<boolean> = async (): Promise<boolean> => {
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user