1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

Refactoring basic setting saving. Fixes #311 #352

This commit is contained in:
Patrik J. Braun 2021-12-11 16:24:07 +01:00
parent 22954550bf
commit 7d70c71109
3 changed files with 32 additions and 24 deletions

View File

@ -5,12 +5,11 @@ import {ObjectManagers} from '../../model/ObjectManagers';
import {Logger} from '../../Logger';
import {Config} from '../../../common/config/private/Config';
import {ConfigDiagnostics} from '../../model/diagnostics/ConfigDiagnostics';
import {BasicConfigDTO} from '../../../common/entities/settings/BasicConfigDTO';
import {BasicConfigDTO, BasicConfigDTOUtil} from '../../../common/entities/settings/BasicConfigDTO';
import {OtherConfigDTO} from '../../../common/entities/settings/OtherConfigDTO';
import {ProjectPath} from '../../ProjectPath';
import {
DatabaseType,
IPrivateConfig,
ServerDataBaseConfig,
ServerIndexingConfig,
ServerJobConfig,
@ -388,19 +387,11 @@ export class SettingsMWs {
try {
const settings: BasicConfigDTO = req.body.settings;
await ConfigDiagnostics.testImageFolder(settings.imagesFolder);
const map = (config: IPrivateConfig, input: BasicConfigDTO) => {
config.Server.port = input.port;
config.Server.host = input.host;
config.Server.Media.folder = input.imagesFolder;
config.Server.Media.tempFolder = input.tempFolder;
config.Client.publicUrl = input.publicUrl;
config.Client.urlBase = input.urlBase;
config.Client.applicationTitle = input.applicationTitle;
};
map(Config, settings);
BasicConfigDTOUtil.mapToConf(Config, settings);
// only updating explicitly set config (not saving config set by the diagnostics)
const original = await Config.original();
map(original, settings);
BasicConfigDTOUtil.mapToConf(original, settings);
original.save();
ProjectPath.reset();
await ConfigDiagnostics.runDiagnostics();

View File

@ -1,3 +1,6 @@
import {IPrivateConfig} from '../../config/private/PrivateConfig';
export interface BasicConfigDTO {
imagesFolder: string;
tempFolder: string;
@ -7,3 +10,24 @@ export interface BasicConfigDTO {
port: number;
host: string;
}
export const BasicConfigDTOUtil = {
mapToDTO: (s: IPrivateConfig): BasicConfigDTO => ({
port: s.Server.port,
host: s.Server.host,
imagesFolder: s.Server.Media.folder,
tempFolder: s.Server.Media.tempFolder,
applicationTitle: s.Client.applicationTitle,
publicUrl: s.Client.publicUrl,
urlBase: s.Client.urlBase
}),
mapToConf: (config: IPrivateConfig, input: BasicConfigDTO) => {
config.Server.port = input.port;
config.Server.host = input.host;
config.Server.Media.folder = input.imagesFolder;
config.Server.Media.tempFolder = input.tempFolder;
config.Client.publicUrl = input.publicUrl;
config.Client.urlBase = input.urlBase;
config.Client.applicationTitle = input.applicationTitle;
}
};

View File

@ -4,7 +4,7 @@ import {AuthenticationService} from '../../../model/network/authentication.servi
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';
import {BasicConfigDTO, BasicConfigDTOUtil} from '../../../../../common/entities/settings/BasicConfigDTO';
@Component({
selector: 'app-settings-basic',
@ -23,15 +23,8 @@ export class BasicSettingsComponent extends SettingsComponentDirective<BasicConf
navigation: NavigationService,
settingsService: BasicSettingsService,
notification: NotificationService) {
super($localize`Basic`, authService, navigation, settingsService, notification, s => ({
port: s.Server.port,
host: s.Server.host,
imagesFolder: s.Server.Media.folder,
tempFolder: s.Server.Media.tempFolder,
applicationTitle: s.Client.applicationTitle,
publicUrl: s.Client.publicUrl,
urlBase: s.Client.urlBase
}));
super($localize`Basic`, authService, navigation, settingsService, notification,
BasicConfigDTOUtil.mapToDTO);
this.checkUrlError();
}
@ -71,7 +64,7 @@ export class BasicSettingsComponent extends SettingsComponentDirective<BasicConf
this.urlBaseChanged = true;
this.checkUrlError();
}
};
}