diff --git a/src/app/app-root/monitor-starter/monitor-starter.component.html b/src/app/app-root/monitor-starter/monitor-starter.component.html new file mode 100644 index 0000000000000000000000000000000000000000..db40f3fa40f01e448ee53646b39f80b6fc0328e4 --- /dev/null +++ b/src/app/app-root/monitor-starter/monitor-starter.component.html @@ -0,0 +1,17 @@ +<mat-card fxFlex="0 0 400px" fxLayout="column"> + <mat-card-title>Testdurchführung überwachen</mat-card-title> + <mat-card-content> + <div fxLayoutGap="10px" fxLayout="column"> + <p *ngIf="monitorScopes.length === 0"> + Sie sind angemeldet. Aktuell sind keine Bereiche zur Überwachung für Sie freigegeben. + </p> + <button mat-raised-button color="primary" (click)="buttonGotoMonitor(ms)" + *ngFor="let ms of monitorScopes"> + {{ms.name}} + </button> + </div> + </mat-card-content> + <mat-card-actions> + <button mat-raised-button color="foreground" (click)="resetLogin()">Neu anmelden</button> + </mat-card-actions> +</mat-card> diff --git a/src/app/app-root/monitor-starter/monitor-starter.component.spec.ts b/src/app/app-root/monitor-starter/monitor-starter.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..af77f81c74d2402ce8fa80e5177664cea9a5a0aa --- /dev/null +++ b/src/app/app-root/monitor-starter/monitor-starter.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { MonitorStarterComponent } from './monitor-starter.component'; + +describe('MonitorStarterComponent', () => { + let component: MonitorStarterComponent; + let fixture: ComponentFixture<MonitorStarterComponent>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ MonitorStarterComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(MonitorStarterComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/app-root/monitor-starter/monitor-starter.component.ts b/src/app/app-root/monitor-starter/monitor-starter.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..22864c6e8af8f245d5ccfbce28b4e82cf9871aa2 --- /dev/null +++ b/src/app/app-root/monitor-starter/monitor-starter.component.ts @@ -0,0 +1,73 @@ +import {Component, OnDestroy, OnInit} from '@angular/core'; +import {AuthAccessKeyType, AuthData, MonitorScopeData} from "../../app.interfaces"; +import {from, Subscription} from "rxjs"; +import {Router} from "@angular/router"; +import {BackendService} from "../../backend.service"; +import {MainDataService} from "../../maindata.service"; +import {concatMap} from "rxjs/operators"; + +@Component({ + templateUrl: './monitor-starter.component.html' +}) +export class MonitorStarterComponent implements OnInit, OnDestroy { + monitorScopes: MonitorScopeData[] = []; + private getMonitorScopeDataSubscription: Subscription = null; + + constructor( + private router: Router, + private bs: BackendService, + private mds: MainDataService + ) { } + + ngOnInit() { + setTimeout(() => { + this.bs.getSessionData().subscribe(authDataUntyped => { + if (typeof authDataUntyped !== 'number') { + const authData = authDataUntyped as AuthData; + if (authData) { + if (authData.token) { + this.monitorScopes = []; + let scopeIdList = []; + if (authData.access[AuthAccessKeyType.TEST_GROUP_MONITOR]) { + scopeIdList = authData.access[AuthAccessKeyType.TEST_GROUP_MONITOR]; + } else if (authData.access[AuthAccessKeyType.WORKSPACE_MONITOR]) { + scopeIdList = authData.access[AuthAccessKeyType.WORKSPACE_MONITOR]; + } + this.getMonitorScopeDataSubscription = from(scopeIdList).pipe( + concatMap(monitorScopeId => { + return this.bs.getMonitorScopeData(monitorScopeId) + })).subscribe(msData => this.monitorScopes.push(msData)); + this.mds.setAuthData(authData); + } else { + this.mds.setAuthData(); + } + } else { + this.mds.setAuthData(); + } + } + }) + }); + } + + buttonGotoMonitor(ms: MonitorScopeData) { + switch (ms.type) { + case "GROUP": + this.router.navigateByUrl('/group-monitor/' + ms.id.toString()); + break; + case "WORKSPACE": + this.router.navigateByUrl('/workspace-monitor/' + ms.id.toString()); + break; + } + } + + resetLogin() { + this.mds.setAuthData(); + this.router.navigate(['/']); + } + + ngOnDestroy() { + if (this.getMonitorScopeDataSubscription !== null) { + this.getMonitorScopeDataSubscription.unsubscribe(); + } + } +} diff --git a/src/app/app-routing-guards.ts b/src/app/app-routing-guards.ts index 99cf69a2456ffbdb76e640cb98368f959487b4e0..5cd5fcd83735b48f8ef0daf238e8ca1a91c21f29 100644 --- a/src/app/app-routing-guards.ts +++ b/src/app/app-routing-guards.ts @@ -25,6 +25,8 @@ export class RouteDispatcherActivateGuard implements CanActivate { this.router.navigate(['/r/code-input']); } else if (authData.access[AuthAccessKeyType.TEST]) { this.router.navigate(['/r/test-starter']); + } else if (authData.access[AuthAccessKeyType.TEST_GROUP_MONITOR] || authData.access[AuthAccessKeyType.WORKSPACE_MONITOR]) { + this.router.navigate(['/r/monitor-starter']); } else { this.router.navigate(['/r/login', '']); } diff --git a/src/app/app.interfaces.ts b/src/app/app.interfaces.ts index 0194286208ff8ce7fa55114b1441736139b2f5ba..4b49ae16baaa3e37bcd2acaf4d3d0ce14e24d370 100644 --- a/src/app/app.interfaces.ts +++ b/src/app/app.interfaces.ts @@ -30,6 +30,12 @@ export interface WorkspaceData { role: "RW" | "RO" | "n.d."; } +export interface MonitorScopeData { + id: string; + name: string; + type: "GROUP" | "WORKSPACE" | "n.d."; +} + export interface BookletData { id: string; label: string; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 3ff9dff50346b0da2ab76035ca5674a1a712eca5..7f9c74ccee668a9e8bfe3c7dcb4e178b3809cbae 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -35,6 +35,7 @@ import { AdminStarterComponent } from './app-root/admin-starter/admin-starter.co import { RouteDispatcherComponent } from './app-root/route-dispatcher/route-dispatcher.component'; import { StatusCardComponent } from './app-root/status-card/status-card.component'; import { TestStarterComponent } from './app-root/test-starter/test-starter.component'; +import { MonitorStarterComponent } from './app-root/monitor-starter/monitor-starter.component'; @@ -49,7 +50,8 @@ import { TestStarterComponent } from './app-root/test-starter/test-starter.compo AdminStarterComponent, RouteDispatcherComponent, StatusCardComponent, - TestStarterComponent + TestStarterComponent, + MonitorStarterComponent ], imports: [ ApplicationModule, diff --git a/src/app/backend.service.ts b/src/app/backend.service.ts index 2770c29311682ff1879ed85585cd35e5211973cc..d225115f440e6999d2906448a3d33d427cdd144b 100644 --- a/src/app/backend.service.ts +++ b/src/app/backend.service.ts @@ -11,7 +11,7 @@ import { SysCheckInfo, AuthData, WorkspaceData, - BookletData + BookletData, MonitorScopeData } from './app.interfaces'; import {ErrorHandler, ServerError} from 'iqb-components'; @@ -82,6 +82,19 @@ export class BackendService { })); } + getMonitorScopeData(monitorScopeId: string): Observable<MonitorScopeData> { + return this.http + .get<MonitorScopeData>(this.serverUrl + 'monitorscope/' + monitorScopeId) // TODO fix route + .pipe(catchError(() => { + console.warn('get monitor scope data failed for ' + monitorScopeId); + return of(<MonitorScopeData>{ + id: monitorScopeId, + name: monitorScopeId, + type: "n.d." + }) + })); + } + getSessionData(): Observable<AuthData | number> { return this.http .get<AuthData>(this.serverUrl + 'session')