From e8c9c209dcc47b7df5ff3d04f783d63c921267e4 Mon Sep 17 00:00:00 2001 From: Maurizio Vitale Date: Mon, 25 Sep 2017 22:13:45 +0100 Subject: [PATCH] Save host only when apply (#2371) [ADF-1581] Demo shell - Improve host setting configuration check --- .../settings/settings.component.html | 2 +- .../components/settings/settings.component.ts | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/demo-shell-ng2/app/components/settings/settings.component.html b/demo-shell-ng2/app/components/settings/settings.component.html index 9e66b624ac..4887e80030 100644 --- a/demo-shell-ng2/app/components/settings/settings.component.html +++ b/demo-shell-ng2/app/components/settings/settings.component.html @@ -51,7 +51,7 @@ {{'SETTINGS.BACK' | translate }} - diff --git a/demo-shell-ng2/app/components/settings/settings.component.ts b/demo-shell-ng2/app/components/settings/settings.component.ts index efef660fdd..e0eca71dd6 100644 --- a/demo-shell-ng2/app/components/settings/settings.component.ts +++ b/demo-shell-ng2/app/components/settings/settings.component.ts @@ -29,23 +29,24 @@ export class SettingsComponent { HOST_REGEX: string = '^(http|https):\/\/.*[^/]$'; ecmHost: string; + ecmHostTmp: string; bpmHost: string; + bpmHostTmp: string; urlFormControlEcm = new FormControl('', [Validators.required, Validators.pattern(this.HOST_REGEX)]); urlFormControlBpm = new FormControl('', [Validators.required, Validators.pattern(this.HOST_REGEX)]); constructor(private settingsService: AlfrescoSettingsService, private storage: StorageService, private logService: LogService) { - this.ecmHost = storage.getItem('ecmHost') || this.settingsService.ecmHost; - this.bpmHost = storage.getItem('bpmHost') || this.settingsService.bpmHost; + this.ecmHostTmp = this.ecmHost = storage.getItem('ecmHost') || this.settingsService.ecmHost; + this.bpmHostTmp = this.bpmHost = storage.getItem('bpmHost') || this.settingsService.bpmHost; } public onChangeECMHost(event: KeyboardEvent): void { let value = (event.target).value.trim(); if (value && this.isValidUrl(value)) { this.logService.info(`ECM host: ${value}`); - this.ecmHost = value; - this.storage.setItem(`ecmHost`, value); + this.ecmHostTmp = value; } else { console.error('Ecm address does not match the pattern'); } @@ -55,13 +56,22 @@ export class SettingsComponent { let value = (event.target).value.trim(); if (value && this.isValidUrl(value)) { this.logService.info(`BPM host: ${value}`); - this.bpmHost = value; - this.storage.setItem(`bpmHost`, value); + this.bpmHostTmp = value; } else { console.error('Bpm address does not match the pattern'); } } + public save(event: KeyboardEvent): void { + if (this.bpmHost !== this.bpmHostTmp) { + this.storage.setItem(`bpmHost`, this.bpmHostTmp); + } + if (this.ecmHost !== this.ecmHostTmp) { + this.storage.setItem(`ecmHost`, this.ecmHostTmp); + } + window.location.href = '/'; + } + isValidUrl(url: string) { return /^(http|https):\/\/.*/.test(url); }