From f4e35e267df0e25f60787b3e5cf725f201b0a2a9 Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Thu, 19 Dec 2024 16:56:53 -0800 Subject: [PATCH] refactor(DataService): add modifiers and remove unused code (#2026) --- .../milestone-grading-view.component.ts | 33 +-- .../node-grading-view.component.ts | 24 +- .../AbstractComponentDataExportStrategy.ts | 2 +- .../strategies/AbstractDataExportStrategy.ts | 4 +- ...alogGuidanceComponentDataExportStrategy.ts | 2 +- .../DiscussionComponentDataExportStrategy.ts | 2 +- .../strategies/ExportStrategyTester.ts | 12 +- .../LabelComponentDataExportStrategy.ts | 2 +- .../OneWorkgroupPerRowDataExportStrategy.ts | 4 +- .../PeerChatComponentDataExportStrategy.ts | 4 +- .../strategies/RawDataExportStrategy.ts | 8 +- .../StudentWorkDataExportStrategy.ts | 6 +- .../student-grading.component.ts | 29 +- .../peer-chat-grading.component.ts | 4 +- src/assets/wise5/services/milestoneService.ts | 9 +- .../wise5/services/studentDataService.ts | 64 ++-- .../wise5/services/teacherDataService.ts | 279 ++++++------------ 17 files changed, 183 insertions(+), 305 deletions(-) diff --git a/src/assets/wise5/classroomMonitor/classroomMonitorComponents/milestones/milestone-grading-view/milestone-grading-view.component.ts b/src/assets/wise5/classroomMonitor/classroomMonitorComponents/milestones/milestone-grading-view/milestone-grading-view.component.ts index 075bed3d065..c46d7d682e4 100644 --- a/src/assets/wise5/classroomMonitor/classroomMonitorComponents/milestones/milestone-grading-view/milestone-grading-view.component.ts +++ b/src/assets/wise5/classroomMonitor/classroomMonitorComponents/milestones/milestone-grading-view/milestone-grading-view.component.ts @@ -32,23 +32,23 @@ export class MilestoneGradingViewComponent extends NodeGradingViewComponent { protected annotationService: AnnotationService, protected classroomStatusService: ClassroomStatusService, protected configService: ConfigService, + protected dataService: TeacherDataService, protected dialog: MatDialog, protected milestoneService: MilestoneService, protected notificationService: NotificationService, protected peerGroupService: TeacherPeerGroupService, - protected projectService: TeacherProjectService, - protected teacherDataService: TeacherDataService + protected projectService: TeacherProjectService ) { super( annotationService, classroomStatusService, configService, + dataService, dialog, milestoneService, notificationService, peerGroupService, - projectService, - teacherDataService + projectService ); } @@ -57,9 +57,8 @@ export class MilestoneGradingViewComponent extends NodeGradingViewComponent { this.node = this.projectService.getNode(this.nodeId); if (this.milestone.report.locations.length > 1) { this.firstNodeId = this.milestone.report.locations[0].nodeId; - this.lastNodeId = this.milestone.report.locations[ - this.milestone.report.locations.length - 1 - ].nodeId; + this.lastNodeId = + this.milestone.report.locations[this.milestone.report.locations.length - 1].nodeId; } this.componentId = this.milestone.componentId; this.retrieveStudentData(); @@ -131,15 +130,7 @@ export class MilestoneGradingViewComponent extends NodeGradingViewComponent { componentType = null, category = 'Navigation', data = { milestoneId: this.milestone.id }; - this.teacherDataService.saveEvent( - context, - nodeId, - componentId, - componentType, - category, - event, - data - ); + this.dataService.saveEvent(context, nodeId, componentId, componentType, category, event, data); } onUpdateExpand({ workgroupId, value }): void { @@ -185,15 +176,7 @@ export class MilestoneGradingViewComponent extends NodeGradingViewComponent { componentType = null, category = 'Navigation', data = { milestoneId: this.milestone.id, workgroupId: workgroupId }; - this.teacherDataService.saveEvent( - context, - nodeId, - componentId, - componentType, - category, - event, - data - ); + this.dataService.saveEvent(context, nodeId, componentId, componentType, category, event, data); } protected sortWorkgroups(): void { diff --git a/src/assets/wise5/classroomMonitor/classroomMonitorComponents/nodeGrading/node-grading-view/node-grading-view.component.ts b/src/assets/wise5/classroomMonitor/classroomMonitorComponents/nodeGrading/node-grading-view/node-grading-view.component.ts index fceefceba27..20fa3957354 100644 --- a/src/assets/wise5/classroomMonitor/classroomMonitorComponents/nodeGrading/node-grading-view/node-grading-view.component.ts +++ b/src/assets/wise5/classroomMonitor/classroomMonitorComponents/nodeGrading/node-grading-view/node-grading-view.component.ts @@ -49,12 +49,12 @@ export class NodeGradingViewComponent implements OnInit { protected annotationService: AnnotationService, protected classroomStatusService: ClassroomStatusService, protected configService: ConfigService, + protected dataService: TeacherDataService, protected dialog: MatDialog, protected milestoneService: MilestoneService, protected notificationService: NotificationService, protected peerGroupService: TeacherPeerGroupService, - protected projectService: TeacherProjectService, - protected teacherDataService: TeacherDataService + protected projectService: TeacherProjectService ) {} ngOnInit(): void { @@ -66,7 +66,7 @@ export class NodeGradingViewComponent implements OnInit { this.maxScore = this.getMaxScore(); this.node = this.projectService.getNode(this.nodeId); this.nodeHasWork = this.projectService.nodeHasWork(this.nodeId); - this.sort = this.teacherDataService.nodeGradingSort; + this.sort = this.dataService.nodeGradingSort; this.nodeContent = this.projectService.getNodeById(this.nodeId); this.milestoneReport = this.milestoneService.getMilestoneReportByNodeId(this.nodeId); this.peerGroupingTags = Array.from(this.peerGroupService.getPeerGroupingTags(this.node)); @@ -113,7 +113,7 @@ export class NodeGradingViewComponent implements OnInit { ); this.subscriptions.add( - this.teacherDataService.studentWorkReceived$.subscribe(({ studentWork }) => { + this.dataService.studentWorkReceived$.subscribe(({ studentWork }) => { const workgroupId = studentWork.workgroupId; if (studentWork.nodeId === this.nodeId && this.workgroupsById[workgroupId]) { this.updateWorkgroup(workgroupId); @@ -122,14 +122,14 @@ export class NodeGradingViewComponent implements OnInit { ); this.subscriptions.add( - this.teacherDataService.currentPeriodChanged$.subscribe(() => { + this.dataService.currentPeriodChanged$.subscribe(() => { this.milestoneReport = this.milestoneService.getMilestoneReportByNodeId(this.nodeId); }) ); } protected retrieveStudentData(node: Node = this.node): void { - this.teacherDataService.retrieveStudentDataForNode(node).subscribe(() => { + this.dataService.retrieveStudentDataForNode(node).subscribe(() => { this.teacherWorkgroupId = this.configService.getWorkgroupId(); this.workgroups = copy(this.configService.getClassmateUserInfos()).filter( (workgroup) => @@ -298,7 +298,7 @@ export class NodeGradingViewComponent implements OnInit { } private getLatestWorkTimeByWorkgroupId(workgroupId: number): string { - const componentStates = this.teacherDataService.getComponentStatesByNodeId(this.nodeId); + const componentStates = this.dataService.getComponentStatesByNodeId(this.nodeId); for (const componentState of componentStates.reverse()) { if (componentState.workgroupId === workgroupId) { return componentState.serverSaveTime; @@ -308,7 +308,7 @@ export class NodeGradingViewComponent implements OnInit { } private getLatestAnnotationTimeByWorkgroupId(workgroupId: number): string { - const annotations = this.teacherDataService.getAnnotationsByNodeId(this.nodeId); + const annotations = this.dataService.getAnnotationsByNodeId(this.nodeId); for (const annotation of annotations.reverse()) { // TODO: support checking for annotations from shared teachers if ( @@ -346,14 +346,14 @@ export class NodeGradingViewComponent implements OnInit { getNodeCompletion(nodeId: string): number { return this.classroomStatusService.getNodeCompletion( nodeId, - this.teacherDataService.getCurrentPeriodId() + this.dataService.getCurrentPeriodId() ).completionPct; } getNodeAverageScore(): any { const averageScore = this.classroomStatusService.getNodeAverageScore( this.nodeId, - this.teacherDataService.getCurrentPeriodId() + this.dataService.getCurrentPeriodId() ); if (averageScore === null) { return 'N/A'; @@ -363,7 +363,7 @@ export class NodeGradingViewComponent implements OnInit { } isWorkgroupShown(workgroup: any): boolean { - return this.teacherDataService.isWorkgroupShown(workgroup); + return this.dataService.isWorkgroupShown(workgroup); } protected showRubric(): void { @@ -379,7 +379,7 @@ export class NodeGradingViewComponent implements OnInit { } else { this.sort = value; } - this.teacherDataService.nodeGradingSort = this.sort; + this.dataService.nodeGradingSort = this.sort; this.sortWorkgroups(); } diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/AbstractComponentDataExportStrategy.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/AbstractComponentDataExportStrategy.ts index 4d1c10b3017..fb3b3ba1fbe 100644 --- a/src/assets/wise5/classroomMonitor/dataExport/strategies/AbstractComponentDataExportStrategy.ts +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/AbstractComponentDataExportStrategy.ts @@ -98,7 +98,7 @@ export abstract class AbstractComponentDataExportStrategy extends AbstractDataEx protected abstract getComponentTypeWithUnderscore(): string; protected getComponentStates(component: any): ComponentState[] { - let componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id); + let componentStates = this.dataService.getComponentStatesByComponentId(component.id); this.sortByWorkgroupIdAndTimestamp(componentStates); this.calculateRevisionNumbers(componentStates); if (this.allOrLatest === 'latest') { diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/AbstractDataExportStrategy.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/AbstractDataExportStrategy.ts index ebfbcf05069..5aac5dbf02b 100644 --- a/src/assets/wise5/classroomMonitor/dataExport/strategies/AbstractDataExportStrategy.ts +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/AbstractDataExportStrategy.ts @@ -17,7 +17,7 @@ export abstract class AbstractDataExportStrategy implements DataExportStrategy { dataExportService: DataExportService; projectService: TeacherProjectService; protected allOrLatest: 'all' | 'latest' = 'all'; - teacherDataService: TeacherDataService; + dataService: TeacherDataService; setDataExportContext(context: DataExportContext) { this.context = context; @@ -26,7 +26,7 @@ export abstract class AbstractDataExportStrategy implements DataExportStrategy { this.configService = context.controller.configService; this.dataExportService = context.controller.dataExportService; this.projectService = context.controller.projectService; - this.teacherDataService = context.controller.dataService; + this.dataService = context.controller.dataService; } abstract export(); diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/DialogGuidanceComponentDataExportStrategy.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/DialogGuidanceComponentDataExportStrategy.ts index 85deae5e663..cd37ddefa42 100644 --- a/src/assets/wise5/classroomMonitor/dataExport/strategies/DialogGuidanceComponentDataExportStrategy.ts +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/DialogGuidanceComponentDataExportStrategy.ts @@ -26,7 +26,7 @@ export class DialogGuidanceComponentDataExportStrategy extends AbstractComponent private addDialogGuidanceSpecificHeaderColumns(component: any, headerRow: string[]): void { headerRow.push(this.itemIdLabel); - const componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id); + const componentStates = this.dataService.getComponentStatesByComponentId(component.id); const ideaNames = this.getIdeaNames(componentStates); const scoreNames = this.getScoreNames(componentStates); for (let i = 1; i <= this.getMaxNumberOfStudentResponses(componentStates); i++) { diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/DiscussionComponentDataExportStrategy.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/DiscussionComponentDataExportStrategy.ts index 1cdb1024221..94fd1b8f7ab 100644 --- a/src/assets/wise5/classroomMonitor/dataExport/strategies/DiscussionComponentDataExportStrategy.ts +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/DiscussionComponentDataExportStrategy.ts @@ -44,7 +44,7 @@ export class DiscussionComponentDataExportStrategy extends AbstractComponentData nodeId: string ) { const rows = []; - const componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id); + const componentStates = this.dataService.getComponentStatesByComponentId(component.id); const structuredPosts = this.getStructuredPosts(componentStates); let rowCounter = 1; for (let threadId of Object.keys(structuredPosts)) { diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/ExportStrategyTester.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/ExportStrategyTester.ts index eac8d110a08..6c9008552f2 100644 --- a/src/assets/wise5/classroomMonitor/dataExport/strategies/ExportStrategyTester.ts +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/ExportStrategyTester.ts @@ -55,7 +55,7 @@ export class ExportStrategyTester { studentWorkTimestamp2 = millisecondsToDateTime(this.studentWorkTimestampMilliseconds2); studentWorkTimestamp3 = millisecondsToDateTime(this.studentWorkTimestampMilliseconds3); studentWorkTimestamp4 = millisecondsToDateTime(this.studentWorkTimestampMilliseconds4); - teacherDataService: TeacherDataService; + dataService: TeacherDataService; teacherProjectService: TeacherProjectService; teacherWebSocketService: TeacherWebSocketService = new TeacherWebSocketService( null, @@ -117,10 +117,10 @@ export class ExportStrategyTester { } setUpTeacherDataService(): void { - this.teacherDataService = new TeacherDataService( - null, + this.dataService = new TeacherDataService( this.annotationService, this.configService, + null, this.teacherProjectService, this.teacherWebSocketService ); @@ -138,7 +138,7 @@ export class ExportStrategyTester { this.componentExportStrategy.configService = this.configService; this.componentExportStrategy.dataExportService = this.dataExportService; this.componentExportStrategy.projectService = this.teacherProjectService; - this.componentExportStrategy.teacherDataService = this.teacherDataService; + this.componentExportStrategy.dataService = this.dataService; } createDataExportComponent(): any { @@ -146,7 +146,7 @@ export class ExportStrategyTester { this.annotationService, this.configService, this.dataExportService, - this.teacherDataService, + this.dataService, null, this.teacherProjectService, null, @@ -159,7 +159,7 @@ export class ExportStrategyTester { } setStudentData(componentStates: any[]): void { - this.teacherDataService.processComponentStates(componentStates); + this.dataService.processComponentStates(componentStates); } setAnnotations(annotations: any[]): void { diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/LabelComponentDataExportStrategy.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/LabelComponentDataExportStrategy.ts index f0519c439a4..d99d691bcf2 100644 --- a/src/assets/wise5/classroomMonitor/dataExport/strategies/LabelComponentDataExportStrategy.ts +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/LabelComponentDataExportStrategy.ts @@ -13,7 +13,7 @@ export class LabelComponentDataExportStrategy extends AbstractComponentDataExpor protected generateComponentHeaderRow(component: any): string[] { const headerRow = [...this.defaultColumnNames]; - const componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id); + const componentStates = this.dataService.getComponentStatesByComponentId(component.id); const maxCountLabel = this.getMaxLabelCount(componentStates); for (let i = 1; i <= maxCountLabel; i++) { headerRow.push(`Label ${i}`); diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/OneWorkgroupPerRowDataExportStrategy.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/OneWorkgroupPerRowDataExportStrategy.ts index 1a3c6269ce9..14b33a593d4 100644 --- a/src/assets/wise5/classroomMonitor/dataExport/strategies/OneWorkgroupPerRowDataExportStrategy.ts +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/OneWorkgroupPerRowDataExportStrategy.ts @@ -116,7 +116,7 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra if (this.exportComponent(selectedNodesMap, nodeId, componentId)) { var columnIdPrefix = nodeId + '-' + componentId; var componentState = - this.teacherDataService.getLatestComponentStateByWorkgroupIdNodeIdAndComponentId( + this.dataService.getLatestComponentStateByWorkgroupIdNodeIdAndComponentId( workgroupId, nodeId, componentId @@ -247,7 +247,7 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra private getLatestBranchPathTakenEvent(workgroupId: number, nodeId: string): any { return ( - this.teacherDataService + this.dataService .getEventsByWorkgroupId(workgroupId) .findLast((event) => event.nodeId === nodeId && event.event === 'branchPathTaken') ?? null ); diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/PeerChatComponentDataExportStrategy.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/PeerChatComponentDataExportStrategy.ts index a1aed519daf..bd603a1fdae 100644 --- a/src/assets/wise5/classroomMonitor/dataExport/strategies/PeerChatComponentDataExportStrategy.ts +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/PeerChatComponentDataExportStrategy.ts @@ -30,7 +30,7 @@ export class PeerChatComponentDataExportStrategy extends AbstractComponentDataEx protected generateComponentHeaderRow(component: any): string[] { const headerRow = [...this.defaultColumnNames]; - const componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id); + const componentStates = this.dataService.getComponentStatesByComponentId(component.id); this.insertPromptColumns(headerRow, component); this.insertQuestionColumns(headerRow, component, componentStates); return headerRow; @@ -110,7 +110,7 @@ export class PeerChatComponentDataExportStrategy extends AbstractComponentDataEx columnNameToNumber: any, nodeId: string ): any[] { - const componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id); + const componentStates = this.dataService.getComponentStatesByComponentId(component.id); const sortedComponentStates = this.sortByPeerGroupIdAndTimestamp(componentStates); const workRows = []; for (let r = 0; r < sortedComponentStates.length; r++) { diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/RawDataExportStrategy.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/RawDataExportStrategy.ts index 6750f1a6765..8f81e5c2fb4 100644 --- a/src/assets/wise5/classroomMonitor/dataExport/strategies/RawDataExportStrategy.ts +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/RawDataExportStrategy.ts @@ -39,9 +39,7 @@ export class RawDataExportStrategy extends AbstractDataExportStrategy { var workgroupId = workgroup.workgroupId; if (this.controller.includeStudentWork) { workgroup.studentWork = []; - var componentStates = this.teacherDataService.getComponentStatesByWorkgroupId( - workgroupId - ); + var componentStates = this.dataService.getComponentStatesByWorkgroupId(workgroupId); if (componentStates != null) { for (var c = 0; c < componentStates.length; c++) { var componentState = componentStates[c]; @@ -59,7 +57,7 @@ export class RawDataExportStrategy extends AbstractDataExportStrategy { } if (this.controller.includeAnnotations) { workgroup.annotations = []; - var annotations = this.teacherDataService.getAnnotationsToWorkgroupId(workgroupId); + var annotations = this.dataService.getAnnotationsToWorkgroupId(workgroupId); if (annotations != null) { for (var a = 0; a < annotations.length; a++) { var annotation = annotations[a]; @@ -77,7 +75,7 @@ export class RawDataExportStrategy extends AbstractDataExportStrategy { } if (this.controller.includeEvents) { workgroup.events = []; - var events = this.teacherDataService.getEventsByWorkgroupId(workgroupId); + var events = this.dataService.getEventsByWorkgroupId(workgroupId); if (events != null) { for (var e = 0; e < events.length; e++) { var event = events[e]; diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/StudentWorkDataExportStrategy.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/StudentWorkDataExportStrategy.ts index 92606fc2cab..f87886173ef 100644 --- a/src/assets/wise5/classroomMonitor/dataExport/strategies/StudentWorkDataExportStrategy.ts +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/StudentWorkDataExportStrategy.ts @@ -93,10 +93,10 @@ export class StudentWorkDataExportStrategy extends AbstractDataExportStrategy { var componentRevisionCounter = {}; let componentStates = []; if (this.exportType === 'allStudentWork') { - componentStates = this.teacherDataService.getComponentStatesByWorkgroupId(workgroupId); + componentStates = this.dataService.getComponentStatesByWorkgroupId(workgroupId); } else if (this.exportType === 'latestStudentWork') { this.injectRevisionCounterIntoComponentStates( - this.teacherDataService.getComponentStatesByWorkgroupId(workgroupId) + this.dataService.getComponentStatesByWorkgroupId(workgroupId) ); componentStates = this.getLatestComponentStatesByWorkgroupId(workgroupId); } @@ -171,7 +171,7 @@ export class StudentWorkDataExportStrategy extends AbstractDataExportStrategy { const componentStates = []; const componentsFound = {}; const componentStatesForWorkgroup = - this.teacherDataService.getComponentStatesByWorkgroupId(workgroupId); + this.dataService.getComponentStatesByWorkgroupId(workgroupId); for (let csb = componentStatesForWorkgroup.length - 1; csb >= 0; csb--) { const componentState = componentStatesForWorkgroup[csb]; const key = componentState.nodeId + '-' + componentState.componentId; diff --git a/src/assets/wise5/classroomMonitor/student-grading/student-grading.component.ts b/src/assets/wise5/classroomMonitor/student-grading/student-grading.component.ts index 9e63bde78e1..9d631bdf198 100644 --- a/src/assets/wise5/classroomMonitor/student-grading/student-grading.component.ts +++ b/src/assets/wise5/classroomMonitor/student-grading/student-grading.component.ts @@ -351,31 +351,14 @@ export class StudentGradingComponent implements OnInit { * @returns boolean whether the workgroup should be shown */ private isNodeShown(nodeId: string): boolean { - let show = false; - const node = this.nodesById[nodeId]; - - if (node.isVisible && (this.projectService.nodeHasWork(nodeId) || this.showNonWorkNodes)) { - let currentStep = this.dataService.getCurrentStep(); - if (currentStep) { - // there is a currently selected step, so check if this one matches - if (currentStep.nodeId === parseInt(nodeId)) { - show = true; - } - } else { - // there is no currently selected step, so show this one - show = true; - } - } - - return show; + return ( + this.nodesById[nodeId].isVisible && + (this.projectService.nodeHasWork(nodeId) || this.showNonWorkNodes) + ); } - setSort(value: string): void { - if (this.sort === value) { - this.sort = `-${value}`; - } else { - this.sort = value; - } + protected setSort(value: string): void { + this.sort = this.sort === value ? `-${value}` : value; // update value in the teacher data service so we can persist across view instances and // workgroup changes diff --git a/src/assets/wise5/components/peerChat/peer-chat-grading/peer-chat-grading.component.ts b/src/assets/wise5/components/peerChat/peer-chat-grading/peer-chat-grading.component.ts index 98b9d4d302c..ad503f16f00 100644 --- a/src/assets/wise5/components/peerChat/peer-chat-grading/peer-chat-grading.component.ts +++ b/src/assets/wise5/components/peerChat/peer-chat-grading/peer-chat-grading.component.ts @@ -23,12 +23,12 @@ export class PeerChatGradingComponent extends PeerChatShowWorkComponent { constructor( protected annotationService: AnnotationService, protected configService: ConfigService, + protected dataService: TeacherDataService, protected nodeService: NodeService, protected notificationService: NotificationService, protected peerChatService: PeerChatService, protected peerGroupService: PeerGroupService, protected projectService: ProjectService, - protected teacherDataService: TeacherDataService, protected teacherWebSocketService: TeacherWebSocketService, protected teacherWorkService: TeacherWorkService ) { @@ -70,7 +70,7 @@ export class PeerChatGradingComponent extends PeerChatShowWorkComponent { isSubmit: true, nodeId: this.nodeId, runId: this.configService.getRunId(), - periodId: this.teacherDataService.getCurrentPeriodId(), + periodId: this.dataService.getCurrentPeriodId(), studentData: { response: response }, diff --git a/src/assets/wise5/services/milestoneService.ts b/src/assets/wise5/services/milestoneService.ts index 9bfee77be82..e34b2957c54 100644 --- a/src/assets/wise5/services/milestoneService.ts +++ b/src/assets/wise5/services/milestoneService.ts @@ -19,9 +19,9 @@ export class MilestoneService { constructor( private achievementService: AchievementService, private configService: ConfigService, + private dataService: TeacherDataService, private milestoneReportService: MilestoneReportService, - private projectService: ProjectService, - private teacherDataService: TeacherDataService + private projectService: ProjectService ) {} getProjectMilestones(): Milestone[] { @@ -49,7 +49,7 @@ export class MilestoneService { } getProjectMilestoneStatus(milestoneId: string): any { - this.periodId = this.teacherDataService.getCurrentPeriod().periodId; + this.periodId = this.dataService.getCurrentPeriod().periodId; this.setWorkgroupsInCurrentPeriod(); let milestone = this.projectService.getAchievementByAchievementId(milestoneId); milestone = this.insertMilestoneItems(milestone); @@ -73,7 +73,8 @@ export class MilestoneService { } insertMilestoneCompletion(milestone: any): any { - const achievementIdToStudentAchievements = this.achievementService.getAchievementIdToStudentAchievementsMappings(); + const achievementIdToStudentAchievements = + this.achievementService.getAchievementIdToStudentAchievementsMappings(); const studentAchievements = achievementIdToStudentAchievements[milestone.id]; const workgroupIdsCompleted = []; const achievementTimes = []; diff --git a/src/assets/wise5/services/studentDataService.ts b/src/assets/wise5/services/studentDataService.ts index 2f4d6f1738f..38cda9dd5c8 100644 --- a/src/assets/wise5/services/studentDataService.ts +++ b/src/assets/wise5/services/studentDataService.ts @@ -47,12 +47,12 @@ export class StudentDataService extends DataService { public updateNodeStatuses$: Observable = this.updateNodeStatusesSource.asObservable(); constructor( + private annotationService: AnnotationService, + private configService: ConfigService, public http: HttpClient, - private AnnotationService: AnnotationService, - private ConfigService: ConfigService, - protected ProjectService: ProjectService + protected projectService: ProjectService ) { - super(ProjectService); + super(projectService); } broadcastComponentStudentData(componentStudentData: any) { @@ -61,7 +61,7 @@ export class StudentDataService extends DataService { retrieveStudentData() { this.nodeStatuses = {}; - if (this.ConfigService.isPreview()) { + if (this.configService.isPreview()) { this.retrieveStudentDataForPreview(); } else { return this.retrieveStudentDataForSignedInStudent(); @@ -76,7 +76,7 @@ export class StudentDataService extends DataService { username: $localize`Preview Student`, userId: '0' }; - this.AnnotationService.setAnnotations(this.studentData.annotations); + this.annotationService.setAnnotations(this.studentData.annotations); this.dataRetrievedSource.next(this.studentData); } @@ -90,17 +90,17 @@ export class StudentDataService extends DataService { retrieveStudentDataForSignedInStudent() { const params = new HttpParams() - .set('runId', this.ConfigService.getRunId()) - .set('workgroupId', this.ConfigService.getWorkgroupId() + '') + .set('runId', this.configService.getRunId()) + .set('workgroupId', this.configService.getWorkgroupId() + '') .set('getStudentWork', true + '') .set('getEvents', true + '') .set('getAnnotations', true + '') - .set('toWorkgroupId', this.ConfigService.getWorkgroupId()); + .set('toWorkgroupId', this.configService.getWorkgroupId()); const options = { params: params }; return this.http - .get(this.ConfigService.getConfigParam('studentDataURL'), options) + .get(this.configService.getConfigParam('studentDataURL'), options) .toPromise() .then((resultData) => { return this.handleStudentDataResponse(resultData); @@ -119,24 +119,24 @@ export class StudentDataService extends DataService { } this.studentData.events = resultData.events; this.studentData.annotations = resultData.annotations; - this.AnnotationService.setAnnotations(this.studentData.annotations); + this.annotationService.setAnnotations(this.studentData.annotations); this.populateHistories(this.studentData.events); this.dataRetrievedSource.next(this.studentData); return this.studentData; } retrieveRunStatus() { - if (this.ConfigService.isPreview()) { + if (this.configService.isPreview()) { this.runStatus = { periods: [] }; } else { - const params = new HttpParams().set('runId', this.ConfigService.getConfigParam('runId')); + const params = new HttpParams().set('runId', this.configService.getConfigParam('runId')); const options = { params: params }; return this.http - .get(this.ConfigService.getConfigParam('runStatusURL'), options) + .get(this.configService.getConfigParam('runStatusURL'), options) .toPromise() .then((runStatus: RunStatus) => { this.runStatus = runStatus; @@ -174,9 +174,9 @@ export class StudentDataService extends DataService { getScoreValueFromScoreAnnotation(scoreAnnotation: any, scoreId: string): number { if (scoreId == null) { - return this.AnnotationService.getScoreValueFromScoreAnnotation(scoreAnnotation); + return this.annotationService.getScoreValueFromScoreAnnotation(scoreAnnotation); } else { - return this.AnnotationService.getSubScoreValueFromScoreAnnotation(scoreAnnotation, scoreId); + return this.annotationService.getSubScoreValueFromScoreAnnotation(scoreAnnotation, scoreId); } } @@ -298,10 +298,10 @@ export class StudentDataService extends DataService { category: category, event: event, data: data, - projectId: this.ConfigService.getProjectId(), - runId: this.ConfigService.getRunId(), - periodId: this.ConfigService.getPeriodId(), - workgroupId: this.ConfigService.getWorkgroupId(), + projectId: this.configService.getProjectId(), + runId: this.configService.getRunId(), + periodId: this.configService.getPeriodId(), + workgroupId: this.configService.getWorkgroupId(), clientSaveTime: new Date().getTime() }; } @@ -317,21 +317,21 @@ export class StudentDataService extends DataService { const studentWorkList = this.prepareComponentStatesForSave(componentStates); this.prepareEventsForSave(events); this.prepareAnnotationsForSave(annotations); - if (this.ConfigService.isPreview()) { + if (this.configService.isPreview()) { return this.handlePreviewSaveToServer(studentWorkList, events, annotations); - } else if (!this.ConfigService.isRunActive()) { + } else if (!this.configService.isRunActive()) { return Promise.resolve(); } else { const params = { - projectId: this.ConfigService.getProjectId(), - runId: this.ConfigService.getRunId(), - workgroupId: this.ConfigService.getWorkgroupId(), + projectId: this.configService.getProjectId(), + runId: this.configService.getRunId(), + workgroupId: this.configService.getWorkgroupId(), studentWorkList: JSON.stringify(studentWorkList), events: JSON.stringify(events), annotations: JSON.stringify(annotations) }; return this.http - .post(this.ConfigService.getConfigParam('studentDataURL'), params) + .post(this.configService.getConfigParam('studentDataURL'), params) .toPromise() .then( (resultData: any) => { @@ -421,7 +421,7 @@ export class StudentDataService extends DataService { for (let l = localStudentWorkList.length - 1; l >= 0; l--) { const localStudentWork = localStudentWorkList[l]; if (this.isMatchingRequestToken(localStudentWork, savedStudentWork)) { - if (this.ConfigService.isPreview()) { + if (this.configService.isPreview()) { this.setDummyIdIntoLocalId(localStudentWork); this.setDummyServerSaveTimeIntoLocalServerSaveTime(localStudentWork); } else { @@ -489,7 +489,7 @@ export class StudentDataService extends DataService { this.setRemoteIdIntoLocalId(savedAnnotation, localAnnotation); this.setRemoteServerSaveTimeIntoLocalServerSaveTime(savedAnnotation, localAnnotation); this.clearRequestToken(localAnnotation); - this.AnnotationService.broadcastAnnotationSavedToServer(localAnnotation); + this.annotationService.broadcastAnnotationSavedToServer(localAnnotation); break; } } @@ -568,7 +568,7 @@ export class StudentDataService extends DataService { } getTotalScore() { - return this.AnnotationService.getTotalScore(this.studentData.annotations); + return this.annotationService.getTotalScore(this.studentData.annotations); } getRunStatus(): RunStatus { @@ -581,7 +581,7 @@ export class StudentDataService extends DataService { getLatestComponentStatesByNodeId(nodeId) { const latestComponentStates = []; - const node = this.ProjectService.getNodeById(nodeId); + const node = this.projectService.getNodeById(nodeId); if (node != null) { const components = node.components; if (components != null) { @@ -618,7 +618,7 @@ export class StudentDataService extends DataService { getStudentWorkById(id) { const params = new HttpParams() - .set('runId', this.ConfigService.getRunId()) + .set('runId', this.configService.getRunId()) .set('id', id + '') .set('getStudentWork', true + '') .set('getEvents', false + '') @@ -628,7 +628,7 @@ export class StudentDataService extends DataService { params: params }; return this.http - .get(this.ConfigService.getConfigParam('studentDataURL'), options) + .get(this.configService.getConfigParam('studentDataURL'), options) .toPromise() .then((resultData: any) => { if (resultData != null && resultData.studentWorkList.length > 0) { diff --git a/src/assets/wise5/services/teacherDataService.ts b/src/assets/wise5/services/teacherDataService.ts index 6b235d30fa5..3900a360bcc 100644 --- a/src/assets/wise5/services/teacherDataService.ts +++ b/src/assets/wise5/services/teacherDataService.ts @@ -17,7 +17,6 @@ export class TeacherDataService extends DataService { studentData: any; currentPeriod = null; currentWorkgroup = null; - currentStep = null; previousStep = null; periods = []; nodeGradingSort = 'team'; @@ -30,13 +29,13 @@ export class TeacherDataService extends DataService { this.currentWorkgroupChangedSource.asObservable(); constructor( + private annotationService: AnnotationService, + private configService: ConfigService, private http: HttpClient, - private AnnotationService: AnnotationService, - private ConfigService: ConfigService, - protected ProjectService: TeacherProjectService, - private TeacherWebSocketService: TeacherWebSocketService + protected projectService: TeacherProjectService, + private webSocketService: TeacherWebSocketService ) { - super(ProjectService); + super(projectService); this.studentData = { annotationsByNodeId: {}, annotationsToWorkgroupId: {}, @@ -47,16 +46,16 @@ export class TeacherDataService extends DataService { this.subscribeToEvents(); } - subscribeToEvents() { - this.AnnotationService.annotationSavedToServer$.subscribe((annotation: Annotation) => { + private subscribeToEvents(): void { + this.annotationService.annotationSavedToServer$.subscribe((annotation: Annotation) => { this.handleAnnotationReceived(annotation); }); - this.TeacherWebSocketService.newAnnotationReceived$.subscribe((annotation: Annotation) => { + this.webSocketService.newAnnotationReceived$.subscribe((annotation: Annotation) => { this.handleAnnotationReceived(annotation); }); - this.TeacherWebSocketService.newStudentWorkReceived$.subscribe(({ studentWork }) => { + this.webSocketService.newStudentWorkReceived$.subscribe(({ studentWork }) => { this.addOrUpdateComponentState(studentWork); this.broadcastStudentWorkReceived({ studentWork: studentWork }); }); @@ -74,27 +73,30 @@ export class TeacherDataService extends DataService { this.studentData.annotationsByNodeId[nodeId] = new Array(); } this.studentData.annotationsByNodeId[nodeId].push(annotation); - this.AnnotationService.setAnnotations(this.studentData.annotations); - this.AnnotationService.broadcastAnnotationReceived(annotation); + this.annotationService.setAnnotations(this.studentData.annotations); + this.annotationService.broadcastAnnotationReceived(annotation); } saveEvent(context, nodeId, componentId, componentType, category, event, data) { - const newEvent = this.createEvent( - context, - nodeId, - componentId, - componentType, - category, - event, - data - ); - const events = [newEvent]; - let body = new HttpParams().set('events', JSON.stringify(events)); + const newEvent = { + projectId: this.configService.getProjectId(), + runId: this.configService.getRunId(), + workgroupId: this.configService.getWorkgroupId(), + clientSaveTime: new Date().getTime(), + context: context, + nodeId: nodeId, + componentId: componentId, + type: componentType, + category: category, + event: event, + data: data + }; + let body = new HttpParams().set('events', JSON.stringify([newEvent])); body = this.addCommonParams(body); const options = { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }; - const url = this.ConfigService.getConfigParam('teacherDataURL'); + const url = this.configService.getConfigParam('teacherDataURL'); return this.http .post(url, body, options) .toPromise() @@ -103,67 +105,31 @@ export class TeacherDataService extends DataService { }); } - saveAddComponentEvent(nodeId: string, newComponent: any): void { - this.saveEvent('AuthoringTool', nodeId, null, null, 'Authoring', 'componentCreated', { - componentId: newComponent.id, - componentType: newComponent.type - }); - } - - addCommonParams(params) { + private addCommonParams(params: any): any { params = this.addProjectIdToHttpParams(params); params = this.addRunIdToHttpParams(params); params = this.addWorkgroupIdToHttpParams(params); return params; } - addProjectIdToHttpParams(params) { - const projectId = this.ConfigService.getProjectId(); - if (projectId != null) { - return params.set('projectId', projectId); - } else { - return params; - } + private addProjectIdToHttpParams(params: any): any { + const projectId = this.configService.getProjectId(); + return projectId != null ? params.set('projectId', projectId) : params; } - addRunIdToHttpParams(params) { - const runId = this.ConfigService.getRunId(); - if (runId != null) { - return params.set('runId', runId); - } else { - return params; - } + private addRunIdToHttpParams(params: any): any { + const runId = this.configService.getRunId(); + return runId != null ? params.set('runId', runId) : params; } - addWorkgroupIdToHttpParams(params) { - const workgroupId = this.ConfigService.getWorkgroupId(); - if (workgroupId != null) { - return params.set('workgroupId', workgroupId); - } else { - return params; - } - } - - createEvent(context, nodeId, componentId, componentType, category, event, data) { - const newEvent = { - projectId: this.ConfigService.getProjectId(), - runId: this.ConfigService.getRunId(), - workgroupId: this.ConfigService.getWorkgroupId(), - clientSaveTime: new Date().getTime(), - context: context, - nodeId: nodeId, - componentId: componentId, - type: componentType, - category: category, - event: event, - data: data - }; - return newEvent; + private addWorkgroupIdToHttpParams(params: any): any { + const workgroupId = this.configService.getWorkgroupId(); + return workgroupId != null ? params.set('workgroupId', workgroupId) : params; } retrieveStudentDataForNode(node: Node): Observable { let params = new HttpParams() - .set('runId', this.ConfigService.getRunId()) + .set('runId', this.configService.getRunId()) .set('getStudentWork', 'true') .set('getAnnotations', 'false') .set('getEvents', 'false'); @@ -174,9 +140,9 @@ export class TeacherDataService extends DataService { return this.retrieveStudentData(params); } - retrieveStudentDataByWorkgroupId(workgroupId) { + retrieveStudentDataByWorkgroupId(workgroupId: string): Observable { const params = new HttpParams() - .set('runId', this.ConfigService.getRunId()) + .set('runId', this.configService.getRunId()) .set('workgroupId', workgroupId) .set('toWorkgroupId', workgroupId) .set('getStudentWork', 'true') @@ -185,9 +151,9 @@ export class TeacherDataService extends DataService { return this.retrieveStudentData(params); } - retrieveAnnotations() { + retrieveAnnotations(): Observable { const params = new HttpParams() - .set('runId', this.ConfigService.getRunId()) + .set('runId', this.configService.getRunId()) .set('getStudentWork', 'false') .set('getEvents', 'false') .set('getAnnotations', 'true'); @@ -195,7 +161,7 @@ export class TeacherDataService extends DataService { } retrieveStudentData(params): Observable { - const url = this.ConfigService.getConfigParam('teacherDataURL'); + const url = this.configService.getConfigParam('teacherDataURL'); const options = { params: params }; @@ -206,7 +172,7 @@ export class TeacherDataService extends DataService { ); } - handleStudentDataResponse(resultData) { + private handleStudentDataResponse(resultData: any): any { const { studentWorkList: componentStates, events, annotations } = resultData; if (componentStates != null) { this.processComponentStates(componentStates); @@ -220,35 +186,29 @@ export class TeacherDataService extends DataService { return resultData; } - processComponentStates(componentStates) { + processComponentStates(componentStates: any[]): void { this.initializeComponentStatesDataStructures(); - for (const componentState of componentStates) { - this.addOrUpdateComponentState(componentState); - } + componentStates.forEach((componentState) => this.addOrUpdateComponentState(componentState)); } - initializeComponentStatesDataStructures(): void { + private initializeComponentStatesDataStructures(): void { this.studentData.componentStatesByWorkgroupId = {}; this.studentData.componentStatesByNodeId = {}; this.studentData.componentStatesByComponentId = {}; } - processEvents(events) { + private processEvents(events: any[]): void { events.sort(serverSaveTimeComparator); this.studentData.allEvents = events; - this.initializeEventsDataStructures(); - for (const event of events) { - this.addEventToEventsByWorkgroupId(event); - this.addEventToEventsByNodeId(event); - } - } - - initializeEventsDataStructures() { this.studentData.eventsByWorkgroupId = {}; this.studentData.eventsByNodeId = {}; + events.forEach((event) => { + this.addEventToEventsByWorkgroupId(event); + this.addEventToEventsByNodeId(event); + }); } - addEventToEventsByWorkgroupId(event) { + private addEventToEventsByWorkgroupId(event: any): void { const eventWorkgroupId = event.workgroupId; if (this.studentData.eventsByWorkgroupId[eventWorkgroupId] == null) { this.studentData.eventsByWorkgroupId[eventWorkgroupId] = new Array(); @@ -256,7 +216,7 @@ export class TeacherDataService extends DataService { this.studentData.eventsByWorkgroupId[eventWorkgroupId].push(event); } - addEventToEventsByNodeId(event) { + private addEventToEventsByNodeId(event: any): void { const eventNodeId = event.nodeId; if (this.studentData.eventsByNodeId[eventNodeId] == null) { this.studentData.eventsByNodeId[eventNodeId] = new Array(); @@ -264,22 +224,18 @@ export class TeacherDataService extends DataService { this.studentData.eventsByNodeId[eventNodeId].push(event); } - processAnnotations(annotations) { - this.initializeAnnotationsDataStructures(); + private processAnnotations(annotations: any[]): void { + this.studentData.annotationsByNodeId = {}; + this.studentData.annotationsToWorkgroupId = {}; this.studentData.annotations = annotations; - for (const annotation of annotations) { + annotations.forEach((annotation) => { this.addAnnotationToAnnotationsToWorkgroupId(annotation); this.addAnnotationToAnnotationsByNodeId(annotation); - } - this.AnnotationService.setAnnotations(this.studentData.annotations); - } - - initializeAnnotationsDataStructures(): void { - this.studentData.annotationsByNodeId = {}; - this.studentData.annotationsToWorkgroupId = {}; + }); + this.annotationService.setAnnotations(this.studentData.annotations); } - addAnnotationToAnnotationsToWorkgroupId(annotation) { + private addAnnotationToAnnotationsToWorkgroupId(annotation: any): void { const annotationWorkgroupId = annotation.toWorkgroupId; if (!this.studentData.annotationsToWorkgroupId[annotationWorkgroupId]) { this.studentData.annotationsToWorkgroupId[annotationWorkgroupId] = new Array(); @@ -287,7 +243,7 @@ export class TeacherDataService extends DataService { this.studentData.annotationsToWorkgroupId[annotationWorkgroupId].push(annotation); } - addAnnotationToAnnotationsByNodeId(annotation) { + private addAnnotationToAnnotationsByNodeId(annotation: any): void { const annotationNodeId = annotation.nodeId; if (!this.studentData.annotationsByNodeId[annotationNodeId]) { this.studentData.annotationsByNodeId[annotationNodeId] = new Array(); @@ -295,16 +251,18 @@ export class TeacherDataService extends DataService { this.studentData.annotationsByNodeId[annotationNodeId].push(annotation); } - addOrUpdateComponentState(componentState) { + private addOrUpdateComponentState(componentState: any): void { this.addComponentStateByWorkgroupId(componentState); this.addComponentStateByNodeId(componentState); this.addComponentStateByComponentId(componentState); } - addComponentStateByWorkgroupId(componentState) { + private addComponentStateByWorkgroupId(componentState: any): void { const workgroupId = componentState.workgroupId; this.initializeComponentStatesByWorkgroupIdIfNecessary(workgroupId); - const index = this.getComponentStateByWorkgroupIdIndex(componentState); + const index = this.studentData.componentStatesByWorkgroupId[ + componentState.workgroupId + ].findIndex((state) => state.id === componentState.id); if (index != -1) { this.studentData.componentStatesByWorkgroupId[workgroupId][index] = componentState; } else { @@ -312,27 +270,18 @@ export class TeacherDataService extends DataService { } } - initializeComponentStatesByWorkgroupIdIfNecessary(workgroupId) { + private initializeComponentStatesByWorkgroupIdIfNecessary(workgroupId: string): void { if (this.studentData.componentStatesByWorkgroupId[workgroupId] == null) { this.studentData.componentStatesByWorkgroupId[workgroupId] = []; } } - getComponentStateByWorkgroupIdIndex(componentState) { - const workgroupId = componentState.workgroupId; - const componentStates = this.studentData.componentStatesByWorkgroupId[workgroupId]; - for (let w = 0; w < componentStates.length; w++) { - if (componentStates[w].id === componentState.id) { - return w; - } - } - return -1; - } - - addComponentStateByNodeId(componentState) { + private addComponentStateByNodeId(componentState: any): void { const nodeId = componentState.nodeId; this.initializeComponentStatesByNodeIdIfNecessary(nodeId); - const index = this.getComponentStateByNodeIdIndex(componentState); + const index = this.studentData.componentStatesByNodeId[componentState.nodeId].findIndex( + (state) => state.id === componentState.id + ); if (index != -1) { this.studentData.componentStatesByNodeId[nodeId][index] = componentState; } else { @@ -340,27 +289,18 @@ export class TeacherDataService extends DataService { } } - initializeComponentStatesByNodeIdIfNecessary(nodeId) { + private initializeComponentStatesByNodeIdIfNecessary(nodeId: string): void { if (this.studentData.componentStatesByNodeId[nodeId] == null) { this.studentData.componentStatesByNodeId[nodeId] = []; } } - getComponentStateByNodeIdIndex(componentState) { - const nodeId = componentState.nodeId; - const componentStates = this.studentData.componentStatesByNodeId[nodeId]; - for (let n = 0; n < componentStates.length; n++) { - if (componentStates[n].id === componentState.id) { - return n; - } - } - return -1; - } - - addComponentStateByComponentId(componentState) { + private addComponentStateByComponentId(componentState: any): void { const componentId = componentState.componentId; this.initializeComponentStatesByComponentIdIfNecessary(componentId); - const index = this.getComponentStateByComponentIdIndex(componentState); + const index = this.studentData.componentStatesByComponentId[ + componentState.componentId + ].findIndex((state) => state.id === componentState.id); if (index != -1) { this.studentData.componentStatesByComponentId[componentId][index] = componentState; } else { @@ -368,32 +308,21 @@ export class TeacherDataService extends DataService { } } - initializeComponentStatesByComponentIdIfNecessary(componentId) { + private initializeComponentStatesByComponentIdIfNecessary(componentId: string): void { if (this.studentData.componentStatesByComponentId[componentId] == null) { this.studentData.componentStatesByComponentId[componentId] = []; } } - getComponentStateByComponentIdIndex(componentState) { - const componentId = componentState.componentId; - const componentStates = this.studentData.componentStatesByComponentId[componentId]; - for (let c = 0; c < componentStates.length; c++) { - if (componentStates[c].id === componentState.id) { - return c; - } - } - return -1; - } - - getComponentStatesByWorkgroupId(workgroupId) { + getComponentStatesByWorkgroupId(workgroupId: number): any[] { return this.studentData.componentStatesByWorkgroupId[workgroupId] || []; } - getComponentStatesByNodeId(nodeId) { + getComponentStatesByNodeId(nodeId: string): any[] { return this.studentData.componentStatesByNodeId[nodeId] || []; } - getComponentStatesByComponentId(componentId) { + getComponentStatesByComponentId(componentId: string): any[] { return this.studentData.componentStatesByComponentId[componentId] || []; } @@ -420,45 +349,41 @@ export class TeacherDataService extends DataService { return getIntersectOfArrays(componentStatesByWorkgroupId, componentStatesByNodeId); } - getComponentStatesByWorkgroupIdAndComponentId(workgroupId, componentId) { + getComponentStatesByWorkgroupIdAndComponentId(workgroupId: number, componentId: string): any[] { const componentStatesByWorkgroupId = this.getComponentStatesByWorkgroupId(workgroupId); const componentStatesByComponentId = this.getComponentStatesByComponentId(componentId); return getIntersectOfArrays(componentStatesByWorkgroupId, componentStatesByComponentId); } - getEventsByWorkgroupId(workgroupId) { + getEventsByWorkgroupId(workgroupId: number): any[] { return this.studentData.eventsByWorkgroupId[workgroupId] || []; } - getEventsByNodeId(nodeId) { + getEventsByNodeId(nodeId: string): any[] { return this.studentData.eventsByNodeId[nodeId] || []; } - getAnnotationsToWorkgroupId(workgroupId: number) { + getAnnotationsToWorkgroupId(workgroupId: number): any[] { return this.studentData.annotationsToWorkgroupId[workgroupId] || []; } - getAnnotationsByNodeId(nodeId: string) { + getAnnotationsByNodeId(nodeId: string): any[] { return this.studentData.annotationsByNodeId[nodeId] || []; } - setCurrentPeriod(period) { + setCurrentPeriod(period: any): void { const previousPeriod = this.currentPeriod; this.currentPeriod = period; this.clearCurrentWorkgroupIfNecessary(this.currentPeriod.periodId); if (previousPeriod == null || previousPeriod.periodId != this.currentPeriod.periodId) { - this.broadcastCurrentPeriodChanged({ + this.currentPeriodChangedSource.next({ previousPeriod: previousPeriod, currentPeriod: this.currentPeriod }); } } - broadcastCurrentPeriodChanged(previousAndCurrentPeriod: any) { - this.currentPeriodChangedSource.next(previousAndCurrentPeriod); - } - - clearCurrentWorkgroupIfNecessary(periodId) { + private clearCurrentWorkgroupIfNecessary(periodId: number): void { const currentWorkgroup = this.getCurrentWorkgroup(); if (currentWorkgroup) { if (periodId !== -1 && currentWorkgroup.periodId !== periodId) { @@ -471,11 +396,11 @@ export class TeacherDataService extends DataService { this.currentPeriod = null; } - getCurrentPeriod() { + getCurrentPeriod(): any { return this.currentPeriod; } - getCurrentPeriodId() { + getCurrentPeriodId(): number { return this.currentPeriod.periodId; } @@ -487,29 +412,17 @@ export class TeacherDataService extends DataService { this.periods = periods; } - setCurrentWorkgroup(workgroup) { + setCurrentWorkgroup(workgroup: any): void { this.currentWorkgroup = workgroup; - this.broadcastCurrentWorkgroupChanged({ currentWorkgroup: this.currentWorkgroup }); - } - - broadcastCurrentWorkgroupChanged(args: any) { - this.currentWorkgroupChangedSource.next(args); + this.currentWorkgroupChangedSource.next({ currentWorkgroup: this.currentWorkgroup }); } - getCurrentWorkgroup() { + getCurrentWorkgroup(): any { return this.currentWorkgroup; } - setCurrentStep(step) { - this.currentStep = step; - } - - getCurrentStep() { - return this.currentStep; - } - getTotalScoreByWorkgroupId(workgroupId: number) { - return this.AnnotationService.getTotalScore( + return this.annotationService.getTotalScore( this.studentData.annotationsToWorkgroupId[workgroupId] ); } @@ -522,11 +435,11 @@ export class TeacherDataService extends DataService { ); } - isWorkgroupInCurrentPeriod(workgroup: any): boolean { + private isWorkgroupInCurrentPeriod(workgroup: any): boolean { return this.currentPeriod.periodId === -1 || workgroup.periodId === this.currentPeriod.periodId; } - isCurrentWorkgroup(workgroupId: number): boolean { + private isCurrentWorkgroup(workgroupId: number): boolean { return this.currentWorkgroup.workgroupId === workgroupId; } }