-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(TeacherDataService): Extract TeacherPauseScreenService (#1891)
- Loading branch information
Showing
10 changed files
with
141 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface RunStatus { | ||
runId?: any; | ||
periods: any[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.