From 7c3e2ee63da5327c28ddca7614f8f75b2b7717ef Mon Sep 17 00:00:00 2001
From: paflov <paf@titelfrei.de>
Date: Wed, 9 Feb 2022 10:43:11 +0100
Subject: [PATCH] Dont't check navigationLeaveRestrictions if unit is already
 time-locked.

Fixes #347
---
 CHANGELOG.md                                  |  4 +--
 .../routing/unit-route-guards.ts              | 27 ++++++++-----------
 2 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1b68bed0..10571bc0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,10 +5,10 @@ Various Bugfixes:
 * (#341) When you visited a test in demo-mode as a monitor, and terminated it, you returned to the starter but didn't see the monitor-monitor button again. That got fixed.
 * (#340) After reload you return to the correct unit now
 * (#335) Order of checks when leaving a unit is fixed: First check completeness, then ask for leaving the timed block
-* 
+* (#347) Dont't check navigationLeaveRestrictions if unit is already time-locked.
 
 Minor Changes
-* In "demo" mode "showTimeLeft2 is off now
+* In "demo" mode "showTimeLeft" is off now
 
 ## 12.0.2
 Use Font Roboto everywhere
diff --git a/src/app/test-controller/routing/unit-route-guards.ts b/src/app/test-controller/routing/unit-route-guards.ts
index 92deb56d..00634e93 100644
--- a/src/app/test-controller/routing/unit-route-guards.ts
+++ b/src/app/test-controller/routing/unit-route-guards.ts
@@ -55,7 +55,7 @@ export class UnitDeactivateGuard implements CanDeactivate<UnithostComponent> {
     private router: Router
   ) {}
 
-  private checkAndSolve_maxTime(newUnit: UnitControllerData, force: boolean): Observable<boolean> {
+  private checkAndSolveMaxTime(newUnit: UnitControllerData): Observable<boolean> {
     if (!this.tcs.currentMaxTimerTestletId) { // leaving unit is not in a timed block
       return of(true);
     }
@@ -67,10 +67,6 @@ export class UnitDeactivateGuard implements CanDeactivate<UnithostComponent> {
     ) {
       return of(true);
     }
-    if (force) {
-      this.tcs.interruptMaxTimer();
-      return of(true);
-    }
     const dialogCDRef = this.confirmDialog.open(ConfirmDialogComponent, {
       width: '500px',
       data: <ConfirmDialogData>{
@@ -95,10 +91,7 @@ export class UnitDeactivateGuard implements CanDeactivate<UnithostComponent> {
       );
   }
 
-  private checkAndSolve_Completeness(newUnit: UnitControllerData, force: boolean): Observable<boolean> {
-    if (force) {
-      return of(true);
-    }
+  private checkAndSolveCompleteness(newUnit: UnitControllerData): Observable<boolean> {
     const direction = (newUnit && this.tcs.currentUnitSequenceId < newUnit.unitDef.sequenceId) ? 'Next' : 'Prev';
     const reasons = this.checkCompleteness(direction);
     if (!reasons.length) {
@@ -109,6 +102,9 @@ export class UnitDeactivateGuard implements CanDeactivate<UnithostComponent> {
 
   private checkCompleteness(direction: 'Next' | 'Prev'): VeronaNavigationDeniedReason[] {
     const unit = this.tcs.rootTestlet.getUnitAt(this.tcs.currentUnitSequenceId);
+    if (unit.unitDef.locked) {
+      return [];
+    }
     const reasons: VeronaNavigationDeniedReason[] = [];
     const checkOnValue = {
       Next: <NavigationLeaveRestrictionValue[]>['ON', 'ALWAYS'],
@@ -183,15 +179,14 @@ export class UnitDeactivateGuard implements CanDeactivate<UnithostComponent> {
     }
 
     const forceNavigation = this.router.getCurrentNavigation().extras?.state?.force ?? false;
+    if (forceNavigation) {
+      this.tcs.interruptMaxTimer();
+      return of(true);
+    }
 
-    return this.checkAndSolve_Completeness(newUnit, forceNavigation)
+    return this.checkAndSolveCompleteness(newUnit)
       .pipe(
-        switchMap(cAsC => {
-          if (!cAsC) {
-            return of(false);
-          }
-          return this.checkAndSolve_maxTime(newUnit, forceNavigation);
-        })
+        switchMap(cAsC => (!cAsC ? of(false) : this.checkAndSolveMaxTime(newUnit)))
       );
   }
 }
-- 
GitLab