From dd6db01c1a0c97501e677256de1a14b66f5b592f Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sun, 27 Oct 2024 23:25:29 +0100 Subject: [PATCH] starting frontend ui --- src/backend/middlewares/admin/ExtensionMWs.ts | 36 +++++++++++++++++++ .../model/extension/ExtensionManager.ts | 2 ++ src/backend/routes/admin/ExtensionRouter.ts | 23 ++++++++++++ src/frontend/app/app.module.ts | 4 ++- .../extension-installer.component.css | 0 .../extension-installer.component.html | 1 + .../extension-installer.component.ts | 10 ++++++ .../extension-installer.service.ts | 18 ++++++++++ 8 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/backend/middlewares/admin/ExtensionMWs.ts create mode 100644 src/backend/routes/admin/ExtensionRouter.ts create mode 100644 src/frontend/app/ui/settings/extension-installer/extension-installer.component.css create mode 100644 src/frontend/app/ui/settings/extension-installer/extension-installer.component.html create mode 100644 src/frontend/app/ui/settings/extension-installer/extension-installer.component.ts create mode 100644 src/frontend/app/ui/settings/extension-installer/extension-installer.service.ts diff --git a/src/backend/middlewares/admin/ExtensionMWs.ts b/src/backend/middlewares/admin/ExtensionMWs.ts new file mode 100644 index 00000000..67979808 --- /dev/null +++ b/src/backend/middlewares/admin/ExtensionMWs.ts @@ -0,0 +1,36 @@ +import {NextFunction, Request, Response} from 'express'; +import {ErrorCodes, ErrorDTO} from '../../../common/entities/Error'; +import {ObjectManagers} from '../../model/ObjectManagers'; +import {StatisticDTO} from '../../../common/entities/settings/StatisticDTO'; +import {MessengerRepository} from '../../model/messenger/MessengerRepository'; +import {JobStartDTO} from '../../../common/entities/job/JobDTO'; + +export class ExtensionMWs { + public static getExtensionList( + req: Request, + res: Response, + next: NextFunction + ): void { + try { + req.resultPipe = ObjectManagers.getInstance().ExtensionManager.repository.fetchList(); + return next(); + } catch (err) { + if (err instanceof Error) { + return next( + new ErrorDTO( + ErrorCodes.JOB_ERROR, + 'Job error: ' + err.toString(), + err + ) + ); + } + return next( + new ErrorDTO( + ErrorCodes.JOB_ERROR, + 'Job error: ' + JSON.stringify(err, null, ' '), + err + ) + ); + } + } +} diff --git a/src/backend/model/extension/ExtensionManager.ts b/src/backend/model/extension/ExtensionManager.ts index 61db3534..ac6cce11 100644 --- a/src/backend/model/extension/ExtensionManager.ts +++ b/src/backend/model/extension/ExtensionManager.ts @@ -13,6 +13,7 @@ import {ExtensionObject} from './ExtensionObject'; import {ExtensionDecoratorObject} from './ExtensionDecorator'; import * as util from 'util'; import {ServerExtensionsEntryConfig} from '../../../common/config/private/subconfigs/ServerExtensionsConfig'; +import {ExtensionRepository} from './ExtensionRepository'; // eslint-disable-next-line @typescript-eslint/no-var-requires const exec = util.promisify(require('child_process').exec); @@ -21,6 +22,7 @@ const LOG_TAG = '[ExtensionManager]'; export class ExtensionManager implements IObjectManager { public static EXTENSION_API_PATH = Config.Server.apiPath + '/extension'; + public repository: ExtensionRepository = new ExtensionRepository(); events: IExtensionEvents; extObjects: { [key: string]: ExtensionObject } = {}; diff --git a/src/backend/routes/admin/ExtensionRouter.ts b/src/backend/routes/admin/ExtensionRouter.ts new file mode 100644 index 00000000..ca52ac84 --- /dev/null +++ b/src/backend/routes/admin/ExtensionRouter.ts @@ -0,0 +1,23 @@ +import {Express} from 'express'; +import {UserRoles} from '../../common/entities/UserDTO'; +import {AuthenticationMWs} from '../middlewares/user/AuthenticationMWs'; +import {RenderingMWs} from '../middlewares/RenderingMWs'; +import {ServerTimingMWs} from '../middlewares/ServerTimingMWs'; +import {ExtensionManager} from '../../model/extension/ExtensionManager'; + +export class UserRouter { + public static route(app: Express): void { + this.addExtensionList(app); + } + + private static addExtensionList(app: Express): void { + app.post( + ExtensionManager.EXTENSION_API_PATH, + AuthenticationMWs.authenticate, + AuthenticationMWs.authorise(UserRoles.Admin), + ServerTimingMWs.addServerTiming, + RenderingMWs.renderSessionUser + ); + } + +} diff --git a/src/frontend/app/app.module.ts b/src/frontend/app/app.module.ts index 3ae1946f..58c08179 100644 --- a/src/frontend/app/app.module.ts +++ b/src/frontend/app/app.module.ts @@ -193,6 +193,7 @@ import {StringifyGridSize} from './pipes/StringifyGridSize'; import {GalleryNavigatorService} from './ui/gallery/navigator/navigator.service'; import {GridSizeIconComponent} from './ui/utils/grid-size-icon/grid-size-icon.component'; import {SortingMethodIconComponent} from './ui/utils/sorting-method-icon/sorting-method-icon.component'; +import { ExtensionInstallerComponent } from './ui/settings/extension-installer/extension-installer.component'; @Injectable() export class MyHammerConfig extends HammerGestureConfig { @@ -345,7 +346,8 @@ Marker.prototype.options.icon = MarkerFactory.defIcon; SortingMethodIconComponent, GridSizeIconComponent, SafeHtmlPipe, - SortingMethodSettingsEntryComponent + SortingMethodSettingsEntryComponent, + ExtensionInstallerComponent ], providers: [ {provide: HTTP_INTERCEPTORS, useClass: CSRFInterceptor, multi: true}, diff --git a/src/frontend/app/ui/settings/extension-installer/extension-installer.component.css b/src/frontend/app/ui/settings/extension-installer/extension-installer.component.css new file mode 100644 index 00000000..e69de29b diff --git a/src/frontend/app/ui/settings/extension-installer/extension-installer.component.html b/src/frontend/app/ui/settings/extension-installer/extension-installer.component.html new file mode 100644 index 00000000..2d3bae81 --- /dev/null +++ b/src/frontend/app/ui/settings/extension-installer/extension-installer.component.html @@ -0,0 +1 @@ +

