src/app/group-monitor/backend.service.ts
Properties |
|
Methods |
|
command | ||||||||||||
command(keyword: string, args: string[], testIds: number[])
|
||||||||||||
Defined in src/app/group-monitor/backend.service.ts:54
|
||||||||||||
Parameters :
Returns :
Observable<CommandResponse>
|
getBooklet | ||||||
getBooklet(bookletName: string)
|
||||||
Defined in src/app/group-monitor/backend.service.ts:22
|
||||||
Parameters :
Returns :
Observable<string | BookletError>
|
getGroupData | ||||||
getGroupData(groupName: string)
|
||||||
Defined in src/app/group-monitor/backend.service.ts:43
|
||||||
Parameters :
Returns :
Observable<GroupData>
|
lock | |||||||||
lock(groupName: string, testIds: number[])
|
|||||||||
Defined in src/app/group-monitor/backend.service.ts:78
|
|||||||||
Parameters :
Returns :
Observable<CommandResponse>
|
observeSessionsMonitor |
observeSessionsMonitor()
|
Defined in src/app/group-monitor/backend.service.ts:18
|
Returns :
Observable<TestSessionData[]>
|
unlock | |||||||||
unlock(groupName: string, testIds: number[])
|
|||||||||
Defined in src/app/group-monitor/backend.service.ts:70
|
|||||||||
Parameters :
Returns :
Observable<CommandResponse>
|
cutConnection |
cutConnection()
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:78
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:37
|
Returns :
void
|
Protected observeEndpointAndChannel |
observeEndpointAndChannel()
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:41
|
Returns :
Observable<T>
|
Private pollNext |
pollNext()
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:49
|
Returns :
void
|
Private scheduleNextPoll |
scheduleNextPoll()
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:90
|
Returns :
void
|
Private subScribeToWsChannel |
subScribeToWsChannel()
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:113
|
Returns :
void
|
Private unsubscribeFromWebsocket |
unsubscribeFromWebsocket()
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:103
|
Returns :
void
|
Protected closeConnection |
closeConnection()
|
Inherited from
WebsocketService
|
Defined in
WebsocketService:47
|
Returns :
void
|
connect |
connect()
|
Inherited from
WebsocketService
|
Defined in
WebsocketService:18
|
Returns :
void
|
getChannel | ||||||
getChannel(channelName: string)
|
||||||
Inherited from
WebsocketService
|
||||||
Defined in
WebsocketService:66
|
||||||
Type parameters :
|
||||||
Parameters :
Returns :
Observable<T>
|
send |
send(event: string, data: any)
|
Inherited from
WebsocketService
|
Defined in
WebsocketService:58
|
Returns :
void
|
initialData |
Type : TestSessionData[]
|
Default value : []
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:16
|
pollingEndpoint |
Type : string
|
Default value : '/monitor/test-sessions'
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:13
|
pollingInterval |
Type : number
|
Default value : 5000
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:14
|
wsChannelName |
Type : string
|
Default value : 'test-sessions'
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:15
|
Protected connectionClosed |
Default value : true
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:28
|
connectionStatus$ |
Type : BehaviorSubject<ConnectionStatus>
|
Default value : new BehaviorSubject<ConnectionStatus>('initial')
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:22
|
data$ |
Type : BehaviorSubject<T>
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:21
|
Private pollingTimeoutId |
Type : number
|
Default value : null
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:26
|
Private wsConnectionStatusSubscription |
Type : Subscription
|
Default value : null
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:24
|
Private wsDataSubscription |
Type : Subscription
|
Default value : null
|
Inherited from
WebsocketBackendService
|
Defined in
WebsocketBackendService:25
|
wsConnected$ |
Default value : new BehaviorSubject<boolean>(null)
|
Inherited from
WebsocketService
|
Defined in
WebsocketService:15
|
Private wsSubject$ |
Type : WebSocketSubject<any>
|
Inherited from
WebsocketService
|
Defined in
WebsocketService:14
|
Private wsSubscription |
Type : Subscription
|
Inherited from
WebsocketService
|
Defined in
WebsocketService:16
|
Protected wsUrl |
Type : string
|
Default value : ''
|
Inherited from
WebsocketService
|
Defined in
WebsocketService:13
|
import { Injectable } from '@angular/core';
import { HttpHeaders } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import {
BookletError, CommandResponse, GroupData, TestSessionData
} from './group-monitor.interfaces';
import { WebsocketBackendService } from '../shared/websocket-backend.service';
import { ApiError } from '../app.interfaces';
@Injectable()
export class BackendService extends WebsocketBackendService<TestSessionData[]> {
pollingEndpoint = '/monitor/test-sessions';
pollingInterval = 5000;
wsChannelName = 'test-sessions';
initialData: TestSessionData[] = [];
observeSessionsMonitor(): Observable<TestSessionData[]> {
return this.observeEndpointAndChannel();
}
getBooklet(bookletName: string): Observable<string|BookletError> {
const headers = new HttpHeaders({ 'Content-Type': 'text/xml' }).set('Accept', 'text/xml');
const missingFileError: BookletError = { error: 'missing-file', species: null };
const generalError: BookletError = { error: 'general', species: null };
return this.http
.get(`${this.serverUrl}booklet/${bookletName}`, { headers, responseType: 'text' })
.pipe(
catchError((err: ApiError) => {
if (err.code === 404) {
// could potentially happen when booklet file was removed since test was started
// TODO interceptor be omitted
return of(missingFileError);
}
// TODO should interceptor should have interfered and moved to error-page ...
// https://github.com/iqb-berlin/testcenter-frontend/issues/53
return of(generalError);
})
);
}
getGroupData(groupName: string): Observable<GroupData> {
// TODO error-handling: interceptor should have interfered and moved to error-page ...
// https://github.com/iqb-berlin/testcenter-frontend/issues/53
return this.http
.get<GroupData>(`${this.serverUrl}monitor/group/${groupName}`)
.pipe(catchError(() => of(<GroupData>{
name: 'error',
label: 'error'
})));
}
command(keyword: string, args: string[], testIds: number[]): Observable<CommandResponse> {
return this.http
.put(
`${this.serverUrl}monitor/command`,
{
keyword,
arguments: args,
timestamp: Date.now() / 1000,
testIds
}
)
.pipe(
map(() => ({ commandType: keyword, testIds }))
);
}
unlock(groupName: string, testIds: number[]): Observable<CommandResponse> {
return this.http
.post(`${this.serverUrl}monitor/group/${groupName}/tests/unlock`, { testIds })
.pipe(
map(() => ({ commandType: 'unlock', testIds }))
);
}
lock(groupName: string, testIds: number[]): Observable<CommandResponse> {
return this.http
.post(`${this.serverUrl}monitor/group/${groupName}/tests/lock`, { testIds })
.pipe(
map(() => ({ commandType: 'unlock', testIds }))
);
}
}