File

src/app/group-monitor/backend.service.ts

Extends

WebsocketBackendService

Index

Properties
Methods

Methods

command
command(keyword: string, args: string[], testIds: number[])
Parameters :
Name Type Optional
keyword string No
args string[] No
testIds number[] No
Returns : Observable<CommandResponse>
getBooklet
getBooklet(bookletName: string)
Parameters :
Name Type Optional
bookletName string No
Returns : Observable<string | BookletError>
getGroupData
getGroupData(groupName: string)
Parameters :
Name Type Optional
groupName string No
lock
lock(groupName: string, testIds: number[])
Parameters :
Name Type Optional
groupName string No
testIds number[] No
Returns : Observable<CommandResponse>
observeSessionsMonitor
observeSessionsMonitor()
Returns : Observable<TestSessionData[]>
unlock
unlock(groupName: string, testIds: number[])
Parameters :
Name Type Optional
groupName string No
testIds number[] No
Returns : Observable<CommandResponse>
cutConnection
cutConnection()
Inherited from WebsocketBackendService
Returns : void
ngOnDestroy
ngOnDestroy()
Inherited from WebsocketBackendService
Returns : void
Protected observeEndpointAndChannel
observeEndpointAndChannel()
Inherited from WebsocketBackendService
Returns : Observable<T>
Private pollNext
pollNext()
Inherited from WebsocketBackendService
Returns : void
Private scheduleNextPoll
scheduleNextPoll()
Inherited from WebsocketBackendService
Returns : void
Private subScribeToWsChannel
subScribeToWsChannel()
Inherited from WebsocketBackendService
Returns : void
Private unsubscribeFromWebsocket
unsubscribeFromWebsocket()
Inherited from WebsocketBackendService
Returns : void
Protected closeConnection
closeConnection()
Inherited from WebsocketService
Returns : void
connect
connect()
Inherited from WebsocketService
Returns : void
getChannel
getChannel(channelName: string)
Inherited from WebsocketService
Type parameters :
  • T
Parameters :
Name Type Optional
channelName string No
Returns : Observable<T>
send
send(event: string, data: any)
Inherited from WebsocketService
Parameters :
Name Type Optional
event string No
data any No
Returns : void

Properties

initialData
Type : TestSessionData[]
Default value : []
Inherited from WebsocketBackendService
pollingEndpoint
Type : string
Default value : '/monitor/test-sessions'
Inherited from WebsocketBackendService
pollingInterval
Type : number
Default value : 5000
Inherited from WebsocketBackendService
wsChannelName
Type : string
Default value : 'test-sessions'
Inherited from WebsocketBackendService
Protected connectionClosed
Default value : true
Inherited from WebsocketBackendService
connectionStatus$
Type : BehaviorSubject<ConnectionStatus>
Default value : new BehaviorSubject<ConnectionStatus>('initial')
Inherited from WebsocketBackendService
data$
Type : BehaviorSubject<T>
Inherited from WebsocketBackendService
Private pollingTimeoutId
Type : number
Default value : null
Inherited from WebsocketBackendService
Private wsConnectionStatusSubscription
Type : Subscription
Default value : null
Inherited from WebsocketBackendService
Private wsDataSubscription
Type : Subscription
Default value : null
Inherited from WebsocketBackendService
wsConnected$
Default value : new BehaviorSubject<boolean>(null)
Inherited from WebsocketService
Private wsSubject$
Type : WebSocketSubject<any>
Inherited from WebsocketService
Private wsSubscription
Type : Subscription
Inherited from WebsocketService
Protected wsUrl
Type : string
Default value : ''
Inherited from WebsocketService
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 }))
      );
  }
}

results matching ""

    No results matching ""