Skip to content

Commit

Permalink
Replaced currentPeriodChanged event with an observable. #2616
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreykwan committed Sep 16, 2020
1 parent 8c2c1b2 commit 88cd174
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MilestoneDetailsController {
) {
this.$translate = $filter('translate');
this.periodId = this.TeacherDataService.getCurrentPeriod().periodId;
$scope.$on('currentPeriodChanged', (event, { currentPeriod }) => {
this.TeacherDataService.currentPeriodChanged$.subscribe(({ currentPeriod }) => {
this.periodId = currentPeriod.periodId;
this.saveMilestoneCurrentPeriodSelectedEvent(currentPeriod);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class NodeGradingViewController {
}
});

this.$scope.$on('currentPeriodChanged', () => {
this.TeacherDataService.currentPeriodChanged$.subscribe(() => {
if (!this.milestone) {
this.milestoneReport = this.MilestoneService.getMilestoneReportByNodeId(this.nodeId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ class NavItemController {
this.getAlertNotifications();
});

this.$rootScope.$on('currentPeriodChanged', (event, args) => {
this.currentPeriod = args.currentPeriod;
this.TeacherDataService.currentPeriodChanged$.subscribe(({ currentPeriod }) => {
this.currentPeriod = currentPeriod;
this.setWorkgroupsOnNodeData();
this.getAlertNotifications();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class PeriodSelectController {
this.currentPeriod = null;
this.periods = [];
this.initializePeriods();
$scope.$on('currentPeriodChanged', (event, args) => {
this.currentPeriod = args.currentPeriod;
this.TeacherDataService.currentPeriodChanged$.subscribe(({ currentPeriod }) => {
this.currentPeriod = currentPeriod;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ class WorkgroupSelectController {
this.setWorkgroups();
}
});

$scope.$on('currentPeriodChanged', (event, args) => {
this.periodId = args.currentPeriod.periodId;
this.TeacherDataService.currentPeriodChanged$.subscribe(({ currentPeriod }) => {
this.periodId = currentPeriod.periodId;
this.setWorkgroups();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class StudentGradingToolsController {
this.icons = { prev: 'chevron_right', next: 'chevron_left' };
}

$scope.$on('currentPeriodChanged', (event, args) => {
this.periodId = args.currentPeriod.periodId;
this.TeacherDataService.currentPeriodChanged$.subscribe(({ currentPeriod }) => {
this.periodId = currentPeriod.periodId;
this.filterForPeriod();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as angular from 'angular';
import { AchievementService } from '../../services/achievementService';
import { MilestoneService } from '../../services/milestoneService';
import { TeacherDataService } from '../../services/teacherDataService';

class MilestonesController {
$translate: any;
Expand All @@ -14,6 +15,7 @@ class MilestonesController {
'$scope',
'AchievementService',
'MilestoneService',
'TeacherDataService',
'moment'
];
constructor(
Expand All @@ -23,6 +25,7 @@ class MilestonesController {
private $scope: any,
private AchievementService: AchievementService,
private MilestoneService: MilestoneService,
private TeacherDataService: TeacherDataService,
private moment: any
) {
this.$translate = this.$filter('translate');
Expand All @@ -36,7 +39,7 @@ class MilestonesController {
}
});

this.$scope.$on('currentPeriodChanged', () => {
this.TeacherDataService.currentPeriodChanged$.subscribe(() => {
for (let milestone of this.milestones) {
this.updateMilestoneStatus(milestone.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class StudentGradingController {
}
});

this.$scope.$on('currentPeriodChanged', (event, args) => {
let periodId = args.currentPeriod.periodId;
this.TeacherDataService.currentPeriodChanged$.subscribe(({ currentPeriod }) => {
let periodId = currentPeriod.periodId;
let currentWorkgroup = this.TeacherDataService.getCurrentWorkgroup();
if (!currentWorkgroup) {
let workgroups = angular.copy(this.ConfigService.getClassmateUserInfos());
Expand Down
9 changes: 8 additions & 1 deletion src/main/webapp/wise5/services/teacherDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { TeacherProjectService } from "./teacherProjectService";
import { TeacherWebSocketService } from "./teacherWebSocketService";
import { Injectable } from "@angular/core";
import { DataService } from "../../site/src/app/services/data.service";
import { Subject } from "rxjs";

@Injectable()
export class TeacherDataService extends DataService {
Expand All @@ -24,6 +25,8 @@ export class TeacherDataService extends DataService {
nodeGradingSort = 'team';
studentGradingSort = 'step';
studentProgressSort = 'team';
private currentPeriodChangedSource: Subject<any> = new Subject<any>();
public currentPeriodChanged$ = this.currentPeriodChangedSource.asObservable();

constructor(
private upgrade: UpgradeModule,
Expand Down Expand Up @@ -824,13 +827,17 @@ export class TeacherDataService extends DataService {
this.currentPeriod = period;
this.clearCurrentWorkgroupIfNecessary(this.currentPeriod.periodId);
if (previousPeriod == null || previousPeriod.periodId != this.currentPeriod.periodId) {
this.getRootScope().$broadcast('currentPeriodChanged', {
this.broadcastCurrentPeriodChanged({
previousPeriod: previousPeriod,
currentPeriod: this.currentPeriod
});
}
}

broadcastCurrentPeriodChanged(previousAndCurrentPeriod: any) {
this.currentPeriodChangedSource.next(previousAndCurrentPeriod);
}

clearCurrentWorkgroupIfNecessary(periodId) {
const currentWorkgroup = this.getCurrentWorkgroup();
if (currentWorkgroup) {
Expand Down

0 comments on commit 88cd174

Please sign in to comment.