From 759e01bc8106fbe72d34df602e4aeb585d71e5bc Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Fri, 25 Oct 2019 12:48:58 +0200
Subject: [PATCH] FIX #12091 TIME 0:30 fix unlock resource + refresh panel
 basket

---
 .../app/actions/actions-list.component.ts     |  3 +-
 src/frontend/app/actions/actions.service.ts   | 73 ++++++++-----------
 .../app/list/basket-list.component.html       |  2 +-
 3 files changed, 35 insertions(+), 43 deletions(-)

diff --git a/src/frontend/app/actions/actions-list.component.ts b/src/frontend/app/actions/actions-list.component.ts
index 25bb27115b6..1d62ba2bf00 100644
--- a/src/frontend/app/actions/actions-list.component.ts
+++ b/src/frontend/app/actions/actions-list.component.ts
@@ -40,6 +40,7 @@ export class ActionsListComponent implements OnInit {
     @Input('currentBasketInfo') currentBasketInfo: any;
 
     @Output('refreshEvent') refreshEvent = new EventEmitter<string>();
+    @Output('refreshEventAfterAction') refreshEventAfterAction = new EventEmitter<string>();
     @Output('refreshPanelFolders') refreshPanelFolders = new EventEmitter<string>();
 
     constructor(
@@ -56,7 +57,7 @@ export class ActionsListComponent implements OnInit {
     ngOnInit(): void {
         // Event after process action 
         this.subscription = this.actionService.catchAction().subscribe(message => {
-            this.refreshEvent.emit();
+            this.refreshEventAfterAction.emit();
             this.refreshPanelFolders.emit();
         });
     }
diff --git a/src/frontend/app/actions/actions.service.ts b/src/frontend/app/actions/actions.service.ts
index 0c2ecd3b8ce..5dde214635d 100644
--- a/src/frontend/app/actions/actions.service.ts
+++ b/src/frontend/app/actions/actions.service.ts
@@ -200,10 +200,14 @@ export class ActionsService {
         }
     }
 
+    unlockResourceAfterActionModal(state: string) {
+        this.stopRefreshResourceLock();
+        if (state !== 'success') {
+            this.unlockResource();
+        }
+    }
 
     endAction(status: any) {
-        this.unlockResource();
-
         this.notify.success(this.lang.action + ' : "' + this.currentAction.label + '" ' + this.lang.done);
 
         this.eventAction.next();
@@ -219,9 +223,8 @@ export class ActionsService {
         });
 
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
@@ -242,9 +245,8 @@ export class ActionsService {
             data: this.setDatasActionToSend()
         });
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
@@ -265,9 +267,8 @@ export class ActionsService {
             data: this.setDatasActionToSend()
         });
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
@@ -288,9 +289,8 @@ export class ActionsService {
             data: this.setDatasActionToSend()
         });
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
@@ -311,9 +311,8 @@ export class ActionsService {
             data: this.setDatasActionToSend()
         });
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
@@ -334,9 +333,8 @@ export class ActionsService {
             data: this.setDatasActionToSend()
         });
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
@@ -357,9 +355,8 @@ export class ActionsService {
             data: this.setDatasActionToSend()
         });
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
@@ -380,9 +377,8 @@ export class ActionsService {
             data: this.setDatasActionToSend()
         });
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
@@ -403,9 +399,8 @@ export class ActionsService {
             data: this.setDatasActionToSend()
         });
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
@@ -433,9 +428,8 @@ export class ActionsService {
             data: this.setDatasActionToSend()
         });
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
@@ -456,9 +450,8 @@ export class ActionsService {
             data: this.setDatasActionToSend()
         });
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
@@ -478,9 +471,8 @@ export class ActionsService {
             data: this.setDatasActionToSend()
         });
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
@@ -501,9 +493,8 @@ export class ActionsService {
             data: this.setDatasActionToSend()
         });
         dialogRef.afterClosed().pipe(
-            tap(() => {
-                this.stopRefreshResourceLock();
-                this.unlockResource();
+            tap((data: any) => {
+                this.unlockResourceAfterActionModal(data);
             }),
             filter((data: string) => data === 'success'),
             tap((result: any) => {
diff --git a/src/frontend/app/list/basket-list.component.html b/src/frontend/app/list/basket-list.component.html
index 664a7a5905d..d8f72ca9d14 100644
--- a/src/frontend/app/list/basket-list.component.html
+++ b/src/frontend/app/list/basket-list.component.html
@@ -199,6 +199,6 @@
             <mat-divider></mat-divider>
         </mat-sidenav>
     </mat-sidenav-container>
-    <app-actions-list (refreshEvent)="refreshDao()" #actionsListContext [contextMode]="true"
+    <app-actions-list (refreshEvent)="refreshDao()" (refreshEventAfterAction)="refreshDaoAfterAction()" #actionsListContext [contextMode]="true"
         [totalRes]="allResInBasket.length" [selectedRes]="selectedRes" [currentBasketInfo]="currentBasketInfo" (refreshPanelFolders)="panelFolder.refreshFoldersTree()">
     </app-actions-list>
\ No newline at end of file
-- 
GitLab