From a5f598d0ecba67fdd4d2466d847c82f21ac3981b Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 8 Jul 2022 21:21:47 +0300 Subject: [PATCH] Fix bug with edit stakeholder form, when enable form fields before save/ --- .../edit-stakeholder.component.ts | 47 +++++-------------- src/app/general/general.component.ts | 1 + 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/app/general/edit-stakeholder/edit-stakeholder.component.ts b/src/app/general/edit-stakeholder/edit-stakeholder.component.ts index 9607989..11ac3cf 100644 --- a/src/app/general/edit-stakeholder/edit-stakeholder.component.ts +++ b/src/app/general/edit-stakeholder/edit-stakeholder.component.ts @@ -14,6 +14,7 @@ import {StringUtils} from "../../openaireLibrary/utils/string-utils.class"; import {NotifyFormComponent} from "../../openaireLibrary/notifications/notify-form/notify-form.component"; import {NotificationUtils} from "../../openaireLibrary/notifications/notification-utils"; import {Notification} from "../../openaireLibrary/notifications/notifications"; +import {NotificationHandler} from "../../openaireLibrary/utils/notification-handler"; declare var UIkit; @@ -277,9 +278,7 @@ export class EditStakeholderComponent implements OnDestroy { public save(callback: Function, errorCallback: Function = null) { if (this.file) { - this.stakeholderFb.get('alias').enable(); - this.stakeholderFb.get('type').enable(); - this.subscriptions.push(this.utilsService.uploadPhoto(this.properties.utilsService + "/upload/" + encodeURIComponent(this.stakeholderFb.value.type) + "/" + encodeURIComponent(this.stakeholderFb.value.alias), this.file).subscribe(res => { + this.subscriptions.push(this.utilsService.uploadPhoto(this.properties.utilsService + "/upload/" + encodeURIComponent(this.stakeholderFb.getRawValue().type) + "/" + encodeURIComponent(this.stakeholderFb.getRawValue().alias), this.file).subscribe(res => { this.deletePhoto(); this.stakeholderFb.get('logoUrl').setValue(res.filename); this.removePhoto(); @@ -298,59 +297,39 @@ export class EditStakeholderComponent implements OnDestroy { public saveStakeholder(callback: Function, errorCallback: Function = null) { if (this.isNew) { - if (!this.stakeholderFb.value.isDefault) { - let stakeholder = this.defaultStakeholders.find(value => value._id === this.stakeholderFb.value.defaultId); - this.stakeholderFb.setValue(this.stakeholderUtils.createFunderFromDefaultProfile(this.stakeholderFb.value, + if (!this.stakeholderFb.getRawValue().isDefault) { + let stakeholder = this.defaultStakeholders.find(value => value._id === this.stakeholderFb.getRawValue().defaultId); + this.stakeholderFb.setValue(this.stakeholderUtils.createFunderFromDefaultProfile(this.stakeholderFb.getRawValue(), (stakeholder ? stakeholder.topics : []))); } this.removePhoto(); this.subscriptions.push(this.stakeholderService.buildStakeholder(this.properties.monitorServiceAPIURL, - this.stakeholderFb.value).subscribe(stakeholder => { + this.stakeholderFb.getRawValue()).subscribe(stakeholder => { this.notification.entity = stakeholder._id; this.notification.stakeholder = stakeholder.alias; this.notification.stakeholderType = stakeholder.type; this.notification.groups = [Role.curator(stakeholder.type)]; this.notify.sendNotification(this.notification); - UIkit.notification(stakeholder.name + ' has been successfully created', { - status: 'success', - timeout: 6000, - pos: 'bottom-right' - }); + NotificationHandler.rise(stakeholder.name + ' has been successfully created'); callback(stakeholder); }, error => { - UIkit.notification('An error has occurred. Please try again later', { - status: 'danger', - timeout: 6000, - pos: 'bottom-right' - }); + NotificationHandler.rise('An error has occurred. Please try again later', 'danger'); if (errorCallback) { errorCallback(error) } })); } else { - this.stakeholderFb.get('alias').enable(); - this.stakeholderFb.get('type').enable(); - this.stakeholderFb.get('index_id').enable(); - this.stakeholderFb.get('index_name').enable(); - this.stakeholderFb.get('index_shortName').enable(); - this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.value).subscribe(stakeholder => { + this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.getRawValue()).subscribe(stakeholder => { this.notification.entity = stakeholder._id; this.notification.stakeholder = stakeholder.alias; this.notification.stakeholderType = stakeholder.type; this.notification.groups = [Role.curator(stakeholder.type), Role.manager(stakeholder.type, stakeholder.alias)]; this.notify.sendNotification(this.notification); - UIkit.notification(stakeholder.name + ' has been successfully saved', { - status: 'success', - timeout: 6000, - pos: 'bottom-right' - }); + NotificationHandler.rise(stakeholder.name + ' has been successfully saved'); callback(stakeholder); }, error => { - UIkit.notification('An error has occurred. Please try again later', { - status: 'danger', - timeout: 6000, - pos: 'bottom-right' - }); + NotificationHandler.rise('An error has occurred. Please try again later', 'danger'); + console.error(error); })); } } @@ -382,7 +361,7 @@ export class EditStakeholderComponent implements OnDestroy { } initPhoto() { - if (this.stakeholderFb.value.isUpload) { + if (this.stakeholderFb.getRawValue().isUpload) { this.photo = this.properties.utilsService + "/download/" + this.stakeholderFb.get('logoUrl').value; } } diff --git a/src/app/general/general.component.ts b/src/app/general/general.component.ts index 50dd542..921890e 100644 --- a/src/app/general/general.component.ts +++ b/src/app/general/general.component.ts @@ -59,6 +59,7 @@ export class GeneralComponent implements OnInit, OnDestroy { this.reset(); this.loading = false; }, (error) => { + console.error(error); this.loading = false; }); }