From 5d9073538a49fdec0485c46646a5ee6b55e87f39 Mon Sep 17 00:00:00 2001
From: paf <paf@titelfrei.de>
Date: Mon, 12 Apr 2021 08:59:39 +0200
Subject: [PATCH] replaces the session if the data.testId

In the frist implementation of the group-monitor the test-sessions replaced a combination of person and test so they needed there own id. Now, they represent only tests and we don't show a person which is a logged in but has not started a test right now anymore, we don'T need the combined id anymore as well.
---
 .../group-monitor/group-monitor.component.ts  |  2 +-
 .../group-monitor/group-monitor.interfaces.ts |  1 -
 .../group-monitor.service.spec.ts             | 36 +++++++++----------
 .../group-monitor/group-monitor.service.ts    | 12 +++----
 src/app/group-monitor/test-session.service.ts |  5 ---
 5 files changed, 25 insertions(+), 31 deletions(-)

diff --git a/src/app/group-monitor/group-monitor.component.ts b/src/app/group-monitor/group-monitor.component.ts
index a5c19d14..3f0d8f38 100644
--- a/src/app/group-monitor/group-monitor.component.ts
+++ b/src/app/group-monitor/group-monitor.component.ts
@@ -123,7 +123,7 @@ export class GroupMonitorComponent implements OnInit, OnDestroy {
     }
   }
 
