From 3479c545bedc3023fe0a5278f91488aa2277c78f Mon Sep 17 00:00:00 2001
From: mechtelm <nicht@mehr.fragen>
Date: Tue, 5 Mar 2019 09:41:15 +0100
Subject: [PATCH] save review works

---
 src/app/test-controller/backend.service.ts    | 35 +++-----
 .../review-dialog.component.html              |  2 +-
 .../test-controller.component.ts              | 81 +++++++++----------
 .../test-controller.interfaces.ts             |  6 +-
 .../test-controller.service.ts                |  4 +-
 .../unithost/unithost.component.ts            | 16 ++--
 6 files changed, 64 insertions(+), 80 deletions(-)

diff --git a/src/app/test-controller/backend.service.ts b/src/app/test-controller/backend.service.ts
index cc481e27..55339d80 100644
--- a/src/app/test-controller/backend.service.ts
+++ b/src/app/test-controller/backend.service.ts
@@ -24,35 +24,22 @@ export class BackendService {
   // 7777777777777777777777777777777777777777777777777777777777777777777777
   // send reviews
   // 7777777777777777777777777777777777777777777777777777777777777777777777
-  saveUnitReview(pToken: string, bookletDbId: number, unit: string, priority: number,
-    categories: string, entry: string): Observable<boolean | ServerError> {
-    const httpOptions = {
-      headers: new HttpHeaders({
-        'Content-Type':  'application/json'
-      })
-    };
+  saveUnitReview(unit: string, priority: number,
+      categories: string, entry: string): Observable<boolean | ServerError> {
     return this.http
-    .post<boolean>(this.serverUrl + 'addUnitReview.php', {au: pToken + '##' + bookletDbId.toString(), u: unit,
-        p: priority, c: categories, e: entry}, httpOptions)
-      .pipe(
-        catchError(this.handle)
-      );
+      .post<boolean>(this.serverSlimUrl_POST + 'review', {u: unit, p: priority, c: categories, e: entry})
+        .pipe(
+          catchError(this.handle)
+        );
   }
 
   // ------------------------------
-  saveBookletReview(pToken: string, bookletDbId: number, priority: number,
-          categories: string, entry: string): Observable<boolean | ServerError> {
-    const httpOptions = {
-      headers: new HttpHeaders({
-        'Content-Type':  'application/json'
-      })
-    };
+  saveBookletReview(priority: number, categories: string, entry: string): Observable<boolean | ServerError> {
     return this.http
-    .post<boolean>(this.serverUrl + 'addBookletReview.php', {au: pToken + '##' + bookletDbId.toString(),
-        p: priority, c: categories, e: entry}, httpOptions)
-      .pipe(
-        catchError(this.handle)
-      );
+      .post<boolean>(this.serverSlimUrl_POST + 'review', {p: priority, c: categories, e: entry})
+        .pipe(
+          catchError(this.handle)
+        );
   }
 
   // 7777777777777777777777777777777777777777777777777777777777777777777777
diff --git a/src/app/test-controller/review-dialog/review-dialog.component.html b/src/app/test-controller/review-dialog/review-dialog.component.html
index ade8aec3..5ad4daf6 100644
--- a/src/app/test-controller/review-dialog/review-dialog.component.html
+++ b/src/app/test-controller/review-dialog/review-dialog.component.html
@@ -6,7 +6,7 @@
         <p>Kommentar für:</p>
         <mat-radio-group formControlName="target" fxLayout="column" fxLayoutGap="4px">
             <mat-radio-button value="b" [matTooltip]="data.bookletname">aktuelles Testheft "{{ data.bookletname }}"</mat-radio-button>
-            <mat-radio-button value="u" [disabled]="data.unitname.length === 0" [matTooltip]="data.unitname">aktuelle Aufgabe "{{ data.unitname }}"</mat-radio-button>
+            <mat-radio-button value="u" [disabled]="data.unitDbKey.length === 0" [matTooltip]="data.unitDbKey">aktuelle Aufgabe "{{ data.unitTitle }}"</mat-radio-button>
         </mat-radio-group>
     </div>
     <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="10px">
diff --git a/src/app/test-controller/test-controller.component.ts b/src/app/test-controller/test-controller.component.ts
index 69d27777..6e656a5a 100644
--- a/src/app/test-controller/test-controller.component.ts
+++ b/src/app/test-controller/test-controller.component.ts
@@ -338,7 +338,8 @@ export class TestControllerComponent implements OnInit, OnDestroy {
         data: {
           loginname: this.tcs.loginname,
           bookletname: this.tcs.rootTestlet.title,
-          unitname: this.tcs.currentUnitTitle
+          unitTitle: this.tcs.currentUnitTitle,
+          unitDbKey: this.tcs.currentUnitDbKey
         }
       });
 
@@ -347,48 +348,44 @@ export class TestControllerComponent implements OnInit, OnDestroy {
           if (result !== false) {
             const targetSelection = (<FormGroup>result).get('target').value;
             if (targetSelection === 'u') {
-      //         this.bs.saveUnitReview(
-      //             this.lds.personToken$.getValue(),
-      //             this.lds.bookletDbId$.getValue(),
-      //             currentUnitId,
-      //             (<FormGroup>result).get('priority').value,
-      //             dialogRef.componentInstance.getCategories(),
-      //             (<FormGroup>result).get('entry').value
-      //           ).subscribe(myData => {
-      //             if (myData instanceof ServerError) {
-      //               const e = myData as ServerError;
-      //               this.snackBar.open(
-      // 'Konnte Kommentar nicht speichern (' + e.code.toString() + ': ' + e.labelNice, '', {duration: 3000});
-      //             } else {
-      //               const ok = myData as boolean;
-      //               if (ok) {
-      //                 this.snackBar.open('Kommentar gespeichert', '', {duration: 1000});
-      //               } else {
-      //                 this.snackBar.open('Konnte Kommentar nicht speichern.', '', {duration: 3000});
-      //               }
-      //             }
-      //           });
+              this.bs.saveUnitReview(
+                  this.tcs.currentUnitDbKey,
+                  (<FormGroup>result).get('priority').value,
+                  dialogRef.componentInstance.getCategories(),
+                  (<FormGroup>result).get('entry').value
+                ).subscribe(myData => {
+                  if (myData instanceof ServerError) {
+                    const e = myData as ServerError;
+                    this.snackBar.open(
+      'Konnte Kommentar nicht speichern (' + e.code.toString() + ': ' + e.labelNice, '', {duration: 3000});
+                  } else {
+                    const ok = myData as boolean;
+                    if (ok) {
+                      this.snackBar.open('Kommentar gespeichert', '', {duration: 1000});
+                    } else {
+                      this.snackBar.open('Konnte Kommentar nicht speichern.', '', {duration: 3000});
+                    }
+                  }
+                });
             } else {
-              // this.bs.saveBookletReview(
-              //   this.lds.personToken$.getValue(),
-              //   this.lds.bookletDbId$.getValue(),
-              // (<FormGroup>result).get('priority').value,
-              //   dialogRef.componentInstance.getCategories(),
-              //   (<FormGroup>result).get('entry').value
-              // ).subscribe(myData => {
-              //   if (myData instanceof ServerError) {
-              //     const e = myData as ServerError;
-              //     this.snackBar.open('Konnte Kommentar nicht speichern (' + e.code.toString()
-              // + ': ' + e.labelNice, '', {duration: 3000});
-              //   } else {
-              //     const ok = myData as boolean;
-              //     if (ok) {
-              //       this.snackBar.open('Kommentar gespeichert', '', {duration: 1000});
-              //     } else {
-              //       this.snackBar.open('Konnte Kommentar nicht speichern.', '', {duration: 3000});
-              //     }
-              //   }
-              // });
+              this.bs.saveBookletReview(
+              (<FormGroup>result).get('priority').value,
+                dialogRef.componentInstance.getCategories(),
+                (<FormGroup>result).get('entry').value
+              ).subscribe(myData => {
+                if (myData instanceof ServerError) {
+                  const e = myData as ServerError;
+                  this.snackBar.open('Konnte Kommentar nicht speichern (' + e.code.toString()
+              + ': ' + e.labelNice, '', {duration: 3000});
+                } else {
+                  const ok = myData as boolean;
+                  if (ok) {
+                    this.snackBar.open('Kommentar gespeichert', '', {duration: 1000});
+                  } else {
+                    this.snackBar.open('Konnte Kommentar nicht speichern.', '', {duration: 3000});
+                  }
+                }
+              });
             }
           }
         }
diff --git a/src/app/test-controller/test-controller.interfaces.ts b/src/app/test-controller/test-controller.interfaces.ts
index 73f88066..56e17ab4 100644
--- a/src/app/test-controller/test-controller.interfaces.ts
+++ b/src/app/test-controller/test-controller.interfaces.ts
@@ -1,16 +1,16 @@
 export interface UnitLogData {
-    unitName: string;
+    unitDbKey: string;
     logEntry: string;
 }
 
 export interface UnitResponseData {
-    unitName: string;
+    unitDbKey: string;
     response: string;
     responseType: string;
 }
 
 export interface UnitRestorePointData {
-    unitName: string;
+    unitDbKey: string;
     unitSequenceId: number;
     restorePoint: string;
 }
diff --git a/src/app/test-controller/test-controller.service.ts b/src/app/test-controller/test-controller.service.ts
index f81b1f41..de4c9803 100644
--- a/src/app/test-controller/test-controller.service.ts
+++ b/src/app/test-controller/test-controller.service.ts
@@ -25,7 +25,7 @@ export class TestControllerService {
     this._currentUnitSequenceId = v;
   }
 
-  public currentUnitId = '';
+  public currentUnitDbKey = '';
   public currentUnitTitle = '';
   public unitPrevEnabled = false;
   public unitNextEnabled = false;
@@ -55,7 +55,7 @@ export class TestControllerService {
     this.mode = '';
     this.loginname = '';
     this.currentUnitSequenceId = 0;
-    this.currentUnitId = '';
+    this.currentUnitDbKey = '';
     this.currentUnitTitle = '';
     this.unitPrevEnabled = false;
     this.unitNextEnabled = false;
diff --git a/src/app/test-controller/unithost/unithost.component.ts b/src/app/test-controller/unithost/unithost.component.ts
index fd60ce90..0d8200cd 100644
--- a/src/app/test-controller/unithost/unithost.component.ts
+++ b/src/app/test-controller/unithost/unithost.component.ts
@@ -24,7 +24,7 @@ export class UnithostComponent implements OnInit, OnDestroy {
           'Verlassen der Aufgabe wird der Hörtext nicht noch einmal gestartet. Trotzdem die Aufgabe verlassen?';
 
   private myUnitNumber = -1;
-  private myUnitName = '';
+  private myUnitDbKey = '';
   private unitTitle = '';
 
   // :::::::::::::::::::::
@@ -115,13 +115,13 @@ export class UnithostComponent implements OnInit, OnDestroy {
               const restorePoint = msgData['restorePoint'] as string;
               if (restorePoint !== undefined) {
                 this.restorePoint$.next({
-                  unitName: this.myUnitName,
+                  unitDbKey: this.myUnitDbKey,
                   unitSequenceId: this.myUnitNumber,
                   restorePoint: restorePoint});
               }
               const response = msgData['response'] as string;
               if (response !== undefined) {
-                this.response$.next({'unitName': this.myUnitName, 'response': response, 'responseType': msgData['responseType']});
+                this.response$.next({unitDbKey: this.myUnitDbKey, response: response, responseType: msgData['responseType']});
               }
               const canLeaveChanged = msgData['canLeave'];
               if (canLeaveChanged !== undefined) {
@@ -179,10 +179,10 @@ export class UnithostComponent implements OnInit, OnDestroy {
         data.forEach(lg => {
           if (lg !== null) {
             if (lg.logEntry.length > 0) {
-              if (typeof myLogs[lg.unitName] === 'undefined') {
-                myLogs[lg.unitName] = [];
+              if (typeof myLogs[lg.unitDbKey] === 'undefined') {
+                myLogs[lg.unitDbKey] = [];
               }
-              myLogs[lg.unitName].push(JSON.stringify(lg.logEntry));
+              myLogs[lg.unitDbKey].push(JSON.stringify(lg.logEntry));
             }
           }
         });
@@ -214,8 +214,8 @@ export class UnithostComponent implements OnInit, OnDestroy {
       if ((this.myUnitNumber >= 1) && (this.myUnitNumber === this.myUnitNumber) && (this.tcs.rootTestlet !== null)) {
         const currentUnit = this.tcs.rootTestlet.getUnitAt(this.myUnitNumber);
         this.unitTitle = currentUnit.unitDef.title; // (currentUnitId + 1).toString() + '. '
-        this.myUnitName = currentUnit.unitDef.id;
-        this.tcs.currentUnitId = this.myUnitName;
+        this.myUnitDbKey = currentUnit.unitDef.alias;
+        this.tcs.currentUnitDbKey = this.myUnitDbKey;
         this.tcs.currentUnitTitle = this.unitTitle;
         this.itemplayerSessionId = Math.floor(Math.random() * 20000000 + 10000000).toString();
 
-- 
GitLab