From 6d3f8d68a153a657d0356b144969aef27e87722b Mon Sep 17 00:00:00 2001
From: mechtelm <nicht@mehr.fragen>
Date: Mon, 20 Apr 2020 11:20:56 +0200
Subject: [PATCH] test-controller loads booklet data

---
 .../test-starter/test-starter.component.ts     |  2 +-
 src/app/app.interfaces.ts                      |  5 +----
 src/app/backend.service.ts                     | 18 ++++++++++++------
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/app/app-root/test-starter/test-starter.component.ts b/src/app/app-root/test-starter/test-starter.component.ts
index 8c60a18e..c9924e4d 100644
--- a/src/app/app-root/test-starter/test-starter.component.ts
+++ b/src/app/app-root/test-starter/test-starter.component.ts
@@ -62,7 +62,7 @@ export class TestStarterComponent implements OnInit {
   }
 
   startTest(b: BookletData) {
-    this.bs.startTest(b.label).subscribe(testId => {
+    this.bs.startTest(b.id).subscribe(testId => {
       if (typeof testId === 'number') {
         const errCode = testId as number;
         if (errCode === 423) {
diff --git a/src/app/app.interfaces.ts b/src/app/app.interfaces.ts
index ae9886ff..9ca63cd4 100644
--- a/src/app/app.interfaces.ts
+++ b/src/app/app.interfaces.ts
@@ -37,15 +37,12 @@ export interface MonitorScopeData {
 }
 
 export interface BookletData {
+  id: string;
   label: string;
   running: boolean;
   locked: boolean;
 }
 
-export interface StartBookletReturn {
-  testId: string;
-}
-
 export interface SysConfig {
   customTexts: KeyValuePairs;
   version: string;
diff --git a/src/app/backend.service.ts b/src/app/backend.service.ts
index fd886fa5..8ecf52b2 100644
--- a/src/app/backend.service.ts
+++ b/src/app/backend.service.ts
@@ -8,7 +8,7 @@ import {
   SysCheckInfo,
   AuthData,
   WorkspaceData,
-  BookletData, MonitorScopeData, StartBookletReturn
+  BookletData, MonitorScopeData
 } from './app.interfaces';
 
 // ============================================================================
@@ -101,10 +101,16 @@ export class BackendService {
 
   getBookletData(bookletId: string): Observable<BookletData> {
     return this.http
-      .get<BookletData>(this.serverUrl + 'booklet/' + bookletId + '/state')
-      .pipe(catchError(() => {
+      .get<BookletData>(this.serverUrl + 'booklet/' + bookletId)
+      .pipe(
+        map(bData => {
+          bData.id = bookletId;
+          return bData
+        }),
+        catchError(() => {
         console.warn('get booklet data failed for ' + bookletId);
         return of(<BookletData>{
+          id: bookletId,
           label: bookletId,
           locked: true,
           running: false
@@ -112,11 +118,11 @@ export class BackendService {
       }));
   }
 
-  startTest(bookletName: string): Observable<string | number> {
+  startTest(bookletId: string): Observable<string | number> {
     return this.http
-      .put<StartBookletReturn>(this.serverUrl + 'test', {bookletName})
+      .put<number>(this.serverUrl + 'test', {bookletId})
       .pipe(
-        map((testId: StartBookletReturn) => String(testId.testId)),
+        map((testId: number) => String(testId)),
         catchError(errCode => of(errCode))
       );
   }
-- 
GitLab