mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
implementing share settings
This commit is contained in:
parent
5b5affd227
commit
47a2aed3b4
@ -70,6 +70,29 @@ export class AdminMWs {
|
||||
}
|
||||
}
|
||||
|
||||
public static async updateShareSettings(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 {
|
||||
//only updating explicitly set config (not saving config set by the diagnostics)
|
||||
const original = Config.original();
|
||||
await ConfigDiagnostics.testSharingConfig(<ClientConfig.SharingConfig>req.body.settings, original);
|
||||
|
||||
Config.Client.Sharing = <ClientConfig.SharingConfig>req.body.settings;
|
||||
original.Client.Sharing = <ClientConfig.SharingConfig>req.body.settings;
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static async updateSearchSettings(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"));
|
||||
|
@ -67,6 +67,12 @@ export class AdminRouter {
|
||||
AdminMWs.updateSearchSettings,
|
||||
RenderingMWs.renderOK
|
||||
);
|
||||
app.put("/api/settings/share",
|
||||
AuthenticationMWs.authenticate,
|
||||
AuthenticationMWs.authorise(UserRoles.Admin),
|
||||
AdminMWs.updateShareSettings,
|
||||
RenderingMWs.renderOK
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
<settings-database></settings-database>
|
||||
<settings-thumbnail></settings-thumbnail>
|
||||
<settings-search></settings-search>
|
||||
<settings-share></settings-share>
|
||||
<settings-map></settings-map>
|
||||
</div>
|
||||
</app-frame>
|
||||
|
@ -50,6 +50,7 @@ import {TooltipModule} from "ngx-bootstrap/tooltip";
|
||||
import {ThumbnailSettingsComponent} from "./settings/thumbnail/thumbanil.settings.component";
|
||||
import {SearchSettingsComponent} from "./settings/search/search.settings.component";
|
||||
import {SettingsService} from "./settings/settings.service";
|
||||
import {ShareSettingsComponent} from "./settings/share/share.settings.component";
|
||||
@Injectable()
|
||||
export class GoogleMapsConfig {
|
||||
apiKey: string;
|
||||
@ -100,6 +101,7 @@ export class GoogleMapsConfig {
|
||||
MapSettingsComponent,
|
||||
ThumbnailSettingsComponent,
|
||||
SearchSettingsComponent,
|
||||
ShareSettingsComponent,
|
||||
StringifyRole],
|
||||
providers: [
|
||||
{provide: LAZY_MAPS_API_CONFIG, useClass: GoogleMapsConfig},
|
||||
|
@ -0,0 +1,3 @@
|
||||
.panel-info {
|
||||
text-align: center;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<form #settingsForm="ngForm">
|
||||
<div class="panel panel-default"
|
||||
[ngClass]="!_settingsService.isSupported()?'panel-warning':''">
|
||||
[ngClass]="_settingsService.settings.enabled && !_settingsService.isSupported()?'panel-warning':''">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title col-sm-4">Search settings</h3>
|
||||
<div class="switch-wrapper col-sm-8">
|
||||
@ -21,45 +21,51 @@
|
||||
<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="autocompleteEnabled">Autocomplete</label>
|
||||
<div class="col-sm-10">
|
||||
<bSwitch
|
||||
id="autocompleteEnabled"
|
||||
class="switch"
|
||||
name="autocompleteEnabled"
|
||||
[switch-on-color]="'primary'"
|
||||
[switch-disabled]="!_settingsService.settings.enabled"
|
||||
[switch-inverse]="'inverse'"
|
||||
[switch-off-text]="'Disabled'"
|
||||
[switch-on-text]="'Enabled'"
|
||||
[switch-handle-width]="'100'"
|
||||
[switch-label-width]="'20'"
|
||||
[(ngModel)]="_settingsService.settings.autocompleteEnabled">
|
||||
</bSwitch>
|
||||
<ng-container *ngIf="_settingsService.settings.enabled || _settingsService.isSupported()">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="autocompleteEnabled">Autocomplete</label>
|
||||
<div class="col-sm-10">
|
||||
<bSwitch
|
||||
id="autocompleteEnabled"
|
||||
class="switch"
|
||||
name="autocompleteEnabled"
|
||||
[switch-on-color]="'primary'"
|
||||
[switch-disabled]="!_settingsService.settings.enabled"
|
||||
[switch-inverse]="'inverse'"
|
||||
[switch-off-text]="'Disabled'"
|
||||
[switch-on-text]="'Enabled'"
|
||||
[switch-handle-width]="'100'"
|
||||
[switch-label-width]="'20'"
|
||||
[(ngModel)]="_settingsService.settings.autocompleteEnabled">
|
||||
</bSwitch>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="instantSearchEnabled">Instant search</label>
|
||||
<div class="col-sm-10">
|
||||
<bSwitch
|
||||
id="instantSearchEnabled"
|
||||
class="switch"
|
||||
name="instantSearchEnabled"
|
||||
[switch-on-color]="'primary'"
|
||||
[switch-disabled]="!_settingsService.settings.enabled"
|
||||
[switch-inverse]="'inverse'"
|
||||
[switch-off-text]="'Disabled'"
|
||||
[switch-on-text]="'Enabled'"
|
||||
[switch-handle-width]="'100'"
|
||||
[switch-label-width]="'20'"
|
||||
[(ngModel)]="_settingsService.settings.instantSearchEnabled">
|
||||
</bSwitch>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="instantSearchEnabled">Instant search</label>
|
||||
<div class="col-sm-10">
|
||||
<bSwitch
|
||||
id="instantSearchEnabled"
|
||||
class="switch"
|
||||
name="instantSearchEnabled"
|
||||
[switch-on-color]="'primary'"
|
||||
[switch-disabled]="!_settingsService.settings.enabled"
|
||||
[switch-inverse]="'inverse'"
|
||||
[switch-off-text]="'Disabled'"
|
||||
[switch-on-text]="'Enabled'"
|
||||
[switch-handle-width]="'100'"
|
||||
[switch-label-width]="'20'"
|
||||
[(ngModel)]="_settingsService.settings.instantSearchEnabled">
|
||||
</bSwitch>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</ng-container>
|
||||
<div class="panel-info" *ngIf="(!_settingsService.settings.enabled && !_settingsService.isSupported())">
|
||||
Search is not supported with these settings
|
||||
</div>
|
||||
<button class="btn btn-success pull-right"
|
||||
[disabled]="!settingsForm.form.valid || !changed || inProgress"
|
||||
(click)="save()">Save
|
||||
|
3
frontend/app/settings/share/share.settings.component.css
Normal file
3
frontend/app/settings/share/share.settings.component.css
Normal file
@ -0,0 +1,3 @@
|
||||
.panel-info {
|
||||
text-align: center;
|
||||
}
|
58
frontend/app/settings/share/share.settings.component.html
Normal file
58
frontend/app/settings/share/share.settings.component.html
Normal file
@ -0,0 +1,58 @@
|
||||
<form #settingsForm="ngForm">
|
||||
<div class="panel panel-default"
|
||||
[ngClass]="_settingsService.settings.enabled && !_settingsService.isSupported()?'panel-warning':''">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title col-sm-4">Share settings</h3>
|
||||
<div class="switch-wrapper col-sm-8">
|
||||
<bSwitch
|
||||
class="switch"
|
||||
name="enabled"
|
||||
[switch-on-color]="'success'"
|
||||
[switch-inverse]="'inverse'"
|
||||
[switch-off-text]="'Disabled'"
|
||||
[switch-on-text]="'Enabled'"
|
||||
[switch-disabled]="inProgress || (!_settingsService.settings.enabled && !_settingsService.isSupported())"
|
||||
[switch-handle-width]="'100'"
|
||||
[switch-label-width]="'20'"
|
||||
[(ngModel)]="_settingsService.settings.enabled">
|
||||
</bSwitch>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div [hidden]="!error" class="alert alert-danger" role="alert"><strong>Error: </strong>{{error}}</div>
|
||||
|
||||
<ng-container *ngIf="_settingsService.settings.enabled || _settingsService.isSupported()">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="passwordProtected">Password protected</label>
|
||||
<div class="col-sm-10">
|
||||
<bSwitch
|
||||
id="passwordProtected"
|
||||
class="switch"
|
||||
name="passwordProtected"
|
||||
[switch-on-color]="'primary'"
|
||||
[switch-disabled]="!_settingsService.settings.enabled"
|
||||
[switch-inverse]="'inverse'"
|
||||
[switch-off-text]="'Disabled'"
|
||||
[switch-on-text]="'Enabled'"
|
||||
[switch-handle-width]="'100'"
|
||||
[switch-label-width]="'20'"
|
||||
[(ngModel)]="_settingsService.settings.passwordProtected">
|
||||
</bSwitch>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</ng-container>
|
||||
<div class="panel-info" *ngIf="(!_settingsService.settings.enabled && !_settingsService.isSupported())">
|
||||
Sharing is not supported with these settings
|
||||
</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>
|
29
frontend/app/settings/share/share.settings.component.ts
Normal file
29
frontend/app/settings/share/share.settings.component.ts
Normal file
@ -0,0 +1,29 @@
|
||||
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 {ClientConfig} from "../../../../common/config/public/ConfigClass";
|
||||
import {ShareSettingsService} from "./share.settings.service";
|
||||
|
||||
@Component({
|
||||
selector: 'settings-share',
|
||||
templateUrl: './share.settings.component.html',
|
||||
styleUrls: ['./share.settings.component.css',
|
||||
'./../_abstract/abstract.settings.component.css'],
|
||||
providers: [ShareSettingsService],
|
||||
})
|
||||
export class ShareSettingsComponent extends SettingsComponent<ClientConfig.SharingConfig> {
|
||||
|
||||
constructor(_authService: AuthenticationService,
|
||||
_navigation: NavigationService,
|
||||
_settingsService: ShareSettingsService,
|
||||
notification: NotificationService) {
|
||||
super("Share", _authService, _navigation, _settingsService, notification);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
25
frontend/app/settings/share/share.settings.service.ts
Normal file
25
frontend/app/settings/share/share.settings.service.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import {Injectable} from "@angular/core";
|
||||
import {NetworkService} from "../../model/network/network.service";
|
||||
import {DatabaseType} from "../../../../common/config/private/IPrivateConfig";
|
||||
import {ClientConfig} from "../../../../common/config/public/ConfigClass";
|
||||
import {SettingsService} from "../settings.service";
|
||||
import {AbstractSettingsService} from "../_abstract/abstract.settings.service";
|
||||
|
||||
@Injectable()
|
||||
export class ShareSettingsService extends AbstractSettingsService<ClientConfig.SharingConfig> {
|
||||
constructor(private _networkService: NetworkService,
|
||||
_settingsService: SettingsService) {
|
||||
super(_settingsService, s => s.Client.Sharing);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public isSupported(): boolean {
|
||||
return this._settingsService.settings.value.Server.database.type != DatabaseType.memory;
|
||||
}
|
||||
|
||||
public updateSettings(settings: ClientConfig.SharingConfig): Promise<void> {
|
||||
return this._networkService.putJson("/settings/share", {settings: settings});
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user