From 8f4e653d507ba5a4803404d89b2f495c876069b2 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 12 Apr 2024 11:14:26 +0300 Subject: [PATCH] [develop | WIP]: Introduce copy field in stakeholder --- .../edit-stakeholder.component.ts | 41 ++++++++++---- .../edit-stakeholder.module.ts | 3 +- monitor-admin/general/general.component.ts | 2 +- .../manageStakeholders.component.html | 7 ++- monitor-admin/utils/indicator-utils.ts | 54 ------------------- monitor/entities/stakeholder.ts | 2 + monitor/services/stakeholder.service.ts | 12 +++-- 7 files changed, 48 insertions(+), 73 deletions(-) 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: `
-
+
@@ -126,6 +126,19 @@ import {StakeholderBaseComponent} from "../../utils/stakeholder-base.component";
+
+
Instance Type
+
+ + +
+
{ 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

-
+
@@ -59,7 +58,7 @@
-
+

Profiles

{ - 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 {