diff --git a/src/assets/wise5/services/gradingNodeService.ts b/src/assets/wise5/services/gradingNodeService.ts index fbb5f29666..d4c83199cb 100644 --- a/src/assets/wise5/services/gradingNodeService.ts +++ b/src/assets/wise5/services/gradingNodeService.ts @@ -11,7 +11,7 @@ export class GradingNodeService extends TeacherNodeService { getNextNodeId(currentId = null): Promise { return super.getNextNodeId(currentId).then((nextNodeId: string) => { if (!nextNodeId) return null; - return this.ProjectService.nodeHasWork(nextNodeId) + return this.projectService.nodeHasWork(nextNodeId) ? nextNodeId : this.getNextNodeId(nextNodeId); }); @@ -45,7 +45,7 @@ export class GradingNodeService extends TeacherNodeService { getPrevNodeId(currentId = null) { const prevNodeId = super.getPrevNodeId(currentId); if (!prevNodeId) return null; - return this.ProjectService.nodeHasWork(prevNodeId) + return this.projectService.nodeHasWork(prevNodeId) ? prevNodeId : this.getPrevNodeId(prevNodeId); } diff --git a/src/assets/wise5/services/nodeService.ts b/src/assets/wise5/services/nodeService.ts index 9ae6d4037a..780f126139 100644 --- a/src/assets/wise5/services/nodeService.ts +++ b/src/assets/wise5/services/nodeService.ts @@ -1,5 +1,3 @@ -'use strict'; - import { Injectable } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { ConfigService } from './configService'; @@ -21,20 +19,19 @@ export class NodeService { constructor( protected dialog: MatDialog, - protected ConfigService: ConfigService, + protected configService: ConfigService, protected constraintService: ConstraintService, - protected ProjectService: ProjectService, - protected DataService: DataService + protected projectService: ProjectService, + protected dataService: DataService ) {} setCurrentNode(nodeId: string): void { - this.DataService.setCurrentNodeByNodeId(nodeId); + this.dataService.setCurrentNodeByNodeId(nodeId); } - goToNextNode() { + goToNextNode(): Promise { return this.getNextNodeId().then((nextNodeId) => { if (nextNodeId != null) { - const mode = this.ConfigService.getMode(); this.setCurrentNode(nextNodeId); } return nextNodeId; @@ -59,30 +56,30 @@ export class NodeService { */ getPrevNodeId(currentId?: string): string { let prevNodeId = null; - const currentNodeId = currentId ?? this.DataService.getCurrentNodeId(); + const currentNodeId = currentId ?? this.dataService.getCurrentNodeId(); if (currentNodeId) { - if (['author', 'classroomMonitor'].includes(this.ConfigService.getMode())) { - const currentNodeOrder = this.ProjectService.getNodeOrderById(currentNodeId); + if (['author', 'classroomMonitor'].includes(this.configService.getMode())) { + const currentNodeOrder = this.projectService.getNodeOrderById(currentNodeId); if (currentNodeOrder) { - const prevId = this.ProjectService.getNodeIdByOrder(currentNodeOrder - 1); + const prevId = this.projectService.getNodeIdByOrder(currentNodeOrder - 1); if (prevId) { - prevNodeId = this.ProjectService.isApplicationNode(prevId) + prevNodeId = this.projectService.isApplicationNode(prevId) ? prevId : this.getPrevNodeId(prevId); } } } else { // get all the nodes that transition to the current node - const nodeIdsByToNodeId = this.ProjectService.getNodesByToNodeId(currentNodeId).map( - (node) => node.id - ); + const nodeIdsByToNodeId = this.projectService + .getNodesByToNodeId(currentNodeId) + .map((node) => node.id); if (nodeIdsByToNodeId.length === 1) { // there is only one node that transitions to the current node prevNodeId = nodeIdsByToNodeId[0]; } else if (nodeIdsByToNodeId.length > 1) { // there are multiple nodes that transition to the current node - const stackHistory = this.DataService.getStackHistory(); + const stackHistory = this.dataService.getStackHistory(); // loop through the stack history node ids from newest to oldest for (let s = stackHistory.length - 1; s >= 0; s--) { @@ -104,10 +101,10 @@ export class NodeService { */ closeNode() { let currentNode = null; - currentNode = this.DataService.getCurrentNode(); + currentNode = this.dataService.getCurrentNode(); if (currentNode) { let currentNodeId = currentNode.id; - let parentNode = this.ProjectService.getParentGroup(currentNodeId); + let parentNode = this.projectService.getParentGroup(currentNodeId); let parentNodeId = parentNode.id; this.setCurrentNode(parentNodeId); } @@ -121,11 +118,11 @@ export class NodeService { * @returns a promise that will return a transition */ protected chooseTransition(nodeId: string, transitionLogic: TransitionLogic): Promise { - if (this.ConfigService.isPreview() && this.chooseTransitionPromises[nodeId] != null) { + if (this.configService.isPreview() && this.chooseTransitionPromises[nodeId] != null) { return this.chooseTransitionPromises[nodeId]; } const promise = this.getChooseTransitionPromise(nodeId, transitionLogic); - if (this.ConfigService.isPreview()) { + if (this.configService.isPreview()) { const availableTransitions = this.getAvailableTransitions(transitionLogic.transitions); const transitionResult = this.transitionResults[nodeId]; if (availableTransitions.length > 1 && transitionResult == null) { @@ -154,7 +151,7 @@ export class NodeService { } else if (availableTransitions.length == 1) { transitionResult = availableTransitions[0]; } else if (availableTransitions.length > 1) { - if (this.ConfigService.isPreview()) { + if (this.configService.isPreview()) { // we are in preview mode so we will let the user choose the branch path to go to if (transitionResult != null) { /* @@ -197,7 +194,7 @@ export class NodeService { const toNodeId = availableTransition.to; const path = { nodeId: toNodeId, - nodeTitle: this.ProjectService.getNodePositionAndTitle(toNodeId), + nodeTitle: this.projectService.getNodePositionAndTitle(toNodeId), transition: availableTransition }; paths.push(path); @@ -220,7 +217,7 @@ export class NodeService { const randomIndex = Math.floor(Math.random() * availableTransitions.length); transitionResult = availableTransitions[randomIndex]; } else if (howToChooseAmongAvailablePaths === 'workgroupId') { - const index = this.ConfigService.getWorkgroupId() % availableTransitions.length; + const index = this.configService.getWorkgroupId() % availableTransitions.length; transitionResult = availableTransitions[index]; } else if (howToChooseAmongAvailablePaths === 'firstAvailable') { transitionResult = availableTransitions[0]; @@ -235,35 +232,24 @@ export class NodeService { * path taken event if necessary. */ evaluateTransitionLogic(): void { - const currentNode = this.ProjectService.getNode(this.DataService.getCurrentNodeId()); + const currentNode = this.projectService.getNode(this.dataService.getCurrentNodeId()); const transitionLogic = currentNode.getTransitionLogic(); - const branchEvents = this.DataService.getBranchPathTakenEventsByNodeId(currentNode.id); + const branchEvents = this.dataService.getBranchPathTakenEventsByNodeId(currentNode.id); const alreadyBranched = branchEvents.length > 0; if ((alreadyBranched && transitionLogic.canChangePath) || !alreadyBranched) { this.chooseTransition(currentNode.id, transitionLogic).then((transition) => { if (transition != null) { - this.createBranchPathTakenEvent(currentNode.id, transition.to); + this.saveBranchPathTakenEvent(currentNode.id, transition.to); } }); } } - /** - * Create a branchPathTaken event - * @param fromNodeId the from node id - * @param toNodeid the to node id - */ - createBranchPathTakenEvent(fromNodeId, toNodeId) { - const nodeId = fromNodeId; - const componentId = null; - const componentType = null; - const category = 'Navigation'; - const event = 'branchPathTaken'; - const eventData = { + private saveBranchPathTakenEvent(fromNodeId: string, toNodeId: string): void { + this.dataService.saveVLEEvent(fromNodeId, null, null, 'Navigation', 'branchPathTaken', { fromNodeId: fromNodeId, toNodeId: toNodeId - }; - this.DataService.saveVLEEvent(nodeId, componentId, componentType, category, event, eventData); + }); } broadcastNodeSubmitClicked(args: any) { diff --git a/src/assets/wise5/services/studentNodeService.ts b/src/assets/wise5/services/studentNodeService.ts index a1fb612909..585efdaaa5 100644 --- a/src/assets/wise5/services/studentNodeService.ts +++ b/src/assets/wise5/services/studentNodeService.ts @@ -80,10 +80,10 @@ export class StudentNodeService extends NodeService { */ getNextNodeId(currentId?: string): Promise { return new Promise((resolve, reject) => { - const currentNodeId = currentId ?? this.DataService.getCurrentNodeId(); - const transitionLogic = this.ProjectService.getNode(currentNodeId).getTransitionLogic(); + const currentNodeId = currentId ?? this.dataService.getCurrentNodeId(); + const transitionLogic = this.projectService.getNode(currentNodeId).getTransitionLogic(); const branchPathTakenEvents = - this.DataService.getBranchPathTakenEventsByNodeId(currentNodeId); + this.dataService.getBranchPathTakenEventsByNodeId(currentNodeId); if (this.hasPreviouslyBranchedAndCannotChange(branchPathTakenEvents, transitionLogic)) { resolve(branchPathTakenEvents.at(-1).data.toNodeId); } else { @@ -100,7 +100,7 @@ export class StudentNodeService extends NodeService { } private resolveNextNodeIdFromTransition(resolve: any, currentNodeId: string): void { - const transitionLogic = this.ProjectService.getNode(currentNodeId).getTransitionLogic(); + const transitionLogic = this.projectService.getNode(currentNodeId).getTransitionLogic(); if (transitionLogic.transitions.length == 0) { this.getNextNodeIdFromParent(resolve, currentNodeId); } else { @@ -111,13 +111,13 @@ export class StudentNodeService extends NodeService { } private getNextNodeIdFromParent(resolve: any, currentNodeId: string): void { - const parentGroupId = this.ProjectService.getParentGroupId(currentNodeId); + const parentGroupId = this.projectService.getParentGroupId(currentNodeId); if (parentGroupId != null) { - const parentTransitionLogic = this.ProjectService.getNode(parentGroupId).getTransitionLogic(); + const parentTransitionLogic = this.projectService.getNode(parentGroupId).getTransitionLogic(); this.chooseTransition(parentGroupId, parentTransitionLogic).then((transition: any) => { const transitionToNodeId = transition.to; - const startId = this.ProjectService.isGroupNode(transitionToNodeId) - ? this.ProjectService.getGroupStartId(transitionToNodeId) + const startId = this.projectService.isGroupNode(transitionToNodeId) + ? this.projectService.getGroupStartId(transitionToNodeId) : null; resolve(startId == null || startId === '' ? transitionToNodeId : startId); }); diff --git a/src/assets/wise5/services/teacherNodeService.ts b/src/assets/wise5/services/teacherNodeService.ts index 202b9c4017..ad28a97fad 100644 --- a/src/assets/wise5/services/teacherNodeService.ts +++ b/src/assets/wise5/services/teacherNodeService.ts @@ -5,7 +5,8 @@ import { Subject, Observable } from 'rxjs'; @Injectable() export class TeacherNodeService extends NodeService { private componentShowSubmitButtonValueChangedSource: Subject = new Subject(); - public componentShowSubmitButtonValueChanged$: Observable = this.componentShowSubmitButtonValueChangedSource.asObservable(); + public componentShowSubmitButtonValueChanged$: Observable = + this.componentShowSubmitButtonValueChangedSource.asObservable(); private deleteStarterStateSource: Subject = new Subject(); public deleteStarterState$: Observable = this.deleteStarterStateSource.asObservable(); private starterStateResponseSource: Subject = new Subject(); @@ -26,12 +27,12 @@ export class TeacherNodeService extends NodeService { getNextNodeId(currentId?: string): Promise { return new Promise((resolve, reject) => { let nextNodeId = null; - const currentNodeId = currentId ?? this.DataService.getCurrentNodeId(); - const currentNodeOrder = this.ProjectService.getNodeOrderById(currentNodeId); + const currentNodeId = currentId ?? this.dataService.getCurrentNodeId(); + const currentNodeOrder = this.projectService.getNodeOrderById(currentNodeId); if (currentNodeOrder) { - const nextId = this.ProjectService.getNodeIdByOrder(currentNodeOrder + 1); + const nextId = this.projectService.getNodeIdByOrder(currentNodeOrder + 1); if (nextId) { - nextNodeId = this.ProjectService.isApplicationNode(nextId) + nextNodeId = this.projectService.isApplicationNode(nextId) ? nextId : this.getNextNodeId(nextId); }