Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/teacher/teacher-tools.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { MilestoneReportService } from '../../assets/wise5/services/milestoneRep
import { RouterModule } from '@angular/router';
import { TeacherToolsRoutingModule } from './teacher-tools-routing.module';
import { TeacherPauseScreenService } from '../../assets/wise5/services/teacherPauseScreenService';
import { RunStatusService } from '../../assets/wise5/services/runStatusService';

@NgModule({
imports: [
Expand All @@ -56,6 +57,7 @@ import { TeacherPauseScreenService } from '../../assets/wise5/services/teacherPa
MoveNodesService,
{ provide: NodeService, useExisting: TeacherNodeService },
ProjectAssetService,
RunStatusService,
SpaceService,
{ provide: PeerGroupService, useExisting: TeacherPeerGroupService },
{ provide: ProjectService, useExisting: TeacherProjectService },
Expand Down
5 changes: 4 additions & 1 deletion src/app/teacher/teacher-tools.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { NotificationService } from '../../assets/wise5/services/notificationSer
import { TeacherWebSocketService } from '../../assets/wise5/services/teacherWebSocketService';
import { NotebookService } from '../../assets/wise5/services/notebookService';
import { AchievementService } from '../../assets/wise5/services/achievementService';
import { RunStatus } from '../../assets/wise5/common/RunStatus';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

import { RunStatusService } from '../../assets/wise5/services/runStatusService';

export const TeacherToolsResolver: ResolveFn<any> = (
route: ActivatedRouteSnapshot,
Expand All @@ -20,14 +22,15 @@ export const TeacherToolsResolver: ResolveFn<any> = (
notebookService: NotebookService = inject(NotebookService),
notificationService: NotificationService = inject(NotificationService),
projectService: ProjectService = inject(ProjectService),
runStatusService: RunStatusService = inject(RunStatusService),
websocketService: TeacherWebSocketService = inject(TeacherWebSocketService)
): Observable<any> =>
configService
.retrieveConfig(`/api/config/classroomMonitor/${route.params['unitId']}`)
.pipe(switchMap(() => projectService.retrieveProject()))
.pipe(switchMap(() => classroomStatusService.retrieveStudentStatuses()))
.pipe(switchMap(() => achievementService.retrieveStudentAchievements()))
.pipe(switchMap(() => dataService.retrieveRunStatus()))
.pipe(switchMap(() => runStatusService.retrieveRunStatus()))
.pipe(switchMap(() => notificationService.retrieveNotifications()))
.pipe(switchMap(() => dataService.retrieveAnnotations()))
.pipe(switchMap(() => notebookService.retrieveNotebookItems()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { MatSnackBarModule } from '@angular/material/snack-bar';
import { MilestoneReportService } from '../services/milestoneReportService';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { TeacherPauseScreenService } from '../services/teacherPauseScreenService';
import { RunStatusService } from '../services/runStatusService';

@NgModule({
imports: [
Expand All @@ -30,6 +31,7 @@ import { TeacherPauseScreenService } from '../services/teacherPauseScreenService
TeacherPeerGroupService,
TeacherProjectService,
TeacherWebSocketService,
RunStatusService,
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting()
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TeacherDataService } from '../services/teacherDataService';
import { TeacherProjectService } from '../services/teacherProjectService';
import { TeacherPauseScreenService } from '../services/teacherPauseScreenService';
import { NavigationEnd, Router } from '@angular/router';
import { RunStatusService } from '../services/runStatusService';

@Component({
selector: 'classroom-monitor',
Expand Down Expand Up @@ -46,6 +47,7 @@ export class ClassroomMonitorComponent implements OnInit {
private pauseScreenService: TeacherPauseScreenService,
private projectService: TeacherProjectService,
private router: Router,
private runStatusService: RunStatusService,
private sessionService: SessionService,
private snackBar: MatSnackBar
) {}
Expand Down Expand Up @@ -204,7 +206,7 @@ export class ClassroomMonitorComponent implements OnInit {

@HostListener('window:beforeunload')
protected unPauseAllPeriods(): void {
this.dataService.getRunStatus().periods.forEach((period) => {
this.runStatusService.getRunStatus().periods.forEach((period) => {
if (period.periodId !== -1 && period.paused) {
this.pauseScreenService.pauseScreensChanged(period.periodId, false);
}
Expand Down
93 changes: 93 additions & 0 deletions src/assets/wise5/services/runStatusService.ts
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();
}
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move inside body of constructor and remove function?


retrieveRunStatus(): Observable<any> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type RunStatus?

Suggested change
retrieveRunStatus(): Observable<any> {
retrieveRunStatus(): Observable<RunStatus> {

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();
})
);
}

private initializePeriods(): void {
const periods = [...this.configService.getPeriods()];
if (this.dataService.getCurrentPeriod() == null) {
this.dataService.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.runStatus.periods = mergedPeriods;
this.dataService.setPeriods(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;
}

getRunStatus(): RunStatus {
return this.runStatus;
}

setRunStatus(runStatus: RunStatus): void {
this.runStatus = runStatus;
}

saveRunStatus(): Observable<void> {
const url = this.configService.getConfigParam('runStatusURL');
const body = new HttpParams()
.set('runId', this.configService.getConfigParam('runId'))
.set('status', JSON.stringify(this.runStatus));
const options = {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
};
return this.http.post<void>(url, body, options);
}

createRunStatus(): RunStatus {
const periods = this.configService.getPeriods();
periods.forEach((period) => (period.paused = false));
return {
runId: this.configService.getConfigParam('runId'),
periods: periods
};
}
}
76 changes: 3 additions & 73 deletions src/assets/wise5/services/teacherDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,7 +22,6 @@ export class TeacherDataService extends DataService {
currentWorkgroup = null;
currentStep = null;
previousStep = null;
private runStatus: RunStatus = null;
periods = [];
nodeGradingSort = 'team';
studentGradingSort = 'step';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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] || [];
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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[]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setPeriods(periods: any[]) {
setPeriods(periods: any[]): void {

this.periods = periods;
}

getVisiblePeriodsById(currentPeriodId: number): any {
Expand Down Expand Up @@ -682,26 +632,6 @@ export class TeacherDataService extends DataService {
return this.getPeriods().find((period) => period.periodId === periodId);
}

saveRunStatus(): Observable<void> {
const url = this.ConfigService.getConfigParam('runStatusURL');
const body = new HttpParams()
.set('runId', this.ConfigService.getConfigParam('runId'))
.set('status', JSON.stringify(this.runStatus));
const options = {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
};
return this.http.post<void>(url, body, options);
}

createRunStatus(): RunStatus {
const periods = this.ConfigService.getPeriods();
periods.forEach((period) => (period.paused = false));
return {
runId: this.ConfigService.getConfigParam('runId'),
periods: periods
};
}

isWorkgroupShown(workgroup): boolean {
return (
this.isWorkgroupInCurrentPeriod(workgroup) &&
Expand Down
12 changes: 7 additions & 5 deletions src/assets/wise5/services/teacherPauseScreenService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Injectable } from '@angular/core';
import { TeacherDataService } from './teacherDataService';
import { TeacherWebSocketService } from './teacherWebSocketService';
import { RunStatusService } from './runStatusService';

@Injectable()
export class TeacherPauseScreenService {
constructor(
private dataService: TeacherDataService,
private runStatusService: RunStatusService,
private webSocketService: TeacherWebSocketService
) {}

Expand All @@ -28,7 +30,7 @@ export class TeacherPauseScreenService {
}

private saveRunStatusThenHandlePauseScreen(periodId: number, isPaused: boolean): void {
this.dataService.saveRunStatus().subscribe(() => {
this.runStatusService.saveRunStatus().subscribe(() => {
if (isPaused) {
this.webSocketService.pauseScreens(periodId);
} else {
Expand All @@ -43,8 +45,8 @@ export class TeacherPauseScreenService {
* @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 (this.runStatusService.getRunStatus() == null) {
this.runStatusService.setRunStatus(this.runStatusService.createRunStatus());
}
if (periodId === -1) {
this.updateAllPeriodsPausedValue(isPaused);
Expand All @@ -54,13 +56,13 @@ export class TeacherPauseScreenService {
}

private updateAllPeriodsPausedValue(isPaused: boolean): void {
for (const period of this.dataService.getRunStatus().periods) {
for (const period of this.runStatusService.getRunStatus().periods) {
period.paused = isPaused;
}
}

private updatePeriodPausedValue(periodId: number, isPaused: boolean): void {
for (const period of this.dataService.getRunStatus().periods) {
for (const period of this.runStatusService.getRunStatus().periods) {
if (period.periodId === periodId) {
period.paused = isPaused;
}
Expand Down
Loading