[Monitor Dashboard | Trunk]: Add get alias method to check if alias is already in use
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@60099 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
29d1c1f883
commit
44c61ac015
|
@ -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";
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 => {
|
||||
|
|
Loading…
Reference in New Issue