Fix bug with edit stakeholder form, when enable form fields before save/

This commit is contained in:
Konstantinos Triantafyllou 2022-07-08 21:21:47 +03:00
parent c134dc4367
commit a5f598d0ec
2 changed files with 14 additions and 34 deletions

View File

@ -14,6 +14,7 @@ import {StringUtils} from "../../openaireLibrary/utils/string-utils.class";
import {NotifyFormComponent} from "../../openaireLibrary/notifications/notify-form/notify-form.component"; import {NotifyFormComponent} from "../../openaireLibrary/notifications/notify-form/notify-form.component";
import {NotificationUtils} from "../../openaireLibrary/notifications/notification-utils"; import {NotificationUtils} from "../../openaireLibrary/notifications/notification-utils";
import {Notification} from "../../openaireLibrary/notifications/notifications"; import {Notification} from "../../openaireLibrary/notifications/notifications";
import {NotificationHandler} from "../../openaireLibrary/utils/notification-handler";
declare var UIkit; declare var UIkit;
@ -277,9 +278,7 @@ export class EditStakeholderComponent implements OnDestroy {
public save(callback: Function, errorCallback: Function = null) { public save(callback: Function, errorCallback: Function = null) {
if (this.file) { if (this.file) {
this.stakeholderFb.get('alias').enable(); 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.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.deletePhoto(); this.deletePhoto();
this.stakeholderFb.get('logoUrl').setValue(res.filename); this.stakeholderFb.get('logoUrl').setValue(res.filename);
this.removePhoto(); this.removePhoto();
@ -298,59 +297,39 @@ export class EditStakeholderComponent implements OnDestroy {
public saveStakeholder(callback: Function, errorCallback: Function = null) { public saveStakeholder(callback: Function, errorCallback: Function = null) {
if (this.isNew) { if (this.isNew) {
if (!this.stakeholderFb.value.isDefault) { if (!this.stakeholderFb.getRawValue().isDefault) {
let stakeholder = this.defaultStakeholders.find(value => value._id === this.stakeholderFb.value.defaultId); let stakeholder = this.defaultStakeholders.find(value => value._id === this.stakeholderFb.getRawValue().defaultId);
this.stakeholderFb.setValue(this.stakeholderUtils.createFunderFromDefaultProfile(this.stakeholderFb.value, this.stakeholderFb.setValue(this.stakeholderUtils.createFunderFromDefaultProfile(this.stakeholderFb.getRawValue(),
(stakeholder ? stakeholder.topics : []))); (stakeholder ? stakeholder.topics : [])));
} }
this.removePhoto(); this.removePhoto();
this.subscriptions.push(this.stakeholderService.buildStakeholder(this.properties.monitorServiceAPIURL, 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.entity = stakeholder._id;
this.notification.stakeholder = stakeholder.alias; this.notification.stakeholder = stakeholder.alias;
this.notification.stakeholderType = stakeholder.type; this.notification.stakeholderType = stakeholder.type;
this.notification.groups = [Role.curator(stakeholder.type)]; this.notification.groups = [Role.curator(stakeholder.type)];
this.notify.sendNotification(this.notification); this.notify.sendNotification(this.notification);
UIkit.notification(stakeholder.name + ' has been <b>successfully created</b>', { NotificationHandler.rise(stakeholder.name + ' has been <b>successfully created</b>');
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
callback(stakeholder); callback(stakeholder);
}, error => { }, error => {
UIkit.notification('An error has occurred. Please try again later', { NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
status: 'danger',
timeout: 6000,
pos: 'bottom-right'
});
if (errorCallback) { if (errorCallback) {
errorCallback(error) errorCallback(error)
} }
})); }));
} else { } else {
this.stakeholderFb.get('alias').enable(); this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.getRawValue()).subscribe(stakeholder => {
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.notification.entity = stakeholder._id; this.notification.entity = stakeholder._id;
this.notification.stakeholder = stakeholder.alias; this.notification.stakeholder = stakeholder.alias;
this.notification.stakeholderType = stakeholder.type; this.notification.stakeholderType = stakeholder.type;
this.notification.groups = [Role.curator(stakeholder.type), Role.manager(stakeholder.type, stakeholder.alias)]; this.notification.groups = [Role.curator(stakeholder.type), Role.manager(stakeholder.type, stakeholder.alias)];
this.notify.sendNotification(this.notification); this.notify.sendNotification(this.notification);
UIkit.notification(stakeholder.name + ' has been <b>successfully saved</b>', { NotificationHandler.rise(stakeholder.name + ' has been <b>successfully saved</b>');
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
callback(stakeholder); callback(stakeholder);
}, error => { }, error => {
UIkit.notification('An error has occurred. Please try again later', { NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
status: 'danger', console.error(error);
timeout: 6000,
pos: 'bottom-right'
});
})); }));
} }
} }
@ -382,7 +361,7 @@ export class EditStakeholderComponent implements OnDestroy {
} }
initPhoto() { initPhoto() {
if (this.stakeholderFb.value.isUpload) { if (this.stakeholderFb.getRawValue().isUpload) {
this.photo = this.properties.utilsService + "/download/" + this.stakeholderFb.get('logoUrl').value; this.photo = this.properties.utilsService + "/download/" + this.stakeholderFb.get('logoUrl').value;
} }
} }

View File

@ -59,6 +59,7 @@ export class GeneralComponent implements OnInit, OnDestroy {
this.reset(); this.reset();
this.loading = false; this.loading = false;
}, (error) => { }, (error) => {
console.error(error);
this.loading = false; this.loading = false;
}); });
} }