[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 stakeholderUtils: StakeholderUtils = new StakeholderUtils();
|
||||||
public defaultStakeholdersOptions: Option[];
|
public defaultStakeholdersOptions: Option[];
|
||||||
public defaultStakeholders: Stakeholder[];
|
public defaultStakeholders: Stakeholder[];
|
||||||
public stakeholders: Stakeholder[];
|
public alias: string[];
|
||||||
public stakeholder: Stakeholder;
|
public stakeholder: Stakeholder;
|
||||||
public isDefault: boolean;
|
public isDefault: boolean;
|
||||||
public isNew: boolean;
|
public isNew: boolean;
|
||||||
|
@ -131,11 +131,11 @@ export class EditStakeholderComponent implements OnDestroy {
|
||||||
this.reset();
|
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.reset();
|
||||||
this.deleteCurrentPhoto = false;
|
this.deleteCurrentPhoto = false;
|
||||||
this.stakeholder = stakeholder;
|
this.stakeholder = stakeholder;
|
||||||
this.stakeholders = stakeholders;
|
this.alias = alias;
|
||||||
this.defaultStakeholders = defaultStakeholders;
|
this.defaultStakeholders = defaultStakeholders;
|
||||||
this.isDefault = isDefault;
|
this.isDefault = isDefault;
|
||||||
this.isNew = isNew;
|
this.isNew = isNew;
|
||||||
|
@ -154,10 +154,8 @@ export class EditStakeholderComponent implements OnDestroy {
|
||||||
alias: this.fb.control(this.stakeholder.alias,
|
alias: this.fb.control(this.stakeholder.alias,
|
||||||
[
|
[
|
||||||
Validators.required,
|
Validators.required,
|
||||||
this.stakeholderUtils.aliasValidator(
|
this.stakeholderUtils.aliasValidatorString(
|
||||||
(this.isDefault) ?
|
this.alias.filter(alias => alias !== this.stakeholder.alias)
|
||||||
this.defaultStakeholders.filter(stakeholder => stakeholder.alias !== this.stakeholder.alias) :
|
|
||||||
this.stakeholders.filter(stakeholder => stakeholder.alias !== this.stakeholder.alias)
|
|
||||||
)]
|
)]
|
||||||
),
|
),
|
||||||
isDefault: this.fb.control((this.isDefault)),
|
isDefault: this.fb.control((this.isDefault)),
|
||||||
|
@ -247,7 +245,6 @@ export class EditStakeholderComponent implements OnDestroy {
|
||||||
this.deletePhoto();
|
this.deletePhoto();
|
||||||
this.removePhoto();
|
this.removePhoto();
|
||||||
this.stakeholderFb.get('logoUrl').setValue(res.filename);
|
this.stakeholderFb.get('logoUrl').setValue(res.filename);
|
||||||
console.debug(this.stakeholderFb.value);
|
|
||||||
this.saveStakeholder(callback, errorCallback);
|
this.saveStakeholder(callback, errorCallback);
|
||||||
}, error => {
|
}, error => {
|
||||||
this.uploadError = "An error has been occurred during upload your image. Try again later";
|
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 {
|
export class GeneralComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
public stakeholder: Stakeholder;
|
public stakeholder: Stakeholder;
|
||||||
public stakeholders: Stakeholder[];
|
public alias: string[];
|
||||||
public properties: EnvProperties = properties;
|
public properties: EnvProperties = properties;
|
||||||
public defaultStakeholders: Stakeholder[];
|
public defaultStakeholders: Stakeholder[];
|
||||||
public loading: boolean = false;
|
public loading: boolean = false;
|
||||||
|
@ -34,11 +34,11 @@ export class GeneralComponent implements OnInit, OnDestroy {
|
||||||
this.title.setTitle(this.stakeholder.name + " | General");
|
this.title.setTitle(this.stakeholder.name + " | General");
|
||||||
let data = zip(
|
let data = zip(
|
||||||
this.stakeholderService.getDefaultStakeholders(this.properties.monitorServiceAPIURL),
|
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.subscriptions.push(data.subscribe(res => {
|
||||||
this.defaultStakeholders = res[0];
|
this.defaultStakeholders = res[0];
|
||||||
this.stakeholders = res[1];
|
this.alias = res[1];
|
||||||
this.reset();
|
this.reset();
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}));
|
}));
|
||||||
|
@ -47,7 +47,7 @@ export class GeneralComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
public reset() {
|
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 stakeholderUtils: StakeholderUtils = new StakeholderUtils();
|
||||||
public defaultStakeholders: Stakeholder[];
|
public defaultStakeholders: Stakeholder[];
|
||||||
public stakeholders: Stakeholder[];
|
public stakeholders: Stakeholder[];
|
||||||
|
public alias: string[];
|
||||||
public stakeholder: Stakeholder;
|
public stakeholder: Stakeholder;
|
||||||
public index: number;
|
public index: number;
|
||||||
public user = null;
|
public user = null;
|
||||||
|
@ -73,13 +74,15 @@ export class ManageStakeholdersComponent implements OnInit, OnDestroy {
|
||||||
}));
|
}));
|
||||||
let data = zip(
|
let data = zip(
|
||||||
this.stakeholderService.getDefaultStakeholders(this.properties.monitorServiceAPIURL),
|
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.subscriptions.push(data.subscribe(res => {
|
||||||
this.defaultStakeholders = res[0];
|
this.defaultStakeholders = res[0];
|
||||||
this.stakeholders = res[1];
|
this.stakeholders = res[1];
|
||||||
this.displayDefaultStakeholders = res[0];
|
this.displayDefaultStakeholders = res[0];
|
||||||
this.displayStakeholders = res[1];
|
this.displayStakeholders = res[1];
|
||||||
|
this.alias = res[2];
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -161,7 +164,7 @@ export class ManageStakeholdersComponent implements OnInit, OnDestroy {
|
||||||
} else {
|
} else {
|
||||||
this.stakeholder = stakeholder;
|
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) {
|
if (this.index !== -1) {
|
||||||
this.callback = (stakeholder: Stakeholder) => {
|
this.callback = (stakeholder: Stakeholder) => {
|
||||||
if (stakeholder.defaultId == null) {
|
if (stakeholder.defaultId == null) {
|
||||||
|
|
|
@ -133,6 +133,17 @@ export class StakeholderUtils {
|
||||||
return 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 {
|
aliasValidator(elements: any[]): ValidatorFn {
|
||||||
return (control: AbstractControl): { [key: string]: string } | null => {
|
return (control: AbstractControl): { [key: string]: string } | null => {
|
||||||
if (control.value && elements.find(element =>
|
if (control.value && elements.find(element =>
|
||||||
|
|
Loading…
Reference in New Issue