diff --git a/backend/middlewares/AdminMWs.ts b/backend/middlewares/AdminMWs.ts index 0b8d0cee..b66ff6ab 100644 --- a/backend/middlewares/AdminMWs.ts +++ b/backend/middlewares/AdminMWs.ts @@ -7,6 +7,7 @@ import {DataBaseConfig, DatabaseType, ThumbnailConfig} from "../../common/config 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 set = Reflect.set; @@ -169,4 +170,33 @@ export class AdminMWs { } + public static async updateBasicSettings(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: BasicConfigDTO = req.body.settings; + await ConfigDiagnostics.testThumbnailFolder(settings.imagesFolder); + Config.Server.port = settings.port; + Config.Server.imagesFolder = settings.imagesFolder; + Config.Client.publicUrl = settings.publicUrl; + Config.Client.applicationTitle = settings.applicationTitle; + //only updating explicitly set config (not saving config set by the diagnostics) + const original = Config.original(); + original.Server.port = settings.port; + original.Server.imagesFolder = settings.imagesFolder; + original.Client.publicUrl = settings.publicUrl; + original.Client.applicationTitle = settings.applicationTitle; + 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 b7656192..9901cd0c 100644 --- a/backend/routes/AdminRouter.ts +++ b/backend/routes/AdminRouter.ts @@ -73,6 +73,12 @@ export class AdminRouter { AdminMWs.updateShareSettings, RenderingMWs.renderOK ); + app.put("/api/settings/basic", + AuthenticationMWs.authenticate, + AuthenticationMWs.authorise(UserRoles.Admin), + AdminMWs.updateBasicSettings, + RenderingMWs.renderOK + ); }; diff --git a/common/entities/settings/BasicConfigDTO.ts b/common/entities/settings/BasicConfigDTO.ts new file mode 100644 index 00000000..9eef8e70 --- /dev/null +++ b/common/entities/settings/BasicConfigDTO.ts @@ -0,0 +1,6 @@ +export interface BasicConfigDTO { + imagesFolder: string; + publicUrl: string; + applicationTitle: string; + port: number; +} diff --git a/frontend/app/admin/admin.component.html b/frontend/app/admin/admin.component.html index fe635070..f53e6692 100644 --- a/frontend/app/admin/admin.component.html +++ b/frontend/app/admin/admin.component.html @@ -21,6 +21,7 @@ + diff --git a/frontend/app/app.module.ts b/frontend/app/app.module.ts index 1ef02b74..d7b4f080 100644 --- a/frontend/app/app.module.ts +++ b/frontend/app/app.module.ts @@ -51,6 +51,7 @@ import {ThumbnailSettingsComponent} from "./settings/thumbnail/thumbanil.setting import {SearchSettingsComponent} from "./settings/search/search.settings.component"; import {SettingsService} from "./settings/settings.service"; import {ShareSettingsComponent} from "./settings/share/share.settings.component"; +import {BasicSettingsComponent} from "./settings/basic/basic.settings.component"; @Injectable() export class GoogleMapsConfig { apiKey: string; @@ -102,6 +103,7 @@ export class GoogleMapsConfig { ThumbnailSettingsComponent, SearchSettingsComponent, ShareSettingsComponent, + BasicSettingsComponent, StringifyRole], providers: [ {provide: LAZY_MAPS_API_CONFIG, useClass: GoogleMapsConfig}, diff --git a/frontend/app/settings/basic/basic.settings.component.css b/frontend/app/settings/basic/basic.settings.component.css new file mode 100644 index 00000000..e69de29b diff --git a/frontend/app/settings/basic/basic.settings.component.html b/frontend/app/settings/basic/basic.settings.component.html new file mode 100644 index 00000000..2fc600a5 --- /dev/null +++ b/frontend/app/settings/basic/basic.settings.component.html @@ -0,0 +1,66 @@ +
+
+
+

Basic settings

+
+
+ + + +
+ +
+ +
+
+
+ +
+ + Port number. Port 80 is usually what you need. +
+
+ +
+ +
+ + Images are loaded from this folder (read permission required) +
+
+ +
+ +
+ + If you access the page form local network its good to know the public url for creating sharing link +
+
+ + + +
+
+ + +
diff --git a/frontend/app/settings/basic/basic.settings.component.ts b/frontend/app/settings/basic/basic.settings.component.ts new file mode 100644 index 00000000..25be1528 --- /dev/null +++ b/frontend/app/settings/basic/basic.settings.component.ts @@ -0,0 +1,30 @@ +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 {BasicSettingsService} from "./basic.settings.service"; +import {BasicConfigDTO} from "../../../../common/entities/settings/BasicConfigDTO"; + +@Component({ + selector: 'settings-basic', + templateUrl: './basic.settings.component.html', + styleUrls: ['./basic.settings.component.css', + './../_abstract/abstract.settings.component.css'], + providers: [BasicSettingsService], +}) +export class BasicSettingsComponent extends SettingsComponent { + + urlPlaceholder = location.origin; + + constructor(_authService: AuthenticationService, + _navigation: NavigationService, + _settingsService: BasicSettingsService, + notification: NotificationService) { + super("Basic", _authService, _navigation, _settingsService, notification); + } + +} + + + diff --git a/frontend/app/settings/basic/basic.settings.service.ts b/frontend/app/settings/basic/basic.settings.service.ts new file mode 100644 index 00000000..cb294f1b --- /dev/null +++ b/frontend/app/settings/basic/basic.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 {BasicConfigDTO} from "../../../../common/entities/settings/BasicConfigDTO"; + +@Injectable() +export class BasicSettingsService extends AbstractSettingsService { + constructor(private _networkService: NetworkService, + _settingsService: SettingsService) { + super(_settingsService, s => ({ + port: s.Server.port, + imagesFolder: s.Server.imagesFolder, + applicationTitle: s.Client.applicationTitle, + publicUrl: s.Client.publicUrl + })); + } + + + public updateSettings(settings: BasicConfigDTO): Promise { + return this._networkService.putJson("/settings/basic", {settings: settings}); + } + +} diff --git a/frontend/app/settings/map/map.settings.component.html b/frontend/app/settings/map/map.settings.component.html index 1f6b1927..a8662bd5 100644 --- a/frontend/app/settings/map/map.settings.component.html +++ b/frontend/app/settings/map/map.settings.component.html @@ -21,7 +21,7 @@ - diff --git a/frontend/app/settings/settings.service.ts b/frontend/app/settings/settings.service.ts index b2decf3e..2a185db0 100644 --- a/frontend/app/settings/settings.service.ts +++ b/frontend/app/settings/settings.service.ts @@ -25,20 +25,22 @@ export class SettingsService { Map: { enabled: true, googleApiKey: "" - }, publicUrl: "", + }, + publicUrl: "", applicationTitle: "", enableCache: true, enableOnScrollRendering: true, enableOnScrollThumbnailPrioritising: true, authenticationRequired: true - }, Server: { + }, + Server: { database: { type: DatabaseType.memory }, - imagesFolder: "", sharing: { updateTimeout: 2000 }, + imagesFolder: "", enableThreading: true, port: 80, thumbnail: { diff --git a/frontend/app/settings/usermanager/usermanager.settings.component.html b/frontend/app/settings/usermanager/usermanager.settings.component.html index ee2a5cc4..becc60dd 100644 --- a/frontend/app/settings/usermanager/usermanager.settings.component.html +++ b/frontend/app/settings/usermanager/usermanager.settings.component.html @@ -57,7 +57,7 @@
- To protect the site with password / have login enable this + To protect the site with password / have login enable this.
diff --git a/frontend/index.html b/frontend/index.html index 73b31e93..45f5cf22 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -3,7 +3,7 @@ - PiGallery2 + Loading..