Newer
Older
import {AuthAccessKeyType, AuthData, BookletData} from "../../app.interfaces";
import {from, Subscription} from "rxjs";
import {concatMap} from "rxjs/operators";
import {Router} from "@angular/router";
import {BackendService} from "../../backend.service";
import {MainDataService} from "../../maindata.service";
@Component({
templateUrl: './test-starter.component.html',
styleUrls: ['./test-starter.component.css']
})
export class TestStarterComponent implements OnInit {
booklets: BookletData[] = [];
private getBookletDataSubscription: Subscription = null;
public bookletSelectTitle = 'Bitte wählen';
constructor(
private router: Router,
private bs: BackendService,
private mds: MainDataService
) { }
setTimeout(() => {
this.bs.getSessionData().subscribe(authDataUntyped => {
if (typeof authDataUntyped !== 'number') {
const authData = authDataUntyped as AuthData;
if (authData) {
if (authData.token) {
if (authData.access[AuthAccessKeyType.TEST]) {
this.booklets = [];
if (this.getBookletDataSubscription !== null) {
this.getBookletDataSubscription.unsubscribe();
}
this.getBookletDataSubscription = from(authData.access[AuthAccessKeyType.TEST]).pipe(
concatMap(bookletId => {
return this.bs.getBookletData(bookletId)
})).subscribe(
bData => {
this.booklets.push(bData)
},
e => {
this.problemText = `Fehler in der Netzwerkverbindung (${e}).`
},
() => {
this.problemText = this.booklets.length > 0 ? '' : 'Für diese Anmeldung wurde kein Test gefunden.'
}
);
}
this.mds.setAuthData(authData);
} else {
this.mds.setAuthData();
}
} else {
this.mds.setAuthData();
}
}
})
});
this.bs.startTest(b.id).subscribe(testId => {
if (typeof testId === 'number') {
const errCode = testId as number;
if (errCode === 423) {
this.problemText = 'Dieser Test ist gesperrt';
}
resetLogin() {
this.mds.setAuthData();
this.router.navigate(['/']);
}
ngOnDestroy() {
if (this.getBookletDataSubscription !== null) {
this.getBookletDataSubscription.unsubscribe();
}
}