-
Notifications
You must be signed in to change notification settings - Fork 5
refactor(TeacherDataService): Extract runStatus-related functions to RunStatusService #1907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,93 @@ | ||||||
| import { HttpClient, HttpParams } from '@angular/common/http'; | ||||||
| import { Injectable } from '@angular/core'; | ||||||
| import { Observable, tap } from 'rxjs'; | ||||||
| import { ConfigService } from './configService'; | ||||||
| import { RunStatus } from '../common/RunStatus'; | ||||||
| import { TeacherDataService } from './teacherDataService'; | ||||||
|
|
||||||
| @Injectable() | ||||||
| export class RunStatusService { | ||||||
| private runStatus: RunStatus; | ||||||
|
|
||||||
| constructor( | ||||||
| private configService: ConfigService, | ||||||
| private dataService: TeacherDataService, | ||||||
| private http: HttpClient | ||||||
| ) { | ||||||
| this.subscribeToEvents(); | ||||||
| } | ||||||
|
|
||||||
| subscribeToEvents(): void { | ||||||
| this.configService.configRetrieved$.subscribe(() => { | ||||||
| if (this.configService.isClassroomMonitor()) { | ||||||
| this.retrieveRunStatus(); | ||||||
| } | ||||||
| }); | ||||||
| } | ||||||
|
||||||
|
|
||||||
| retrieveRunStatus(): Observable<any> { | ||||||
|
||||||
| retrieveRunStatus(): Observable<any> { | |
| retrieveRunStatus(): Observable<RunStatus> { |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,7 +14,6 @@ import { isMatchingPeriods } from '../common/period/period'; | |||||
| import { getIntersectOfArrays } from '../common/array/array'; | ||||||
| import { serverSaveTimeComparator } from '../common/object/object'; | ||||||
| import { Annotation } from '../common/Annotation'; | ||||||
| import { RunStatus } from '../common/RunStatus'; | ||||||
|
|
||||||
| @Injectable() | ||||||
| export class TeacherDataService extends DataService { | ||||||
|
|
@@ -23,7 +22,6 @@ export class TeacherDataService extends DataService { | |||||
| currentWorkgroup = null; | ||||||
| currentStep = null; | ||||||
| previousStep = null; | ||||||
| private runStatus: RunStatus = null; | ||||||
| periods = []; | ||||||
| nodeGradingSort = 'team'; | ||||||
| studentGradingSort = 'step'; | ||||||
|
|
@@ -65,12 +63,6 @@ export class TeacherDataService extends DataService { | |||||
| this.addOrUpdateComponentState(studentWork); | ||||||
| this.broadcastStudentWorkReceived({ studentWork: studentWork }); | ||||||
| }); | ||||||
|
|
||||||
| this.ConfigService.configRetrieved$.subscribe(() => { | ||||||
| if (this.ConfigService.isClassroomMonitor()) { | ||||||
| this.retrieveRunStatus(); | ||||||
| } | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| private handleAnnotationReceived(annotation: Annotation): void { | ||||||
|
|
@@ -396,19 +388,6 @@ export class TeacherDataService extends DataService { | |||||
| return -1; | ||||||
| } | ||||||
|
|
||||||
| retrieveRunStatus(): Observable<any> { | ||||||
| const options = { | ||||||
| params: new HttpParams().set('runId', this.ConfigService.getConfigParam('runId')), | ||||||
| headers: { 'Content-Type': 'application/x-www-form-urlencoded' } | ||||||
| }; | ||||||
| return this.http.get(this.ConfigService.getConfigParam('runStatusURL'), options).pipe( | ||||||
| tap((runStatus: RunStatus) => { | ||||||
| this.runStatus = runStatus; | ||||||
| this.initializePeriods(); | ||||||
| }) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| getComponentStatesByWorkgroupId(workgroupId) { | ||||||
| return this.studentData.componentStatesByWorkgroupId[workgroupId] || []; | ||||||
| } | ||||||
|
|
@@ -569,31 +548,6 @@ export class TeacherDataService extends DataService { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private initializePeriods(): void { | ||||||
| const periods = [...this.ConfigService.getPeriods()]; | ||||||
| if (this.currentPeriod == null) { | ||||||
| this.setCurrentPeriod(periods[0]); | ||||||
| } | ||||||
| periods.unshift({ periodId: -1, periodName: $localize`All Periods` }); | ||||||
| let mergedPeriods = periods; | ||||||
| if (this.runStatus.periods != null) { | ||||||
| mergedPeriods = this.mergeConfigAndRunStatusPeriods(periods, this.runStatus.periods); | ||||||
| } | ||||||
| this.periods = mergedPeriods; | ||||||
| this.runStatus.periods = mergedPeriods; | ||||||
| } | ||||||
|
|
||||||
| private mergeConfigAndRunStatusPeriods(configPeriods: any[], runStatusPeriods: any[]): any[] { | ||||||
| const mergedPeriods = []; | ||||||
| configPeriods.forEach((configPeriod) => { | ||||||
| const runStatusPeriod = runStatusPeriods.find( | ||||||
| (runStatusPeriod) => runStatusPeriod.periodId === configPeriod.periodId | ||||||
| ); | ||||||
| mergedPeriods.push(runStatusPeriod != null ? runStatusPeriod : configPeriod); | ||||||
| }); | ||||||
| return mergedPeriods; | ||||||
| } | ||||||
|
|
||||||
| setCurrentPeriod(period) { | ||||||
| const previousPeriod = this.currentPeriod; | ||||||
| this.currentPeriod = period; | ||||||
|
|
@@ -631,16 +585,12 @@ export class TeacherDataService extends DataService { | |||||
| return this.currentPeriod.periodId; | ||||||
| } | ||||||
|
|
||||||
| getPeriods() { | ||||||
| getPeriods(): any[] { | ||||||
| return this.periods; | ||||||
| } | ||||||
|
|
||||||
| getRunStatus(): RunStatus { | ||||||
| return this.runStatus; | ||||||
| } | ||||||
|
|
||||||
| setRunStatus(runStatus: RunStatus): void { | ||||||
| this.runStatus = runStatus; | ||||||
| setPeriods(periods: any[]) { | ||||||
|
||||||
| setPeriods(periods: any[]) { | |
| setPeriods(periods: any[]): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?