Commit a112ae1f authored by Alex ORLUC's avatar Alex ORLUC

FIX #12074 TIME 0:20 fix lock resource

parent 05d88d0c
......@@ -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 */
......
......@@ -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();
}
}
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment