From f6bb9827d0d21562798e1973ceb65dfc69341c71 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Fri, 19 Jul 2024 11:34:00 +0200 Subject: [PATCH] fix(Application):fixed manager comments in mail and in modifications --- .../adjustment-detail.component.html | 2 +- .../adjustment-detail.component.ts | 7 +- .../application-detail.component.html | 40 +- .../application-detail.component.ts | 14 +- .../application-vo-actions.component.ts | 819 +++++++++--------- 5 files changed, 460 insertions(+), 422 deletions(-) diff --git a/src/app/applications/application-detail/adjustment-detail/adjustment-detail.component.html b/src/app/applications/application-detail/adjustment-detail/adjustment-detail.component.html index 8f26c85b91..24f00b89dd 100644 --- a/src/app/applications/application-detail/adjustment-detail/adjustment-detail.component.html +++ b/src/app/applications/application-detail/adjustment-detail/adjustment-detail.component.html @@ -3,7 +3,7 @@ Comment by reviewer: - {{ application?.project_application_manager_comment }} + {{ comment }} diff --git a/src/app/applications/application-detail/adjustment-detail/adjustment-detail.component.ts b/src/app/applications/application-detail/adjustment-detail/adjustment-detail.component.ts index ff6c9c4515..640464e032 100644 --- a/src/app/applications/application-detail/adjustment-detail/adjustment-detail.component.ts +++ b/src/app/applications/application-detail/adjustment-detail/adjustment-detail.component.ts @@ -1,5 +1,4 @@ import { Component, Input, OnInit } from '@angular/core'; -import { Application } from '../../application.model/application.model'; import { is_vo, elixir_id } from '../../../shared/globalvar'; /** @@ -10,11 +9,9 @@ import { is_vo, elixir_id } from '../../../shared/globalvar'; templateUrl: './adjustment-detail.component.html', }) export class AdjustmentDetailComponent implements OnInit { - @Input() application: Application; is_vo: boolean = is_vo; + @Input() comment: string; elixir_id: string = elixir_id; - ngOnInit() { - - } + ngOnInit() {} } diff --git a/src/app/applications/application-detail/application-detail.component.html b/src/app/applications/application-detail/application-detail.component.html index 5ad723dca7..3399cb7e20 100644 --- a/src/app/applications/application-detail/application-detail.component.html +++ b/src/app/applications/application-detail/application-detail.component.html @@ -58,6 +58,26 @@ >Application Adjustment + +
@@ -99,8 +119,22 @@
-
- -
+ @if (COMMENT_TAB_ACTIVE) { +
+ +
+ } @else if (MODIFICATION_COMMENT_TAB_ACTIVE) { +
+ +
+ } @else if (LIFETIME_COMMENT_TAB_ACTIVE) { +
+ +
+ } diff --git a/src/app/applications/application-detail/application-detail.component.ts b/src/app/applications/application-detail/application-detail.component.ts index ef5f794798..c30f9414b4 100644 --- a/src/app/applications/application-detail/application-detail.component.ts +++ b/src/app/applications/application-detail/application-detail.component.ts @@ -28,6 +28,8 @@ export class ApplicationDetailComponent extends ApplicationBaseClassComponent im MODIFICATION_TAB: number = 4; EXTENSION_TAB: number = 5; COMMENT_TAB: number = 6; + MODIFICATION_COMMENT_TAB: number = 7; + LIFETIME_COMMENT_TAB: number = 8; PI_USER_TAB_ACTIVE: boolean = true; INFORMATION_TAB_ACTIVE: boolean = false; RESOURCE_TAB_ACTIVE: boolean = false; @@ -35,7 +37,8 @@ export class ApplicationDetailComponent extends ApplicationBaseClassComponent im MODIFICATION_TAB_ACTIVE: boolean = false; EXTENSION_TAB_ACTIVE: boolean = false; COMMENT_TAB_ACTIVE: boolean = false; - + MODIFICATION_COMMENT_TAB_ACTIVE: boolean = false; + LIFETIME_COMMENT_TAB_ACTIVE: boolean = false; @Input() application: Application; @Input() default_tab: number = this.PI_USER_TAB; @@ -52,10 +55,13 @@ export class ApplicationDetailComponent extends ApplicationBaseClassComponent im this.MODIFICATION_TAB_ACTIVE = false; this.EXTENSION_TAB_ACTIVE = false; this.COMMENT_TAB_ACTIVE = false; + this.MODIFICATION_COMMENT_TAB_ACTIVE = false; + this.LIFETIME_COMMENT_TAB_ACTIVE = false; } setTab(tab_num: number): void { this.setAllTabsFalse(); + console.log(tab_num); switch (tab_num) { case this.PI_USER_TAB: this.PI_USER_TAB_ACTIVE = true; @@ -78,6 +84,12 @@ export class ApplicationDetailComponent extends ApplicationBaseClassComponent im case this.COMMENT_TAB: this.COMMENT_TAB_ACTIVE = true; break; + case this.LIFETIME_COMMENT_TAB: + this.LIFETIME_COMMENT_TAB_ACTIVE = true; + break; + case this.MODIFICATION_COMMENT_TAB: + this.MODIFICATION_COMMENT_TAB_ACTIVE = true; + break; default: break; } diff --git a/src/app/applications/application-vo-actions/application-vo-actions.component.ts b/src/app/applications/application-vo-actions/application-vo-actions.component.ts index 86ef775905..8437177895 100644 --- a/src/app/applications/application-vo-actions/application-vo-actions.component.ts +++ b/src/app/applications/application-vo-actions/application-vo-actions.component.ts @@ -14,15 +14,9 @@ import { is_vo } from '../../shared/globalvar'; import { ApplicationsService } from '../../api-connector/applications.service'; import { VoService } from '../../api-connector/vo.service'; import { GroupService } from '../../api-connector/group.service'; -import { - AdjustLifetimeRequestComponent, -} from '../../projectmanagement/modals/adjust-lifetime/adjust-lifetime-request.component'; -import { - AdjustApplicationComponent, -} from '../../projectmanagement/modals/adjust-application/adjust-application.component'; -import { - ModificationRequestComponent, -} from '../../projectmanagement/modals/modification-request/modification-request.component'; +import { AdjustLifetimeRequestComponent } from '../../projectmanagement/modals/adjust-lifetime/adjust-lifetime-request.component'; +import { AdjustApplicationComponent } from '../../projectmanagement/modals/adjust-application/adjust-application.component'; +import { ModificationRequestComponent } from '../../projectmanagement/modals/modification-request/modification-request.component'; import { ConfirmationModalComponent } from '../../shared/modal/confirmation-modal.component'; import { ClientLimitsComponent } from '../../vo_manager/clients/modals/client-limits..component'; import { NotificationModalComponent } from '../../shared/modal/notification-modal'; @@ -35,386 +29,219 @@ import { NotificationModalComponent } from '../../shared/modal/notification-moda export class ApplicationVoActionsComponent extends AbstractBaseClass implements OnInit { private subscription: Subscription = new Subscription(); - @Input() application: Application; - @Input() tabState: ApplicationTabStates = ApplicationTabStates.SUBMITTED; - @Input() computeCenters: ComputecenterComponent[] = []; - @Output() reloadNumbersTrigger: EventEmitter = new EventEmitter(); - @Output() reloadApplicationTrigger: EventEmitter = new EventEmitter(); - @Output() removeApplicationTrigger: EventEmitter = new EventEmitter(); - @Output() switchCollapseEvent: EventEmitter = new EventEmitter(); - - bsModalRef: BsModalRef; - is_vo_admin: boolean = false; - selectedComputeCenter: ComputecenterComponent; - - ngOnInit() { - this.is_vo_admin = is_vo; - } - - constructor( - private applicationsService: ApplicationsService, - private modalService: BsModalService, - private voService: VoService, - private groupService: GroupService, - private adjustLifeTimeExtensionModal: AdjustLifetimeRequestComponent, - private adjustApplicationModal: AdjustApplicationComponent, - ) { - super(); - } - - triggerRemoveApplication() { - this.removeApplicationTrigger.emit(this.application.project_application_id); - } - - showAdjustLifetimeExtensionModal() { - this.adjustLifeTimeExtensionModal - .showAdjustLifetimeExtensionModal(this.application) - .subscribe((eventSuccess: boolean) => { - if (eventSuccess) { - this.triggerReloadApplication(); - this.showNotificationModal( - 'Success', - 'The lifetime of the extension request were adjusted successfully!', - 'success', - ); - } else { - this.showNotificationModal('Failed', 'The adjustment of the lifetime has failed!', 'danger'); - } - }); - } - - triggerReloadApplication(): void { - this.reloadApplicationTrigger.emit(); - - } - - showAdjustApplicationModal() { - this.adjustApplicationModal.showAdjustApplicationModal(this.application).subscribe((changed: boolean) => { - if (changed) { + @Input() application: Application; + @Input() tabState: ApplicationTabStates = ApplicationTabStates.SUBMITTED; + @Input() computeCenters: ComputecenterComponent[] = []; + @Output() reloadNumbersTrigger: EventEmitter = new EventEmitter(); + @Output() reloadApplicationTrigger: EventEmitter = new EventEmitter(); + @Output() removeApplicationTrigger: EventEmitter = new EventEmitter(); + @Output() switchCollapseEvent: EventEmitter = new EventEmitter(); + + bsModalRef: BsModalRef; + is_vo_admin: boolean = false; + selectedComputeCenter: ComputecenterComponent; + + ngOnInit() { + this.is_vo_admin = is_vo; + } + + constructor( + private applicationsService: ApplicationsService, + private modalService: BsModalService, + private voService: VoService, + private groupService: GroupService, + private adjustLifeTimeExtensionModal: AdjustLifetimeRequestComponent, + private adjustApplicationModal: AdjustApplicationComponent, + ) { + super(); + } + + triggerRemoveApplication() { + this.removeApplicationTrigger.emit(this.application.project_application_id); + } + + showAdjustLifetimeExtensionModal() { + this.adjustLifeTimeExtensionModal + .showAdjustLifetimeExtensionModal(this.application) + .subscribe((eventSuccess: boolean) => { + if (eventSuccess) { this.triggerReloadApplication(); - - this.showNotificationModal('Success', 'The resources of the application were adjusted successfully!', 'success'); + this.showNotificationModal( + 'Success', + 'The lifetime of the extension request were adjusted successfully!', + 'success', + ); } else { - this.showNotificationModal('Failed', 'The adjustment of the resources has failed!', 'danger'); + this.showNotificationModal('Failed', 'The adjustment of the lifetime has failed!', 'danger'); } }); - } - - showModificationAdjustmentModal() { - const initialState = { - project: this.application, - adjustment: true, - }; + } - this.bsModalRef = this.modalService.show(ModificationRequestComponent, { - initialState, - class: 'modal-lg', - }); - this.subscribeToBsModalRef(); - // this.subscribeForExtensionResult(this.ExtensionRequestType.MODIFICATION); - } + triggerReloadApplication(): void { + this.reloadApplicationTrigger.emit(); + console.log('trgger reloaded'); + } - triggerReloadNumbers() { - this.reloadNumbersTrigger.emit(); - } - - setCurrentUserProcessingVoManager(application: Application): void { - if (this.is_vo_admin) { - this.voService.setCurrentUserProcessingVoManager(application.project_application_id).subscribe((res: any) => { - application.processing_vo_initials = res['processing_vo_initials']; - }); - } - } - - showConfirmationModal(action: ConfirmationActions): void { - let initialState = {}; - if (action === ConfirmationActions.APPROVE_APPLICATION) { - const application_center = !this.selectedComputeCenter.FacilityId; - initialState = { application: this.application, action, application_center }; - } else { - initialState = { - application: this.application, - action, - }; - } - this.bsModalRef = this.modalService.show(ConfirmationModalComponent, { initialState, class: 'modal-lg' }); - this.subscribeToBsModalRef(); - } - - unsetProcessingVoManager(application: Application): void { - if (this.is_vo_admin) { - this.voService.unsetProcessingVoManager(application.project_application_id).subscribe(() => { - application.processing_vo_initials = null; - }); - } - } - - showClientsLimitsModal(is_modification_request: boolean = false): void { - let initialState = {}; - if (is_modification_request) { - initialState = { - compute_center_id: this.application.project_application_compute_center.FacilityId, - application: this.application, - is_modification_request, - }; - } else { - initialState = { - compute_center_id: this.selectedComputeCenter.FacilityId, - application: this.application, - is_modification_request, - }; - } - - this.bsModalRef = this.modalService.show(ClientLimitsComponent, { initialState }); - this.subscribeToBsModalRef(); - } - - removeApplicationFromFacilityConfirmation(): void { - this.groupService.removeGroupFromResource(this.application.project_application_perun_id.toString()).subscribe( - (): void => { - this.triggerReloadApplication(); - this.showNotificationModal('Success', 'The application was removed from the compute center', 'success'); - }, - (): void => { - this.showNotificationModal('Failed', 'The application was removed from the compute center', 'danger'); - }, - ); - } + showAdjustApplicationModal() { + this.adjustApplicationModal.showAdjustApplicationModal(this.application).subscribe((changed: boolean) => { + if (changed) { + this.triggerReloadApplication(); - assignGroupToFacility(): void { - if (this.selectedComputeCenter) { - this.groupService - .assignGroupToResource(this.application.project_application_perun_id, this.selectedComputeCenter.FacilityId) - .subscribe( - (): void => { - this.triggerReloadApplication(); - - this.showNotificationModal('Success', 'The project was assigned to the facility.', 'success'); - }, - (error: object): void => { - console.log(error); - this.showNotificationModal('Failed', 'Project could not be created!', 'danger'); - }, - ); + this.showNotificationModal('Success', 'The resources of the application were adjusted successfully!', 'success'); } else { - this.showNotificationModal('Failed', 'You need to select an compute center!', 'danger'); + this.showNotificationModal('Failed', 'The adjustment of the resources has failed!', 'danger'); } - } - - resetApplicationPI(): void { - this.applicationsService.resetPIValidation(this.application).subscribe(() => { - this.triggerReloadApplication(); + }); + } + + showModificationAdjustmentModal() { + const initialState = { + project: this.application, + adjustment: true, + }; + + this.bsModalRef = this.modalService.show(ModificationRequestComponent, { + initialState, + class: 'modal-lg', + }); + this.subscribeToBsModalRef(); + // this.subscribeForExtensionResult(this.ExtensionRequestType.MODIFICATION); + } + + triggerReloadNumbers() { + this.reloadNumbersTrigger.emit(); + } + + setCurrentUserProcessingVoManager(application: Application): void { + if (this.is_vo_admin) { + this.voService.setCurrentUserProcessingVoManager(application.project_application_id).subscribe((res: any) => { + application.processing_vo_initials = res['processing_vo_initials']; }); } - - switchCollaps() { - this.switchCollapseEvent.emit(); + } + + showConfirmationModal(action: ConfirmationActions): void { + let initialState = {}; + if (action === ConfirmationActions.APPROVE_APPLICATION) { + const application_center = !this.selectedComputeCenter.FacilityId; + initialState = { application: this.application, action, application_center }; + } else { + initialState = { + application: this.application, + action, + }; } - - showNotificationModal( - notificationModalTitle: string, - notificationModalMessage: string, - notificationModalType: string, - ) { - const initialState = { notificationModalTitle, notificationModalType, notificationModalMessage }; - if (this.bsModalRef) { - this.bsModalRef.hide(); - } - - this.bsModalRef = this.modalService.show(NotificationModalComponent, { initialState }); - this.bsModalRef.setClass('modal-lg'); + this.bsModalRef = this.modalService.show(ConfirmationModalComponent, { initialState, class: 'modal-lg' }); + this.subscribeToBsModalRef(); + } + + unsetProcessingVoManager(application: Application): void { + if (this.is_vo_admin) { + this.voService.unsetProcessingVoManager(application.project_application_id).subscribe(() => { + application.processing_vo_initials = null; + }); } - - createSimpleVmProjectGroup(): void { - this.showNotificationModal('Info', 'Creating Project...', 'info'); - - if (this.selectedComputeCenter && this.selectedComputeCenter.FacilityId) { - this.groupService - .createGroupByApplication(this.application.project_application_id, this.selectedComputeCenter.FacilityId) - .subscribe( - (res: any): void => { - if (!res['client_available'] && !res['created']) { - this.showNotificationModal( - 'Failed', - `The client ${res['client_name']} has not the necessary resources left!`, - 'danger', - ); - } else { - this.showNotificationModal('Success', 'The project was created!', 'success'); - this.triggerRemoveApplication(); - this.triggerReloadNumbers(); - } - }, - (error: any): void => { - console.log(error); - const errorMessage = error && error.error === 'locked' - ? 'Project is locked and could not be created!' - : 'Project could not be created!'; - - this.showNotificationModal('Failed', errorMessage, 'danger'); - console.log(error); - }, - ); - } + } + + showClientsLimitsModal(is_modification_request: boolean = false): void { + let initialState = {}; + if (is_modification_request) { + initialState = { + compute_center_id: this.application.project_application_compute_center.FacilityId, + application: this.application, + is_modification_request, + }; + } else { + initialState = { + compute_center_id: this.selectedComputeCenter.FacilityId, + application: this.application, + is_modification_request, + }; } - approveModificationRequest(): void { - this.applicationsService.approveModificationRequest(this.application.project_application_id).subscribe( - (res: Response): void => { - this.showNotificationModal('Success', 'The resource modification request was approved!', 'success'); - if (!this.application.project_application_openstack_project) { - if (res.status === HttpStatusCode.Accepted) { - this.triggerRemoveApplication(); - this.triggerReloadNumbers(); + this.bsModalRef = this.modalService.show(ClientLimitsComponent, { initialState }); + this.subscribeToBsModalRef(); + } - // this.all_applications.splice(this.all_applications.indexOf(application), 1); - } - } else { + removeApplicationFromFacilityConfirmation(): void { + this.groupService.removeGroupFromResource(this.application.project_application_perun_id.toString()).subscribe( + (): void => { + this.triggerReloadApplication(); + this.showNotificationModal('Success', 'The application was removed from the compute center', 'success'); + }, + (): void => { + this.showNotificationModal('Failed', 'The application was removed from the compute center', 'danger'); + }, + ); + } + + assignGroupToFacility(): void { + if (this.selectedComputeCenter) { + this.groupService + .assignGroupToResource(this.application.project_application_perun_id, this.selectedComputeCenter.FacilityId) + .subscribe( + (): void => { this.triggerReloadApplication(); - } - }, - (err: any): void => { - console.log('error', err.status); - this.showNotificationModal('Failed', 'Approval of resource modification failed!', 'danger'); - }, - ); - } - - declineModificationRequest(): void { - this.applicationsService.deleteModificationRequest(this.application.project_application_id).subscribe( - (): void => { - this.showNotificationModal('Declined', 'The resource modification request was declined!', 'success'); - this.triggerReloadNumbers(); - this.triggerRemoveApplication(); - - this.triggerReloadApplication(); - }, - (err: any): void => { - console.log('error', err.status); - this.showNotificationModal('Failed', 'Decline of resource modification failed!', 'danger'); - }, - ); - } - - deleteApplication(): void { - // const idx: number = this.all_applications.indexOf(application); - this.subscription.add( - this.applicationsService.deleteApplication(this.application.project_application_id).subscribe( - (): void => { - this.showNotificationModal('Success', 'The application has been successfully removed', 'success'); - this.triggerRemoveApplication(); - this.triggerReloadNumbers(); + this.showNotificationModal('Success', 'The project was assigned to the facility.', 'success'); }, - (): void => { - this.updateNotificationModal('Failed', 'Application could not be removed!', true, 'danger'); + (error: object): void => { + console.log(error); + this.showNotificationModal('Failed', 'Project could not be created!', 'danger'); }, - ), - ); - } - - declineLifetimeExtension(): void { - this.applicationsService.deleteAdditionalLifetimeRequests(this.application.project_application_id).subscribe( - (): void => { - this.showNotificationModal('Declined', 'The project extension was declined!', 'success'); - this.triggerRemoveApplication(); - this.triggerReloadNumbers(); - }, - (err: any): void => { - console.log('error', err.status); - this.showNotificationModal('Failed', 'Decline of project extension failed!', 'danger'); - }, - ); + ); + } else { + this.showNotificationModal('Failed', 'You need to select an compute center!', 'danger'); } - - declineCreditExtension(): void { - this.applicationsService.deleteAdditionalCreditsRequests(this.application.project_application_id).subscribe( - (): void => { - this.showNotificationModal('Declined', 'The credit extension request was declined!', 'success'); - this.triggerRemoveApplication(); - this.triggerReloadNumbers(); - }, - (err: any): void => { - console.log('error', err.status); - this.showNotificationModal('Failed', 'Decline of credit extension failed!', 'danger'); - }, - ); + } + + resetApplicationPI(): void { + this.applicationsService.resetPIValidation(this.application).subscribe(() => { + this.triggerReloadApplication(); + }); + } + + switchCollaps() { + this.switchCollapseEvent.emit(); + } + + showNotificationModal( + notificationModalTitle: string, + notificationModalMessage: string, + notificationModalType: string, + ) { + const initialState = { notificationModalTitle, notificationModalType, notificationModalMessage }; + if (this.bsModalRef) { + this.bsModalRef.hide(); } - declineApplication(): void { - // const idx: number = this.all_applications.indexOf(app); - this.applicationsService.declineApplication(this.application.project_application_id).subscribe( - (): void => { - const message: string = 'The Application was declined.'; + this.bsModalRef = this.modalService.show(NotificationModalComponent, { initialState }); + this.bsModalRef.setClass('modal-lg'); + } - this.showNotificationModal('Success', message, 'success'); - this.triggerRemoveApplication(); - this.triggerReloadNumbers(); - }, - (): void => { - this.showNotificationModal('Failed', 'Application could not be declined!', 'danger'); - }, - ); - } + createSimpleVmProjectGroup(): void { + this.showNotificationModal('Info', 'Creating Project...', 'info'); - approveLifetimeExtension(): void { - this.applicationsService.approveAdditionalLifetime(this.application.project_application_id).subscribe( - (res: Response): void => { - if (this.application.project_application_openstack_project) { - this.triggerReloadApplication(); - this.showNotificationModal('Success', 'The request has been sent to the facility manager.', 'success'); - } else { - this.showNotificationModal('Success', 'The project has been extended!', 'success'); - } - if (!this.application.project_application_openstack_project) { - if (res.status === HttpStatusCode.Accepted) { - this.triggerReloadNumbers(); - this.triggerRemoveApplication(); - } - } - }, - (err: any): void => { - console.log('error', err.status); - this.showNotificationModal('Failed', 'Project lifetime could not be extendend!', 'danger'); - }, - ); - } - - approveCreditExtension(): void { - this.applicationsService.approveAdditionalCreditsRequest(this.application.project_application_id).subscribe( - (res: Response): void => { - this.showNotificationModal('Success', 'The credit extension request was approved!', 'success'); - if (!this.application.project_application_openstack_project) { - if (res.status === HttpStatusCode.Accepted) { - this.triggerReloadNumbers(); - this.triggerRemoveApplication(); - } - } else { - this.triggerReloadApplication(); - } - }, - (err: any): void => { - console.log('error', err.status); - this.showNotificationModal('Failed', 'Approval of credit extension failed!', 'danger'); - }, - ); - } - - createOpenStackProjectGroup(): void { + if (this.selectedComputeCenter && this.selectedComputeCenter.FacilityId) { this.groupService - .createGroupOpenStack(this.application.project_application_id, this.selectedComputeCenter.FacilityId) + .createGroupByApplication(this.application.project_application_id, this.selectedComputeCenter.FacilityId) .subscribe( - (result: { [key: string]: string }): void => { - if (result['Error']) { - this.showNotificationModal('Failed', result['Error'], 'danger'); + (res: any): void => { + if (!res['client_available'] && !res['created']) { + this.showNotificationModal( + 'Failed', + `The client ${res['client_name']} has not the necessary resources left!`, + 'danger', + ); } else { - this.showNotificationModal('Success', 'The project was assigned to the facility.', 'success'); - this.triggerReloadApplication(); - // this.switchApproveLocked(false); + this.showNotificationModal('Success', 'The project was created!', 'success'); + this.triggerRemoveApplication(); + this.triggerReloadNumbers(); } }, (error: any): void => { - const errorMessage = error && error.error === 'locked' + console.log(error); + const errorMessage = error && error.error === 'locked' ? 'Project is locked and could not be created!' : 'Project could not be created!'; @@ -423,66 +250,234 @@ export class ApplicationVoActionsComponent extends AbstractBaseClass implements }, ); } + } + + approveModificationRequest(): void { + this.applicationsService.approveModificationRequest(this.application.project_application_id).subscribe( + (res: Response): void => { + this.showNotificationModal('Success', 'The resource modification request was approved!', 'success'); + if (!this.application.project_application_openstack_project) { + if (res.status === HttpStatusCode.Accepted) { + this.triggerRemoveApplication(); + this.triggerReloadNumbers(); - /** - * Function to listen to modal results. - */ - subscribeToBsModalRef(): void { - this.subscription.add( - this.bsModalRef.content.event.subscribe((result: any) => { - let action = null; - if ('action' in result) { - action = result['action']; - } - if ('createSimpleVM' in result) { - this.createSimpleVmProjectGroup(); - } - if (action === ConfirmationActions.APPROVE_MODIFICATION) { - this.approveModificationRequest(); - } - if ('closed' in result) { - // this.switchApproveLocked(false); - } - if (action === ConfirmationActions.DECLINE_MODIFICATION) { - this.declineModificationRequest(); - } - if (action === ConfirmationActions.DELETE_APPLICATION) { - this.deleteApplication(); - } - if (action === ConfirmationActions.DECLINE_EXTENSION) { - this.declineLifetimeExtension(); - } - if (action === ConfirmationActions.DECLINE_CREDITS) { - this.declineCreditExtension(); - } - if (action === ConfirmationActions.DECLINE_APPLICATION) { - this.declineApplication(); + // this.all_applications.splice(this.all_applications.indexOf(application), 1); } + } else { + this.triggerReloadApplication(); + } + }, + (err: any): void => { + console.log('error', err.status); + this.showNotificationModal('Failed', 'Approval of resource modification failed!', 'danger'); + }, + ); + } + + declineModificationRequest(): void { + this.applicationsService.deleteModificationRequest(this.application.project_application_id).subscribe( + (): void => { + this.showNotificationModal('Declined', 'The resource modification request was declined!', 'success'); + this.triggerReloadNumbers(); + this.triggerRemoveApplication(); - if (action === ConfirmationActions.APPROVE_EXTENSION) { - this.approveLifetimeExtension(); - } - if (action === ConfirmationActions.RESET_PI) { - this.resetApplicationPI(); - } - if (action === ConfirmationActions.APPROVE_CREDITS) { - this.approveCreditExtension(); + this.triggerReloadApplication(); + }, + (err: any): void => { + console.log('error', err.status); + this.showNotificationModal('Failed', 'Decline of resource modification failed!', 'danger'); + }, + ); + } + + deleteApplication(): void { + // const idx: number = this.all_applications.indexOf(application); + + this.subscription.add( + this.applicationsService.deleteApplication(this.application.project_application_id).subscribe( + (): void => { + this.showNotificationModal('Success', 'The application has been successfully removed', 'success'); + this.triggerRemoveApplication(); + this.triggerReloadNumbers(); + }, + (): void => { + this.updateNotificationModal('Failed', 'Application could not be removed!', true, 'danger'); + }, + ), + ); + } + + declineLifetimeExtension(): void { + this.applicationsService.deleteAdditionalLifetimeRequests(this.application.project_application_id).subscribe( + (): void => { + this.showNotificationModal('Declined', 'The project extension was declined!', 'success'); + this.triggerRemoveApplication(); + this.triggerReloadNumbers(); + }, + (err: any): void => { + console.log('error', err.status); + this.showNotificationModal('Failed', 'Decline of project extension failed!', 'danger'); + }, + ); + } + + declineCreditExtension(): void { + this.applicationsService.deleteAdditionalCreditsRequests(this.application.project_application_id).subscribe( + (): void => { + this.showNotificationModal('Declined', 'The credit extension request was declined!', 'success'); + this.triggerRemoveApplication(); + this.triggerReloadNumbers(); + }, + (err: any): void => { + console.log('error', err.status); + this.showNotificationModal('Failed', 'Decline of credit extension failed!', 'danger'); + }, + ); + } + + declineApplication(): void { + // const idx: number = this.all_applications.indexOf(app); + this.applicationsService.declineApplication(this.application.project_application_id).subscribe( + (): void => { + const message: string = 'The Application was declined.'; + + this.showNotificationModal('Success', message, 'success'); + this.triggerRemoveApplication(); + this.triggerReloadNumbers(); + }, + (): void => { + this.showNotificationModal('Failed', 'Application could not be declined!', 'danger'); + }, + ); + } + + approveLifetimeExtension(): void { + this.applicationsService.approveAdditionalLifetime(this.application.project_application_id).subscribe( + (res: Response): void => { + if (this.application.project_application_openstack_project) { + this.triggerReloadApplication(); + this.showNotificationModal('Success', 'The request has been sent to the facility manager.', 'success'); + } else { + this.showNotificationModal('Success', 'The project has been extended!', 'success'); + } + if (!this.application.project_application_openstack_project) { + if (res.status === HttpStatusCode.Accepted) { + this.triggerReloadNumbers(); + this.triggerRemoveApplication(); } - if (action === ConfirmationActions.APPROVE_APPLICATION) { - if (this.application.project_application_openstack_project) { - this.createOpenStackProjectGroup(); - } + } + }, + (err: any): void => { + console.log('error', err.status); + this.showNotificationModal('Failed', 'Project lifetime could not be extendend!', 'danger'); + }, + ); + } + + approveCreditExtension(): void { + this.applicationsService.approveAdditionalCreditsRequest(this.application.project_application_id).subscribe( + (res: Response): void => { + this.showNotificationModal('Success', 'The credit extension request was approved!', 'success'); + if (!this.application.project_application_openstack_project) { + if (res.status === HttpStatusCode.Accepted) { + this.triggerReloadNumbers(); + this.triggerRemoveApplication(); } - if (action === 'adjustedModificationRequest') { - // this.isLoaded = false; - // this.changeTabState(ApplicationTabStates.MODIFICATION_EXTENSION); + } else { + this.triggerReloadApplication(); + } + }, + (err: any): void => { + console.log('error', err.status); + this.showNotificationModal('Failed', 'Approval of credit extension failed!', 'danger'); + }, + ); + } + + createOpenStackProjectGroup(): void { + this.groupService + .createGroupOpenStack(this.application.project_application_id, this.selectedComputeCenter.FacilityId) + .subscribe( + (result: { [key: string]: string }): void => { + if (result['Error']) { + this.showNotificationModal('Failed', result['Error'], 'danger'); + } else { + this.showNotificationModal('Success', 'The project was assigned to the facility.', 'success'); + this.triggerReloadApplication(); + // this.switchApproveLocked(false); } - }), + }, + (error: any): void => { + const errorMessage = error && error.error === 'locked' + ? 'Project is locked and could not be created!' + : 'Project could not be created!'; + + this.showNotificationModal('Failed', errorMessage, 'danger'); + console.log(error); + }, ); - } + } + + /** + * Function to listen to modal results. + */ + subscribeToBsModalRef(): void { + this.subscription.add( + this.bsModalRef.content.event.subscribe((result: any) => { + let action = null; + if ('action' in result) { + action = result['action']; + } + if ('createSimpleVM' in result) { + this.createSimpleVmProjectGroup(); + } + if (action === ConfirmationActions.APPROVE_MODIFICATION) { + this.approveModificationRequest(); + } + if ('closed' in result) { + // this.switchApproveLocked(false); + } + if (action === ConfirmationActions.DECLINE_MODIFICATION) { + this.declineModificationRequest(); + } + if (action === ConfirmationActions.DELETE_APPLICATION) { + this.deleteApplication(); + } + if (action === ConfirmationActions.DECLINE_EXTENSION) { + this.declineLifetimeExtension(); + } + if (action === ConfirmationActions.DECLINE_CREDITS) { + this.declineCreditExtension(); + } + if (action === ConfirmationActions.DECLINE_APPLICATION) { + this.declineApplication(); + } - isCollapsed: boolean = true; - protected readonly Application_States = Application_States; - protected readonly ConfirmationActions = ConfirmationActions; - protected readonly ApplicationTabStates = ApplicationTabStates; + if (action === ConfirmationActions.APPROVE_EXTENSION) { + this.approveLifetimeExtension(); + } + if (action === ConfirmationActions.RESET_PI) { + this.resetApplicationPI(); + } + if (action === ConfirmationActions.APPROVE_CREDITS) { + this.approveCreditExtension(); + } + if (action === ConfirmationActions.APPROVE_APPLICATION) { + if (this.application.project_application_openstack_project) { + this.createOpenStackProjectGroup(); + } + } + if (action === 'adjustedModificationRequest') { + this.triggerReloadApplication(); + // this.isLoaded = false; + // this.changeTabState(ApplicationTabStates.MODIFICATION_EXTENSION); + } + }), + ); + } + + isCollapsed: boolean = true; + protected readonly Application_States = Application_States; + protected readonly ConfirmationActions = ConfirmationActions; + protected readonly ApplicationTabStates = ApplicationTabStates; }