mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
implementing basic settings
This commit is contained in:
parent
47a2aed3b4
commit
9745ab216f
@ -7,6 +7,7 @@ import {DataBaseConfig, DatabaseType, ThumbnailConfig} from "../../common/config
|
|||||||
import {Config} from "../../common/config/private/Config";
|
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 set = Reflect.set;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,12 @@ export class AdminRouter {
|
|||||||
AdminMWs.updateShareSettings,
|
AdminMWs.updateShareSettings,
|
||||||
RenderingMWs.renderOK
|
RenderingMWs.renderOK
|
||||||
);
|
);
|
||||||
|
app.put("/api/settings/basic",
|
||||||
|
AuthenticationMWs.authenticate,
|
||||||
|
AuthenticationMWs.authorise(UserRoles.Admin),
|
||||||
|
AdminMWs.updateBasicSettings,
|
||||||
|
RenderingMWs.renderOK
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
6
common/entities/settings/BasicConfigDTO.ts
Normal file
6
common/entities/settings/BasicConfigDTO.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export interface BasicConfigDTO {
|
||||||
|
imagesFolder: string;
|
||||||
|
publicUrl: string;
|
||||||
|
applicationTitle: string;
|
||||||
|
port: number;
|
||||||
|
}
|
@ -21,6 +21,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<settings-basic></settings-basic>
|
||||||
<settings-usermanager></settings-usermanager>
|
<settings-usermanager></settings-usermanager>
|
||||||
<settings-database></settings-database>
|
<settings-database></settings-database>
|
||||||
<settings-thumbnail></settings-thumbnail>
|
<settings-thumbnail></settings-thumbnail>
|
||||||
|
@ -51,6 +51,7 @@ import {ThumbnailSettingsComponent} from "./settings/thumbnail/thumbanil.setting
|
|||||||
import {SearchSettingsComponent} from "./settings/search/search.settings.component";
|
import {SearchSettingsComponent} from "./settings/search/search.settings.component";
|
||||||
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";
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GoogleMapsConfig {
|
export class GoogleMapsConfig {
|
||||||
apiKey: string;
|
apiKey: string;
|
||||||
@ -102,6 +103,7 @@ export class GoogleMapsConfig {
|
|||||||
ThumbnailSettingsComponent,
|
ThumbnailSettingsComponent,
|
||||||
SearchSettingsComponent,
|
SearchSettingsComponent,
|
||||||
ShareSettingsComponent,
|
ShareSettingsComponent,
|
||||||
|
BasicSettingsComponent,
|
||||||
StringifyRole],
|
StringifyRole],
|
||||||
providers: [
|
providers: [
|
||||||
{provide: LAZY_MAPS_API_CONFIG, useClass: GoogleMapsConfig},
|
{provide: LAZY_MAPS_API_CONFIG, useClass: GoogleMapsConfig},
|
||||||
|
66
frontend/app/settings/basic/basic.settings.component.html
Normal file
66
frontend/app/settings/basic/basic.settings.component.html
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<form #settingsForm="ngForm" class="form-horizontal">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">Basic 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="applicationTitle">Page title</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="text" class="form-control" placeholder="Pigallery 2"
|
||||||
|
id="applicationTitle"
|
||||||
|
[(ngModel)]="_settingsService.settings.applicationTitle"
|
||||||
|
name="applicationTitle" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label" for="port">Port</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="number" class="form-control" placeholder="80"
|
||||||
|
id="port"
|
||||||
|
min="0"
|
||||||
|
step="1"
|
||||||
|
max="65535"
|
||||||
|
[(ngModel)]="_settingsService.settings.port"
|
||||||
|
name="port" required>
|
||||||
|
<span class="help-block">Port number. Port 80 is usually what you need.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label" for="folder">Images folder</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="text" class="form-control" placeholder="path"
|
||||||
|
id="folder"
|
||||||
|
[(ngModel)]="_settingsService.settings.imagesFolder"
|
||||||
|
name="folder" required>
|
||||||
|
<span class="help-block">Images are loaded from this folder (read permission required)</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label" for="publicUrl">Page public url</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="url" class="form-control" placeholder="{{urlPlaceholder}}"
|
||||||
|
id="publicUrl"
|
||||||
|
[(ngModel)]="_settingsService.settings.publicUrl"
|
||||||
|
name="publicUrl">
|
||||||
|
<span class="help-block">If you access the page form local network its good to know the public url for creating sharing link</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>
|
30
frontend/app/settings/basic/basic.settings.component.ts
Normal file
30
frontend/app/settings/basic/basic.settings.component.ts
Normal file
@ -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<BasicConfigDTO> {
|
||||||
|
|
||||||
|
urlPlaceholder = location.origin;
|
||||||
|
|
||||||
|
constructor(_authService: AuthenticationService,
|
||||||
|
_navigation: NavigationService,
|
||||||
|
_settingsService: BasicSettingsService,
|
||||||
|
notification: NotificationService) {
|
||||||
|
super("Basic", _authService, _navigation, _settingsService, notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
24
frontend/app/settings/basic/basic.settings.service.ts
Normal file
24
frontend/app/settings/basic/basic.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 {BasicConfigDTO} from "../../../../common/entities/settings/BasicConfigDTO";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BasicSettingsService extends AbstractSettingsService<BasicConfigDTO> {
|
||||||
|
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<void> {
|
||||||
|
return this._networkService.putJson("/settings/basic", {settings: settings});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -21,7 +21,7 @@
|
|||||||
<div [hidden]="!error" class="alert alert-danger" role="alert"><strong>Error: </strong>{{error}}</div>
|
<div [hidden]="!error" class="alert alert-danger" role="alert"><strong>Error: </strong>{{error}}</div>
|
||||||
|
|
||||||
|
|
||||||
<input type="text" class="form-control" placeholder="Google api key" autofocus
|
<input type="text" class="form-control" placeholder="Google api key"
|
||||||
[(ngModel)]="_settingsService.settings.googleApiKey"
|
[(ngModel)]="_settingsService.settings.googleApiKey"
|
||||||
[disabled]="!_settingsService.settings.enabled"
|
[disabled]="!_settingsService.settings.enabled"
|
||||||
name="googleApiKey" required>
|
name="googleApiKey" required>
|
||||||
|
@ -25,20 +25,22 @@ export class SettingsService {
|
|||||||
Map: {
|
Map: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
googleApiKey: ""
|
googleApiKey: ""
|
||||||
}, publicUrl: "",
|
},
|
||||||
|
publicUrl: "",
|
||||||
applicationTitle: "",
|
applicationTitle: "",
|
||||||
enableCache: true,
|
enableCache: true,
|
||||||
enableOnScrollRendering: true,
|
enableOnScrollRendering: true,
|
||||||
enableOnScrollThumbnailPrioritising: true,
|
enableOnScrollThumbnailPrioritising: true,
|
||||||
authenticationRequired: true
|
authenticationRequired: true
|
||||||
}, Server: {
|
},
|
||||||
|
Server: {
|
||||||
database: {
|
database: {
|
||||||
type: DatabaseType.memory
|
type: DatabaseType.memory
|
||||||
},
|
},
|
||||||
imagesFolder: "",
|
|
||||||
sharing: {
|
sharing: {
|
||||||
updateTimeout: 2000
|
updateTimeout: 2000
|
||||||
},
|
},
|
||||||
|
imagesFolder: "",
|
||||||
enableThreading: true,
|
enableThreading: true,
|
||||||
port: 80,
|
port: 80,
|
||||||
thumbnail: {
|
thumbnail: {
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<div class="panel-info" *ngIf="!enabled">
|
<div class="panel-info" *ngIf="!enabled">
|
||||||
To protect the site with password / have login enable this
|
To protect the site with password / have login enable this.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<base href="/"/>
|
<base href="/"/>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>PiGallery2</title>
|
<title>Loading..</title>
|
||||||
<link rel="shortcut icon" href="assets/icon.png">
|
<link rel="shortcut icon" href="assets/icon.png">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link href="../node_modules/ng2-toastr/bundles/ng2-toastr.min.css" rel="stylesheet"/>
|
<link href="../node_modules/ng2-toastr/bundles/ng2-toastr.min.css" rel="stylesheet"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user