Skip to content

Commit

Permalink
fix(Unit Library): Create run does not redirect to Class Schedule (#1079
Browse files Browse the repository at this point in the history
)
  • Loading branch information
geoffreykwan authored Mar 7, 2023
1 parent 1b6e1bd commit ea21cbb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export class MockTeacherService {
});
}

broadcastRunChanges() {}

setTabIndex() {}

checkClassroomAuthorization(): Observable<string> {
Expand Down
16 changes: 10 additions & 6 deletions src/app/teacher/create-run-dialog/create-run-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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<CreateRunDialogComponent>,
@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;
Expand Down Expand Up @@ -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;
});
Expand Down
71 changes: 28 additions & 43 deletions src/app/teacher/teacher-run-list/teacher-run-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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() {
Expand All @@ -50,6 +51,7 @@ export class TeacherRunListComponent implements OnInit {
.subscribe((runs: TeacherRun[]) => {
this.setRuns(runs);
this.processRuns();
this.highlightNewRunIfNecessary();
this.loaded = true;
});
}
Expand All @@ -76,56 +78,18 @@ 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);
this.processRuns();
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();
Expand Down Expand Up @@ -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;
}
}
}
}
2 changes: 1 addition & 1 deletion src/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8383,7 +8383,7 @@ Click &quot;Cancel&quot; to keep the invalid JSON open so you can fix it.</sourc
<source>All Periods</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/teacher/teacher-run-list/teacher-run-list.component.ts</context>
<context context-type="linenumber">153</context>
<context context-type="linenumber">117</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/classroomMonitor/classroomMonitorComponents/nodeProgress/nav-item/nav-item.component.ts</context>
Expand Down

0 comments on commit ea21cbb

Please sign in to comment.