From 1e4230d1330a52df6a92dc1fac5b1585564616ec Mon Sep 17 00:00:00 2001 From: mechtelm <nicht@mehr.fragen> Date: Sat, 23 Feb 2019 20:59:05 +0100 Subject: [PATCH] seems to work again --- src/app/authorisation.class.ts | 28 ------------- src/app/start/start.component.ts | 7 ++-- src/app/test-controller/backend.service.ts | 40 ++++++++++--------- .../start-lock-input.component.ts | 3 +- .../tc-menu-buttons.component.ts | 8 ++-- .../tc-sidenavi-button.component.ts | 3 +- .../test-controller.classes.ts | 13 +++--- .../test-controller.component.ts | 21 +++++----- .../test-controller/test-controller.module.ts | 2 +- .../test-controller.service.ts | 7 ++-- .../unithost/unithost.component.ts | 10 +++-- 11 files changed, 62 insertions(+), 80 deletions(-) delete mode 100644 src/app/authorisation.class.ts diff --git a/src/app/authorisation.class.ts b/src/app/authorisation.class.ts deleted file mode 100644 index 2ad6f7e5..00000000 --- a/src/app/authorisation.class.ts +++ /dev/null @@ -1,28 +0,0 @@ -export class AuthorisationX { - readonly personToken: string; - readonly bookletId: number; - - static fromPersonTokenAndBookletId(personToken: string, bookletId: number): AuthorisationX { - return new AuthorisationX(personToken + '##' + bookletId.toString()); - } - - constructor(authString: string) { - if ((typeof authString !== 'string') || (authString.length === 0)) { - this.personToken = ''; - this.bookletId = 0; - } else { - const retSplits = authString.split('##'); - this.personToken = retSplits[0]; - - if (retSplits.length > 1) { - this.bookletId = +retSplits[1]; - } else { - this.bookletId = 0; - } - } - } - - toAuthString(): string { - return this.personToken + '##' + this.bookletId.toString(); - } -} diff --git a/src/app/start/start.component.ts b/src/app/start/start.component.ts index e232b6b5..72d4e1c2 100644 --- a/src/app/start/start.component.ts +++ b/src/app/start/start.component.ts @@ -300,9 +300,10 @@ export class StartComponent implements OnInit { // # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # buttonEndTest() { - const auth = this.lds.authorisation$.getValue(); - if ((this.lds.loginMode$.getValue() === 'hot') && (auth !== null)) { - this.bs.endBooklet(auth.personToken, auth.bookletId).subscribe( + const pToken = this.lds.personToken$.getValue(); + const bookletDbId = this.lds.bookletDbId$.getValue(); + if ((this.lds.loginMode$.getValue() === 'hot') && (bookletDbId !== 0)) { + this.bs.endBooklet(pToken, bookletDbId).subscribe( finOkUntyped => { if (finOkUntyped instanceof ServerError) { const e = finOkUntyped as ServerError; diff --git a/src/app/test-controller/backend.service.ts b/src/app/test-controller/backend.service.ts index ed41dc7f..5d4bdae0 100644 --- a/src/app/test-controller/backend.service.ts +++ b/src/app/test-controller/backend.service.ts @@ -2,7 +2,6 @@ import { Injectable, Inject } from '@angular/core'; import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http'; import { Observable, of } from 'rxjs'; import { catchError, map, tap, switchMap } from 'rxjs/operators'; -import { Authorisation } from '../authorisation.class'; import { BookletData, UnitData } from './test-controller.interfaces'; import { ServerError } from './test-controller.classes'; @@ -19,7 +18,7 @@ export class BackendService { } // 7777777777777777777777777777777777777777777777777777777777777777777777 - saveUnitReview(auth: Authorisation, unit: string, priority: number, + saveUnitReview(pToken: string, bookletDbId: number, unit: string, priority: number, categories: string, entry: string): Observable<boolean | ServerError> { const httpOptions = { headers: new HttpHeaders({ @@ -27,7 +26,7 @@ export class BackendService { }) }; return this.http - .post<boolean>(this.serverUrl + 'addUnitReview.php', {au: auth.toAuthString(), u: unit, + .post<boolean>(this.serverUrl + 'addUnitReview.php', {au: pToken + '##' + bookletDbId.toString(), u: unit, p: priority, c: categories, e: entry}, httpOptions) .pipe( catchError(this.handle) @@ -35,14 +34,15 @@ export class BackendService { } // 7777777777777777777777777777777777777777777777777777777777777777777777 - saveBookletReview(auth: Authorisation, priority: number, categories: string, entry: string): Observable<boolean | ServerError> { + saveBookletReview(pToken: string, bookletDbId: number, priority: number, + categories: string, entry: string): Observable<boolean | ServerError> { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }; return this.http - .post<boolean>(this.serverUrl + 'addBookletReview.php', {au: auth.toAuthString(), + .post<boolean>(this.serverUrl + 'addBookletReview.php', {au: pToken + '##' + bookletDbId.toString(), p: priority, c: categories, e: entry}, httpOptions) .pipe( catchError(this.handle) @@ -50,21 +50,21 @@ export class BackendService { } // 7777777777777777777777777777777777777777777777777777777777777777777777 - getBookletData(auth: Authorisation): Observable<BookletData | ServerError> { + getBookletData(pToken: string, bookletDbId: number): Observable<BookletData | ServerError> { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }; return this.http - .post<BookletData>(this.serverUrl + 'getBookletData.php', {au: auth.toAuthString()}, httpOptions) + .post<BookletData>(this.serverUrl + 'getBookletData.php', {au: pToken + '##' + bookletDbId.toString()}, httpOptions) .pipe( catchError(this.handle) ); } // 7777777777777777777777777777777777777777777777777777777777777777777777 - getUnitData(auth: Authorisation, unitid: string): Observable<UnitData | ServerError> { + getUnitData(pToken: string, bookletDbId: number, unitid: string): Observable<UnitData | ServerError> { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' @@ -72,14 +72,14 @@ export class BackendService { }; return this.http - .post<UnitData>(this.serverUrl + 'getUnitData.php', {au: auth.toAuthString(), u: unitid}, httpOptions) + .post<UnitData>(this.serverUrl + 'getUnitData.php', {au: pToken + '##' + bookletDbId.toString(), u: unitid}, httpOptions) .pipe( catchError(this.handle) ); } // 888888888888888888888888888888888888888888888888888888888888888888 - setBookletStatus(auth: Authorisation, state: {}): Observable<string | ServerError> { + setBookletStatus(pToken: string, bookletDbId: number, state: {}): Observable<string | ServerError> { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' @@ -90,7 +90,7 @@ export class BackendService { // } else { // this.lastBookletState = sessiontoken + JSON.stringify(state); return this.http - .post<string>(this.serverUrl + 'setBookletStatus.php', {au: auth.toAuthString(), state: state}, httpOptions) + .post<string>(this.serverUrl + 'setBookletStatus.php', {au: pToken + '##' + bookletDbId.toString(), state: state}, httpOptions) .pipe( catchError(this.handle) ); @@ -138,7 +138,7 @@ export class BackendService { } // 888888888888888888888888888888888888888888888888888888888888888888 - getUnitResourceTxt(auth: Authorisation, resId: string): Observable<string | ServerError> { + getUnitResourceTxt(pToken: string, bookletDbId: number, resId: string): Observable<string | ServerError> { const myHttpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' @@ -147,7 +147,7 @@ export class BackendService { }; return this.http - .post<string>(this.serverUrl + 'getUnitResourceTxt.php', {au: auth.toAuthString(), r: resId}, myHttpOptions) + .post<string>(this.serverUrl + 'getUnitResourceTxt.php', {au: pToken + '##' + bookletDbId.toString(), r: resId}, myHttpOptions) .pipe( catchError(this.handle) ); @@ -155,7 +155,8 @@ export class BackendService { // 888888888888888888888888888888888888888888888888888888888888888888 // 7777777777777777777777777777777777777777777777777777777777777777777777 - setUnitResponses(auth: Authorisation, unit: string, unitdata: string, responseType: string): Observable<boolean | ServerError> { + setUnitResponses(pToken: string, bookletDbId: number, unit: string, + unitdata: string, responseType: string): Observable<boolean | ServerError> { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' @@ -163,35 +164,36 @@ export class BackendService { }; return this.http .post<boolean>(this.serverUrl + 'setUnitResponse.php', - {au: auth.toAuthString(), u: unit, d: JSON.stringify(unitdata), rt: responseType}, httpOptions) + {au: pToken + '##' + bookletDbId.toString(), u: unit, d: JSON.stringify(unitdata), rt: responseType}, httpOptions) .pipe( catchError(this.handle) ); } // 7777777777777777777777777777777777777777777777777777777777777777777777 - setUnitRestorePoint(auth: Authorisation, unit: string, unitdata: string): Observable<boolean | ServerError> { + setUnitRestorePoint(pToken: string, bookletDbId: number, unit: string, unitdata: string): Observable<boolean | ServerError> { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }; return this.http - .post<boolean>(this.serverUrl + 'setUnitRestorePoint.php', {au: auth.toAuthString(), u: unit, d: JSON.stringify(unitdata)}, httpOptions) + .post<boolean>(this.serverUrl + 'setUnitRestorePoint.php', + {au: pToken + '##' + bookletDbId.toString(), u: unit, d: JSON.stringify(unitdata)}, httpOptions) .pipe( catchError(this.handle) ); } // 7777777777777777777777777777777777777777777777777777777777777777777777 - setUnitLog(auth: Authorisation, unit: string, unitdata: string[]): Observable<boolean | ServerError> { + setUnitLog(pToken: string, bookletDbId: number, unit: string, unitdata: string[]): Observable<boolean | ServerError> { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }; return this.http - .post<boolean>(this.serverUrl + 'setUnitLog.php', {au: auth.toAuthString(), u: unit, d: unitdata}, httpOptions) + .post<boolean>(this.serverUrl + 'setUnitLog.php', {au: pToken + '##' + bookletDbId.toString(), u: unit, d: unitdata}, httpOptions) .pipe( catchError(this.handle) ); diff --git a/src/app/test-controller/start-lock-input/start-lock-input.component.ts b/src/app/test-controller/start-lock-input/start-lock-input.component.ts index a92393a1..ca87b1f5 100644 --- a/src/app/test-controller/start-lock-input/start-lock-input.component.ts +++ b/src/app/test-controller/start-lock-input/start-lock-input.component.ts @@ -1,7 +1,8 @@ import { MAT_DIALOG_DATA } from '@angular/material'; import { FormBuilder, FormGroup } from '@angular/forms'; import { Component, OnInit, Inject } from '@angular/core'; -import { StartLockData } from '../test-controller.service'; +import { StartLockData } from '../test-controller.interfaces'; + @Component({ templateUrl: './start-lock-input.component.html', diff --git a/src/app/test-controller/tc-menu-buttons/tc-menu-buttons.component.ts b/src/app/test-controller/tc-menu-buttons/tc-menu-buttons.component.ts index 8d2bd54e..377bdb6a 100644 --- a/src/app/test-controller/tc-menu-buttons/tc-menu-buttons.component.ts +++ b/src/app/test-controller/tc-menu-buttons/tc-menu-buttons.component.ts @@ -69,7 +69,8 @@ export class TcMenuButtonsComponent implements OnInit { const targetSelection = (<FormGroup>result).get('target').value; if (targetSelection === 'u') { this.bs.saveUnitReview( - this.lds.authorisation$.getValue(), + this.lds.personToken$.getValue(), + this.lds.bookletDbId$.getValue(), currentUnitId, (<FormGroup>result).get('priority').value, dialogRef.componentInstance.getCategories(), @@ -89,8 +90,9 @@ export class TcMenuButtonsComponent implements OnInit { }); } else { this.bs.saveBookletReview( - this.lds.authorisation$.getValue(), - (<FormGroup>result).get('priority').value, + this.lds.personToken$.getValue(), + this.lds.bookletDbId$.getValue(), + (<FormGroup>result).get('priority').value, dialogRef.componentInstance.getCategories(), (<FormGroup>result).get('entry').value ).subscribe(myData => { diff --git a/src/app/test-controller/tc-sidenavi-button/tc-sidenavi-button.component.ts b/src/app/test-controller/tc-sidenavi-button/tc-sidenavi-button.component.ts index 4078858f..93af7a16 100644 --- a/src/app/test-controller/tc-sidenavi-button/tc-sidenavi-button.component.ts +++ b/src/app/test-controller/tc-sidenavi-button/tc-sidenavi-button.component.ts @@ -1,5 +1,6 @@ -import { UnitDef, TestControllerService } from './../test-controller.service'; +import { TestControllerService } from '../test-controller.service'; import { Component, OnInit, Input } from '@angular/core'; +import { UnitDef } from '../test-controller.classes'; @Component({ selector: 'tc-sidenavi-button', diff --git a/src/app/test-controller/test-controller.classes.ts b/src/app/test-controller/test-controller.classes.ts index f97015f3..34d6bdde 100644 --- a/src/app/test-controller/test-controller.classes.ts +++ b/src/app/test-controller/test-controller.classes.ts @@ -1,6 +1,5 @@ import { BackendService } from './backend.service'; import { TestControllerService } from './test-controller.service'; -import { Authorisation } from '../authorisation.class'; import { Observable, of, BehaviorSubject, forkJoin } from 'rxjs'; import { switchMap } from 'rxjs/operators'; import { UnitData, BookletData } from './test-controller.interfaces'; @@ -56,8 +55,8 @@ export class UnitDef { return myResources; } - loadOk(bs: BackendService, tcs: TestControllerService, auth: Authorisation): Observable<boolean> { - return bs.getUnitData(auth, this.id) + loadOk(bs: BackendService, tcs: TestControllerService, pToken: string, bookletDbId: number): Observable<boolean> { + return bs.getUnitData(pToken, bookletDbId, this.id) .pipe( switchMap(myData => { if (myData instanceof ServerError) { @@ -93,10 +92,10 @@ export class UnitDef { } if (this.unitDefinitionType.length > 0) { - return tcs.loadItemplayerOk(auth, this.unitDefinitionType).pipe( + return tcs.loadItemplayerOk(pToken, bookletDbId, this.unitDefinitionType).pipe( switchMap(ok => { if (ok && definitionRef.length > 0) { - return bs.getUnitResourceTxt(auth, definitionRef).pipe( + return bs.getUnitResourceTxt(pToken, bookletDbId, definitionRef).pipe( switchMap(def => { if (def instanceof ServerError) { return of(false); @@ -249,10 +248,10 @@ export class BookletDef { } } - loadUnits(bs: BackendService, tcs: TestControllerService, auth: Authorisation): Observable<boolean[]> { + loadUnits(bs: BackendService, tcs: TestControllerService, pToken: string, bookletDbId: number): Observable<boolean[]> { const myUnitLoadings = []; for (let i = 0; i < this.units.length; i++) { - myUnitLoadings.push(this.units[i].loadOk(bs, tcs, auth)); + myUnitLoadings.push(this.units[i].loadOk(bs, tcs, pToken, bookletDbId)); } return forkJoin(myUnitLoadings); } diff --git a/src/app/test-controller/test-controller.component.ts b/src/app/test-controller/test-controller.component.ts index 9a3e5833..c25600c2 100644 --- a/src/app/test-controller/test-controller.component.ts +++ b/src/app/test-controller/test-controller.component.ts @@ -16,7 +16,7 @@ export class TestControllerComponent implements OnInit { private allUnits: UnitDef[] = []; private statusMsg = ''; private dataLoading = false; - private myLastAuthString = ''; // to avoid double load + private myLastBooklet = 0; // to avoid double load constructor ( private tcs: TestControllerService, @@ -36,23 +36,24 @@ export class TestControllerComponent implements OnInit { ngOnInit() { this.loadBooklet('init'); - this.lds.authorisation$.subscribe(authori => { + this.lds.bookletDbId$.subscribe(authori => { this.loadBooklet('subsc'); }); } private loadBooklet(s: string) { - const auth = this.lds.authorisation$.getValue(); - console.log('Booklet: ' + s); - if (auth == null) { + const pToken = this.lds.personToken$.getValue(); + const bookletDbId = this.lds.bookletDbId$.getValue(); + + if (bookletDbId === 0) { this.resetBookletData(); - this.myLastAuthString = ''; + this.myLastBooklet = 0; } else { - if (this.myLastAuthString !== auth.toAuthString()) { - this.myLastAuthString = auth.toAuthString(); + if (this.myLastBooklet !== bookletDbId) { + this.myLastBooklet = bookletDbId; this.dataLoading = true; - this.bs.getBookletData(auth).subscribe(myData => { + this.bs.getBookletData(pToken, bookletDbId).subscribe(myData => { if (myData instanceof ServerError) { const e = myData as ServerError; this.lds.globalErrorMsg$.next(e); @@ -62,7 +63,7 @@ export class TestControllerComponent implements OnInit { this.lds.globalErrorMsg$.next(null); const myBookletData = myData as BookletData; const myBookletDef = new BookletDef(myBookletData); - myBookletDef.loadUnits(this.bs, this.tcs, auth).subscribe(okList => { + myBookletDef.loadUnits(this.bs, this.tcs, pToken, bookletDbId).subscribe(okList => { this.dataLoading = false; this.tcs.booklet$.next(myBookletDef); this.tcs.showNaviButtons$.next(myBookletDef.unlockedUnitCount() > 1); diff --git a/src/app/test-controller/test-controller.module.ts b/src/app/test-controller/test-controller.module.ts index 4360af37..d6442e1d 100644 --- a/src/app/test-controller/test-controller.module.ts +++ b/src/app/test-controller/test-controller.module.ts @@ -1,4 +1,4 @@ -export { TestControllerService, SessionDataToSend } from './test-controller.service'; +export { TestControllerService } from './test-controller.service'; import { BackendService } from './backend.service'; import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; diff --git a/src/app/test-controller/test-controller.service.ts b/src/app/test-controller/test-controller.service.ts index f50b40f2..7cd44377 100644 --- a/src/app/test-controller/test-controller.service.ts +++ b/src/app/test-controller/test-controller.service.ts @@ -93,14 +93,14 @@ export class TestControllerService { } // 7777777777777777777777777777777777777777777777777777777777777777777777 - loadItemplayerOk(auth: Authorisation, unitDefinitionType: string): Observable<boolean> { + loadItemplayerOk(pToken: string, bookletDbId: number, unitDefinitionType: string): Observable<boolean> { unitDefinitionType = this.normaliseFileName(unitDefinitionType, 'html'); if (this.itemplayers.hasOwnProperty(unitDefinitionType)) { return of(true); } else { // to avoid multiple calls before returning: this.itemplayers[unitDefinitionType] = null; - return this.bs.getUnitResourceTxt(auth, unitDefinitionType) + return this.bs.getUnitResourceTxt(pToken, bookletDbId, unitDefinitionType) .pipe( switchMap(myData => { if (myData instanceof ServerError) { @@ -158,7 +158,8 @@ export class TestControllerService { const currentBooklet = this.booklet$.getValue(); if ((targetUnitSequenceId >= 0) && (currentBooklet !== null) && (targetUnitSequenceId < currentBooklet.units.length)) { this.currentUnitPos$.next(targetUnitSequenceId); - this.bs.setBookletStatus(this.lds.authorisation$.getValue(), {u: targetUnitSequenceId}).subscribe(); + + this.bs.setBookletStatus(this.lds.personToken$.getValue(), this.lds.bookletDbId$.getValue(), {u: targetUnitSequenceId}).subscribe(); } } } diff --git a/src/app/test-controller/unithost/unithost.component.ts b/src/app/test-controller/unithost/unithost.component.ts index c12985a4..f1671c22 100644 --- a/src/app/test-controller/unithost/unithost.component.ts +++ b/src/app/test-controller/unithost/unithost.component.ts @@ -171,7 +171,8 @@ export class UnithostComponent implements OnInit, OnDestroy { this.restorePoints[data.unitName] = data.restorePoint; if (this.lds.loginMode$.getValue() !== 'review') { - this.bs.setUnitRestorePoint(this.lds.authorisation$.getValue(), data.unitName, data.restorePoint) + this.bs.setUnitRestorePoint(this.lds.personToken$.getValue(), + this.lds.bookletDbId$.getValue(), data.unitName, data.restorePoint) .subscribe(); } } @@ -182,7 +183,8 @@ export class UnithostComponent implements OnInit, OnDestroy { debounceTime(300) ).subscribe(data => { if ((data !== null) && (this.lds.loginMode$.getValue() !== 'review')) { - this.bs.setUnitResponses(this.lds.authorisation$.getValue(), data.unitName, data.response, data.responseType) + this.bs.setUnitResponses(this.lds.personToken$.getValue(), + this.lds.bookletDbId$.getValue(), data.unitName, data.response, data.responseType) .subscribe(); } }); @@ -205,7 +207,7 @@ export class UnithostComponent implements OnInit, OnDestroy { }); for (const unitName in myLogs) { if (myLogs[unitName].length > 0) { - this.bs.setUnitLog(this.lds.authorisation$.getValue(), unitName, myLogs[unitName]).subscribe(); + this.bs.setUnitLog(this.lds.personToken$.getValue(), this.lds.bookletDbId$.getValue(), unitName, myLogs[unitName]).subscribe(); } } } @@ -235,7 +237,7 @@ export class UnithostComponent implements OnInit, OnDestroy { this.loadItemplayer(); }); - this.lds.authorisation$.subscribe(auth => { + this.lds.bookletDbId$.subscribe(auth => { this.restorePoints = {}; }); -- GitLab