From 0e7a1ca6fffb4da8b21e74493421c4aebffc8def Mon Sep 17 00:00:00 2001 From: Alex ORLUC <alex.orluc@maarch.org> Date: Tue, 7 Jul 2020 19:06:49 +0200 Subject: [PATCH] FIX #14199 TIME 1 fix unlock resource --- src/frontend/app/actions/actions.service.ts | 8 +++--- src/frontend/app/process/process.component.ts | 4 ++- src/frontend/app/signature-book.component.ts | 25 +++++++++++-------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/frontend/app/actions/actions.service.ts b/src/frontend/app/actions/actions.service.ts index 6d569c55fee..89c74562c1d 100644 --- a/src/frontend/app/actions/actions.service.ts +++ b/src/frontend/app/actions/actions.service.ts @@ -46,6 +46,7 @@ export class ActionsService { currentResourceLock: any = null; lockMode: boolean = true; + actionEnded: boolean = false; currentAction: any = null; currentUserId: number = null; @@ -140,6 +141,7 @@ export class ActionsService { async launchAction(action: any, userId: number, groupId: number, basketId: number, resIds: number[], datas: any, lockRes: boolean = true) { if (this.setActionInformations(action, userId, groupId, basketId, resIds)) { + this.actionEnded = false; this.loading = true; this.lockMode = lockRes; this.setResourceInformations(datas); @@ -207,10 +209,8 @@ export class ActionsService { } lockResource(userId: number = this.currentUserId, groupId: number = this.currentGroupId, basketId: number = this.currentBasketId, resIds: number[] = this.currentResIds) { - console.log(`Verouillage des documents ${resIds}`); this.http.put(`../../rest/resourcesList/users/${userId}/groups/${groupId}/baskets/${basketId}/lock`, { resources: resIds }).pipe( - tap(() => console.debug(`Cycle lock : `, this.currentResourceLock)), catchError((err: any) => { this.notify.handleErrors(err); return of(false); @@ -219,7 +219,6 @@ export class ActionsService { this.currentResourceLock = setInterval(() => { this.http.put(`../../rest/resourcesList/users/${userId}/groups/${groupId}/baskets/${basketId}/lock`, { resources: resIds }).pipe( - tap(() => console.debug(`Cycle lock : `, this.currentResourceLock)), catchError((err: any) => { if (err.status === 403) { clearInterval(this.currentResourceLock); @@ -233,7 +232,6 @@ export class ActionsService { unlockResource(userId: number = this.currentUserId, groupId: number = this.currentGroupId, basketId: number = this.currentBasketId, resIds: number[] = this.currentResIds) { if (resIds.length > 0) { - console.debug(`Unlock ressource : ${resIds}`); this.http.put(`../../rest/resourcesList/users/${userId}/groups/${groupId}/baskets/${basketId}/unlock`, { resources: resIds }).pipe( catchError((err: any) => { this.notify.handleErrors(err); @@ -245,7 +243,6 @@ export class ActionsService { stopRefreshResourceLock() { if (this.currentResourceLock !== null) { - console.debug('Cycle lock cancel'); clearInterval(this.currentResourceLock); } } @@ -277,6 +274,7 @@ export class ActionsService { this.notify.success(this.lang.action + ' : "' + this.currentAction.label + '" ' + this.lang.done); + this.actionEnded = true; this.eventAction.next(resIds); } diff --git a/src/frontend/app/process/process.component.ts b/src/frontend/app/process/process.component.ts index 137e0070ea1..2dc71fe5f3e 100755 --- a/src/frontend/app/process/process.component.ts +++ b/src/frontend/app/process/process.component.ts @@ -657,7 +657,9 @@ export class ProcessComponent implements OnInit, OnDestroy { ngOnDestroy() { if (!this.detailMode) { this.actionService.stopRefreshResourceLock(); - this.actionService.unlockResource(this.currentUserId, this.currentGroupId, this.currentBasketId, [this.currentResourceInformations.resId]); + if (!this.actionService.actionEnded) { + this.actionService.unlockResource(this.currentUserId, this.currentGroupId, this.currentBasketId, [this.currentResourceInformations.resId]); + } } // unsubscribe to ensure no memory leaks this.subscription.unsubscribe(); diff --git a/src/frontend/app/signature-book.component.ts b/src/frontend/app/signature-book.component.ts index 180318639e0..14fdd52c0d1 100755 --- a/src/frontend/app/signature-book.component.ts +++ b/src/frontend/app/signature-book.component.ts @@ -469,15 +469,17 @@ export class SignatureBookComponent implements OnInit, OnDestroy { } async changeLocation(resId: number, origin: string) { - const data: any = await this.actionService.canExecuteAction([resId], this.userId, this.groupId, this.basketId); - - if (data === true) { - this.actionService.stopRefreshResourceLock(); - this.actionService.unlockResource(this.userId, this.groupId, this.basketId, [this.resId]); - const path = 'signatureBook/users/' + this.userId + '/groups/' + this.groupId + '/baskets/' + this.basketId + '/resources/' + resId; - this.router.navigate([path]); - } else { - this.backToBasket(); + if (resId !== this.resId) { + const data: any = await this.actionService.canExecuteAction([resId], this.userId, this.groupId, this.basketId); + + if (data === true) { + this.actionService.stopRefreshResourceLock(); + this.actionService.unlockResource(this.userId, this.groupId, this.basketId, [this.resId]); + const path = 'signatureBook/users/' + this.userId + '/groups/' + this.groupId + '/baskets/' + this.basketId + '/resources/' + resId; + this.router.navigate([path]); + } else { + this.backToBasket(); + } } } @@ -563,7 +565,10 @@ export class SignatureBookComponent implements OnInit, OnDestroy { ngOnDestroy() { this.actionService.stopRefreshResourceLock(); - this.actionService.unlockResource(this.userId, this.groupId, this.basketId, [this.resId]); + + if (!this.actionService.actionEnded) { + this.actionService.unlockResource(this.userId, this.groupId, this.basketId, [this.resId]); + } // unsubscribe to ensure no memory leaks this.subscription.unsubscribe(); -- GitLab