diff --git a/src/app/maindata.service.ts b/src/app/maindata.service.ts index 452e6b221a26a4f4c5419bcb04a8d1aa8a78b842..8722aae164a98c1344448f7381535e63dadd7e2b 100644 --- a/src/app/maindata.service.ts +++ b/src/app/maindata.service.ts @@ -107,6 +107,13 @@ export class MainDataService { this.setNewLoginData(myLoginData); } + + getBookletDbId(): number { + + return this.loginData$.getValue().booklet; + } + + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ endBooklet () { const myLoginData = this.loginData$.getValue(); diff --git a/src/app/test-controller/backend.service.ts b/src/app/test-controller/backend.service.ts index 9c0011c0d920dc5f86c3a0b342562bb319b7fe98..41ab161e6b4c8b7e4341fb7f90873f47dfc778b7 100644 --- a/src/app/test-controller/backend.service.ts +++ b/src/app/test-controller/backend.service.ts @@ -1,9 +1,9 @@ import { Injectable, Inject } from '@angular/core'; -import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http'; +import { HttpClient, HttpErrorResponse, HttpParams } from '@angular/common/http'; import { Observable, of } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { BookletData, UnitData, TaggedString } from './test-controller.interfaces'; -import {ServerError} from "iqb-components"; +import { ServerError } from 'iqb-components'; @Injectable({ @@ -13,6 +13,8 @@ export class BackendService { private serverSlimUrl_GET = ''; private serverSlimUrl_POST = ''; + private serverUrl2 = 'http://localhost/testcenter-iqb-php/'; + constructor( @Inject('SERVER_URL') private serverUrl: string, private http: HttpClient) { @@ -21,56 +23,49 @@ export class BackendService { this.serverUrl = this.serverUrl + 'php_tc/'; } - // 7777777777777777777777777777777777777777777777777777777777777777777777 - // send reviews - // 7777777777777777777777777777777777777777777777777777777777777777777777 - saveUnitReview(unit: string, priority: number, - categories: string, entry: string): Observable<boolean | ServerError> { + + saveUnitReview(testId: number, unitName: string, priority: number, categories: string, entry: string) + : Observable<boolean | ServerError> { + return this.http - .post<boolean>(this.serverSlimUrl_POST + 'review', {u: unit, p: priority, c: categories, e: entry}) - .pipe( - catchError(this.handle) - ); + .put<boolean>(this.serverUrl2 + `test/${testId}/unit/${unitName}/review`, {priority, categories, entry}) + .pipe(catchError(this.handle)); } - // ------------------------------ - saveBookletReview(priority: number, categories: string, entry: string): Observable<boolean | ServerError> { + + saveBookletReview(testId: number, priority: number, categories: string, entry: string): Observable<boolean | ServerError> { + return this.http - .post<boolean>(this.serverSlimUrl_POST + 'review', {p: priority, c: categories, e: entry}) - .pipe( - catchError(this.handle) - ); + .put<boolean>(this.serverUrl2 + `test/${testId}/review`, {priority, categories, entry}) + .pipe(catchError(this.handle)); } - // 7777777777777777777777777777777777777777777777777777777777777777777777 - // get - // 7777777777777777777777777777777777777777777777777777777777777777777777 - getBookletData(): Observable<BookletData | ServerError> { - return this.http.get<BookletData>(this.serverSlimUrl_GET + 'bookletdata') - .pipe( - catchError(this.handle) - ); + getBookletData(testId: number): Observable<BookletData | ServerError> { + + return this.http + .get<BookletData>(this.serverUrl2 + 'test/' + testId) + .pipe(catchError(this.handle)); } - // ------------------------------ - getUnitData(unitid: string): Observable<UnitData | ServerError> { - return this.http.get<UnitData>(this.serverSlimUrl_GET + 'unitdata/' + unitid) - .pipe( - catchError(this.handle) - ); + + getUnitData(testId: number, unitid: string): Observable<UnitData | ServerError> { + + return this.http + .get<UnitData>(this.serverUrl2 + 'test/' + testId + '/unit/' + unitid) + .pipe(catchError(this.handle)); } - // ------------------------------ + getResource(internalKey: string, resId: string, versionning = false): Observable<TaggedString | ServerError> { - const myHttpOptions = { - headers: new HttpHeaders({ - 'Content-Type': 'application/json' - }), - responseType: 'text' as 'json' - }; - const urlSuffix = versionning ? '?v=1' : ''; - return this.http.get<string>(this.serverSlimUrl_GET + 'resource/' + resId + urlSuffix, myHttpOptions) + + return this.http + .get( + this.serverUrl2 + 'resource/' + resId, + { + params: new HttpParams().set('v', versionning ? '1' : 'f'), + responseType: 'text' + }) .pipe( map(def => <TaggedString>{tag: internalKey, value: def}), catchError(this.handle) @@ -112,21 +107,21 @@ export class BackendService { ); } - newUnitResponse(bookletDbId: number, timestamp: number, - unitDbKey: string, response: string, responseType: string): Observable<boolean | ServerError> { + + newUnitResponse(testId: number, timestamp: number, unitName: string, response: string, responseType: string) + : Observable<boolean | ServerError> { + return this.http - .post<boolean>(this.serverSlimUrl_POST + 'response', {b: bookletDbId, u: unitDbKey, t: timestamp, r: response, rt: responseType}) - .pipe( - catchError(this.handle) - ); + .put<boolean>(this.serverUrl2 + `test/${testId}/unit/${unitName}/response`, {timestamp, response, responseType}) + .pipe(catchError(this.handle)); } - newUnitRestorePoint(bookletDbId: number, unitDbKey: string, timestamp: number, restorePoint: string): Observable<boolean | ServerError> { + + newUnitRestorePoint(testId: number, unitName: string, timestamp: number, restorePoint: string): Observable<boolean | ServerError> { + return this.http - .post<boolean>(this.serverSlimUrl_POST + 'restorepoint', {b: bookletDbId, u: unitDbKey, t: timestamp, r: restorePoint}) - .pipe( - catchError(this.handle) - ); + .put<boolean>(this.serverUrl2 + `test/${testId}/unit/${unitName}/restorepoint`, {timestamp, restorePoint}) + .pipe(catchError(this.handle)); } @@ -148,42 +143,3 @@ export class BackendService { return of(myreturn); } } - - - // ------------------------------ - // getUnitResource(sessiontoken: string, resId: string): Observable<string | ServerError> { - // const myHttpOptions = { - // headers: new HttpHeaders({ - // 'Content-Type': 'application/json' - // }), - // responseType: 'arraybuffer' as 'json' - // }; - - // return this.http - // .post<ArrayBuffer>(this.serverUrl + 'getUnitResource.php', {st: sessiontoken, r: resId}, myHttpOptions) - // .pipe( - // map((r: ArrayBuffer) => { - // let str64 = ''; - // const alen = r.byteLength; - // for (let i = 0; i < alen; i++) { - // str64 += String.fromCharCode(r[i]); - // } - // return window.btoa(str64); - // }), - // catchError(this.handle) - // ); - // } - // getUnitResource64(sessiontoken: string, resId: string): Observable<string | ServerError> { - // const myHttpOptions = { - // headers: new HttpHeaders({ - // 'Content-Type': 'application/json' - // }), - // responseType: 'text' as 'json' - // }; - - // return this.http - // .post<string>(this.serverUrl + 'getUnitResource64.php', {st: sessiontoken, r: resId}, myHttpOptions) - // .pipe( - // catchError(this.handle) - // ); - // } diff --git a/src/app/test-controller/test-controller.component.ts b/src/app/test-controller/test-controller.component.ts index 4a217e0694642820712b93fed605604671d7b569..824e83f700b5e892924dad914b6730cdfafc5725 100644 --- a/src/app/test-controller/test-controller.component.ts +++ b/src/app/test-controller/test-controller.component.ts @@ -11,8 +11,8 @@ import { UnitDef, Testlet, EnvironmentData, MaxTimerData } from './test-controll import { LastStateKey, LogEntryKey, BookletData, UnitData, MaxTimerDataType, TaggedString } from './test-controller.interfaces'; import { Subscription, Observable, of, from } from 'rxjs'; import { switchMap, concatMap } from 'rxjs/operators'; -import {CustomtextService, ServerError} from "iqb-components"; -import {appconfig} from "../app.config"; +import { CustomtextService, ServerError } from 'iqb-components'; +import { appconfig } from '../app.config'; @Component({ templateUrl: './test-controller.component.html', @@ -299,8 +299,7 @@ export class TestControllerComponent implements OnInit, OnDestroy { // '''''''''''''''''''''''''''''''''''''''''''''''''''' private loadUnitOk (myUnit: UnitDef, sequenceId: number): Observable<boolean> { myUnit.setCanEnter('n', 'Fehler beim Laden'); - - return this.bs.getUnitData(myUnit.id) + return this.bs.getUnitData(this.mds.getBookletDbId(), myUnit.id) .pipe( switchMap(myData => { if (myData instanceof ServerError) { @@ -476,7 +475,7 @@ export class TestControllerComponent implements OnInit, OnDestroy { this.tcs.loginname = loginData.loginname; this.tcs.dataLoading = true; - this.bs.getBookletData().subscribe(myData => { + this.bs.getBookletData(this.mds.getBookletDbId()).subscribe(myData => { if (myData instanceof ServerError) { const e = myData as ServerError; this.mds.globalErrorMsg$.next(e); @@ -614,41 +613,31 @@ export class TestControllerComponent implements OnInit, OnDestroy { const targetSelection = (<FormGroup>result).get('target').value; if (targetSelection === 'u') { this.bs.saveUnitReview( + this.mds.getBookletDbId(), 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}); + myData.code.toString() + ': ' + myData.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.snackBar.open('Kommentar gespeichert', '', {duration: 1000}); } }); } else { this.bs.saveBookletReview( - (<FormGroup>result).get('priority').value, + this.mds.getBookletDbId(), + (<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}); + this.snackBar.open('Konnte Kommentar nicht speichern (' + myData.code.toString() + + ': ' + myData.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.snackBar.open('Kommentar gespeichert', '', {duration: 1000}); } }); } diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 8778184373cf253ece5a95e9f60f49a1f3e21b8b..a2e305d175a05edabd7bf350dae161d60204deb9 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -5,8 +5,7 @@ export const environment = { production: false, // testcenterUrl: 'https://www.iqb-testcenter.de/', - testcenterUrl: 'https://ocba.iqb.hu-berlin.de/', - // testcenterUrl: 'http://localhost/testcenter-iqb-php/', + testcenterUrl: 'http://localhost/tmp/', appName: 'IQB-Testcenter', appPublisher: 'IQB - Institut zur Qualitätsentwicklung im Bildungswesen', appVersion: '0 (dev)'