diff --git a/backend/middlewares/AdminMWs.ts b/backend/middlewares/AdminMWs.ts index b66ff6ab..6e4ed263 100644 --- a/backend/middlewares/AdminMWs.ts +++ b/backend/middlewares/AdminMWs.ts @@ -8,6 +8,7 @@ import {Config} from "../../common/config/private/Config"; import {ConfigDiagnostics} from "../model/ConfigDiagnostics"; import {ClientConfig} from "../../common/config/public/ConfigClass"; import {BasicConfigDTO} from "../../common/entities/settings/BasicConfigDTO"; +import {OtherConfigDTO} from "../../common/entities/settings/OtherConfigDTO"; import set = Reflect.set; @@ -199,4 +200,32 @@ export class AdminMWs { } + public static async updateOtherSettings(req: Request, res: Response, next: NextFunction) { + if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) { + return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, "settings is needed")); + } + + try { + const settings: OtherConfigDTO = req.body.settings; + Config.Client.enableCache = settings.enableCache; + Config.Client.enableOnScrollRendering = settings.enableOnScrollRendering; + Config.Client.enableOnScrollThumbnailPrioritising = settings.enableOnScrollThumbnailPrioritising; + + //only updating explicitly set config (not saving config set by the diagnostics) + const original = Config.original(); + original.Client.enableCache = settings.enableCache; + original.Client.enableOnScrollRendering = settings.enableOnScrollRendering; + original.Client.enableOnScrollThumbnailPrioritising = settings.enableOnScrollThumbnailPrioritising; + original.Server.enableThreading = settings.enableThreading; + original.save(); + await ConfigDiagnostics.runDiagnostics(); + Logger.info(LOG_TAG, "new config:"); + Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t')); + return next(); + } catch (err) { + return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, "Settings error: " + JSON.stringify(err, null, ' '), err)); + } + } + + } diff --git a/backend/routes/AdminRouter.ts b/backend/routes/AdminRouter.ts index 9901cd0c..ff298f7b 100644 --- a/backend/routes/AdminRouter.ts +++ b/backend/routes/AdminRouter.ts @@ -79,6 +79,12 @@ export class AdminRouter { AdminMWs.updateBasicSettings, RenderingMWs.renderOK ); + app.put("/api/settings/other", + AuthenticationMWs.authenticate, + AuthenticationMWs.authorise(UserRoles.Admin), + AdminMWs.updateOtherSettings, + RenderingMWs.renderOK + ); }; diff --git a/common/entities/settings/OtherConfigDTO.ts b/common/entities/settings/OtherConfigDTO.ts new file mode 100644 index 00000000..8a059001 --- /dev/null +++ b/common/entities/settings/OtherConfigDTO.ts @@ -0,0 +1,6 @@ +export interface OtherConfigDTO { + enableCache: boolean; + enableOnScrollRendering: boolean; + enableOnScrollThumbnailPrioritising: boolean; + enableThreading: boolean; +} diff --git a/frontend/app/admin/admin.component.html b/frontend/app/admin/admin.component.html index f53e6692..d976fcf0 100644 --- a/frontend/app/admin/admin.component.html +++ b/frontend/app/admin/admin.component.html @@ -28,5 +28,6 @@ + diff --git a/frontend/app/app.module.ts b/frontend/app/app.module.ts index d7b4f080..c6339896 100644 --- a/frontend/app/app.module.ts +++ b/frontend/app/app.module.ts @@ -52,6 +52,7 @@ import {SearchSettingsComponent} from "./settings/search/search.settings.compone import {SettingsService} from "./settings/settings.service"; import {ShareSettingsComponent} from "./settings/share/share.settings.component"; import {BasicSettingsComponent} from "./settings/basic/basic.settings.component"; +import {OtherSettingsComponent} from "./settings/other/other.settings.component"; @Injectable() export class GoogleMapsConfig { apiKey: string; @@ -104,6 +105,7 @@ export class GoogleMapsConfig { SearchSettingsComponent, ShareSettingsComponent, BasicSettingsComponent, + OtherSettingsComponent, StringifyRole], providers: [ {provide: LAZY_MAPS_API_CONFIG, useClass: GoogleMapsConfig}, diff --git a/frontend/app/settings/_abstract/abstract.settings.component.ts b/frontend/app/settings/_abstract/abstract.settings.component.ts index 399efa6e..abcee424 100644 --- a/frontend/app/settings/_abstract/abstract.settings.component.ts +++ b/frontend/app/settings/_abstract/abstract.settings.component.ts @@ -20,7 +20,7 @@ export abstract class SettingsComponent implements OnInit, OnDestroy { private _authService: AuthenticationService, private _navigation: NavigationService, public _settingsService: AbstractSettingsService, - private notification: NotificationService) { + protected notification: NotificationService) { } ngOnInit() { @@ -59,14 +59,17 @@ export abstract class SettingsComponent implements OnInit, OnDestroy { await this._settingsService.updateSettings(this._settingsService.settings); await this.getSettings(); this.notification.success(this.name + ' settings saved', "Success"); + this.inProgress = false; + return true; } catch (err) { console.log(err); if (err.message) { this.error = (err).message; } } - this.inProgress = false; + this.inProgress = false; + return false; } } diff --git a/frontend/app/settings/basic/basic.settings.component.ts b/frontend/app/settings/basic/basic.settings.component.ts index 25be1528..ad837f6c 100644 --- a/frontend/app/settings/basic/basic.settings.component.ts +++ b/frontend/app/settings/basic/basic.settings.component.ts @@ -24,6 +24,15 @@ export class BasicSettingsComponent extends SettingsComponent { super("Basic", _authService, _navigation, _settingsService, notification); } + public async save(): Promise { + const val = await super.save(); + if (val == true) { + + this.notification.info('Restart the server to apply the new settings'); + } + return val; + } + } diff --git a/frontend/app/settings/other/other.settings.component.css b/frontend/app/settings/other/other.settings.component.css new file mode 100644 index 00000000..e69de29b diff --git a/frontend/app/settings/other/other.settings.component.html b/frontend/app/settings/other/other.settings.component.html new file mode 100644 index 00000000..7f930b99 --- /dev/null +++ b/frontend/app/settings/other/other.settings.component.html @@ -0,0 +1,100 @@ + + + + Other settings + + + Error: {{error}} + + + + Threading + + + + Runs directory scanning and thumbnail generation (only for Jimp) in a different thread + + + + + Scroll based thumbnail + generation + + + + Those thumbnails get higher priority that are visible on the screen + + + + + Lazy image rendering + + + + Shows only the required amount of photos at once. Renders more if page bottom is reached + + + + + + Cache + + + + Caches directory contents and search results for better performance + + + + + Save + + Reset + + + + + + diff --git a/frontend/app/settings/other/other.settings.component.ts b/frontend/app/settings/other/other.settings.component.ts new file mode 100644 index 00000000..0baa89e8 --- /dev/null +++ b/frontend/app/settings/other/other.settings.component.ts @@ -0,0 +1,37 @@ +import {Component} from "@angular/core"; +import {SettingsComponent} from "../_abstract/abstract.settings.component"; +import {AuthenticationService} from "../../model/network/authentication.service"; +import {NavigationService} from "../../model/navigation.service"; +import {NotificationService} from "../../model/notification.service"; +import {OtherSettingsService} from "./other.settings.service"; +import {OtherConfigDTO} from "../../../../common/entities/settings/OtherConfigDTO"; + +@Component({ + selector: 'settings-other', + templateUrl: './other.settings.component.html', + styleUrls: ['./other.settings.component.css', + './../_abstract/abstract.settings.component.css'], + providers: [OtherSettingsService], +}) +export class OtherSettingsComponent extends SettingsComponent { + + constructor(_authService: AuthenticationService, + _navigation: NavigationService, + _settingsService: OtherSettingsService, + notification: NotificationService) { + super("Other", _authService, _navigation, _settingsService, notification); + } + + + public async save(): Promise { + const val = await super.save(); + if (val == true) { + + this.notification.info('Restart the server to apply the new settings', "Info"); + } + return val; + } +} + + + diff --git a/frontend/app/settings/other/other.settings.service.ts b/frontend/app/settings/other/other.settings.service.ts new file mode 100644 index 00000000..12c0feee --- /dev/null +++ b/frontend/app/settings/other/other.settings.service.ts @@ -0,0 +1,24 @@ +import {Injectable} from "@angular/core"; +import {NetworkService} from "../../model/network/network.service"; +import {AbstractSettingsService} from "../_abstract/abstract.settings.service"; +import {SettingsService} from "../settings.service"; +import {OtherConfigDTO} from "../../../../common/entities/settings/OtherConfigDTO"; + +@Injectable() +export class OtherSettingsService extends AbstractSettingsService { + constructor(private _networkService: NetworkService, + _settingsService: SettingsService) { + super(_settingsService, s => ({ + enableThreading: s.Server.enableThreading, + enableOnScrollThumbnailPrioritising: s.Client.enableOnScrollThumbnailPrioritising, + enableOnScrollRendering: s.Client.enableOnScrollRendering, + enableCache: s.Client.enableCache + })); + } + + + public updateSettings(settings: OtherConfigDTO): Promise { + return this._networkService.putJson("/settings/other", {settings: settings}); + } + +}