From 256048837443d8069e77832e203eb901ca357d18 Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Thu, 22 Aug 2024 15:21:14 -0700 Subject: [PATCH] refactor(TeacherProjectService): Extract RemoveNodeIdFromTransitionsService (#1914) --- src/app/services/deleteNodeService.spec.ts | 14 +- src/app/services/moveNodesService.spec.ts | 13 +- src/app/services/projectService.spec.ts | 7 +- ...removeNodeIdFromTransitionsService.spec.ts | 38 ++ .../services/teacherProjectService.spec.ts | 14 +- src/app/teacher/teacher-authoring.module.ts | 2 + ...hoose-move-node-location.component.spec.ts | 17 +- ...project-authoring-lesson.component.spec.ts | 2 + .../project-authoring-step.component.spec.ts | 2 + .../project-authoring.component.spec.ts | 2 + .../wise5/services/deleteNodeService.ts | 10 +- src/assets/wise5/services/moveNodesService.ts | 18 +- .../removeNodeIdFromTransitionsService.ts | 482 ++++++++++++++++++ .../wise5/services/teacherProjectService.ts | 467 ----------------- src/messages.xlf | 14 +- 15 files changed, 591 insertions(+), 511 deletions(-) create mode 100644 src/app/services/removeNodeIdFromTransitionsService.spec.ts create mode 100644 src/assets/wise5/services/removeNodeIdFromTransitionsService.ts diff --git a/src/app/services/deleteNodeService.spec.ts b/src/app/services/deleteNodeService.spec.ts index 6f10895ce0..d909556ad0 100644 --- a/src/app/services/deleteNodeService.spec.ts +++ b/src/app/services/deleteNodeService.spec.ts @@ -7,6 +7,7 @@ import { TeacherProjectService } from '../../assets/wise5/services/teacherProjec import { StudentTeacherCommonServicesModule } from '../student-teacher-common-services.module'; import demoProjectJSON_import from './sampleData/curriculum/Demo.project.json'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { RemoveNodeIdFromTransitionsService } from '../../assets/wise5/services/removeNodeIdFromTransitionsService'; let demoProjectJSON: any; let projectService: TeacherProjectService; @@ -15,9 +16,16 @@ let service: DeleteNodeService; describe('DeleteNodeService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [StudentTeacherCommonServicesModule], - providers: [CopyNodesService, DeleteNodeService, TeacherProjectService, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()] -}); + imports: [StudentTeacherCommonServicesModule], + providers: [ + CopyNodesService, + DeleteNodeService, + RemoveNodeIdFromTransitionsService, + TeacherProjectService, + provideHttpClient(withInterceptorsFromDi()), + provideHttpClientTesting() + ] + }); demoProjectJSON = copy(demoProjectJSON_import); projectService = TestBed.inject(TeacherProjectService); service = TestBed.inject(DeleteNodeService); diff --git a/src/app/services/moveNodesService.spec.ts b/src/app/services/moveNodesService.spec.ts index fa95179530..9bd945c202 100644 --- a/src/app/services/moveNodesService.spec.ts +++ b/src/app/services/moveNodesService.spec.ts @@ -3,6 +3,7 @@ import { MoveNodesService } from '../../assets/wise5/services/moveNodesService'; import { copy } from '../../assets/wise5/common/object/object'; import demoProjectJSON_import from './sampleData/curriculum/Demo.project.json'; import { TeacherProjectService } from '../../assets/wise5/services/teacherProjectService'; +import { RemoveNodeIdFromTransitionsService } from '../../assets/wise5/services/removeNodeIdFromTransitionsService'; import { StudentTeacherCommonServicesModule } from '../student-teacher-common-services.module'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; @@ -16,9 +17,15 @@ let teacherProjectService: TeacherProjectService; describe('MoveNodesService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [StudentTeacherCommonServicesModule], - providers: [MoveNodesService, TeacherProjectService, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()] -}); + imports: [StudentTeacherCommonServicesModule], + providers: [ + MoveNodesService, + RemoveNodeIdFromTransitionsService, + TeacherProjectService, + provideHttpClient(withInterceptorsFromDi()), + provideHttpClientTesting() + ] + }); service = TestBed.inject(MoveNodesService); demoProjectJSON = copy(demoProjectJSON_import); teacherProjectService = TestBed.inject(TeacherProjectService); diff --git a/src/app/services/projectService.spec.ts b/src/app/services/projectService.spec.ts index 50dc674b02..9083c3302b 100644 --- a/src/app/services/projectService.spec.ts +++ b/src/app/services/projectService.spec.ts @@ -31,9 +31,9 @@ let twoLessonsProjectJSON: any; describe('ProjectService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [StudentTeacherCommonServicesModule], - providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()] -}); + imports: [StudentTeacherCommonServicesModule], + providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()] + }); http = TestBed.inject(HttpTestingController); configService = TestBed.inject(ConfigService); service = TestBed.inject(ProjectService); @@ -89,7 +89,6 @@ describe('ProjectService', () => { // MARK: Tests for Node and Group Id functions // TODO: add test for service.getNodePositionAndTitle() // TODO: add test for service.deconsteNode() - // TODO: add test for service.removeNodeIdFromTransitions() // TODO: add test for service.removeNodeIdFromGroups() // TODO: add test for service.createComponent() // TODO: add test for service.addComponentToNode() diff --git a/src/app/services/removeNodeIdFromTransitionsService.spec.ts b/src/app/services/removeNodeIdFromTransitionsService.spec.ts new file mode 100644 index 0000000000..3557166a30 --- /dev/null +++ b/src/app/services/removeNodeIdFromTransitionsService.spec.ts @@ -0,0 +1,38 @@ +import { TestBed } from '@angular/core/testing'; +import { StudentTeacherCommonServicesModule } from '../student-teacher-common-services.module'; +import { TeacherProjectService } from '../../assets/wise5/services/teacherProjectService'; +import { RemoveNodeIdFromTransitionsService } from '../../assets/wise5/services/removeNodeIdFromTransitionsService'; +import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import demoProjectJSON_import from './sampleData/curriculum/Demo.project.json'; +import { copy } from '../../assets/wise5/common/object/object'; + +let demoProjectJSON: any; +let projectService: TeacherProjectService; +let service: RemoveNodeIdFromTransitionsService; +describe('RemoveNodeIdFromTransitionsService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [StudentTeacherCommonServicesModule], + providers: [ + RemoveNodeIdFromTransitionsService, + TeacherProjectService, + provideHttpClient(withInterceptorsFromDi()) + ] + }); + demoProjectJSON = copy(demoProjectJSON_import); + projectService = TestBed.inject(TeacherProjectService); + service = TestBed.inject(RemoveNodeIdFromTransitionsService); + }); + shouldRemoveTransitionsGoingOutOfGroupInChildNodesOfGroup(); +}); + +function shouldRemoveTransitionsGoingOutOfGroupInChildNodesOfGroup() { + it('should remove transitions going out of group in child nodes of group', () => { + projectService.setProject(demoProjectJSON); + expect(projectService.getTransitionsByFromNodeId('node18').length).toEqual(1); + expect(projectService.getTransitionsByFromNodeId('node19').length).toEqual(1); + service.removeTransitionsOutOfGroup('group1'); + expect(projectService.getTransitionsByFromNodeId('node18').length).toEqual(1); + expect(projectService.getTransitionsByFromNodeId('node19').length).toEqual(0); + }); +} diff --git a/src/app/services/teacherProjectService.spec.ts b/src/app/services/teacherProjectService.spec.ts index 05b233f218..5290c7d72d 100644 --- a/src/app/services/teacherProjectService.spec.ts +++ b/src/app/services/teacherProjectService.spec.ts @@ -9,6 +9,7 @@ import { StudentTeacherCommonServicesModule } from '../student-teacher-common-se import { copy } from '../../assets/wise5/common/object/object'; import { DeleteNodeService } from '../../assets/wise5/services/deleteNodeService'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { RemoveNodeIdFromTransitionsService } from '../../assets/wise5/services/removeNodeIdFromTransitionsService'; let service: TeacherProjectService; let configService: ConfigService; let deleteNodeService: DeleteNodeService; @@ -31,6 +32,7 @@ describe('TeacherProjectService', () => { imports: [StudentTeacherCommonServicesModule], providers: [ DeleteNodeService, + RemoveNodeIdFromTransitionsService, TeacherProjectService, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting() @@ -62,7 +64,6 @@ describe('TeacherProjectService', () => { shouldNotAddSpaceIfItDoesExist(); shouldAddSpaceIfItDoesntExist(); shouldRemoveSpaces(); - shouldRemoveTransitionsGoingOutOfGroupInChildNodesOfGroup(); removeNodeFromGroup(); insertNodeAfterInTransitions(); shouldNotBeAbleToInsertANodeAfterAnotherNodeWhenTheyAreDifferentTypes(); @@ -315,17 +316,6 @@ function shouldRemoveSpaces() { }); } -function shouldRemoveTransitionsGoingOutOfGroupInChildNodesOfGroup() { - it('should remove transitions going out of group in child nodes of group', () => { - service.setProject(demoProjectJSON); - expect(service.getTransitionsByFromNodeId('node18').length).toEqual(1); - expect(service.getTransitionsByFromNodeId('node19').length).toEqual(1); - service.removeTransitionsOutOfGroup('group1'); - expect(service.getTransitionsByFromNodeId('node18').length).toEqual(1); - expect(service.getTransitionsByFromNodeId('node19').length).toEqual(0); - }); -} - function expectChildNodeIdLength(nodeId, expectedLength) { expect(service.getChildNodeIdsById(nodeId).length).toEqual(expectedLength); } diff --git a/src/app/teacher/teacher-authoring.module.ts b/src/app/teacher/teacher-authoring.module.ts index 6c9506626f..3e2f3692ff 100644 --- a/src/app/teacher/teacher-authoring.module.ts +++ b/src/app/teacher/teacher-authoring.module.ts @@ -36,6 +36,7 @@ import { TeacherProjectTranslationService } from '../../assets/wise5/services/te import { DeleteTranslationsService } from '../../assets/wise5/services/deleteTranslationsService'; import { CopyTranslationsService } from '../../assets/wise5/services/copyTranslationsService'; import { NotifyAuthorService } from '../../assets/wise5/services/notifyAuthorService'; +import { RemoveNodeIdFromTransitionsService } from '../../assets/wise5/services/removeNodeIdFromTransitionsService'; @NgModule({ imports: [StudentTeacherCommonModule, AuthoringToolModule, RouterModule, AuthoringRoutingModule], @@ -63,6 +64,7 @@ import { NotifyAuthorService } from '../../assets/wise5/services/notifyAuthorSer DeleteTranslationsService, { provide: PeerGroupService, useExisting: TeacherPeerGroupService }, { provide: ProjectService, useExisting: TeacherProjectService }, + RemoveNodeIdFromTransitionsService, TeacherDataService, TeacherDiscussionService, TeacherNodeService, diff --git a/src/assets/wise5/authoringTool/choose-node-location/choose-move-node-location/choose-move-node-location.component.spec.ts b/src/assets/wise5/authoringTool/choose-node-location/choose-move-node-location/choose-move-node-location.component.spec.ts index a460f0c07c..fb21ab6f2e 100644 --- a/src/assets/wise5/authoringTool/choose-node-location/choose-move-node-location/choose-move-node-location.component.spec.ts +++ b/src/assets/wise5/authoringTool/choose-node-location/choose-move-node-location/choose-move-node-location.component.spec.ts @@ -6,6 +6,7 @@ import { provideHttpClientTesting } from '@angular/common/http/testing'; import { StudentTeacherCommonServicesModule } from '../../../../../app/student-teacher-common-services.module'; import { MoveNodesService } from '../../../services/moveNodesService'; import { TeacherProjectService } from '../../../services/teacherProjectService'; +import { RemoveNodeIdFromTransitionsService } from '../../../services/removeNodeIdFromTransitionsService'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; let component: ChooseMoveNodeLocationComponent; @@ -13,11 +14,17 @@ let fixture: ComponentFixture; describe('ChooseMoveNodeLocationComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ChooseMoveNodeLocationComponent], - schemas: [NO_ERRORS_SCHEMA], - imports: [RouterTestingModule, StudentTeacherCommonServicesModule], - providers: [MoveNodesService, TeacherProjectService, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()] -}); + declarations: [ChooseMoveNodeLocationComponent], + schemas: [NO_ERRORS_SCHEMA], + imports: [RouterTestingModule, StudentTeacherCommonServicesModule], + providers: [ + MoveNodesService, + RemoveNodeIdFromTransitionsService, + TeacherProjectService, + provideHttpClient(withInterceptorsFromDi()), + provideHttpClientTesting() + ] + }); window.history.pushState( { selectedNodeIds: ['node1'] diff --git a/src/assets/wise5/authoringTool/project-authoring-lesson/project-authoring-lesson.component.spec.ts b/src/assets/wise5/authoringTool/project-authoring-lesson/project-authoring-lesson.component.spec.ts index 9f15eb3e0e..82017cd1f0 100644 --- a/src/assets/wise5/authoringTool/project-authoring-lesson/project-authoring-lesson.component.spec.ts +++ b/src/assets/wise5/authoringTool/project-authoring-lesson/project-authoring-lesson.component.spec.ts @@ -22,6 +22,7 @@ import { DeleteTranslationsService } from '../../services/deleteTranslationsServ import { provideRouter } from '@angular/router'; import { CopyTranslationsService } from '../../services/copyTranslationsService'; import { TeacherProjectTranslationService } from '../../services/teacherProjectTranslationService'; +import { RemoveNodeIdFromTransitionsService } from '../../services/removeNodeIdFromTransitionsService'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; let component: ProjectAuthoringLessonComponent; @@ -56,6 +57,7 @@ describe('ProjectAuthoringLessonComponent', () => { DeleteNodeService, DeleteTranslationsService, provideRouter([]), + RemoveNodeIdFromTransitionsService, TeacherDataService, TeacherProjectService, TeacherProjectTranslationService, diff --git a/src/assets/wise5/authoringTool/project-authoring-step/project-authoring-step.component.spec.ts b/src/assets/wise5/authoringTool/project-authoring-step/project-authoring-step.component.spec.ts index dd5b7f3250..5c02d242bd 100644 --- a/src/assets/wise5/authoringTool/project-authoring-step/project-authoring-step.component.spec.ts +++ b/src/assets/wise5/authoringTool/project-authoring-step/project-authoring-step.component.spec.ts @@ -17,6 +17,7 @@ import { DeleteTranslationsService } from '../../services/deleteTranslationsServ import { provideRouter } from '@angular/router'; import { CopyTranslationsService } from '../../services/copyTranslationsService'; import { TeacherProjectTranslationService } from '../../services/teacherProjectTranslationService'; +import { RemoveNodeIdFromTransitionsService } from '../../services/removeNodeIdFromTransitionsService'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; const nodeId1 = 'nodeId1'; @@ -44,6 +45,7 @@ describe('ProjectAuthoringStepComponent', () => { DeleteNodeService, DeleteTranslationsService, provideRouter([]), + RemoveNodeIdFromTransitionsService, TeacherDataService, TeacherProjectService, TeacherProjectTranslationService, diff --git a/src/assets/wise5/authoringTool/project-authoring/project-authoring.component.spec.ts b/src/assets/wise5/authoringTool/project-authoring/project-authoring.component.spec.ts index 0c38db0e49..d838e6f532 100644 --- a/src/assets/wise5/authoringTool/project-authoring/project-authoring.component.spec.ts +++ b/src/assets/wise5/authoringTool/project-authoring/project-authoring.component.spec.ts @@ -38,6 +38,7 @@ import { AddStepButtonComponent } from '../add-step-button/add-step-button.compo import { DeleteTranslationsService } from '../../services/deleteTranslationsService'; import { CopyTranslationsService } from '../../services/copyTranslationsService'; import { TeacherProjectTranslationService } from '../../services/teacherProjectTranslationService'; +import { RemoveNodeIdFromTransitionsService } from '../../services/removeNodeIdFromTransitionsService'; let configService: ConfigService; let component: ProjectAuthoringComponent; @@ -83,6 +84,7 @@ describe('ProjectAuthoringComponent', () => { DeleteTranslationsService, MoveNodesService, provideRouter([]), + RemoveNodeIdFromTransitionsService, TeacherDataService, TeacherProjectService, TeacherProjectTranslationService, diff --git a/src/assets/wise5/services/deleteNodeService.ts b/src/assets/wise5/services/deleteNodeService.ts index f45df5bdd5..301d27eaa0 100644 --- a/src/assets/wise5/services/deleteNodeService.ts +++ b/src/assets/wise5/services/deleteNodeService.ts @@ -1,9 +1,13 @@ import { Injectable } from '@angular/core'; import { TeacherProjectService } from './teacherProjectService'; +import { RemoveNodeIdFromTransitionsService } from './removeNodeIdFromTransitionsService'; @Injectable() export class DeleteNodeService { - constructor(protected ProjectService: TeacherProjectService) {} + constructor( + protected ProjectService: TeacherProjectService, + private removeNodeIdFromTransitionsService: RemoveNodeIdFromTransitionsService + ) {} /** * Delete a node from the project and update transitions. @@ -23,7 +27,7 @@ export class DeleteNodeService { if (this.ProjectService.isGroupNode(nodeId)) { this.removeChildNodes(nodeId); } - this.ProjectService.removeNodeIdFromTransitions(nodeId); + this.removeNodeIdFromTransitionsService.remove(nodeId); this.ProjectService.removeNodeIdFromGroups(nodeId); this.removeNodeIdFromNodes(nodeId); } @@ -117,7 +121,7 @@ export class DeleteNodeService { const group = this.ProjectService.getNodeById(groupId); for (let i = 0; i < group.ids.length; i++) { const childId = group.ids[i]; - this.ProjectService.removeNodeIdFromTransitions(childId); + this.removeNodeIdFromTransitionsService.remove(childId); this.ProjectService.removeNodeIdFromGroups(childId); this.removeNodeIdFromNodes(childId); i--; // so it won't skip the next element diff --git a/src/assets/wise5/services/moveNodesService.ts b/src/assets/wise5/services/moveNodesService.ts index e77d43be9e..9889805676 100644 --- a/src/assets/wise5/services/moveNodesService.ts +++ b/src/assets/wise5/services/moveNodesService.ts @@ -1,9 +1,13 @@ import { Injectable } from '@angular/core'; import { TeacherProjectService } from './teacherProjectService'; +import { RemoveNodeIdFromTransitionsService } from './removeNodeIdFromTransitionsService'; @Injectable() export class MoveNodesService { - constructor(protected projectService: TeacherProjectService) {} + constructor( + protected projectService: TeacherProjectService, + private removeNodeIdFromTransitionsService: RemoveNodeIdFromTransitionsService + ) {} /** * Move nodes inside an active/inactive group node @@ -20,7 +24,7 @@ export class MoveNodesService { const stationaryNodeIsActive = this.projectService.isActive(groupNodeId); if (movingNodeIsActive && stationaryNodeIsActive) { - this.projectService.removeNodeIdFromTransitions(nodeId); + this.removeNodeIdFromTransitionsService.remove(nodeId); this.projectService.removeNodeIdFromGroups(nodeId); if (n == 0) { @@ -31,7 +35,7 @@ export class MoveNodesService { this.projectService.insertNodeAfterInGroups(nodeId, groupNodeId); } } else if (movingNodeIsActive && !stationaryNodeIsActive) { - this.projectService.removeNodeIdFromTransitions(nodeId); + this.removeNodeIdFromTransitionsService.remove(nodeId); this.projectService.removeNodeIdFromGroups(nodeId); if (n == 0) { @@ -50,7 +54,7 @@ export class MoveNodesService { this.projectService.insertNodeAfterInGroups(nodeId, groupNodeId); } } else if (!movingNodeIsActive && !stationaryNodeIsActive) { - this.projectService.removeNodeIdFromTransitions(nodeId); + this.removeNodeIdFromTransitionsService.remove(nodeId); this.projectService.removeNodeIdFromGroups(nodeId); if (n == 0) { @@ -172,12 +176,12 @@ export class MoveNodesService { const movingNodeIsActive = this.projectService.isActive(nodeId); const stationaryNodeIsActive = this.projectService.isActive(moveAfterNodeId); if (movingNodeIsActive && stationaryNodeIsActive) { - this.projectService.removeNodeIdFromTransitions(nodeId); + this.removeNodeIdFromTransitionsService.remove(nodeId); this.projectService.removeNodeIdFromGroups(nodeId); this.projectService.insertNodeAfterInGroups(nodeId, moveAfterNodeId); this.projectService.insertNodeAfterInTransitions(node, moveAfterNodeId); } else if (movingNodeIsActive && !stationaryNodeIsActive) { - this.projectService.removeNodeIdFromTransitions(nodeId); + this.removeNodeIdFromTransitionsService.remove(nodeId); this.projectService.removeNodeIdFromGroups(nodeId); this.moveToInactive(node, moveAfterNodeId); } else if (!movingNodeIsActive && stationaryNodeIsActive) { @@ -185,7 +189,7 @@ export class MoveNodesService { this.projectService.insertNodeAfterInGroups(nodeId, moveAfterNodeId); this.projectService.insertNodeAfterInTransitions(node, moveAfterNodeId); } else if (!movingNodeIsActive && !stationaryNodeIsActive) { - this.projectService.removeNodeIdFromTransitions(nodeId); + this.removeNodeIdFromTransitionsService.remove(nodeId); this.projectService.removeNodeIdFromGroups(nodeId); this.moveInactiveNodeToInactiveSection(node, moveAfterNodeId); } diff --git a/src/assets/wise5/services/removeNodeIdFromTransitionsService.ts b/src/assets/wise5/services/removeNodeIdFromTransitionsService.ts new file mode 100644 index 0000000000..dcb7c36928 --- /dev/null +++ b/src/assets/wise5/services/removeNodeIdFromTransitionsService.ts @@ -0,0 +1,482 @@ +import { Injectable } from '@angular/core'; +import { TeacherProjectService } from './teacherProjectService'; +import { copy } from '../common/object/object'; + +@Injectable() +export class RemoveNodeIdFromTransitionsService { + constructor(private projectService: TeacherProjectService) {} + + /** + * Update the transitions to handle removing a node + * @param nodeId the node id to remove + */ + remove(nodeId: string): void { + const nodeToRemove = this.projectService.getNodeById(nodeId); + const nodesByToNodeId = this.projectService.getNodesByToNodeId(nodeId); + + const nodeToRemoveTransitionLogic = nodeToRemove.transitionLogic; + let nodeToRemoveTransitions = []; + + if (nodeToRemoveTransitionLogic != null && nodeToRemoveTransitionLogic.transitions != null) { + nodeToRemoveTransitions = nodeToRemoveTransitionLogic.transitions; + } + + const parentIdOfNodeToRemove = this.projectService.getParentGroupId(nodeId); + this.updateParentGroupStartId(nodeId); + + for (let n = 0; n < nodesByToNodeId.length; n++) { + const node = nodesByToNodeId[n]; + if (node != null) { + const parentIdOfFromNode = this.projectService.getParentGroupId(node.id); + const transitionLogic = node.transitionLogic; + + if (transitionLogic != null) { + const transitions = transitionLogic.transitions; + for (let t = 0; t < transitions.length; t++) { + const transition = transitions[t]; + if (nodeId === transition.to) { + // we have found the transition to the node we are removing + + // copy the transitions from the node we are removing + let transitionsCopy = copy(nodeToRemoveTransitions); + + /* + * if the parent from group is different than the parent removing group + * remove transitions that are to a node in a different group than + * the parent removing group + */ + + if (parentIdOfFromNode != parentIdOfNodeToRemove) { + for (let tc = 0; tc < transitionsCopy.length; tc++) { + const tempTransition = transitionsCopy[tc]; + if (tempTransition != null) { + const tempToNodeId = tempTransition.to; + if (tempToNodeId != null) { + const parentIdOfToNode = this.projectService.getParentGroupId(tempToNodeId); + if (parentIdOfNodeToRemove != parentIdOfToNode) { + // remove the transition + transitionsCopy.splice(tc, 1); + tc--; + } + } + } + } + } + + if (this.isFirstNodeInBranchPath(nodeId)) { + /* + * Get the node ids that have a branchPathTaken + * constraint from the before node and to the node + * we are removing. If there are any, we need to + * update the branchPathTaken constraint with the + * next nodeId that comes after the node we are + * removing. + */ + const nodeIdsInBranch = this.projectService.getNodeIdsInBranch(node.id, nodeId); + + if (nodeIdsInBranch != null) { + for (let nodeIdInBranch of nodeIdsInBranch) { + const nodeInBranch = this.projectService.getNodeById(nodeIdInBranch); + for (let transitionCopy of transitionsCopy) { + if (transitionCopy != null) { + const currentFromNodeId = node.id; + const currentToNodeId = nodeId; + const newFromNodeId = node.id; + const newToNodeId = transitionCopy.to; + + /* + * change the branch path taken constraint by changing + * the toNodeId + */ + this.updateBranchPathTakenConstraint( + nodeInBranch, + currentFromNodeId, + currentToNodeId, + newFromNodeId, + newToNodeId + ); + } + } + } + } + } else if (this.projectService.isBranchPoint(nodeId)) { + /* + * get all the branches that have the node we + * are removing as the start point + */ + const branches = this.projectService.getBranchesByBranchStartPointNodeId(nodeId); + + for (let branch of branches) { + if (branch != null) { + /* + * get the branch paths. these paths do not + * contain the start point or merge point. + */ + const branchPaths = branch.paths; + + if (branchPaths != null) { + for (let branchPath of branchPaths) { + if (branchPath != null) { + const currentFromNodeId = nodeId; + const currentToNodeId = branchPath[0]; + const newFromNodeId = node.id; + const newToNodeId = branchPath[0]; + for (let branchPathNodeId of branchPath) { + const branchPathNode = + this.projectService.getNodeById(branchPathNodeId); + this.updateBranchPathTakenConstraint( + branchPathNode, + currentFromNodeId, + currentToNodeId, + newFromNodeId, + newToNodeId + ); + } + } + } + } + } + } + } + + // remove the transition to the node we are removing + const transitionRemoved = transitions.splice(t, 1)[0]; + + if (transitionsCopy != null) { + let insertIndex = t; + + /* + * loop through all the transitions from the node we are removing + * and insert them into the transitions of the from node + * e.g. + * the node that comes before the node we are removing has these transitions + * "transitions": [ + * { + * "to": "node4" + * }, + * { + * "to": "node6" + * } + * ] + * + * we are removing node4. node4 has a transition to node5. + * + * the node that comes before the node we are removing now has these transitions + * "transitions": [ + * { + * "to": "node5" + * }, + * { + * "to": "node6" + * } + * ] + */ + for (let transitionCopy of transitionsCopy) { + if (!this.isTransitionExist(transitions, transitionCopy)) { + const toNodeId = transitionCopy.to; + if ( + this.projectService.isApplicationNode(node.id) && + this.projectService.isGroupNode(toNodeId) && + this.hasGroupStartId(toNodeId) + ) { + this.projectService.addToTransition( + node, + this.projectService.getGroupStartId(toNodeId) + ); + } else { + if (transitionRemoved.criteria != null) { + transitionCopy.criteria = transitionRemoved.criteria; + } + transitions.splice(insertIndex, 0, transitionCopy); + insertIndex++; + } + } + } + } + t--; + + // check if the node we are moving is a group + if (this.projectService.isGroupNode(nodeId)) { + /* + * we are moving a group so we need to update transitions that + * go into the group + */ + const groupIdWeAreMoving = nodeId; + const groupThatTransitionsToGroupWeAreMoving = node; + this.updateChildrenTransitionsIntoGroupWeAreMoving( + groupThatTransitionsToGroupWeAreMoving, + groupIdWeAreMoving + ); + } + } + } + + if ( + transitions.length === 0 && + parentIdOfNodeToRemove != 'group0' && + parentIdOfNodeToRemove != this.projectService.getParentGroupId(node.id) + ) { + /* + * the from node no longer has any transitions so we will make it transition to the + * parent of the node we are removing + */ + this.projectService.addToTransition(node, parentIdOfNodeToRemove); + } + + if (this.projectService.isBranchPoint(nodeId)) { + /* + * the node we are deleting is a branch point so we to + * copy the transition logic to the node that comes + * before it + */ + node.transitionLogic = copy(nodeToRemoveTransitionLogic); + + /* + * set the transitions for the node that comes before + * the one we are removing + */ + node.transitionLogic.transitions = transitions; + } + } + } + } + + if (nodeToRemoveTransitionLogic != null) { + nodeToRemoveTransitionLogic.transitions = []; + } + + if (this.projectService.isGroupNode(nodeId)) { + this.removeTransitionsOutOfGroup(nodeId); + } + } + + /** + * Update the parent group start id if the node we are removing is the start id + * @param nodeId The node we are removing + */ + private updateParentGroupStartId(nodeId: string): void { + const parentGroup = this.projectService.getParentGroup(nodeId); + if (parentGroup != null && parentGroup.startId === nodeId) { + const transitions = this.projectService.getTransitionsFromNode( + this.projectService.getNodeById(nodeId) + ); + if (transitions.length > 0) { + for (const transition of transitions) { + const toNodeId = transition.to; + // Make sure the to node id is in the same group because a step can transition to a step + // in a different group. If the to node id is in a different group, we would not want to + // use it as the start id of this group. + if (this.projectService.getParentGroupId(toNodeId) === parentGroup.id) { + parentGroup.startId = toNodeId; + } + } + } else { + parentGroup.startId = ''; + } + } + } + + /** + * Check if a node is the first node in a branch path + * @param nodeId the node id + * @return whether the node is the first node in a branch path + */ + private isFirstNodeInBranchPath(nodeId: string): boolean { + for (const node of this.projectService.getNodes()) { + if (node.transitionLogic?.transitions?.length > 1) { + for (const transition of node.transitionLogic.transitions) { + if (transition.to === nodeId) { + return true; + } + } + } + } + return false; + } + + /** + * Update a node's branchPathTaken constraint's fromNodeId and toNodeId + * @param node update the branch path taken constraints in this node + * @param currentFromNodeId the current from node id + * @param currentToNodeId the current to node id + * @param newFromNodeId the new from node id + * @param newToNodeId the new to node id + */ + private updateBranchPathTakenConstraint( + node: any, + currentFromNodeId: string, + currentToNodeId: string, + newFromNodeId: string, + newToNodeId: string + ): void { + for (let constraint of node.constraints) { + for (let removalCriterion of constraint.removalCriteria) { + if (removalCriterion.name === 'branchPathTaken') { + const params = removalCriterion.params; + if (params.fromNodeId === currentFromNodeId && params.toNodeId === currentToNodeId) { + params.fromNodeId = newFromNodeId; + params.toNodeId = newToNodeId; + } + } + } + } + } + + private isTransitionExist(transitions: any[], transition: any): boolean { + for (const tempTransition of transitions) { + if (tempTransition.from === transition.from && tempTransition.to === transition.to) { + return true; + } + } + return false; + } + + private hasGroupStartId(nodeId: string): boolean { + const startId = this.projectService.getGroupStartId(nodeId); + return startId != null && startId != ''; + } + + /* + * Update the step transitions that point into the group we are moving + * For example + * group1 has children node1 and node2 (node2 transitions to node3) + * group2 has children node3 and node4 (node4 transitions to node5) + * group3 has children node5 and node6 + * if we move group2 after group3 we will need to change the + * transition from node2 to node3 and make node2 transition to node5 + * the result will be + * group1 has children node1 and node2 (node2 transitions to node5) + * group3 has children node5 and node6 + * group2 has children node3 and node4 (node4 transitions to node5) + * note: the (node4 transition to node5) will be removed later + * when is called removeTransitionsOutOfGroup + * note: when group2 is added in a later function call, we will add + * the node6 to node3 transition + * @param groupThatTransitionsToGroupWeAreMoving the group object + * that transitions to the group we are moving. we may need to update + * the transitions of this group's children. + * @param groupIdWeAreMoving the group id of the group we are moving + */ + private updateChildrenTransitionsIntoGroupWeAreMoving( + groupThatTransitionsToGroupWeAreMoving: any, + groupIdWeAreMoving: string + ): void { + if (groupThatTransitionsToGroupWeAreMoving != null && groupIdWeAreMoving != null) { + const group = this.projectService.getNodeById(groupIdWeAreMoving); + if (group != null) { + // get all the nodes that have a transition to the node we are removing + const nodesByToNodeId = this.projectService.getNodesByToNodeId(groupIdWeAreMoving); + + // get the transitions of the node we are removing + const nodeToRemoveTransitionLogic = group.transitionLogic; + let nodeToRemoveTransitions = []; + + if ( + nodeToRemoveTransitionLogic != null && + nodeToRemoveTransitionLogic.transitions != null + ) { + nodeToRemoveTransitions = nodeToRemoveTransitionLogic.transitions; + } + + if (nodeToRemoveTransitions.length == 0) { + /* + * The group we are moving is the last group in the project + * and does not have any transitions. We will loop through + * all the nodes that transition into this group and remove + * those transitions. + */ + + // get child ids of the group that comes before the group we are moving + const childIds = groupThatTransitionsToGroupWeAreMoving.ids; + + if (childIds != null) { + for (let childId of childIds) { + const transitionsFromChild = this.projectService.getTransitionsByFromNodeId(childId); + if (transitionsFromChild != null) { + for (let tfc = 0; tfc < transitionsFromChild.length; tfc++) { + const transitionFromChild = transitionsFromChild[tfc]; + if (transitionFromChild != null) { + const toNodeId = transitionFromChild.to; + const toNodeIdParentGroupId = this.projectService.getParentGroupId(toNodeId); + + if (groupIdWeAreMoving === toNodeIdParentGroupId) { + // the transition is to a child in the group we are moving + transitionsFromChild.splice(tfc, 1); + + /* + * move the counter back one because we have just removed an + * element from the array + */ + tfc--; + } + } + } + } + } + } + } else if (nodeToRemoveTransitions.length > 0) { + // get the first group that comes after the group we are removing + const firstNodeToRemoveTransition = nodeToRemoveTransitions[0]; + const firstNodeToRemoveTransitionToNodeId = firstNodeToRemoveTransition.to; + + if (this.projectService.isGroupNode(firstNodeToRemoveTransitionToNodeId)) { + // get the group that comes after the group we are moving + const groupNode = this.projectService.getNodeById(firstNodeToRemoveTransitionToNodeId); + + // get child ids of the group that comes before the group we are moving + const childIds = groupThatTransitionsToGroupWeAreMoving.ids; + + if (childIds != null) { + for (let childId of childIds) { + const transitionsFromChild = + this.projectService.getTransitionsByFromNodeId(childId); + if (transitionsFromChild != null) { + for (let transitionFromChild of transitionsFromChild) { + if (transitionFromChild != null) { + const toNodeId = transitionFromChild.to; + + // get the parent group id of the toNodeId + const toNodeIdParentGroupId = this.projectService.getParentGroupId(toNodeId); + + if (groupIdWeAreMoving === toNodeIdParentGroupId) { + // the transition is to a child in the group we are moving + + if (groupNode.startId == null || groupNode.startId === '') { + // change the transition to point to the after group + transitionFromChild.to = firstNodeToRemoveTransitionToNodeId; + } else { + // change the transition to point to the start id of the after group + transitionFromChild.to = groupNode.startId; + } + } + } + } + } + } + } + } + } + } + } + } + + /** + * Remove transition from nodes in the specified group that go out of the group + * @param nodeId the group id + */ + removeTransitionsOutOfGroup(groupId: string): void { + const group = this.projectService.getNodeById(groupId); + for (const childId of group.ids) { + const transitions = this.projectService.getTransitionsByFromNodeId(childId); + for (let t = 0; t < transitions.length; t++) { + const transition = transitions[t]; + const parentGroupId = this.projectService.getParentGroupId(transition.to); + if (parentGroupId != groupId) { + // this is a transition that goes out of the specified group + transitions.splice(t, 1); + t--; // so it won't skip the next element + } + } + } + } +} diff --git a/src/assets/wise5/services/teacherProjectService.ts b/src/assets/wise5/services/teacherProjectService.ts index cf71c2b2bc..98e9423af3 100644 --- a/src/assets/wise5/services/teacherProjectService.ts +++ b/src/assets/wise5/services/teacherProjectService.ts @@ -830,34 +830,6 @@ export class TeacherProjectService extends ProjectService { node.constraints.push(constraint); } - /** - * Update a node's branchPathTaken constraint's fromNodeId and toNodeId - * @param node update the branch path taken constraints in this node - * @param currentFromNodeId the current from node id - * @param currentToNodeId the current to node id - * @param newFromNodeId the new from node id - * @param newToNodeId the new to node id - */ - updateBranchPathTakenConstraint( - node, - currentFromNodeId, - currentToNodeId, - newFromNodeId, - newToNodeId - ) { - for (let constraint of node.constraints) { - for (let removalCriterion of constraint.removalCriteria) { - if (removalCriterion.name === 'branchPathTaken') { - const params = removalCriterion.params; - if (params.fromNodeId === currentFromNodeId && params.toNodeId === currentToNodeId) { - params.fromNodeId = newFromNodeId; - params.toNodeId = newToNodeId; - } - } - } - } - } - /** * Insert a node into a group * @param nodeIdToInsert the node id to insert @@ -1112,270 +1084,6 @@ export class TeacherProjectService extends ProjectService { }); } - /** - * Update the transitions to handle removing a node - * @param nodeId the node id to remove - */ - removeNodeIdFromTransitions(nodeId) { - const nodeToRemove = this.getNodeById(nodeId); - const nodesByToNodeId = this.getNodesByToNodeId(nodeId); - - const nodeToRemoveTransitionLogic = nodeToRemove.transitionLogic; - let nodeToRemoveTransitions = []; - - if (nodeToRemoveTransitionLogic != null && nodeToRemoveTransitionLogic.transitions != null) { - nodeToRemoveTransitions = nodeToRemoveTransitionLogic.transitions; - } - - const parentIdOfNodeToRemove = this.getParentGroupId(nodeId); - this.updateParentGroupStartId(nodeId); - - for (let n = 0; n < nodesByToNodeId.length; n++) { - const node = nodesByToNodeId[n]; - if (node != null) { - const parentIdOfFromNode = this.getParentGroupId(node.id); - const transitionLogic = node.transitionLogic; - - if (transitionLogic != null) { - const transitions = transitionLogic.transitions; - for (let t = 0; t < transitions.length; t++) { - const transition = transitions[t]; - if (nodeId === transition.to) { - // we have found the transition to the node we are removing - - // copy the transitions from the node we are removing - let transitionsCopy = copy(nodeToRemoveTransitions); - - /* - * if the parent from group is different than the parent removing group - * remove transitions that are to a node in a different group than - * the parent removing group - */ - - if (parentIdOfFromNode != parentIdOfNodeToRemove) { - for (let tc = 0; tc < transitionsCopy.length; tc++) { - const tempTransition = transitionsCopy[tc]; - if (tempTransition != null) { - const tempToNodeId = tempTransition.to; - if (tempToNodeId != null) { - const parentIdOfToNode = this.getParentGroupId(tempToNodeId); - if (parentIdOfNodeToRemove != parentIdOfToNode) { - // remove the transition - transitionsCopy.splice(tc, 1); - tc--; - } - } - } - } - } - - if (this.isFirstNodeInBranchPath(nodeId)) { - /* - * Get the node ids that have a branchPathTaken - * constraint from the before node and to the node - * we are removing. If there are any, we need to - * update the branchPathTaken constraint with the - * next nodeId that comes after the node we are - * removing. - */ - const nodeIdsInBranch = this.getNodeIdsInBranch(node.id, nodeId); - - if (nodeIdsInBranch != null) { - for (let nodeIdInBranch of nodeIdsInBranch) { - const nodeInBranch = this.getNodeById(nodeIdInBranch); - for (let transitionCopy of transitionsCopy) { - if (transitionCopy != null) { - const currentFromNodeId = node.id; - const currentToNodeId = nodeId; - const newFromNodeId = node.id; - const newToNodeId = transitionCopy.to; - - /* - * change the branch path taken constraint by changing - * the toNodeId - */ - this.updateBranchPathTakenConstraint( - nodeInBranch, - currentFromNodeId, - currentToNodeId, - newFromNodeId, - newToNodeId - ); - } - } - } - } - } else if (this.isBranchPoint(nodeId)) { - /* - * get all the branches that have the node we - * are removing as the start point - */ - const branches = this.getBranchesByBranchStartPointNodeId(nodeId); - - for (let branch of branches) { - if (branch != null) { - /* - * get the branch paths. these paths do not - * contain the start point or merge point. - */ - const branchPaths = branch.paths; - - if (branchPaths != null) { - for (let branchPath of branchPaths) { - if (branchPath != null) { - const currentFromNodeId = nodeId; - const currentToNodeId = branchPath[0]; - const newFromNodeId = node.id; - const newToNodeId = branchPath[0]; - for (let branchPathNodeId of branchPath) { - const branchPathNode = this.getNodeById(branchPathNodeId); - this.updateBranchPathTakenConstraint( - branchPathNode, - currentFromNodeId, - currentToNodeId, - newFromNodeId, - newToNodeId - ); - } - } - } - } - } - } - } - - // remove the transition to the node we are removing - const transitionRemoved = transitions.splice(t, 1)[0]; - - if (transitionsCopy != null) { - let insertIndex = t; - - /* - * loop through all the transitions from the node we are removing - * and insert them into the transitions of the from node - * e.g. - * the node that comes before the node we are removing has these transitions - * "transitions": [ - * { - * "to": "node4" - * }, - * { - * "to": "node6" - * } - * ] - * - * we are removing node4. node4 has a transition to node5. - * - * the node that comes before the node we are removing now has these transitions - * "transitions": [ - * { - * "to": "node5" - * }, - * { - * "to": "node6" - * } - * ] - */ - for (let transitionCopy of transitionsCopy) { - if (!this.isTransitionExist(transitions, transitionCopy)) { - const toNodeId = transitionCopy.to; - if ( - this.isApplicationNode(node.id) && - this.isGroupNode(toNodeId) && - this.hasGroupStartId(toNodeId) - ) { - this.addToTransition(node, this.getGroupStartId(toNodeId)); - } else { - if (transitionRemoved.criteria != null) { - transitionCopy.criteria = transitionRemoved.criteria; - } - transitions.splice(insertIndex, 0, transitionCopy); - insertIndex++; - } - } - } - } - t--; - - // check if the node we are moving is a group - if (this.isGroupNode(nodeId)) { - /* - * we are moving a group so we need to update transitions that - * go into the group - */ - const groupIdWeAreMoving = nodeId; - const groupThatTransitionsToGroupWeAreMoving = node; - this.updateChildrenTransitionsIntoGroupWeAreMoving( - groupThatTransitionsToGroupWeAreMoving, - groupIdWeAreMoving - ); - } - } - } - - if ( - transitions.length === 0 && - parentIdOfNodeToRemove != 'group0' && - parentIdOfNodeToRemove != this.getParentGroupId(node.id) - ) { - /* - * the from node no longer has any transitions so we will make it transition to the - * parent of the node we are removing - */ - this.addToTransition(node, parentIdOfNodeToRemove); - } - - if (this.isBranchPoint(nodeId)) { - /* - * the node we are deleting is a branch point so we to - * copy the transition logic to the node that comes - * before it - */ - node.transitionLogic = copy(nodeToRemoveTransitionLogic); - - /* - * set the transitions for the node that comes before - * the one we are removing - */ - node.transitionLogic.transitions = transitions; - } - } - } - } - - if (nodeToRemoveTransitionLogic != null) { - nodeToRemoveTransitionLogic.transitions = []; - } - - if (this.isGroupNode(nodeId)) { - this.removeTransitionsOutOfGroup(nodeId); - } - } - - /** - * Update the parent group start id if the node we are removing is the start id - * @param nodeId The node we are removing - */ - private updateParentGroupStartId(nodeId: string): void { - const parentGroup = this.getParentGroup(nodeId); - if (parentGroup != null && parentGroup.startId === nodeId) { - const transitions = this.getTransitionsFromNode(this.getNodeById(nodeId)); - if (transitions.length > 0) { - for (const transition of transitions) { - const toNodeId = transition.to; - // Make sure the to node id is in the same group because a step can transition to a step - // in a different group. If the to node id is in a different group, we would not want to - // use it as the start id of this group. - if (this.getParentGroupId(toNodeId) === parentGroup.id) { - parentGroup.startId = toNodeId; - } - } - } else { - parentGroup.startId = ''; - } - } - } - /** * Check if a node is a branch point. A branch point is a node with more * than one transition. @@ -1413,15 +1121,6 @@ export class TeacherProjectService extends ProjectService { return result; } - isTransitionExist(transitions: any[], transition: any) { - for (const tempTransition of transitions) { - if (tempTransition.from === transition.from && tempTransition.to === transition.to) { - return true; - } - } - return false; - } - /** * Remove the node id from all groups * @param nodeId the node id to remove @@ -1594,11 +1293,6 @@ export class TeacherProjectService extends ProjectService { } } - hasGroupStartId(nodeId) { - const startId = this.getGroupStartId(nodeId); - return startId != null && startId != ''; - } - /** * Update the transitions so that the fromGroup points to the newToGroup * @@ -2106,149 +1800,6 @@ export class TeacherProjectService extends ProjectService { } } - /** - * Remove transition from nodes in the specified group that go out of the group - * @param nodeId the group id - */ - removeTransitionsOutOfGroup(groupId) { - const group = this.getNodeById(groupId); - for (const childId of group.ids) { - const transitions = this.getTransitionsByFromNodeId(childId); - for (let t = 0; t < transitions.length; t++) { - const transition = transitions[t]; - const parentGroupId = this.getParentGroupId(transition.to); - if (parentGroupId != groupId) { - // this is a transition that goes out of the specified group - transitions.splice(t, 1); - t--; // so it won't skip the next element - } - } - } - } - - /* - * Update the step transitions that point into the group we are moving - * For example - * group1 has children node1 and node2 (node2 transitions to node3) - * group2 has children node3 and node4 (node4 transitions to node5) - * group3 has children node5 and node6 - * if we move group2 after group3 we will need to change the - * transition from node2 to node3 and make node2 transition to node5 - * the result will be - * group1 has children node1 and node2 (node2 transitions to node5) - * group3 has children node5 and node6 - * group2 has children node3 and node4 (node4 transitions to node5) - * note: the (node4 transition to node5) will be removed later - * when is called removeTransitionsOutOfGroup - * note: when group2 is added in a later function call, we will add - * the node6 to node3 transition - * @param groupThatTransitionsToGroupWeAreMoving the group object - * that transitions to the group we are moving. we may need to update - * the transitions of this group's children. - * @param groupIdWeAreMoving the group id of the group we are moving - */ - updateChildrenTransitionsIntoGroupWeAreMoving( - groupThatTransitionsToGroupWeAreMoving, - groupIdWeAreMoving - ) { - if (groupThatTransitionsToGroupWeAreMoving != null && groupIdWeAreMoving != null) { - const group = this.getNodeById(groupIdWeAreMoving); - if (group != null) { - // get all the nodes that have a transition to the node we are removing - const nodesByToNodeId = this.getNodesByToNodeId(groupIdWeAreMoving); - - // get the transitions of the node we are removing - const nodeToRemoveTransitionLogic = group.transitionLogic; - let nodeToRemoveTransitions = []; - - if ( - nodeToRemoveTransitionLogic != null && - nodeToRemoveTransitionLogic.transitions != null - ) { - nodeToRemoveTransitions = nodeToRemoveTransitionLogic.transitions; - } - - if (nodeToRemoveTransitions.length == 0) { - /* - * The group we are moving is the last group in the project - * and does not have any transitions. We will loop through - * all the nodes that transition into this group and remove - * those transitions. - */ - - // get child ids of the group that comes before the group we are moving - const childIds = groupThatTransitionsToGroupWeAreMoving.ids; - - if (childIds != null) { - for (let childId of childIds) { - const transitionsFromChild = this.getTransitionsByFromNodeId(childId); - if (transitionsFromChild != null) { - for (let tfc = 0; tfc < transitionsFromChild.length; tfc++) { - const transitionFromChild = transitionsFromChild[tfc]; - if (transitionFromChild != null) { - const toNodeId = transitionFromChild.to; - const toNodeIdParentGroupId = this.getParentGroupId(toNodeId); - - if (groupIdWeAreMoving === toNodeIdParentGroupId) { - // the transition is to a child in the group we are moving - transitionsFromChild.splice(tfc, 1); - - /* - * move the counter back one because we have just removed an - * element from the array - */ - tfc--; - } - } - } - } - } - } - } else if (nodeToRemoveTransitions.length > 0) { - // get the first group that comes after the group we are removing - const firstNodeToRemoveTransition = nodeToRemoveTransitions[0]; - const firstNodeToRemoveTransitionToNodeId = firstNodeToRemoveTransition.to; - - if (this.isGroupNode(firstNodeToRemoveTransitionToNodeId)) { - // get the group that comes after the group we are moving - const groupNode = this.getNodeById(firstNodeToRemoveTransitionToNodeId); - - // get child ids of the group that comes before the group we are moving - const childIds = groupThatTransitionsToGroupWeAreMoving.ids; - - if (childIds != null) { - for (let childId of childIds) { - const transitionsFromChild = this.getTransitionsByFromNodeId(childId); - if (transitionsFromChild != null) { - for (let transitionFromChild of transitionsFromChild) { - if (transitionFromChild != null) { - const toNodeId = transitionFromChild.to; - - // get the parent group id of the toNodeId - const toNodeIdParentGroupId = this.getParentGroupId(toNodeId); - - if (groupIdWeAreMoving === toNodeIdParentGroupId) { - // the transition is to a child in the group we are moving - - if (groupNode.startId == null || groupNode.startId === '') { - // change the transition to point to the after group - transitionFromChild.to = firstNodeToRemoveTransitionToNodeId; - } else { - // change the transition to point to the start id of the after group - transitionFromChild.to = groupNode.startId; - } - } - } - } - } - } - } - } - } - } - } - } - /** * Get an unused component id * @param componentIdsToSkip (optional) An array of additional component ids @@ -2485,24 +2036,6 @@ export class TeacherProjectService extends ProjectService { return branchPathTakenConstraints; } - /** - * Check if a node is the first node in a branch path - * @param nodeId the node id - * @return whether the node is the first node in a branch path - */ - isFirstNodeInBranchPath(nodeId) { - for (const node of this.getNodes()) { - if (node.transitionLogic?.transitions?.length > 1) { - for (const transition of node.transitionLogic.transitions) { - if (transition.to === nodeId) { - return true; - } - } - } - } - return false; - } - addSpace(space) { if (this.project.spaces == null) { this.project.spaces = []; diff --git a/src/messages.xlf b/src/messages.xlf index 5f3fbacbf3..1f7c7e827d 100644 --- a/src/messages.xlf +++ b/src/messages.xlf @@ -18957,46 +18957,46 @@ Category Name: Are you sure you want to overwrite the current line data? src/assets/wise5/components/graph/graph-student/graph-student.component.ts - 231 + 237 The series you are trying to add a point to is currently hidden. Please show the series by clicking the series name in the legend and try adding the point again. src/assets/wise5/components/graph/graph-student/graph-student.component.ts - 846 + 852 You can not edit this series. Please choose a series that can be edited. src/assets/wise5/components/graph/graph-student/graph-student.component.ts - 860 + 866 Are you sure you want to reset the series? src/assets/wise5/components/graph/graph-student/graph-student.component.ts - 1093 + 1099 Are you sure you want to reset the "" series? src/assets/wise5/components/graph/graph-student/graph-student.component.ts - 1095 + 1101 Trial src/assets/wise5/components/graph/graph-student/graph-student.component.ts - 1593 + 1518 src/assets/wise5/components/graph/graph-student/graph-student.component.ts - 2417 + 2350