add loading when editing/creating stakeholder profiles

This commit is contained in:
Alex Martzios 2022-08-04 12:28:55 +03:00
parent 48467c7172
commit bcbbefc277
5 changed files with 19 additions and 5 deletions

View File

@ -117,6 +117,7 @@ export class EditStakeholderComponent implements OnDestroy {
public stakeholder: Stakeholder; public stakeholder: Stakeholder;
public isDefault: boolean; public isDefault: boolean;
public isNew: boolean; public isNew: boolean;
public loading: boolean = false;
public types: Option[]; public types: Option[];
public properties: EnvProperties = properties; public properties: EnvProperties = properties;
private subscriptions: any[] = []; private subscriptions: any[] = [];
@ -275,6 +276,7 @@ export class EditStakeholderComponent implements OnDestroy {
} }
public save(callback: Function, errorCallback: Function = null) { public save(callback: Function, errorCallback: Function = null) {
this.loading = true;
if (this.file) { if (this.file) {
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.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.deletePhoto();
@ -310,11 +312,13 @@ export class EditStakeholderComponent implements OnDestroy {
this.notify.sendNotification(this.notification); this.notify.sendNotification(this.notification);
NotificationHandler.rise(stakeholder.name + ' has been <b>successfully created</b>'); NotificationHandler.rise(stakeholder.name + ' has been <b>successfully created</b>');
callback(stakeholder); callback(stakeholder);
this.loading = false;
}, error => { }, error => {
NotificationHandler.rise('An error has occurred. Please try again later', 'danger'); NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
if (errorCallback) { if (errorCallback) {
errorCallback(error) errorCallback(error)
} }
this.loading = false;
})); }));
} else { } 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()).subscribe(stakeholder => {
@ -324,10 +328,14 @@ export class EditStakeholderComponent implements OnDestroy {
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);
NotificationHandler.rise(stakeholder.name + ' has been <b>successfully saved</b>'); NotificationHandler.rise(stakeholder.name + ' has been <b>successfully saved</b>');
callback(stakeholder); callback(stakeholder);
this.loading = false;
}, error => { }, error => {
NotificationHandler.rise('An error has occurred. Please try again later', 'danger'); NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
console.error(error); if (errorCallback) {
errorCallback(error)
}
this.loading = false;
})); }));
} }
} }

View File

@ -123,7 +123,10 @@
id="edit_modal" [large]="true" classTitle="uk-background-primary uk-light" id="edit_modal" [large]="true" classTitle="uk-background-primary uk-light"
(alertOutput)="editStakeholderComponent.save(callback)" (alertOutput)="editStakeholderComponent.save(callback)"
[okDisabled]="editStakeholderComponent.disabled"> [okDisabled]="editStakeholderComponent.disabled">
<div class="uk-padding"> <div class="uk-height-large uk-position-relative" *ngIf="editStakeholderComponent.loading">
<loading class="uk-position-center"></loading>
</div>
<div class="uk-padding" [class.uk-hidden]="editStakeholderComponent.loading">
<edit-stakeholder #editStakeholderComponent></edit-stakeholder> <edit-stakeholder #editStakeholderComponent></edit-stakeholder>
</div> </div>
</modal-alert> </modal-alert>

View File

@ -178,6 +178,7 @@ export class ManageStakeholdersComponent implements OnInit, OnDestroy {
if(index != -1) { if(index != -1) {
this.alias[index] = stakeholder.alias; this.alias[index] = stakeholder.alias;
} }
this.editStakeholderModal.cancel();
}; };
this.editStakeholderModal.alertTitle = 'Edit ' + this.stakeholder.name; this.editStakeholderModal.alertTitle = 'Edit ' + this.stakeholder.name;
this.editStakeholderModal.okButtonText = 'Save Changes'; this.editStakeholderModal.okButtonText = 'Save Changes';
@ -189,6 +190,7 @@ export class ManageStakeholdersComponent implements OnInit, OnDestroy {
this.stakeholders.push(stakeholder); this.stakeholders.push(stakeholder);
} }
this.alias.push(stakeholder.alias); this.alias.push(stakeholder.alias);
this.editStakeholderModal.cancel();
}; };
this.editStakeholderModal.alertTitle = 'Create a new ' + (isDefault?'Default ':'') + 'Profile'; this.editStakeholderModal.alertTitle = 'Create a new ' + (isDefault?'Default ':'') + 'Profile';
this.editStakeholderModal.okButtonText = 'Create'; this.editStakeholderModal.okButtonText = 'Create';
@ -196,6 +198,7 @@ export class ManageStakeholdersComponent implements OnInit, OnDestroy {
this.editStakeholderModal.cancelButtonText = 'Cancel'; this.editStakeholderModal.cancelButtonText = 'Cancel';
this.editStakeholderModal.okButtonLeft = false; this.editStakeholderModal.okButtonLeft = false;
this.editStakeholderModal.alertMessage = false; this.editStakeholderModal.alertMessage = false;
this.editStakeholderModal.stayOpen = true;
this.editStakeholderModal.open(); this.editStakeholderModal.open();
} }

@ -1 +1 @@
Subproject commit d55b1819de86b435ad5533949720cba322ae089a Subproject commit fd9794ec3aa5fd031a3642febf4c2a4d20425cd7

@ -1 +1 @@
Subproject commit ff0dadc5dd278b9b6fcc86502541c1f9dc39945c Subproject commit ee5eeb0ccc7e8a1b7086730fbce597faa9b25b13