diff --git a/src/app/teacher/create-run-dialog/create-run-dialog.component.spec.ts b/src/app/teacher/create-run-dialog/create-run-dialog.component.spec.ts index 7470b04572c..c3c4a6f0f81 100644 --- a/src/app/teacher/create-run-dialog/create-run-dialog.component.spec.ts +++ b/src/app/teacher/create-run-dialog/create-run-dialog.component.spec.ts @@ -29,8 +29,6 @@ export class MockTeacherService { }); } - broadcastRunChanges() {} - setTabIndex() {} checkClassroomAuthorization(): Observable { diff --git a/src/app/teacher/create-run-dialog/create-run-dialog.component.ts b/src/app/teacher/create-run-dialog/create-run-dialog.component.ts index b009db92823..9ba3cf3c795 100644 --- a/src/app/teacher/create-run-dialog/create-run-dialog.component.ts +++ b/src/app/teacher/create-run-dialog/create-run-dialog.component.ts @@ -8,6 +8,7 @@ import { UserService } from '../../services/user.service'; import { ConfigService } from '../../services/config.service'; import { ListClassroomCoursesDialogComponent } from '../list-classroom-courses-dialog/list-classroom-courses-dialog.component'; import { TeacherRun } from '../teacher-run'; +import { Router } from '@angular/router'; @Component({ selector: 'create-run-dialog', @@ -29,13 +30,14 @@ export class CreateRunDialogComponent { run: TeacherRun = null; constructor( + private configService: ConfigService, + @Inject(MAT_DIALOG_DATA) public data: any, public dialog: MatDialog, public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: any, + private fb: FormBuilder, + private router: Router, private teacherService: TeacherService, - private userService: UserService, - private configService: ConfigService, - private fb: FormBuilder + private userService: UserService ) { this.project = data.project; this.maxStudentsPerTeam = 3; @@ -127,8 +129,10 @@ export class CreateRunDialogComponent { ) .subscribe((newRun: TeacherRun) => { this.run = new TeacherRun(newRun); - this.dialogRef.afterClosed().subscribe((result) => { - this.teacherService.broadcastRunChanges(this.run); + this.dialogRef.afterClosed().subscribe(() => { + this.router.navigate(['/teacher/home/schedule'], { + queryParams: { newRunId: newRun.id } + }); }); this.isCreated = true; }); diff --git a/src/app/teacher/teacher-run-list/teacher-run-list.component.ts b/src/app/teacher/teacher-run-list/teacher-run-list.component.ts index 45816f344b4..30ffae67d3d 100644 --- a/src/app/teacher/teacher-run-list/teacher-run-list.component.ts +++ b/src/app/teacher/teacher-run-list/teacher-run-list.component.ts @@ -2,7 +2,7 @@ import { Component, Inject, LOCALE_ID, OnInit } from '@angular/core'; import { TeacherService } from '../teacher.service'; import { TeacherRun } from '../teacher-run'; import { ConfigService } from '../../services/config.service'; -import { Router } from '@angular/router'; +import { ActivatedRoute, Params, Router } from '@angular/router'; import { formatDate } from '@angular/common'; import { Observable, of, Subscription } from 'rxjs'; import { UserService } from '../../services/user.service'; @@ -27,11 +27,12 @@ export class TeacherRunListComponent implements OnInit { subscriptions: Subscription = new Subscription(); constructor( - private teacherService: TeacherService, private configService: ConfigService, + @Inject(LOCALE_ID) private localeID: string, + private route: ActivatedRoute, private router: Router, - private userService: UserService, - @Inject(LOCALE_ID) private localeID: string + private teacherService: TeacherService, + private userService: UserService ) {} ngOnInit() { @@ -50,6 +51,7 @@ export class TeacherRunListComponent implements OnInit { .subscribe((runs: TeacherRun[]) => { this.setRuns(runs); this.processRuns(); + this.highlightNewRunIfNecessary(); this.loaded = true; }); } @@ -76,36 +78,11 @@ export class TeacherRunListComponent implements OnInit { private subscribeToRuns(): void { this.subscriptions.add( this.teacherService.runs$.subscribe((run: TeacherRun) => { - if (this.isNewRun(run)) { - this.addNewRun(run); - } else { - this.updateExistingRun(run); - } + this.updateExistingRun(run); }) ); } - private addNewRun(newRun: TeacherRun): void { - newRun.isHighlighted = true; - this.runs.unshift(newRun); - this.runs.sort(this.sortByStartTimeDesc); - this.populatePeriods(); - this.periods.sort(); - this.populateFilterOptions(); - this.reset(); - if (!this.showAll) { - const index = this.getRunIndex(newRun); - if (index > 9) { - this.showAll = true; - } - } - this.router.navigateByUrl('teacher/home/schedule').then(() => { - setTimeout(() => { - document.getElementById(`run${newRun.id}`).scrollIntoView(); - }, 1000); - }); - } - private updateExistingRun(updatedRun: TeacherRun): void { const runIndex = this.runs.findIndex((run) => run.id === updatedRun.id); this.runs.splice(runIndex, 1, updatedRun); @@ -113,19 +90,6 @@ export class TeacherRunListComponent implements OnInit { this.reset(); } - private isNewRun(run: TeacherRun) { - return !this.runs.some((existingRun) => existingRun.id === run.id); - } - - private getRunIndex(run: TeacherRun): number { - for (let i = 0; i < this.runs.length; i++) { - if (this.runs[i].id === run.id) { - return i; - } - } - return null; - } - private processRuns(): void { this.filteredRuns = this.runs; this.populatePeriods(); @@ -231,4 +195,25 @@ export class TeacherRunListComponent implements OnInit { isRunActive(run) { return run.isActive(this.configService.getCurrentServerTime()); } + + private highlightNewRunIfNecessary(): void { + this.route.queryParams.subscribe((queryParams: Params) => { + if (queryParams.newRunId != null) { + const newRunId = parseInt(queryParams.newRunId); + if (!isNaN(newRunId)) { + this.highlightNewRun(newRunId); + } + // remove the newRunId parameter from the url + this.router.navigate(['/teacher/home/schedule'], { queryParams: { newRunId: null } }); + } + }); + } + + private highlightNewRun(runId: number): void { + for (const run of this.runs) { + if (run.id === runId) { + run.isHighlighted = true; + } + } + } } diff --git a/src/messages.xlf b/src/messages.xlf index 5d9a3e71ccc..b5971328b21 100644 --- a/src/messages.xlf +++ b/src/messages.xlf @@ -8383,7 +8383,7 @@ Click "Cancel" to keep the invalid JSON open so you can fix it.All Periods src/app/teacher/teacher-run-list/teacher-run-list.component.ts - 153 + 117 src/assets/wise5/classroomMonitor/classroomMonitorComponents/nodeProgress/nav-item/nav-item.component.ts