extension-installer works!

diff --git a/src/frontend/app/ui/settings/extension-installer/extension-installer.component.ts b/src/frontend/app/ui/settings/extension-installer/extension-installer.component.ts new file mode 100644 index 00000000..ab6d4e97 --- /dev/null +++ b/src/frontend/app/ui/settings/extension-installer/extension-installer.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-extension-installer', + templateUrl: './extension-installer.component.html', + styleUrls: ['./extension-installer.component.css'] +}) +export class ExtensionInstallerComponent { + +} diff --git a/src/frontend/app/ui/settings/extension-installer/extension-installer.service.ts b/src/frontend/app/ui/settings/extension-installer/extension-installer.service.ts new file mode 100644 index 00000000..aa40e72b --- /dev/null +++ b/src/frontend/app/ui/settings/extension-installer/extension-installer.service.ts @@ -0,0 +1,18 @@ +import { Injectable } from '@angular/core'; +import {NetworkService} from '../../../model/network/network.service'; +import {UserDTO} from '../../../../../common/entities/UserDTO'; + +@Injectable({ + providedIn: 'root' +}) +export class ExtensionInstallerService { + + constructor(private networkService: NetworkService) { + } + + + + public getExtensions(): Promise> { + return this.networkService.getJson('/user/list'); + } +}