diff --git a/monitor-admin/general/edit-stakeholder/edit-stakeholder.component.ts b/monitor-admin/general/edit-stakeholder/edit-stakeholder.component.ts
index 72be3c8a..05eafbd5 100644
--- a/monitor-admin/general/edit-stakeholder/edit-stakeholder.component.ts
+++ b/monitor-admin/general/edit-stakeholder/edit-stakeholder.component.ts
@@ -20,7 +20,7 @@ import {StakeholderBaseComponent} from "../../utils/stakeholder-base.component";
template: `
{
this.user = user;
if (this.isCurator) {
@@ -220,6 +235,7 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
funderType: this.fb.control(this.stakeholder.funderType),
topics: this.fb.control(this.stakeholder.topics),
isUpload: this.fb.control(this.stakeholder.isUpload),
+ copy: this.fb.control(this.stakeholder.copy),
logoUrl: this.fb.control(this.stakeholder.logoUrl),
});
if (this.stakeholder.isUpload) {
@@ -246,7 +262,7 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
this.subscriptions.push(this.stakeholderFb.get('type').valueChanges.subscribe(value => {
this.onTypeChange(value, defaultStakeholders);
}));
- this.stakeholderFb.setControl('defaultId', this.fb.control(stakeholder.defaultId, (this.isDefault && !this.isNew) ? [] : Validators.required));
+ this.stakeholderFb.setControl('defaultId', this.fb.control(this.stakeholder.defaultId, (this.isDefault && !this.isNew) ? [] : Validators.required));
if (!this.isNew) {
this.notification = NotificationUtils.editStakeholder(this.user.firstname + ' ' + this.user.lastname, this.stakeholder.name);
this.notify.reset(this.notification.message);
@@ -304,6 +320,13 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
return this.isNew && this.stakeholderFb.get('type').valid && !!this.defaultStakeholdersOptions;
}
+ public get canChangeCopy(): boolean {
+ return this.isCurator &&
+ !this.stakeholderFb.get('isDefault').getRawValue() &&
+ this.stakeholderFb.get('defaultId').getRawValue() &&
+ this.stakeholderFb.get('defaultId').getRawValue() !== '-1';
+ }
+
reset() {
this.uploadError = null;
this.stakeholderFb = null;
@@ -350,15 +373,15 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
public saveStakeholder(callback: Function, errorCallback: Function = null) {
if (this.isNew) {
- let defaultStakeholder = this.defaultStakeholders.find(value => value._id === this.stakeholderFb.getRawValue().defaultId);
- this.stakeholderFb.setValue(this.stakeholderUtils.createFunderFromDefaultProfile(this.stakeholderFb.getRawValue(),
- (defaultStakeholder ? defaultStakeholder.topics : []), this.stakeholderFb.getRawValue().isDefault));
- this.removePhoto();
+ let copyId = null;
if (this.stakeholderFb.getRawValue().isDefault) {
+ copyId = this.stakeholderFb.getRawValue().defaultId !== '-1'?this.stakeholderFb.getRawValue().defaultId:null;
this.stakeholderFb.get('defaultId').setValue(null);
+ this.stakeholderFb.removeControl('isDefault');
}
+ this.removePhoto();
this.subscriptions.push(this.stakeholderService.buildStakeholder(this.properties.monitorServiceAPIURL,
- this.stakeholderFb.getRawValue()).subscribe(stakeholder => {
+ this.stakeholderFb.getRawValue(), copyId).subscribe(stakeholder => {
this.notification.entity = stakeholder._id;
this.notification.stakeholder = stakeholder.alias;
this.notification.stakeholderType = stakeholder.type;
@@ -375,7 +398,7 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
this.loading = false;
}));
} else {
- this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.getRawValue()).subscribe(stakeholder => {
+ this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.getRawValue(), [], this.isFull).subscribe(stakeholder => {
this.notification.entity = stakeholder._id;
this.notification.stakeholder = stakeholder.alias;
this.notification.stakeholderType = stakeholder.type;
diff --git a/monitor-admin/general/edit-stakeholder/edit-stakeholder.module.ts b/monitor-admin/general/edit-stakeholder/edit-stakeholder.module.ts
index 0ebec4d3..5e325317 100644
--- a/monitor-admin/general/edit-stakeholder/edit-stakeholder.module.ts
+++ b/monitor-admin/general/edit-stakeholder/edit-stakeholder.module.ts
@@ -5,9 +5,10 @@ import {InputModule} from "../../../sharedComponents/input/input.module";
import {ReactiveFormsModule} from "@angular/forms";
import {IconsModule} from "../../../utils/icons/icons.module";
import {NotifyFormModule} from "../../../notifications/notify-form/notify-form.module";
+import {MatSlideToggleModule} from "@angular/material/slide-toggle";
@NgModule({
- imports: [CommonModule, InputModule, ReactiveFormsModule, IconsModule, NotifyFormModule],
+ imports: [CommonModule, InputModule, ReactiveFormsModule, IconsModule, NotifyFormModule, MatSlideToggleModule],
declarations: [EditStakeholderComponent],
exports: [EditStakeholderComponent]
})
diff --git a/monitor-admin/general/general.component.ts b/monitor-admin/general/general.component.ts
index fda34d94..2f28f504 100644
--- a/monitor-admin/general/general.component.ts
+++ b/monitor-admin/general/general.component.ts
@@ -48,7 +48,7 @@ export class GeneralComponent extends BaseComponent implements OnInit {
}
public reset() {
- this.editStakeholderComponent.init(this.stakeholder, this.alias, this.defaultStakeholders, this.stakeholder.defaultId == null, false)
+ this.editStakeholderComponent.init(this.stakeholder, this.alias, this.defaultStakeholders, this.stakeholder.defaultId == null, false, true)
}
public save() {
diff --git a/monitor-admin/manageStakeholders/manageStakeholders.component.html b/monitor-admin/manageStakeholders/manageStakeholders.component.html
index a876d32a..c96d3f63 100644
--- a/monitor-admin/manageStakeholders/manageStakeholders.component.html
+++ b/monitor-admin/manageStakeholders/manageStakeholders.component.html
@@ -31,7 +31,7 @@
-
+
Profile Templates
pageSize"
(pageChange)="updateCurrentTemplatesPage($event)"
@@ -39,8 +39,7 @@
[totalResults]="displayDefaultStakeholders.length">
-
+
@@ -59,7 +58,7 @@
-
+
Profiles
pageSize"
(pageChange)="updateCurrentPage($event)"
diff --git a/monitor-admin/utils/indicator-utils.ts b/monitor-admin/utils/indicator-utils.ts
index 3e8cf554..41ecbea3 100644
--- a/monitor-admin/utils/indicator-utils.ts
+++ b/monitor-admin/utils/indicator-utils.ts
@@ -127,60 +127,6 @@ export class StakeholderUtils {
return types;
}
- public createFunderFromDefaultProfile(funder: Stakeholder, defaultTopics: Topic[], isDefault: boolean = false): Stakeholder {
- funder.topics = HelperFunctions.copy(defaultTopics);
- for (let topic of funder.topics) {
- topic.defaultId = !isDefault ? topic._id : null;
- topic._id = null;
- for (let category of topic.categories) {
- category.defaultId = !isDefault ? category._id : null;
- category._id = null;
- let subTokeep: SubCategory[] = [];
- for (let subCategory of category.subCategories) {
- subCategory.defaultId = !isDefault ? subCategory._id : null;
- subCategory._id = null;
- subTokeep.push(subCategory);
- for (let section of subCategory.charts) {
- let chartsTokeep: Indicator[] = [];
- section.defaultId = !isDefault ? section._id : null;
- section.stakeholderAlias = funder.alias;
- section._id = null;
- for (let indicator of section.indicators) {
- indicator.defaultId = !isDefault ? indicator._id : null;
- indicator._id = null;
- chartsTokeep.push(indicator);
- for (let indicatorPath of indicator.indicatorPaths) {
- if (indicatorPath.parameters) {
- Object.keys(indicatorPath.parameters).forEach(key => {
- if (key == "index_name") {
- indicatorPath.parameters[key] = funder.index_name;
- } else if (key == "index_id") {
- indicatorPath.parameters[key] = funder.index_id;
- } else if (key == "index_shortName") {
- indicatorPath.parameters[key] = funder.index_shortName.toLowerCase();
- }
- });
- }
- }
- }
- section.indicators = chartsTokeep;
- }
- for (let section of subCategory.numbers) {
- section.defaultId = !isDefault ? section._id : null;
- section.stakeholderAlias = funder.alias;
- section._id = null;
- for (let indicator of section.indicators) {
- indicator.defaultId = !isDefault ? indicator._id : null;
- indicator._id = null;
- }
- }
-
- }
- category.subCategories = subTokeep;
- }
- }
- return funder;
- }
aliasValidatorString(elements: string[]): ValidatorFn {
return (control: AbstractControl): { [key: string]: string } | null => {
diff --git a/monitor/entities/stakeholder.ts b/monitor/entities/stakeholder.ts
index a33506ac..a1670174 100644
--- a/monitor/entities/stakeholder.ts
+++ b/monitor/entities/stakeholder.ts
@@ -37,6 +37,7 @@ export class Stakeholder {
isUpload: boolean = false;
description: string;
topics: any[];
+ copy: boolean = true;
details?: any;
constructor(_id: string, type: StakeholderType, index_id: string, index_name: string, index_shortName: string, alias: string, visibility: Visibility, logoUrl: string, defaultId: string = null, description: string = null) {
@@ -50,6 +51,7 @@ export class Stakeholder {
this.visibility = visibility;
this.logoUrl = logoUrl;
this.description = description;
+ this.copy = !!this.defaultId && this.defaultId !== '-1';
this.topics = [];
}
diff --git a/monitor/services/stakeholder.service.ts b/monitor/services/stakeholder.service.ts
index d8b8bf30..4c597cd2 100644
--- a/monitor/services/stakeholder.service.ts
+++ b/monitor/services/stakeholder.service.ts
@@ -116,11 +116,15 @@ export class StakeholderService {
}));
}
- buildStakeholder(url: string, stakeholder: Stakeholder): Observable {
+ buildStakeholder(url: string, stakeholder: Stakeholder, copyId: string): Observable {
if (stakeholder.alias && stakeholder.alias.startsWith('/')) {
stakeholder.alias = stakeholder.alias.slice(1);
}
- return this.http.post(url + '/build-stakeholder', stakeholder, CustomOptions.registryOptions()).pipe(map(stakeholder => {
+ let copy = {
+ stakeholder: stakeholder,
+ copyId: copyId
+ }
+ return this.http.post(url + '/build-stakeholder', copy, CustomOptions.registryOptions()).pipe(map(stakeholder => {
return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholder));
}));
}
@@ -129,12 +133,12 @@ export class StakeholderService {
return this.http.post(url + '/' + path.join('/') + '/change-visibility' + '?visibility=' + visibility + (propagate ? '&propagate=true' : ''), null, CustomOptions.registryOptions());
}
- saveElement(url: string, element: any, path: string[] = []): Observable {
+ saveElement(url: string, element: any, path: string[] = [], isFull: boolean = false): Observable {
if (element.alias && element.alias.startsWith('/')) {
element.alias = element.alias.slice(1);
}
return this.http.post(url + ((path.length > 0) ? '/' : '') + path.join('/') +
- '/save', element, CustomOptions.registryOptions()).pipe(map(element => {
+ '/save' + (isFull?'/full':''), element, CustomOptions.registryOptions()).pipe(map(element => {
if (path.length === 0) {
return HelperFunctions.copy(Stakeholder.checkIsUpload(element));
} else {