-  trackSession = (index: number, session: TestSession): number => session.id;
+  trackSession = (index: number, session: TestSession): number => session.data.testId;
 
   setTableSorting(sort: Sort): void {
     if (!sort.active || sort.direction === '') {
diff --git a/src/app/group-monitor/group-monitor.interfaces.ts b/src/app/group-monitor/group-monitor.interfaces.ts
index d4e8891b..8d086bbd 100644
--- a/src/app/group-monitor/group-monitor.interfaces.ts
+++ b/src/app/group-monitor/group-monitor.interfaces.ts
@@ -5,7 +5,6 @@ export interface TestSession {
   readonly data: TestSessionData;
   readonly state: TestSessionSuperState;
   readonly current: UnitContext|null;
-  readonly id: number;
   readonly booklet: Booklet|BookletError;
   readonly clearedCodes: Record<string, unknown>|null;
   readonly timeLeft: Record<string, unknown>|null;
diff --git a/src/app/group-monitor/group-monitor.service.spec.ts b/src/app/group-monitor/group-monitor.service.spec.ts
index f7121983..eb2ae757 100644
--- a/src/app/group-monitor/group-monitor.service.spec.ts
+++ b/src/app/group-monitor/group-monitor.service.spec.ts
@@ -117,14 +117,14 @@ describe('GroupMonitorService', () => {
       // eslint-disable-next-line @typescript-eslint/dot-notation
       service['replaceCheckedSessions']([unitTestExampleSessions[1]]);
       const sorted = service.sortSessions({ active: '_checked', direction: 'asc' }, [...unitTestExampleSessions]);
-      expect(sorted[0].id).toEqual(unitTestExampleSessions[1].id);
+      expect(sorted[0].data.testId).toEqual(unitTestExampleSessions[1].data.testId);
     });
 
     it('should sort by checked reverse', () => {
       // eslint-disable-next-line @typescript-eslint/dot-notation
       service['replaceCheckedSessions']([unitTestExampleSessions[1]]);
       const sorted = service.sortSessions({ active: '_checked', direction: 'desc' }, [...unitTestExampleSessions]);
-      expect(sorted[2].id).toEqual(unitTestExampleSessions[1].id);
+      expect(sorted[2].data.testId).toEqual(unitTestExampleSessions[1].data.testId);
     });
 
     it('should sort by superstate', () => {
@@ -185,23 +185,23 @@ describe('GroupMonitorService', () => {
         type: 'bookletName',
         value: 'example_booklet_1'
       };
-      let result = filterSessions(sessionsSet, [removeEverythingButBooklet1]).map(s => s.id);
-      expect(result).toEqual([10001]);
+      let result = filterSessions(sessionsSet, [removeEverythingButBooklet1]).map(s => s.data.testId);
+      expect(result).toEqual([1]);
 
       const removeHotRunReturn: TestSessionFilter = {
         type: 'mode',
         value: 'run-hot-return'
       };
-      result = filterSessions(sessionsSet, [removeHotRunReturn]).map(s => s.id);
-      expect(result).toEqual([20003]);
+      result = filterSessions(sessionsSet, [removeHotRunReturn]).map(s => s.data.testId);
+      expect(result).toEqual([3]);
 
       const removeStatusControllerRunning: TestSessionFilter = {
         type: 'testState',
         value: 'CONTROLLER',
         subValue: 'RUNNING'
       };
-      result = filterSessions(sessionsSet, [removeStatusControllerRunning]).map(s => s.id);
-      expect(result).toEqual([10002, 20003]);
+      result = filterSessions(sessionsSet, [removeStatusControllerRunning]).map(s => s.data.testId);
+      expect(result).toEqual([2, 3]);
 
       const removeStatusControllerNotRunning: TestSessionFilter = {
         not: true,
@@ -209,29 +209,29 @@ describe('GroupMonitorService', () => {
         value: 'CONTROLLER',
         subValue: 'RUNNING'
       };
-      result = filterSessions(sessionsSet, [removeStatusControllerNotRunning]).map(s => s.id);
-      expect(result).toEqual([10001]);
+      result = filterSessions(sessionsSet, [removeStatusControllerNotRunning]).map(s => s.data.testId);
+      expect(result).toEqual([1]);
 
       const removePending: TestSessionFilter = {
         type: 'state',
         value: 'pending'
       };
-      result = filterSessions(sessionsSet, [removePending]).map(s => s.id);
-      expect(result).toEqual([10001, 10002]);
+      result = filterSessions(sessionsSet, [removePending]).map(s => s.data.testId);
+      expect(result).toEqual([1, 2]);
 
       const removeBookletSpecies1: TestSessionFilter = {
         type: 'bookletSpecies',
         value: 'example-species-1'
       };
-      result = filterSessions(sessionsSet, [removeBookletSpecies1]).map(s => s.id);
-      expect(result).toEqual([10002, 20003]);
+      result = filterSessions(sessionsSet, [removeBookletSpecies1]).map(s => s.data.testId);
+      expect(result).toEqual([2, 3]);
 
-      result = filterSessions(sessionsSet, [removeBookletSpecies1, removePending]).map(s => s.id);
-      expect(result).toEqual([10002]);
+      result = filterSessions(sessionsSet, [removeBookletSpecies1, removePending]).map(s => s.data.testId);
+      expect(result).toEqual([2]);
 
       result = filterSessions(sessionsSet, [removeBookletSpecies1, removeStatusControllerRunning, removeHotRunReturn])
-        .map(s => s.id);
-      expect(result).toEqual([20003]);
+        .map(s => s.data.testId);
+      expect(result).toEqual([3]);
     });
   });
 
diff --git a/src/app/group-monitor/group-monitor.service.ts b/src/app/group-monitor/group-monitor.service.ts
index 7e823174..ac2afc17 100644
--- a/src/app/group-monitor/group-monitor.service.ts
+++ b/src/app/group-monitor/group-monitor.service.ts
@@ -198,8 +198,8 @@ export class GroupMonitorService {
     const newCheckedSessions: { [sessionFullId: number]: TestSession } = {};
     sessions
       .forEach(session => {
-        if (this.checkingOptions.autoCheckAll || (typeof this._checked[session.id] !== 'undefined')) {
-          newCheckedSessions[session.id] = session;
+        if (this.checkingOptions.autoCheckAll || (typeof this._checked[session.data.testId] !== 'undefined')) {
+          newCheckedSessions[session.data.testId] = session;
         }
       });
     this._checked = newCheckedSessions;
@@ -340,7 +340,7 @@ export class GroupMonitorService {
   }
 
   isChecked(session: TestSession): boolean {
-    return (typeof this._checked[session.id] !== 'undefined');
+    return (typeof this._checked[session.data.testId] !== 'undefined');
   }
 
   // todo unit test
@@ -376,7 +376,7 @@ export class GroupMonitorService {
     if (this.checkingOptions.autoCheckAll) {
       return;
     }
-    this._checked[session.id] = session;
+    this._checked[session.data.testId] = session;
     this.onCheckedChanged();
   }
 
@@ -385,7 +385,7 @@ export class GroupMonitorService {
       return;
     }
     if (this.isChecked(session)) {
-      delete this._checked[session.id];
+      delete this._checked[session.data.testId];
     }
     this.onCheckedChanged();
   }
@@ -407,7 +407,7 @@ export class GroupMonitorService {
   private replaceCheckedSessions(sessionsToCheck: TestSession[]): void {
     const newCheckedSessions = {};
     sessionsToCheck
-      .forEach(session => { newCheckedSessions[session.id] = session; });
+      .forEach(session => { newCheckedSessions[session.data.testId] = session; });
     this._checked = newCheckedSessions;
     this.onCheckedChanged();
   }
diff --git a/src/app/group-monitor/test-session.service.ts b/src/app/group-monitor/test-session.service.ts
index 66158713..9ca3c31a 100644
--- a/src/app/group-monitor/test-session.service.ts
+++ b/src/app/group-monitor/test-session.service.ts
@@ -28,7 +28,6 @@ export class TestSessionService {
     const current = isBooklet(booklet) ? TestSessionService.getCurrent(booklet.units, session.unitName) : null;
     return {
       data: session,
-      id: TestSessionService.getId(session),
       state: TestSessionService.getSuperState(session),
       current: current && current.unit ? current : null,
       booklet,
@@ -44,10 +43,6 @@ export class TestSessionService {
       .join(glue);
   }
 
-  private static getId(session: TestSessionData): number {
-    return session.personId * 10000 + session.testId;
-  }
-
   private static getSuperState(session: TestSessionData): TestSessionSuperState {
     const state = session.testState;
 
-- 
GitLab