diff --git a/src/frontend/app/actions/actions.service.ts b/src/frontend/app/actions/actions.service.ts index 1571b6a287823f22a1b9ea40366d0add66b07581..8cdfc55ba1c1f2967c00c6a3b56198c515e1778e 100644 --- a/src/frontend/app/actions/actions.service.ts +++ b/src/frontend/app/actions/actions.service.ts @@ -120,25 +120,37 @@ export class ActionsService { if (this.setActionInformations(action, userId, groupId, basketId, resIds)) { this.loading = true; this.setResourceInformations(datas); - this.http.put(`../../rest/resourcesList/users/${userId}/groups/${groupId}/baskets/${basketId}/lock`, { resources: resIds }).pipe( - tap((data: any) => { - if (this.canExecuteAction(data.lockedResources, data.lockers, resIds)) { - try { - this.lockResource(); - this[action.component](); + if (this.mode !== 'process') { + this.http.put(`../../rest/resourcesList/users/${userId}/groups/${groupId}/baskets/${basketId}/lock`, { resources: resIds }).pipe( + tap((data: any) => { + if (this.canExecuteAction(data.lockedResources, data.lockers, resIds)) { + try { + this.lockResource(); + this[action.component](); + } + catch (error) { + console.log(error); + console.log(action); + alert(this.lang.actionNotExist); + } } - catch (error) { - console.log(error); - console.log(action); - alert(this.lang.actionNotExist); - } - } - }), - catchError((err: any) => { - this.notify.handleErrors(err); - return of(false); - }) - ).subscribe(); + }), + catchError((err: any) => { + this.notify.handleErrors(err); + return of(false); + }) + ).subscribe(); + } else { + try { + this[action.component](); + } + catch (error) { + console.log(error); + console.log(action); + alert(this.lang.actionNotExist); + } + } + } } @@ -204,7 +216,7 @@ export class ActionsService { unlockResourceAfterActionModal(state: string) { this.stopRefreshResourceLock(); - if (state !== 'success') { + if (state !== 'success' && this.mode !== 'process') { this.unlockResource(); } } @@ -213,10 +225,6 @@ export class ActionsService { this.notify.success(this.lang.action + ' : "' + this.currentAction.label + '" ' + this.lang.done); this.eventAction.next(); - - if (this.mode === 'process') { - this.router.navigate([`/basketList/users/${this.currentUserId}/groups/${this.currentGroupId}/baskets/${this.currentBasketId}`]); - } } /* OPEN SPECIFIC ACTION */ diff --git a/src/frontend/app/process/process.component.ts b/src/frontend/app/process/process.component.ts index 8fcc8c17ff0327ce5920e27ffaf89dee5535e70a..b7f8127621aaf7ef2d4474da244fe259de706afa 100644 --- a/src/frontend/app/process/process.component.ts +++ b/src/frontend/app/process/process.component.ts @@ -13,7 +13,7 @@ import { Overlay } from '@angular/cdk/overlay'; import { AppService } from '../../service/app.service'; import { ActionsService } from '../actions/actions.service'; import { tap, catchError, map, finalize } from 'rxjs/operators'; -import { of } from 'rxjs'; +import { of, Subscription } from 'rxjs'; import { DocumentViewerComponent } from '../viewer/document-viewer.component'; @Component({ @@ -106,6 +106,10 @@ export class ProcessComponent implements OnInit { currentTool: string = 'dashboard'; + subscription: Subscription; + + actionEnded: boolean = false; + @ViewChild('snav', { static: true }) sidenavLeft: MatSidenav; @ViewChild('snav2', { static: true }) sidenavRight: MatSidenav; @@ -125,6 +129,12 @@ export class ProcessComponent implements OnInit { public actionService: ActionsService, private router: Router ) { + // Event after process action + this.subscription = this.actionService.catchAction().subscribe(message => { + this.actionEnded = true; + clearInterval(this.currentResourceLock); + this.router.navigate([`/basketList/users/${this.currentUserId}/groups/${this.currentGroupId}/baskets/${this.currentBasketId}`]); + }); } ngOnInit(): void { @@ -173,6 +183,10 @@ export class ProcessComponent implements OnInit { }); } + isActionEnded() { + return this.actionEnded; + } + loadResource() { this.http.get(`../../rest/resources/${this.currentResourceInformations.resId}?light=true`).pipe( tap((data: any) => { @@ -254,4 +268,10 @@ export class ProcessComponent implements OnInit { isModalOpen() { return this.modalModule.map(module => module.id).indexOf(this.currentTool) > -1; } + + ngOnDestroy() { + // unsubscribe to ensure no memory leaks + this.subscription.unsubscribe(); + } + } diff --git a/src/frontend/service/app.guard.ts b/src/frontend/service/app.guard.ts index f1db35bb1e6c5854e441d48df7df2198a8d978b7..552a3d855a5f54ccf630601391264c9263db1836 100644 --- a/src/frontend/service/app.guard.ts +++ b/src/frontend/service/app.guard.ts @@ -47,7 +47,9 @@ export class AppGuard implements CanActivate { }) export class AfterProcessGuard implements CanDeactivate<ProcessComponent> { canDeactivate(component: ProcessComponent): boolean { - component.unlockResource(); + if (!component.isActionEnded()) { + component.unlockResource(); + } /*if(component.hasUnsavedData()){ if (confirm("You have unsaved changes! If you leave, your changes will be lost.")) { return true;