From dc9079c47e43a5e2738220294574ddaee95c4b6a Mon Sep 17 00:00:00 2001
From: paf <paf@titelfrei.de>
Date: Wed, 16 Sep 2020 12:50:27 +0200
Subject: [PATCH] display if test is paused and al

---
 .../group-monitor.component.html              |  4 ++--
 .../group-monitor/group-monitor.component.ts  | 24 ++++++++++++++++---
 .../test-view/test-view.component.css         |  2 ++
 .../test-view/test-view.component.html        |  3 ++-
 4 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/src/app/group-monitor/group-monitor.component.html b/src/app/group-monitor/group-monitor.component.html
index dc806f64..5ef4de7b 100644
--- a/src/app/group-monitor/group-monitor.component.html
+++ b/src/app/group-monitor/group-monitor.component.html
@@ -77,11 +77,11 @@
             </div>
 
             <div class="toolbar-section">
-                <button mat-raised-button class="control" color="primary" (click)="testCommandResume()" [disabled]="!countCheckedSessions()">
+                <button mat-raised-button class="control" color="primary" (click)="testCommandResume()" [disabled]="!isResumeAllowed()">
                     <mat-icon>play_arrow</mat-icon>WEITER
                 </button>
 
-                <button mat-raised-button class="control" color="primary" (click)="testCommandPause()" [disabled]="!countCheckedSessions()">
+                <button mat-raised-button class="control" color="primary" (click)="testCommandPause()" [disabled]="!isPauseAllowed()">
                     <mat-icon>pause</mat-icon>PAUSE
                 </button>
             </div>
diff --git a/src/app/group-monitor/group-monitor.component.ts b/src/app/group-monitor/group-monitor.component.ts
index f5e04161..206a1952 100644
--- a/src/app/group-monitor/group-monitor.component.ts
+++ b/src/app/group-monitor/group-monitor.component.ts
@@ -93,6 +93,10 @@ export class GroupMonitorComponent implements OnInit, OnDestroy {
     return session.personId * 10000 +  session.testId;
   }
 
+  private static hasState(state: object, key: string, value: any = null): boolean {
+    return ((typeof state[key] !== 'undefined') && ((value !== null) ? (state[key] === value) : true));
+  }
+
   ngOnInit(): void {
     this.routingSubscription = this.route.params.subscribe(params => {
       this.ownGroup$ = this.bs.getGroupData(params['group-name']);
@@ -232,14 +236,16 @@ export class GroupMonitorComponent implements OnInit, OnDestroy {
 
   testCommandResume() {
     const testIds = Object.values(this.checkedSessions)
-        .filter(session => session.testId && session.testId > -1) // TODO only paused tests...
+        .filter(session => session.testId && session.testId > -1)
+        .filter(session => GroupMonitorComponent.hasState(session.testState, 'CONTROLLER', 'PAUSED'))
         .map(session => session.testId);
     this.bs.command('resume', [], testIds);
   }
 
   testCommandPause() {
     const testIds = Object.values(this.checkedSessions)
-        .filter(session => session.testId && session.testId > -1) // TODO filter paused tests...
+        .filter(session => session.testId && session.testId > -1)
+        .filter(session => !GroupMonitorComponent.hasState(session.testState, 'CONTROLLER', 'PAUSED'))
         .map(session => session.testId);
     this.bs.command('pause', [], testIds);
   }
@@ -247,7 +253,7 @@ export class GroupMonitorComponent implements OnInit, OnDestroy {
   testCommandGoto() {
     if ((this.sessionCheckedGroupCount === 1) && (Object.keys(this.checkedSessions).length > 0)) {
       const testIds = Object.values(this.checkedSessions)
-          .filter(session => session.testId && session.testId > -1) // TODO filter paused tests...
+          .filter(session => session.testId && session.testId > -1)
           .map(session => session.testId);
       this.bs.command('goto', ['id', GroupMonitorComponent.getFirstUnit(this.selectedElement.element).id], testIds);
     }
@@ -342,4 +348,16 @@ export class GroupMonitorComponent implements OnInit, OnDestroy {
       this.selectedElement = null;
     }
   }
+
+  isPauseAllowed(): boolean {
+    return Object.values(this.checkedSessions)
+        .filter(session => GroupMonitorComponent.hasState(session.testState, 'CONTROLLER', 'PAUSED'))
+        .length === 0;
+  }
+
+  isResumeAllowed() {
+    return Object.values(this.checkedSessions)
+        .filter(session => !GroupMonitorComponent.hasState(session.testState, 'CONTROLLER', 'PAUSED'))
+        .length === 0;
+  }
 }
diff --git a/src/app/group-monitor/test-view/test-view.component.css b/src/app/group-monitor/test-view/test-view.component.css
index 6cb437d1..6c97a4a8 100644
--- a/src/app/group-monitor/test-view/test-view.component.css
+++ b/src/app/group-monitor/test-view/test-view.component.css
@@ -63,6 +63,7 @@ mat-icon + h1 {
     background: #001C1C;
 }
 
+.pending .unit,
 .locked .unit {
     background: #333333;
 }
@@ -87,6 +88,7 @@ mat-icon + h1 {
     color: #333333;
 }
 
+.pending .unit.current,
 .locked .unit.current {
     background: #b2b2b2;
     color: #333333;
diff --git a/src/app/group-monitor/test-view/test-view.component.html b/src/app/group-monitor/test-view/test-view.component.html
index 75479b97..c465f9a9 100644
--- a/src/app/group-monitor/test-view/test-view.component.html
+++ b/src/app/group-monitor/test-view/test-view.component.html
@@ -101,7 +101,8 @@
                  [class]="{
                     locked: hasState(testSession.testState, 'status', 'locked'),
                     paused: hasState(testSession.testState, 'CONTROLLER', 'PAUSED'),
-                    error: hasState(testSession.testState, 'CONTROLLER', 'ERROR')
+                    error: hasState(testSession.testState, 'CONTROLLER', 'ERROR'),
+                    pending: !hasState(testSession.testState, 'CONTROLLER')
                  }"
                  [ngSwitch]="displayOptions.view"
                  (mouseleave)="mark()"
-- 
GitLab