Skip to content
Snippets Groups Projects
Commit fc2f9df7 authored by mechtelm's avatar mechtelm
Browse files

monitor starter prepared - not tested

parent 04fb5218
No related branches found
No related tags found
No related merge requests found
<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>
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();
});
});
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();
}
}
}
...@@ -25,6 +25,8 @@ export class RouteDispatcherActivateGuard implements CanActivate { ...@@ -25,6 +25,8 @@ export class RouteDispatcherActivateGuard implements CanActivate {
this.router.navigate(['/r/code-input']); this.router.navigate(['/r/code-input']);
} else if (authData.access[AuthAccessKeyType.TEST]) { } else if (authData.access[AuthAccessKeyType.TEST]) {
this.router.navigate(['/r/test-starter']); 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 { } else {
this.router.navigate(['/r/login', '']); this.router.navigate(['/r/login', '']);
} }
......
...@@ -30,6 +30,12 @@ export interface WorkspaceData { ...@@ -30,6 +30,12 @@ export interface WorkspaceData {
role: "RW" | "RO" | "n.d."; role: "RW" | "RO" | "n.d.";
} }
export interface MonitorScopeData {
id: string;
name: string;
type: "GROUP" | "WORKSPACE" | "n.d.";
}
export interface BookletData { export interface BookletData {
id: string; id: string;
label: string; label: string;
......
...@@ -35,6 +35,7 @@ import { AdminStarterComponent } from './app-root/admin-starter/admin-starter.co ...@@ -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 { RouteDispatcherComponent } from './app-root/route-dispatcher/route-dispatcher.component';
import { StatusCardComponent } from './app-root/status-card/status-card.component'; import { StatusCardComponent } from './app-root/status-card/status-card.component';
import { TestStarterComponent } from './app-root/test-starter/test-starter.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 ...@@ -49,7 +50,8 @@ import { TestStarterComponent } from './app-root/test-starter/test-starter.compo
AdminStarterComponent, AdminStarterComponent,
RouteDispatcherComponent, RouteDispatcherComponent,
StatusCardComponent, StatusCardComponent,
TestStarterComponent TestStarterComponent,
MonitorStarterComponent
], ],
imports: [ imports: [
ApplicationModule, ApplicationModule,
......
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
SysCheckInfo, SysCheckInfo,
AuthData, AuthData,
WorkspaceData, WorkspaceData,
BookletData BookletData, MonitorScopeData
} from './app.interfaces'; } from './app.interfaces';
import {ErrorHandler, ServerError} from 'iqb-components'; import {ErrorHandler, ServerError} from 'iqb-components';
...@@ -82,6 +82,19 @@ export class BackendService { ...@@ -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> { getSessionData(): Observable<AuthData | number> {
return this.http return this.http
.get<AuthData>(this.serverUrl + 'session') .get<AuthData>(this.serverUrl + 'session')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment