Skip to content

Commit

Permalink
refactor(TeacherProjectService): Move removeNodeFromInactiveNodes() t…
Browse files Browse the repository at this point in the history
…o MoveNodesService (#1920)
  • Loading branch information
hirokiterashima authored Aug 27, 2024
1 parent c1fcca2 commit 143d0e3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 64 deletions.
46 changes: 42 additions & 4 deletions src/assets/wise5/services/moveNodesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ export class MoveNodesService {
* also move all of its children to active.
*/
private moveToActive(node: any): void {
this.projectService.removeNodeFromInactiveNodes(node.id);
this.removeNodeFromInactiveNodes(node.id);
this.projectService.addNode(node);
if (this.projectService.isGroupNode(node.id)) {
for (const childId of node.ids) {
this.projectService.addNode(this.projectService.removeNodeFromInactiveNodes(childId));
this.projectService.addNode(this.removeNodeFromInactiveNodes(childId));
}
}
}
Expand All @@ -132,7 +132,7 @@ export class MoveNodesService {
* @param nodeIdToInsertInside place the node inside this
*/
private moveFromInactiveToInactiveInsertInside(node: any, nodeIdToInsertInside: string): void {
this.projectService.removeNodeFromInactiveNodes(node.id);
this.removeNodeFromInactiveNodes(node.id);
if (this.projectService.isGroupNode(node.id)) {
/*
* remove the group's child nodes from our data structures so that we can
Expand Down Expand Up @@ -200,7 +200,45 @@ export class MoveNodesService {
}

private moveInactiveNodeToInactiveSection(node: any, nodeIdToInsertAfter: string): void {
this.projectService.removeNodeFromInactiveNodes(node.id);
this.removeNodeFromInactiveNodes(node.id);
this.projectService.addInactiveNodeInsertAfter(node, nodeIdToInsertAfter);
}

private removeNodeFromInactiveNodes(nodeId: string): void {
let node = null;
if (this.projectService.getParentGroup(nodeId) != null) {
this.projectService.removeChildFromParent(nodeId);
}

const inactiveNodes = this.projectService.project.inactiveNodes;
for (let i = 0; i < inactiveNodes.length; i++) {
let inactiveNode = inactiveNodes[i];
if (inactiveNode.id === nodeId) {
node = inactiveNode;
inactiveNodes.splice(i, 1);
break;
}
}
this.removeNodeFromInactiveStepNodes(nodeId);
this.removeNodeFromInactiveGroupNodes(nodeId);
return node;
}

private removeNodeFromInactiveStepNodes(nodeId: string): void {
for (let i = 0; i < this.projectService.inactiveStepNodes.length; i++) {
if (nodeId == this.projectService.inactiveStepNodes[i].id) {
this.projectService.inactiveStepNodes.splice(i, 1);
break;
}
}
}

private removeNodeFromInactiveGroupNodes(nodeId: string): void {
for (let i = 0; i < this.projectService.inactiveGroupNodes.length; i++) {
if (nodeId == this.projectService.inactiveGroupNodes[i].id) {
this.projectService.inactiveGroupNodes.splice(i, 1);
break;
}
}
}
}
60 changes: 0 additions & 60 deletions src/assets/wise5/services/teacherProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1549,38 +1549,6 @@ export class TeacherProjectService extends ProjectService {
return groupsThatPointToNodeId;
}

/**
* Remove the node from the inactive nodes array
* @param nodeId the node to remove
* @returns the node that was removed
*/
removeNodeFromInactiveNodes(nodeId) {
let node = null;
if (nodeId != null) {
let parentGroup = this.getParentGroup(nodeId);
if (parentGroup != null) {
this.removeChildFromParent(nodeId);
}

let inactiveNodes = this.project.inactiveNodes;
if (inactiveNodes != null) {
for (let i = 0; i < inactiveNodes.length; i++) {
let inactiveNode = inactiveNodes[i];
if (inactiveNode != null) {
if (nodeId === inactiveNode.id) {
node = inactiveNode;
inactiveNodes.splice(i, 1);
break;
}
}
}
}
this.removeNodeFromInactiveStepNodes(nodeId);
this.removeNodeFromInactiveGroupNodes(nodeId);
}
return node;
}

/**
* Remove the child node from the parent group.
* @param nodeId The child node to remove from the parent.
Expand Down Expand Up @@ -1623,34 +1591,6 @@ export class TeacherProjectService extends ProjectService {
}
}

/**
* Remove the node from the inactive step nodes array.
* @param nodeId The node id of the node we want to remove from the
* inactive step nodes array.
*/
removeNodeFromInactiveStepNodes(nodeId) {
for (let i = 0; i < this.inactiveStepNodes.length; i++) {
if (nodeId == this.inactiveStepNodes[i].id) {
this.inactiveStepNodes.splice(i, 1);
break;
}
}
}

/**
* Remove the node from the inactive group nodes array.
* @param nodeId The node id of the group we want to remove from the
* inactive group nodes array.
*/
removeNodeFromInactiveGroupNodes(nodeId) {
for (let i = 0; i < this.inactiveGroupNodes.length; i++) {
if (nodeId == this.inactiveGroupNodes[i].id) {
this.inactiveGroupNodes.splice(i, 1);
break;
}
}
}

/**
* Add a group's cthild nodes to the inactive nodes.
* @param node The group node.
Expand Down

0 comments on commit 143d0e3

Please sign in to comment.