diff --git a/src/app/teacher/teacher-tools.module.ts b/src/app/teacher/teacher-tools.module.ts index a1e461d39f3..06690d48c09 100644 --- a/src/app/teacher/teacher-tools.module.ts +++ b/src/app/teacher/teacher-tools.module.ts @@ -31,6 +31,7 @@ import { TeacherNodeService } from '../../assets/wise5/services/teacherNodeServi import { MilestoneReportService } from '../../assets/wise5/services/milestoneReportService'; import { RouterModule } from '@angular/router'; import { TeacherToolsRoutingModule } from './teacher-tools-routing.module'; +import { TeacherPauseScreenService } from '../../assets/wise5/services/teacherPauseScreenService'; @NgModule({ imports: [ @@ -61,6 +62,7 @@ import { TeacherToolsRoutingModule } from './teacher-tools-routing.module'; TeacherDataService, TeacherDiscussionService, TeacherNodeService, + TeacherPauseScreenService, TeacherPeerGroupService, TeacherProjectService, TeacherWebSocketService, diff --git a/src/assets/wise5/classroomMonitor/classroom-monitor-testing.module.ts b/src/assets/wise5/classroomMonitor/classroom-monitor-testing.module.ts index f7fcd0844f7..095026a748e 100644 --- a/src/assets/wise5/classroomMonitor/classroom-monitor-testing.module.ts +++ b/src/assets/wise5/classroomMonitor/classroom-monitor-testing.module.ts @@ -12,19 +12,26 @@ import { TeacherPeerGroupService } from '../services/teacherPeerGroupService'; import { MatSnackBarModule } from '@angular/material/snack-bar'; import { MilestoneReportService } from '../services/milestoneReportService'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { TeacherPauseScreenService } from '../services/teacherPauseScreenService'; -@NgModule({ imports: [BrowserAnimationsModule, - MatDialogModule, - MatSnackBarModule, - StudentTeacherCommonServicesModule], providers: [ - ClassroomStatusService, - MilestoneService, - MilestoneReportService, - TeacherDataService, - TeacherPeerGroupService, - TeacherProjectService, - TeacherWebSocketService, - provideHttpClient(withInterceptorsFromDi()), - provideHttpClientTesting() - ] }) +@NgModule({ + imports: [ + BrowserAnimationsModule, + MatDialogModule, + MatSnackBarModule, + StudentTeacherCommonServicesModule + ], + providers: [ + ClassroomStatusService, + MilestoneService, + MilestoneReportService, + TeacherDataService, + TeacherPauseScreenService, + TeacherPeerGroupService, + TeacherProjectService, + TeacherWebSocketService, + provideHttpClient(withInterceptorsFromDi()), + provideHttpClientTesting() + ] +}) export class ClassroomMonitorTestingModule {} diff --git a/src/assets/wise5/classroomMonitor/classroom-monitor.component.ts b/src/assets/wise5/classroomMonitor/classroom-monitor.component.ts index 6a21025ae9e..957103d0f90 100644 --- a/src/assets/wise5/classroomMonitor/classroom-monitor.component.ts +++ b/src/assets/wise5/classroomMonitor/classroom-monitor.component.ts @@ -11,6 +11,7 @@ import { NotificationService } from '../services/notificationService'; import { SessionService } from '../services/sessionService'; import { TeacherDataService } from '../services/teacherDataService'; import { TeacherProjectService } from '../services/teacherProjectService'; +import { TeacherPauseScreenService } from '../services/teacherPauseScreenService'; import { NavigationEnd, Router } from '@angular/router'; @Component({ @@ -42,6 +43,7 @@ export class ClassroomMonitorComponent implements OnInit { private nodeService: NodeService, private notebookService: NotebookService, private notificationService: NotificationService, + private pauseScreenService: TeacherPauseScreenService, private projectService: TeacherProjectService, private router: Router, private sessionService: SessionService, @@ -204,7 +206,7 @@ export class ClassroomMonitorComponent implements OnInit { protected unPauseAllPeriods(): void { this.dataService.getRunStatus().periods.forEach((period) => { if (period.periodId !== -1 && period.paused) { - this.dataService.pauseScreensChanged(period.periodId, false); + this.pauseScreenService.pauseScreensChanged(period.periodId, false); } }); } diff --git a/src/assets/wise5/classroomMonitor/classroomMonitorComponents/pause-screens-menu/pause-screens-menu.component.ts b/src/assets/wise5/classroomMonitor/classroomMonitorComponents/pause-screens-menu/pause-screens-menu.component.ts index cd95a8f7223..0aadc2f4d01 100644 --- a/src/assets/wise5/classroomMonitor/classroomMonitorComponents/pause-screens-menu/pause-screens-menu.component.ts +++ b/src/assets/wise5/classroomMonitor/classroomMonitorComponents/pause-screens-menu/pause-screens-menu.component.ts @@ -1,5 +1,6 @@ import { Component } from '@angular/core'; import { TeacherDataService } from '../../../services/teacherDataService'; +import { TeacherPauseScreenService } from '../../../services/teacherPauseScreenService'; class Period { paused: boolean; @@ -15,17 +16,20 @@ export class PauseScreensMenuComponent { allPeriodsPaused: boolean; periods: Period[]; - constructor(private dataService: TeacherDataService) { + constructor( + private dataService: TeacherDataService, + private pauseScreenService: TeacherPauseScreenService + ) { this.periods = this.dataService.getPeriods().filter((period) => period.periodId !== -1); } togglePeriod(period: Period): void { - this.dataService.pauseScreensChanged(period.periodId, period.paused); + this.pauseScreenService.pauseScreensChanged(period.periodId, period.paused); } toggleAllPeriods(): void { this.periods.forEach((period) => { - this.dataService.pauseScreensChanged(period.periodId, this.allPeriodsPaused); + this.pauseScreenService.pauseScreensChanged(period.periodId, this.allPeriodsPaused); }); } } diff --git a/src/assets/wise5/common/RunStatus.ts b/src/assets/wise5/common/RunStatus.ts new file mode 100644 index 00000000000..23f243f1154 --- /dev/null +++ b/src/assets/wise5/common/RunStatus.ts @@ -0,0 +1,4 @@ +export interface RunStatus { + runId?: any; + periods: any[]; +} diff --git a/src/assets/wise5/services/configService.ts b/src/assets/wise5/services/configService.ts index f18d2e3ff04..b9ed90ec369 100644 --- a/src/assets/wise5/services/configService.ts +++ b/src/assets/wise5/services/configService.ts @@ -14,7 +14,10 @@ export class ConfigService { private configRetrievedSource: Subject = new Subject(); public configRetrieved$: Observable = this.configRetrievedSource.asObservable(); - constructor(private http: HttpClient, @Inject(LOCALE_ID) private localeID: string) {} + constructor( + private http: HttpClient, + @Inject(LOCALE_ID) private localeID: string + ) {} setConfig(config) { this.config = config; @@ -182,7 +185,7 @@ export class ConfigService { return null; } - getPeriods() { + getPeriods(): any[] { const myUserInfo = this.getMyUserInfo(); if (myUserInfo != null) { const myClassInfo = myUserInfo.myClassInfo; diff --git a/src/assets/wise5/services/studentDataService.ts b/src/assets/wise5/services/studentDataService.ts index d637b0b097b..fa9edd29e4a 100644 --- a/src/assets/wise5/services/studentDataService.ts +++ b/src/assets/wise5/services/studentDataService.ts @@ -8,13 +8,14 @@ import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable, Subject } from 'rxjs'; import { DataService } from '../../../app/services/data.service'; import { generateRandomKey } from '../common/string/string'; +import { RunStatus } from '../common/RunStatus'; @Injectable() export class StudentDataService extends DataService { dummyStudentWorkId: number = 1; nodeStatuses: any = {}; previousStep = null; - runStatus: any = null; + runStatus: RunStatus = null; saveToServerRequestCount: number = 0; stackHistory = []; // array of node id's studentData: any = { @@ -139,7 +140,7 @@ export class StudentDataService extends DataService { return this.http .get(this.ConfigService.getConfigParam('runStatusURL'), options) .toPromise() - .then((runStatus: any) => { + .then((runStatus: RunStatus) => { this.runStatus = runStatus; if (this.runStatus != null && this.runStatus.periods == null) { this.runStatus.periods = []; @@ -603,7 +604,7 @@ export class StudentDataService extends DataService { return this.AnnotationService.getTotalScore(this.studentData.annotations); } - getRunStatus() { + getRunStatus(): RunStatus { return this.runStatus; } diff --git a/src/assets/wise5/services/teacherDataService.ts b/src/assets/wise5/services/teacherDataService.ts index 5ac5da4e42d..842f6b903c4 100644 --- a/src/assets/wise5/services/teacherDataService.ts +++ b/src/assets/wise5/services/teacherDataService.ts @@ -14,6 +14,7 @@ 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 { @@ -22,7 +23,7 @@ export class TeacherDataService extends DataService { currentWorkgroup = null; currentStep = null; previousStep = null; - runStatus = null; + private runStatus: RunStatus = null; periods = []; nodeGradingSort = 'team'; studentGradingSort = 'step'; @@ -401,7 +402,7 @@ export class TeacherDataService extends DataService { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }; return this.http.get(this.ConfigService.getConfigParam('runStatusURL'), options).pipe( - tap((runStatus: any) => { + tap((runStatus: RunStatus) => { this.runStatus = runStatus; this.initializePeriods(); }) @@ -634,10 +635,14 @@ export class TeacherDataService extends DataService { return this.periods; } - getRunStatus() { + getRunStatus(): RunStatus { return this.runStatus; } + setRunStatus(runStatus: RunStatus): void { + this.runStatus = runStatus; + } + getVisiblePeriodsById(currentPeriodId: number): any { if (currentPeriodId === -1) { return this.getPeriods().slice(1); @@ -677,35 +682,7 @@ export class TeacherDataService extends DataService { return this.getPeriods().find((period) => period.periodId === periodId); } - /** - * The pause screen status was changed for the given periodId. Update period accordingly. - * @param periodId the id of the period to toggle - * @param isPaused Boolean whether the period should be paused or not - */ - pauseScreensChanged(periodId: number, isPaused: boolean): void { - this.updatePausedRunStatusValue(periodId, isPaused); - this.saveRunStatusThenHandlePauseScreen(periodId, isPaused); - const context = 'ClassroomMonitor', - nodeId = null, - componentId = null, - componentType = null, - category = 'TeacherAction', - data = { periodId: periodId }, - event = isPaused ? 'pauseScreen' : 'unPauseScreen'; - this.saveEvent(context, nodeId, componentId, componentType, category, event, data); - } - - private saveRunStatusThenHandlePauseScreen(periodId: number, isPaused: boolean): void { - this.saveRunStatus().subscribe(() => { - if (isPaused) { - this.TeacherWebSocketService.pauseScreens(periodId); - } else { - this.TeacherWebSocketService.unPauseScreens(periodId); - } - }); - } - - private saveRunStatus(): Observable { + saveRunStatus(): Observable { const url = this.ConfigService.getConfigParam('runStatusURL'); const body = new HttpParams() .set('runId', this.ConfigService.getConfigParam('runId')) @@ -716,23 +693,7 @@ export class TeacherDataService extends DataService { return this.http.post(url, body, options); } - /** - * Update the paused value for a period in our run status - * @param periodId the period id or -1 for all periods - * @param isPaused whether the period is paused or not - */ - private updatePausedRunStatusValue(periodId: number, isPaused: boolean): void { - if (this.runStatus == null) { - this.runStatus = this.createRunStatus(); - } - if (periodId === -1) { - this.updateAllPeriodsPausedValue(isPaused); - } else { - this.updatePeriodPausedValue(periodId, isPaused); - } - } - - private createRunStatus(): any { + createRunStatus(): RunStatus { const periods = this.ConfigService.getPeriods(); periods.forEach((period) => (period.paused = false)); return { @@ -741,20 +702,6 @@ export class TeacherDataService extends DataService { }; } - private updateAllPeriodsPausedValue(isPaused: boolean): void { - for (const period of this.runStatus.periods) { - period.paused = isPaused; - } - } - - private updatePeriodPausedValue(periodId: number, isPaused: boolean): void { - for (const period of this.runStatus.periods) { - if (period.periodId === periodId) { - period.paused = isPaused; - } - } - } - isWorkgroupShown(workgroup): boolean { return ( this.isWorkgroupInCurrentPeriod(workgroup) && diff --git a/src/assets/wise5/services/teacherPauseScreenService.ts b/src/assets/wise5/services/teacherPauseScreenService.ts new file mode 100644 index 00000000000..5d13af037c8 --- /dev/null +++ b/src/assets/wise5/services/teacherPauseScreenService.ts @@ -0,0 +1,69 @@ +import { Injectable } from '@angular/core'; +import { TeacherDataService } from './teacherDataService'; +import { TeacherWebSocketService } from './teacherWebSocketService'; + +@Injectable() +export class TeacherPauseScreenService { + constructor( + private dataService: TeacherDataService, + private webSocketService: TeacherWebSocketService + ) {} + + /** + * The pause screen status was changed for the given periodId. Update period accordingly. + * @param periodId the id of the period to toggle + * @param isPaused Boolean whether the period should be paused or not + */ + pauseScreensChanged(periodId: number, isPaused: boolean): void { + this.updatePausedRunStatusValue(periodId, isPaused); + this.saveRunStatusThenHandlePauseScreen(periodId, isPaused); + const context = 'ClassroomMonitor', + nodeId = null, + componentId = null, + componentType = null, + category = 'TeacherAction', + data = { periodId: periodId }, + event = isPaused ? 'pauseScreen' : 'unPauseScreen'; + this.dataService.saveEvent(context, nodeId, componentId, componentType, category, event, data); + } + + private saveRunStatusThenHandlePauseScreen(periodId: number, isPaused: boolean): void { + this.dataService.saveRunStatus().subscribe(() => { + if (isPaused) { + this.webSocketService.pauseScreens(periodId); + } else { + this.webSocketService.unPauseScreens(periodId); + } + }); + } + + /** + * Update the paused value for a period in our run status + * @param periodId the period id or -1 for all periods + * @param isPaused whether the period is paused or not + */ + private updatePausedRunStatusValue(periodId: number, isPaused: boolean): void { + if (this.dataService.getRunStatus() == null) { + this.dataService.setRunStatus(this.dataService.createRunStatus()); + } + if (periodId === -1) { + this.updateAllPeriodsPausedValue(isPaused); + } else { + this.updatePeriodPausedValue(periodId, isPaused); + } + } + + private updateAllPeriodsPausedValue(isPaused: boolean): void { + for (const period of this.dataService.getRunStatus().periods) { + period.paused = isPaused; + } + } + + private updatePeriodPausedValue(periodId: number, isPaused: boolean): void { + for (const period of this.dataService.getRunStatus().periods) { + if (period.periodId === periodId) { + period.paused = isPaused; + } + } + } +} diff --git a/src/messages.xlf b/src/messages.xlf index 879b7d278e6..5e2b526c7bd 100644 --- a/src/messages.xlf +++ b/src/messages.xlf @@ -9958,7 +9958,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it. src/assets/wise5/classroomMonitor/classroom-monitor.component.ts - 84 + 86 src/assets/wise5/classroomMonitor/classroomMonitorComponents/shared/tool-bar/tool-bar.component.ts @@ -9987,7 +9987,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it. src/assets/wise5/classroomMonitor/classroom-monitor.component.ts - 147 + 149 src/assets/wise5/vle/vle.component.ts @@ -10002,7 +10002,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it. src/assets/wise5/classroomMonitor/classroom-monitor.component.ts - 148 + 150 src/assets/wise5/vle/vle.component.ts @@ -13222,14 +13222,14 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.Classroom Monitor src/assets/wise5/classroomMonitor/classroom-monitor.component.ts - 34 + 35 Grade by Step src/assets/wise5/classroomMonitor/classroom-monitor.component.ts - 91 + 93 src/assets/wise5/classroomMonitor/classroomMonitorComponents/shared/tool-bar/tool-bar.component.ts @@ -13240,7 +13240,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.Grade by Student src/assets/wise5/classroomMonitor/classroom-monitor.component.ts - 104 + 106 src/assets/wise5/classroomMonitor/classroomMonitorComponents/shared/tool-bar/tool-bar.component.ts @@ -13251,7 +13251,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.Manage Students src/assets/wise5/classroomMonitor/classroom-monitor.component.ts - 111 + 113 src/assets/wise5/classroomMonitor/classroomMonitorComponents/shared/tool-bar/tool-bar.component.ts @@ -13262,7 +13262,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.Student Notebooks src/assets/wise5/classroomMonitor/classroom-monitor.component.ts - 118 + 120 src/assets/wise5/classroomMonitor/classroomMonitorComponents/shared/tool-bar/tool-bar.component.ts @@ -13273,7 +13273,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.Data Export src/assets/wise5/classroomMonitor/classroom-monitor.component.ts - 125 + 127 src/assets/wise5/classroomMonitor/classroomMonitorComponents/shared/tool-bar/tool-bar.component.ts @@ -13284,7 +13284,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.Error: Data is not being saved! Check your internet connection. src/assets/wise5/classroomMonitor/classroom-monitor.component.ts - 190 + 192 @@ -14230,7 +14230,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it. src/assets/wise5/services/teacherDataService.ts - 576 + 577 @@ -21738,7 +21738,7 @@ If this problem continues, let your teacher know and move on to the next activit Student src/assets/wise5/services/configService.ts - 560 + 563 @@ -21955,28 +21955,28 @@ If this problem continues, let your teacher know and move on to the next activit Preview Student src/assets/wise5/services/studentDataService.ts - 77 + 78 StudentDataService.saveComponentEvent: component, category, event args must not be null src/assets/wise5/services/studentDataService.ts - 244 + 245 StudentDataService.saveComponentEvent: nodeId, componentId, componentType must not be null src/assets/wise5/services/studentDataService.ts - 254 + 255 StudentDataService.saveVLEEvent: category and event args must not be null src/assets/wise5/services/studentDataService.ts - 263 + 264