Skip to content

Commit

Permalink
refactor(TeacherDataService): retrieveRunStatus() returns Observable (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima authored Oct 12, 2023
1 parent 8ac83f4 commit 8addd6b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 68 deletions.
70 changes: 16 additions & 54 deletions src/assets/wise5/services/teacherDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,6 @@ export class TeacherDataService extends DataService {
return this.retrieveStudentData(params);
}

retrieveLatestStudentDataByNodeIdAndComponentIdAndPeriodId(nodeId, componentId, periodId) {
let params = new HttpParams()
.set('runId', this.ConfigService.getRunId())
.set('nodeId', nodeId)
.set('componentId', componentId)
.set('getStudentWork', 'true')
.set('getEvents', 'false')
.set('getAnnotations', 'false')
.set('onlyGetLatest', 'true');
if (periodId != null) {
params = params.set('periodId', periodId);
}
return this.retrieveStudentData(params).subscribe((result) => {
return result.studentWorkList;
});
}

retrieveStudentData(params): Observable<any> {
const url = this.ConfigService.getConfigParam('teacherDataURL');
const options = {
Expand Down Expand Up @@ -440,20 +423,17 @@ export class TeacherDataService extends DataService {
return -1;
}

retrieveRunStatus() {
const url = this.ConfigService.getConfigParam('runStatusURL');
const params = new HttpParams().set('runId', this.ConfigService.getConfigParam('runId'));
retrieveRunStatus(): Observable<any> {
const options = {
params: params,
params: new HttpParams().set('runId', this.ConfigService.getConfigParam('runId')),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
};
return this.http
.get(url, options)
.toPromise()
.then((data: any) => {
this.runStatus = data;
return this.http.get(this.ConfigService.getConfigParam('runStatusURL'), options).pipe(
tap((runStatus: any) => {
this.runStatus = runStatus;
this.initializePeriods();
});
})
);
}

getComponentStatesByWorkgroupId(workgroupId) {
Expand Down Expand Up @@ -616,12 +596,12 @@ export class TeacherDataService extends DataService {
}
}

initializePeriods() {
private initializePeriods(): void {
const periods = [...this.ConfigService.getPeriods()];
if (this.currentPeriod == null) {
this.setCurrentPeriod(periods[0]);
}
this.addAllPeriods(periods);
periods.unshift({ periodId: -1, periodName: $localize`All Periods` });
let mergedPeriods = periods;
if (this.runStatus.periods != null) {
mergedPeriods = this.mergeConfigAndRunStatusPeriods(periods, this.runStatus.periods);
Expand All @@ -630,35 +610,17 @@ export class TeacherDataService extends DataService {
this.runStatus.periods = mergedPeriods;
}

addAllPeriods(periods: any[]): void {
periods.unshift({
periodId: -1,
periodName: $localize`All Periods`
});
}

mergeConfigAndRunStatusPeriods(configPeriods, runStatusPeriods) {
private mergeConfigAndRunStatusPeriods(configPeriods: any[], runStatusPeriods: any[]): any[] {
const mergedPeriods = [];
for (const configPeriod of configPeriods) {
const runStatusPeriod = this.getRunStatusPeriodById(runStatusPeriods, configPeriod.periodId);
if (runStatusPeriod == null) {
mergedPeriods.push(configPeriod);
} else {
mergedPeriods.push(runStatusPeriod);
}
}
configPeriods.forEach((configPeriod) => {
const runStatusPeriod = runStatusPeriods.find(
(runStatusPeriod) => runStatusPeriod.periodId === configPeriod.periodId
);
mergedPeriods.push(runStatusPeriod != null ? runStatusPeriod : configPeriod);
});
return mergedPeriods;
}

getRunStatusPeriodById(runStatusPeriods, periodId) {
for (const runStatusPeriod of runStatusPeriods) {
if (runStatusPeriod.periodId == periodId) {
return runStatusPeriod;
}
}
return null;
}

setCurrentPeriod(period) {
const previousPeriod = this.currentPeriod;
this.currentPeriod = period;
Expand Down
31 changes: 17 additions & 14 deletions src/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7568,19 +7568,15 @@ Click &quot;Cancel&quot; to keep the invalid JSON open so you can fix it.</sourc
<context context-type="linenumber">27</context>
</context-group>
</trans-unit>
<trans-unit id="c6a2c19b6bd10c35aca82f19ffebdc75a2fc164c" datatype="html">
<source><x id="INTERPOLATION" equiv-text="{{ scheduledTotal() }}"/> scheduled</source>
<trans-unit id="5a83883d5ab9830c841b4773eef887ac24e9cc7a" datatype="html">
<source><x id="INTERPOLATION" equiv-text="{{ getRunTotal(&apos;isScheduled&apos;) }}"/> scheduled</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/student/student-run-list/student-run-list.component.html</context>
<context context-type="linenumber">30</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/teacher/teacher-run-list/teacher-run-list.component.html</context>
<context context-type="linenumber">46</context>
</context-group>
</trans-unit>
<trans-unit id="db39827bab98f8af5e0a97d4614a0d667e98fcb6" datatype="html">
<source><x id="INTERPOLATION" equiv-text="{{ activeTotal() }}"/> active</source>
<trans-unit id="81603b1750f2555f39786b321c2a2e5eb810fdbd" datatype="html">
<source><x id="INTERPOLATION" equiv-text="{{ getRunTotal(&apos;isActive&apos;) }}"/> active</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/student/student-run-list/student-run-list.component.html</context>
<context context-type="linenumber">33</context>
Expand Down Expand Up @@ -8949,6 +8945,13 @@ Click &quot;Cancel&quot; to keep the invalid JSON open so you can fix it.</sourc
<context context-type="linenumber">43</context>
</context-group>
</trans-unit>
<trans-unit id="c6a2c19b6bd10c35aca82f19ffebdc75a2fc164c" datatype="html">
<source><x id="INTERPOLATION" equiv-text="{{ scheduledTotal() }}"/> scheduled</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/teacher/teacher-run-list/teacher-run-list.component.html</context>
<context context-type="linenumber">46</context>
</context-group>
</trans-unit>
<trans-unit id="1e5e23363e949f7dcbaf034bdb141a561132a10e" datatype="html">
<source>Clear filters</source>
<context-group purpose="location">
Expand Down Expand Up @@ -12784,14 +12787,14 @@ Click &quot;Cancel&quot; to keep the invalid JSON open so you can fix it.</sourc
<source>New Team <x id="PH" equiv-text="newWorkgroupId"/> has been created.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/classroomMonitor/classroomMonitorComponents/manageStudents/add-team-dialog/add-team-dialog.component.ts</context>
<context context-type="linenumber">82</context>
<context context-type="linenumber">83</context>
</context-group>
</trans-unit>
<trans-unit id="545651489407570329" datatype="html">
<source>Error: Could not create team.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/classroomMonitor/classroomMonitorComponents/manageStudents/add-team-dialog/add-team-dialog.component.ts</context>
<context context-type="linenumber">87</context>
<context context-type="linenumber">90</context>
</context-group>
</trans-unit>
<trans-unit id="6babfd035bd01c83b35e9440bd51b8b3b45e15d6" datatype="html">
Expand Down Expand Up @@ -12906,7 +12909,7 @@ Click &quot;Cancel&quot; to keep the invalid JSON open so you can fix it.</sourc
<source>Moved Team <x id="PH" equiv-text="this.team.workgroupId"/> to Period <x id="PH_1" equiv-text="this.selectedPeriod.periodName"/>.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/classroomMonitor/classroomMonitorComponents/manageStudents/change-team-period-dialog/change-team-period-dialog.component.ts</context>
<context context-type="linenumber">54</context>
<context context-type="linenumber">55</context>
</context-group>
</trans-unit>
<trans-unit id="f67c125d12ba3ed0ae20a680c77d342d3a72a0fe" datatype="html">
Expand Down Expand Up @@ -12994,14 +12997,14 @@ Click &quot;Cancel&quot; to keep the invalid JSON open so you can fix it.</sourc
<source>Moved student to Team <x id="PH" equiv-text="workgroupId"/>.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/classroomMonitor/classroomMonitorComponents/manageStudents/manage-team/manage-team.component.ts</context>
<context context-type="linenumber">106</context>
<context context-type="linenumber">107</context>
</context-group>
</trans-unit>
<trans-unit id="784919496056996013" datatype="html">
<source>Error: Could not move student.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/classroomMonitor/classroomMonitorComponents/manageStudents/manage-team/manage-team.component.ts</context>
<context context-type="linenumber">109</context>
<context context-type="linenumber">112</context>
</context-group>
</trans-unit>
<trans-unit id="9b83b532c3f74e3d6e25a6ba749eef54324bea48" datatype="html">
Expand Down Expand Up @@ -13605,7 +13608,7 @@ Click &quot;Cancel&quot; to keep the invalid JSON open so you can fix it.</sourc
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/teacherDataService.ts</context>
<context context-type="linenumber">636</context>
<context context-type="linenumber">604</context>
</context-group>
</trans-unit>
<trans-unit id="6933068701447776492" datatype="html">
Expand Down

0 comments on commit 8addd6b

Please sign in to comment.