184 lines
4.9 KiB
TypeScript
184 lines
4.9 KiB
TypeScript
/** @file
|
|
* @author Edouard DUPIN
|
|
* @copyright 2018, Edouard DUPIN, all right reserved
|
|
* @license PROPRIETARY (see license file)
|
|
*/
|
|
|
|
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
import { SettingsService } from 'app/service';
|
|
import { isSettingsItem, SettingsItem, SettingType } from 'common/component/render-settings/render-settings';
|
|
import {
|
|
isNullOrUndefined,
|
|
isObject,
|
|
isOptionalArrayOf,
|
|
isOptionalOf,
|
|
isString,
|
|
} from 'common/utils';
|
|
|
|
|
|
export interface SettingsItem222 {
|
|
// Displayed Title
|
|
title?: string;
|
|
// Description of the parameter
|
|
description?: string;
|
|
// If true the parameter is applied directly to the backend
|
|
directApply?: boolean;
|
|
// Parameter key to SET/GET or the sub-menu
|
|
values?: SettingsItem[];
|
|
// Local new Parameters:
|
|
newValues?: object;
|
|
// local state: if undefined => no change, otherwise the number of wrong values.
|
|
state?: number;
|
|
// values get from the server.
|
|
serverValues?: object;
|
|
}
|
|
|
|
export function isSettingsItem222(data: any): data is SettingsItem222 {
|
|
if (isNullOrUndefined(data)) {
|
|
return false;
|
|
}
|
|
if (!isObject(data)) {
|
|
return false;
|
|
}
|
|
if (!isOptionalOf(data.title, isString)) {
|
|
return false;
|
|
}
|
|
if (!isOptionalOf(data.description, isString)) {
|
|
return false;
|
|
}
|
|
if (!isOptionalOf(data.key, isString)) {
|
|
return false;
|
|
}
|
|
if (!isOptionalArrayOf(data.values, isSettingsItem)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Component({
|
|
selector: 'app-settings',
|
|
templateUrl: './settings.html',
|
|
styleUrls: ['./settings.less'],
|
|
})
|
|
export class SettingsScene implements OnInit {
|
|
page = '';
|
|
|
|
constructor(
|
|
private settingService: SettingsService,
|
|
private cdr: ChangeDetectorRef,
|
|
) {}
|
|
menu: SettingsItem222[] = [
|
|
{
|
|
title: 'Authentication:',
|
|
description: 'Manage the right of access to the web-services',
|
|
values: undefined,
|
|
},
|
|
];
|
|
|
|
// this permit to clear the input menu...
|
|
|
|
configureEditInput() {
|
|
const root = this.menu[0];
|
|
root.values = [
|
|
{
|
|
type: SettingType.BOOLEAN,
|
|
title: 'Enable Sign-in',
|
|
description: 'Enable User to sign-in (only authorize administrators).',
|
|
key: 'SIGN_IN_ENABLE',
|
|
value: root.serverValues["SIGN_IN_ENABLE"],
|
|
},
|
|
{
|
|
type: SettingType.LINE,
|
|
},
|
|
{
|
|
type: SettingType.BOOLEAN,
|
|
title: 'Enable Sign-up',
|
|
description: 'Enable unregister user to sign-up (register) on this web-site.',
|
|
key: 'SIGN_UP_ENABLE',
|
|
value: root.serverValues["SIGN_UP_ENABLE"],
|
|
},
|
|
{
|
|
type: SettingType.STRING,
|
|
title: 'Sign-up e-mail filter',
|
|
description: 'Specify the e-mail filtering to sign-up (regex).',
|
|
key: 'SIGN_UP_FILTER',
|
|
value: root.serverValues["SIGN_UP_FILTER"],
|
|
},
|
|
{
|
|
type: SettingType.BOOLEAN,
|
|
title: 'e-mail validation required',
|
|
description: 'Force-user to validate his e-mail to access on service.',
|
|
key: 'EMAIL_VALIDATION_REQUIRED',
|
|
value: root.serverValues["EMAIL_VALIDATION_REQUIRED"],
|
|
},
|
|
],
|
|
this.menu[0].state = undefined;
|
|
this.menu[0].newValues = {};
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.settingService
|
|
.gets(['SIGN_IN_ENABLE', 'SIGN_UP_ENABLE', 'SIGN_UP_FILTER', 'EMAIL_VALIDATION_REQUIRED'])
|
|
.then((response: object) => {
|
|
console.log(`??? get full response: ${JSON.stringify(response, null, 4)}`);
|
|
this.menu[0].serverValues = response;
|
|
this.configureEditInput();
|
|
})
|
|
.catch((error: any) => {
|
|
console.log(`??? get ERROR response: ${JSON.stringify(error, null, 4)}`);
|
|
});
|
|
}
|
|
onState(value: number, elem: SettingsItem222) {
|
|
console.log(`changeState : ${JSON.stringify(value, null, 2)}`);
|
|
elem.state = value;
|
|
// we do not change the main ref ==> notify angular that something have change and need to be re-render???
|
|
this.cdr.detectChanges();
|
|
}
|
|
onDeltaValues(value: any, elem: SettingsItem222) {
|
|
console.log(`onDeltaValues : ${JSON.stringify(value, null, 2)}`);
|
|
elem.newValues = value;
|
|
// we do not change the main ref ==> notify angular that something have change and need to be re-render???
|
|
this.cdr.detectChanges();
|
|
}
|
|
/*
|
|
changeValueElement(newValue: string, elem: SettingsItem222, parent: SettingsItem222): void {
|
|
if (elem.value === newValue) {
|
|
elem.newValue = undefined;
|
|
this.updateSendNeeded(parent);
|
|
return;
|
|
}
|
|
elem.newValue = newValue;
|
|
this.updateSendNeeded(parent);
|
|
}
|
|
updateSendNeeded(parent: SettingsItem222) {
|
|
if (isNullOrUndefined(parent.value)) {
|
|
return;
|
|
}
|
|
if (!isArrayOf(parent.value, isSettingsItem222)) {
|
|
console.log('Error Can not convert type setting menu');
|
|
return;
|
|
}
|
|
let needUpdate = false;
|
|
for (let elem of parent.value) {
|
|
if (!isUndefined(elem.newValue)) {
|
|
needUpdate = true;
|
|
break;
|
|
}
|
|
}
|
|
parent.newValue = needUpdate;
|
|
}
|
|
onUpdate(parent: SettingsItem222) {}
|
|
*/
|
|
onUpdate(elem: SettingsItem222) {
|
|
this.settingService.sets(elem.newValues)
|
|
.then((result: object) => {
|
|
// TODO ...
|
|
//multipleResponse.add(key, result);
|
|
})
|
|
.catch((error: any) => {
|
|
//multipleResponse.fail(key, error);
|
|
});
|
|
}
|
|
}
|