diff --git a/src/app/general/edit-stakeholder/edit-stakeholder.component.ts b/src/app/general/edit-stakeholder/edit-stakeholder.component.ts index ebcf7b4..41e6f4f 100644 --- a/src/app/general/edit-stakeholder/edit-stakeholder.component.ts +++ b/src/app/general/edit-stakeholder/edit-stakeholder.component.ts @@ -105,7 +105,7 @@ export class EditStakeholderComponent implements OnDestroy { public stakeholderUtils: StakeholderUtils = new StakeholderUtils(); public defaultStakeholdersOptions: Option[]; public defaultStakeholders: Stakeholder[]; - public stakeholders: Stakeholder[]; + public alias: string[]; public stakeholder: Stakeholder; public isDefault: boolean; public isNew: boolean; @@ -131,11 +131,11 @@ export class EditStakeholderComponent implements OnDestroy { this.reset(); } - public init(stakeholder: Stakeholder, stakeholders: Stakeholder[], defaultStakeholders: Stakeholder[], isDefault: boolean, isNew: boolean) { + public init(stakeholder: Stakeholder, alias: string[], defaultStakeholders: Stakeholder[], isDefault: boolean, isNew: boolean) { this.reset(); this.deleteCurrentPhoto = false; this.stakeholder = stakeholder; - this.stakeholders = stakeholders; + this.alias = alias; this.defaultStakeholders = defaultStakeholders; this.isDefault = isDefault; this.isNew = isNew; @@ -154,10 +154,8 @@ export class EditStakeholderComponent implements OnDestroy { alias: this.fb.control(this.stakeholder.alias, [ Validators.required, - this.stakeholderUtils.aliasValidator( - (this.isDefault) ? - this.defaultStakeholders.filter(stakeholder => stakeholder.alias !== this.stakeholder.alias) : - this.stakeholders.filter(stakeholder => stakeholder.alias !== this.stakeholder.alias) + this.stakeholderUtils.aliasValidatorString( + this.alias.filter(alias => alias !== this.stakeholder.alias) )] ), isDefault: this.fb.control((this.isDefault)), @@ -247,7 +245,6 @@ export class EditStakeholderComponent implements OnDestroy { this.deletePhoto(); this.removePhoto(); this.stakeholderFb.get('logoUrl').setValue(res.filename); - console.debug(this.stakeholderFb.value); this.saveStakeholder(callback, errorCallback); }, error => { this.uploadError = "An error has been occurred during upload your image. Try again later"; diff --git a/src/app/general/general.component.ts b/src/app/general/general.component.ts index 77939f6..b12a171 100644 --- a/src/app/general/general.component.ts +++ b/src/app/general/general.component.ts @@ -15,7 +15,7 @@ import {Title} from "@angular/platform-browser"; export class GeneralComponent implements OnInit, OnDestroy { public stakeholder: Stakeholder; - public stakeholders: Stakeholder[]; + public alias: string[]; public properties: EnvProperties = properties; public defaultStakeholders: Stakeholder[]; public loading: boolean = false; @@ -34,11 +34,11 @@ export class GeneralComponent implements OnInit, OnDestroy { this.title.setTitle(this.stakeholder.name + " | General"); let data = zip( this.stakeholderService.getDefaultStakeholders(this.properties.monitorServiceAPIURL), - this.stakeholderService.getStakeholders(this.properties.monitorServiceAPIURL) + this.stakeholderService.getAlias(this.properties.monitorServiceAPIURL) ); this.subscriptions.push(data.subscribe(res => { this.defaultStakeholders = res[0]; - this.stakeholders = res[1]; + this.alias = res[1]; this.reset(); this.loading = false; })); @@ -47,7 +47,7 @@ export class GeneralComponent implements OnInit, OnDestroy { } public reset() { - this.editStakeholderComponent.init(this.stakeholder, this.stakeholders, this.defaultStakeholders, this.stakeholder.defaultId == null, false) + this.editStakeholderComponent.init(this.stakeholder, this.alias, this.defaultStakeholders, this.stakeholder.defaultId == null, false) } diff --git a/src/app/manageStakeholders/manageStakeholders.component.ts b/src/app/manageStakeholders/manageStakeholders.component.ts index 14863b6..9a498a7 100644 --- a/src/app/manageStakeholders/manageStakeholders.component.ts +++ b/src/app/manageStakeholders/manageStakeholders.component.ts @@ -28,6 +28,7 @@ export class ManageStakeholdersComponent implements OnInit, OnDestroy { public stakeholderUtils: StakeholderUtils = new StakeholderUtils(); public defaultStakeholders: Stakeholder[]; public stakeholders: Stakeholder[]; + public alias: string[]; public stakeholder: Stakeholder; public index: number; public user = null; @@ -73,13 +74,15 @@ export class ManageStakeholdersComponent implements OnInit, OnDestroy { })); let data = zip( this.stakeholderService.getDefaultStakeholders(this.properties.monitorServiceAPIURL), - this.stakeholderService.getMyStakeholders(this.properties.monitorServiceAPIURL) + this.stakeholderService.getMyStakeholders(this.properties.monitorServiceAPIURL), + this.stakeholderService.getAlias(this.properties.monitorServiceAPIURL) ); this.subscriptions.push(data.subscribe(res => { this.defaultStakeholders = res[0]; this.stakeholders = res[1]; this.displayDefaultStakeholders = res[0]; this.displayStakeholders = res[1]; + this.alias = res[2]; this.loading = false; })); @@ -161,7 +164,7 @@ export class ManageStakeholdersComponent implements OnInit, OnDestroy { } else { this.stakeholder = stakeholder; } - this.editStakeholderComponent.init(this.stakeholder, this.stakeholders, this.defaultStakeholders, isDefault, this.index === -1); + this.editStakeholderComponent.init(this.stakeholder, this.alias, this.defaultStakeholders, isDefault, this.index === -1); if (this.index !== -1) { this.callback = (stakeholder: Stakeholder) => { if (stakeholder.defaultId == null) { diff --git a/src/app/utils/indicator-utils.ts b/src/app/utils/indicator-utils.ts index 78a643b..a57d0f1 100644 --- a/src/app/utils/indicator-utils.ts +++ b/src/app/utils/indicator-utils.ts @@ -132,6 +132,17 @@ export class StakeholderUtils { //console.log (funder); return funder; } + + aliasValidatorString(elements: string[]): ValidatorFn { + return (control: AbstractControl): { [key: string]: string } | null => { + if (control.value && elements.find(element => + element === control.value + )) { + return {'error': 'Alias already in use'}; + } + return null; + } + } aliasValidator(elements: any[]): ValidatorFn { return (control: AbstractControl): { [key: string]: string } | null => {