mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
implementing other settings
This commit is contained in:
parent
9745ab216f
commit
836f20eea4
@ -8,6 +8,7 @@ import {Config} from "../../common/config/private/Config";
|
|||||||
import {ConfigDiagnostics} from "../model/ConfigDiagnostics";
|
import {ConfigDiagnostics} from "../model/ConfigDiagnostics";
|
||||||
import {ClientConfig} from "../../common/config/public/ConfigClass";
|
import {ClientConfig} from "../../common/config/public/ConfigClass";
|
||||||
import {BasicConfigDTO} from "../../common/entities/settings/BasicConfigDTO";
|
import {BasicConfigDTO} from "../../common/entities/settings/BasicConfigDTO";
|
||||||
|
import {OtherConfigDTO} from "../../common/entities/settings/OtherConfigDTO";
|
||||||
import set = Reflect.set;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,12 @@ export class AdminRouter {
|
|||||||
AdminMWs.updateBasicSettings,
|
AdminMWs.updateBasicSettings,
|
||||||
RenderingMWs.renderOK
|
RenderingMWs.renderOK
|
||||||
);
|
);
|
||||||
|
app.put("/api/settings/other",
|
||||||
|
AuthenticationMWs.authenticate,
|
||||||
|
AuthenticationMWs.authorise(UserRoles.Admin),
|
||||||
|
AdminMWs.updateOtherSettings,
|
||||||
|
RenderingMWs.renderOK
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
6
common/entities/settings/OtherConfigDTO.ts
Normal file
6
common/entities/settings/OtherConfigDTO.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export interface OtherConfigDTO {
|
||||||
|
enableCache: boolean;
|
||||||
|
enableOnScrollRendering: boolean;
|
||||||
|
enableOnScrollThumbnailPrioritising: boolean;
|
||||||
|
enableThreading: boolean;
|
||||||
|
}
|
@ -28,5 +28,6 @@
|
|||||||
<settings-search></settings-search>
|
<settings-search></settings-search>
|
||||||
<settings-share></settings-share>
|
<settings-share></settings-share>
|
||||||
<settings-map></settings-map>
|
<settings-map></settings-map>
|
||||||
|
<settings-other></settings-other>
|
||||||
</div>
|
</div>
|
||||||
</app-frame>
|
</app-frame>
|
||||||
|
@ -52,6 +52,7 @@ import {SearchSettingsComponent} from "./settings/search/search.settings.compone
|
|||||||
import {SettingsService} from "./settings/settings.service";
|
import {SettingsService} from "./settings/settings.service";
|
||||||
import {ShareSettingsComponent} from "./settings/share/share.settings.component";
|
import {ShareSettingsComponent} from "./settings/share/share.settings.component";
|
||||||
import {BasicSettingsComponent} from "./settings/basic/basic.settings.component";
|
import {BasicSettingsComponent} from "./settings/basic/basic.settings.component";
|
||||||
|
import {OtherSettingsComponent} from "./settings/other/other.settings.component";
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GoogleMapsConfig {
|
export class GoogleMapsConfig {
|
||||||
apiKey: string;
|
apiKey: string;
|
||||||
@ -104,6 +105,7 @@ export class GoogleMapsConfig {
|
|||||||
SearchSettingsComponent,
|
SearchSettingsComponent,
|
||||||
ShareSettingsComponent,
|
ShareSettingsComponent,
|
||||||
BasicSettingsComponent,
|
BasicSettingsComponent,
|
||||||
|
OtherSettingsComponent,
|
||||||
StringifyRole],
|
StringifyRole],
|
||||||
providers: [
|
providers: [
|
||||||
{provide: LAZY_MAPS_API_CONFIG, useClass: GoogleMapsConfig},
|
{provide: LAZY_MAPS_API_CONFIG, useClass: GoogleMapsConfig},
|
||||||
|
@ -20,7 +20,7 @@ export abstract class SettingsComponent<T> implements OnInit, OnDestroy {
|
|||||||
private _authService: AuthenticationService,
|
private _authService: AuthenticationService,
|
||||||
private _navigation: NavigationService,
|
private _navigation: NavigationService,
|
||||||
public _settingsService: AbstractSettingsService<T>,
|
public _settingsService: AbstractSettingsService<T>,
|
||||||
private notification: NotificationService) {
|
protected notification: NotificationService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -59,14 +59,17 @@ export abstract class SettingsComponent<T> implements OnInit, OnDestroy {
|
|||||||
await this._settingsService.updateSettings(this._settingsService.settings);
|
await this._settingsService.updateSettings(this._settingsService.settings);
|
||||||
await this.getSettings();
|
await this.getSettings();
|
||||||
this.notification.success(this.name + ' settings saved', "Success");
|
this.notification.success(this.name + ' settings saved', "Success");
|
||||||
|
this.inProgress = false;
|
||||||
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
if (err.message) {
|
if (err.message) {
|
||||||
this.error = (<ErrorDTO>err).message;
|
this.error = (<ErrorDTO>err).message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.inProgress = false;
|
|
||||||
|
|
||||||
|
this.inProgress = false;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,15 @@ export class BasicSettingsComponent extends SettingsComponent<BasicConfigDTO> {
|
|||||||
super("Basic", _authService, _navigation, _settingsService, notification);
|
super("Basic", _authService, _navigation, _settingsService, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async save(): Promise<boolean> {
|
||||||
|
const val = await super.save();
|
||||||
|
if (val == true) {
|
||||||
|
|
||||||
|
this.notification.info('Restart the server to apply the new settings');
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
100
frontend/app/settings/other/other.settings.component.html
Normal file
100
frontend/app/settings/other/other.settings.component.html
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<form #settingsForm="ngForm" class="form-horizontal">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">Other settings</h3>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div [hidden]="!error" class="alert alert-danger" role="alert"><strong>Error: </strong>{{error}}</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label" for="enableThreading">Threading</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<bSwitch
|
||||||
|
id="enableThreading"
|
||||||
|
class="switch"
|
||||||
|
name="enableThreading"
|
||||||
|
[switch-on-color]="'primary'"
|
||||||
|
[switch-inverse]="'inverse'"
|
||||||
|
[switch-off-text]="'Disabled'"
|
||||||
|
[switch-on-text]="'Enabled'"
|
||||||
|
[switch-handle-width]="'100'"
|
||||||
|
[switch-label-width]="'20'"
|
||||||
|
[(ngModel)]="_settingsService.settings.enableThreading">
|
||||||
|
</bSwitch>
|
||||||
|
<span class="help-block">Runs directory scanning and thumbnail generation (only for Jimp) in a different thread</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label" for="enableOnScrollThumbnailPrioritising">Scroll based thumbnail
|
||||||
|
generation</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<bSwitch
|
||||||
|
id="enableOnScrollThumbnailPrioritising"
|
||||||
|
class="switch"
|
||||||
|
name="enableOnScrollThumbnailPrioritising"
|
||||||
|
[switch-on-color]="'primary'"
|
||||||
|
[switch-inverse]="'inverse'"
|
||||||
|
[switch-off-text]="'Disabled'"
|
||||||
|
[switch-on-text]="'Enabled'"
|
||||||
|
[switch-handle-width]="'100'"
|
||||||
|
[switch-label-width]="'20'"
|
||||||
|
[(ngModel)]="_settingsService.settings.enableOnScrollThumbnailPrioritising">
|
||||||
|
</bSwitch>
|
||||||
|
<span class="help-block">Those thumbnails get higher priority that are visible on the screen</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label" for="enableOnScrollRendering">Lazy image rendering</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<bSwitch
|
||||||
|
id="enableOnScrollRendering"
|
||||||
|
class="switch"
|
||||||
|
name="enableOnScrollRendering"
|
||||||
|
[switch-on-color]="'primary'"
|
||||||
|
[switch-inverse]="'inverse'"
|
||||||
|
[switch-off-text]="'Disabled'"
|
||||||
|
[switch-on-text]="'Enabled'"
|
||||||
|
[switch-handle-width]="'100'"
|
||||||
|
[switch-label-width]="'20'"
|
||||||
|
[(ngModel)]="_settingsService.settings.enableOnScrollRendering">
|
||||||
|
</bSwitch>
|
||||||
|
<span class="help-block">Shows only the required amount of photos at once. Renders more if page bottom is reached</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label" for="enableCache">Cache</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<bSwitch
|
||||||
|
id="enableCache"
|
||||||
|
class="switch"
|
||||||
|
name="enableCache"
|
||||||
|
[switch-on-color]="'primary'"
|
||||||
|
[switch-inverse]="'inverse'"
|
||||||
|
[switch-off-text]="'Disabled'"
|
||||||
|
[switch-on-text]="'Enabled'"
|
||||||
|
[switch-handle-width]="'100'"
|
||||||
|
[switch-label-width]="'20'"
|
||||||
|
[(ngModel)]="_settingsService.settings.enableCache">
|
||||||
|
</bSwitch>
|
||||||
|
<span class="help-block">Caches directory contents and search results for better performance</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<button class="btn btn-success pull-right"
|
||||||
|
[disabled]="!settingsForm.form.valid || !changed || inProgress"
|
||||||
|
(click)="save()">Save
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-default pull-right"
|
||||||
|
(click)="reset()">Reset
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</form>
|
37
frontend/app/settings/other/other.settings.component.ts
Normal file
37
frontend/app/settings/other/other.settings.component.ts
Normal file
@ -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<OtherConfigDTO> {
|
||||||
|
|
||||||
|
constructor(_authService: AuthenticationService,
|
||||||
|
_navigation: NavigationService,
|
||||||
|
_settingsService: OtherSettingsService,
|
||||||
|
notification: NotificationService) {
|
||||||
|
super("Other", _authService, _navigation, _settingsService, notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async save(): Promise<boolean> {
|
||||||
|
const val = await super.save();
|
||||||
|
if (val == true) {
|
||||||
|
|
||||||
|
this.notification.info('Restart the server to apply the new settings', "Info");
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
24
frontend/app/settings/other/other.settings.service.ts
Normal file
24
frontend/app/settings/other/other.settings.service.ts
Normal file
@ -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<OtherConfigDTO> {
|
||||||
|
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<void> {
|
||||||
|
return this._networkService.putJson("/settings/other", {settings: settings});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user