Skip to content

Commit

Permalink
refactor(TeacherDataService): Move getVisiblePeriodsById() to PeerGro…
Browse files Browse the repository at this point in the history
…upDialog, where it's called. Clean up logic.
  • Loading branch information
hirokiterashima committed Nov 26, 2024
1 parent 6108d91 commit e2cf8b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ import { TeacherProjectService } from '../../../../services/teacherProjectServic
@Component({
selector: 'peer-group-dialog',
templateUrl: './peer-group-dialog.component.html',
styleUrls: ['./peer-group-dialog.component.scss']
styleUrl: './peer-group-dialog.component.scss'
})
export class PeerGroupDialogComponent implements OnInit {
currentPeriodChangedSubscription: Subscription;
peerGroupingName: string;
periods: any[];
private currentPeriodChangedSubscription: Subscription;
protected peerGroupingName: string;
protected periods: any[];

constructor(
private dataService: TeacherDataService,
@Inject(MAT_DIALOG_DATA) public peerGroupingTag: string,
private teacherDataService: TeacherDataService,
private teacherProjectService: TeacherProjectService
private projectService: TeacherProjectService
) {}

ngOnInit() {
this.setPeriods(this.teacherDataService.getCurrentPeriodId());
this.peerGroupingName = this.teacherProjectService.getPeerGrouping(this.peerGroupingTag).name;
this.subscribeToPeriodChanged();
}

subscribeToPeriodChanged(): void {
this.currentPeriodChangedSubscription = this.teacherDataService.currentPeriodChanged$.subscribe(
ngOnInit(): void {
this.setPeriods(this.dataService.getCurrentPeriodId());
this.peerGroupingName = this.projectService.getPeerGrouping(this.peerGroupingTag).name;
this.currentPeriodChangedSubscription = this.dataService.currentPeriodChanged$.subscribe(
({ currentPeriod }) => {
this.setPeriods(currentPeriod.periodId);
}
);
}

setPeriods(periodId: number): void {
this.periods = this.teacherDataService.getVisiblePeriodsById(periodId);
ngOnDestroy(): void {
this.currentPeriodChangedSubscription.unsubscribe();
}

ngOnDestroy() {
this.currentPeriodChangedSubscription.unsubscribe();
private setPeriods(periodId: number): void {
const allPeriods = this.dataService.getPeriods();
this.periods =
periodId === -1
? allPeriods.slice(1)
: [allPeriods.find((period) => period.periodId === periodId)];
}
}
12 changes: 0 additions & 12 deletions src/assets/wise5/services/teacherDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,6 @@ export class TeacherDataService extends DataService {
this.periods = periods;
}

getVisiblePeriodsById(currentPeriodId: number): any {
if (currentPeriodId === -1) {
return this.getPeriods().slice(1);
} else {
return [this.getPeriodById(currentPeriodId)];
}
}

setCurrentWorkgroup(workgroup) {
this.currentWorkgroup = workgroup;
this.broadcastCurrentWorkgroupChanged({ currentWorkgroup: this.currentWorkgroup });
Expand Down Expand Up @@ -613,10 +605,6 @@ export class TeacherDataService extends DataService {
);
}

private getPeriodById(periodId: number): any {
return this.getPeriods().find((period) => period.periodId === periodId);
}

isWorkgroupShown(workgroup): boolean {
return (
this.isWorkgroupInCurrentPeriod(workgroup) &&
Expand Down

0 comments on commit e2cf8b4

Please sign in to comment.