1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-04 10:34:45 +02:00

implementing basic settings

This commit is contained in:
Braun Patrik 2017-07-15 16:09:48 +02:00
parent 47a2aed3b4
commit 9745ab216f
13 changed files with 173 additions and 6 deletions

View File

@ -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));
}
}
}

View File

@ -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
);
};

View File

@ -0,0 +1,6 @@
export interface BasicConfigDTO {
imagesFolder: string;
publicUrl: string;
applicationTitle: string;
port: number;
}

View File

@ -21,6 +21,7 @@
</div>
</div>
<settings-basic></settings-basic>
<settings-usermanager></settings-usermanager>
<settings-database></settings-database>
<settings-thumbnail></settings-thumbnail>

View File

@ -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},

View 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>

View 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);
}
}

View 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});
}
}

View File

@ -21,7 +21,7 @@
<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"
[disabled]="!_settingsService.settings.enabled"
name="googleApiKey" required>

View File

@ -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: {

View File

@ -57,7 +57,7 @@
</button>
</ng-container>
<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>

View File

@ -3,7 +3,7 @@
<head>
<base href="/"/>
<meta charset="UTF-8">
<title>PiGallery2</title>
<title>Loading..</title>
<link rel="shortcut icon" href="assets/icon.png">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="../node_modules/ng2-toastr/bundles/ng2-toastr.min.css" rel="stylesheet"/>