Skip to content

Commit

Permalink
refactor(Authoring): Rename nodeIdToInsertInsideOrAfter to targetLoca…
Browse files Browse the repository at this point in the history
…tion (#1739)
  • Loading branch information
geoffreykwan authored Apr 18, 2024
1 parent 6348a59 commit 7568dab
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h6 *ngIf="item.order != 0 && item.node.type == 'group'">
mat-button
color="primary"
routerLink="../choose-unit"
[state]="{ nodeIdToInsertInsideOrAfter: nodeIdToInsertInsideOrAfter }"
[state]="{ targetId: targetId }"
aria-label="Back"
i18n-aria-label
i18n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h5 i18n>Choose a unit from which to import step(s).</h5>
mat-button
color="primary"
routerLink="../../choose-template"
[state]="{ nodeIdToInsertInsideOrAfter: nodeIdToInsertInsideOrAfter }"
[state]="{ targetId: targetId }"
i18n
>
Back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Subscription } from 'rxjs';
export class ChooseImportUnitComponent {
protected libraryProjects: any[];
protected myProjects: any[];
protected nodeIdToInsertInsideOrAfter: string;
protected targetId: string;
private subscriptions: Subscription = new Subscription();

constructor(
Expand All @@ -23,7 +23,7 @@ export class ChooseImportUnitComponent {
) {}

ngOnInit(): void {
this.nodeIdToInsertInsideOrAfter = history.state.nodeIdToInsertInsideOrAfter;
this.targetId = history.state.targetId;
this.myProjects = this.configService.getAuthorableProjects();
this.subscriptions.add(
this.projectLibraryService.getLibraryProjects().subscribe((libraryProjects) => {
Expand All @@ -41,7 +41,7 @@ export class ChooseImportUnitComponent {
relativeTo: this.route,
state: {
importProjectId: project.id,
nodeIdToInsertInsideOrAfter: this.nodeIdToInsertInsideOrAfter
targetId: this.targetId
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class AddStepButtonComponent {
this.router.navigate(['add-node', 'choose-template'], {
relativeTo: this.route,
state: {
nodeIdToInsertInsideOrAfter: nodeId
targetId: nodeId
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TeacherProjectService } from '../../../services/teacherProjectService';
@Directive()
export abstract class AbstractImportStepComponent implements OnInit {
protected importProjectId: number;
protected nodeIdToInsertInsideOrAfter: string;
protected targetId: string;

constructor(
protected configService: ConfigService,
Expand All @@ -20,7 +20,7 @@ export abstract class AbstractImportStepComponent implements OnInit {
) {}

ngOnInit(): void {
this.nodeIdToInsertInsideOrAfter = history.state.nodeIdToInsertInsideOrAfter;
this.targetId = history.state.targetId;
this.importProjectId = history.state.importProjectId;
}

Expand All @@ -29,7 +29,7 @@ export abstract class AbstractImportStepComponent implements OnInit {
.copyNodes(nodesToImport, this.importProjectId, this.configService.getProjectId())
.subscribe((copiedNodes: any[]) => {
const nodesWithNewNodeIds = this.projectService.getNodesWithNewIds(copiedNodes);
this.insertNodesService.insertNodes(nodesWithNewNodeIds, this.nodeIdToInsertInsideOrAfter);
this.insertNodesService.insertNodes(nodesWithNewNodeIds, this.targetId);
this.projectService.checkPotentialStartNodeIdChangeThenSaveProject().then(() => {
this.projectService.refreshProject();
this.router.navigate(['../../..'], { relativeTo: this.route });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h5 i18n>Select components to add to your new step (optional):</h5>
mat-button
class="mat-primary"
routerLink="../choose-template"
[state]="{ nodeIdToInsertInsideOrAfter: nodeIdToInsertInsideOrAfter }"
[state]="{ targetId: targetId }"
i18n
>
Back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class AddYourOwnNode {
});
protected componentTypes: any[];
protected initialComponents: string[] = [];
protected nodeIdToInsertInsideOrAfter: string;
protected targetId: string;

constructor(
private componentTypeService: ComponentTypeService,
Expand All @@ -27,7 +27,7 @@ export class AddYourOwnNode {
) {}

ngOnInit() {
this.nodeIdToInsertInsideOrAfter = history.state.nodeIdToInsertInsideOrAfter;
this.targetId = history.state.targetId;
this.componentTypes = this.componentTypeService.getComponentTypes();
}

Expand All @@ -45,10 +45,10 @@ export class AddYourOwnNode {

protected submit(): void {
const newNode = this.projectService.createNode(this.addNodeFormGroup.controls['title'].value);
if (this.isGroupNode(this.nodeIdToInsertInsideOrAfter)) {
this.projectService.createNodeInside(newNode, this.nodeIdToInsertInsideOrAfter);
if (this.isGroupNode(this.targetId)) {
this.projectService.createNodeInside(newNode, this.targetId);
} else {
this.projectService.createNodeAfter(newNode, this.nodeIdToInsertInsideOrAfter);
this.projectService.createNodeAfter(newNode, this.targetId);
}
this.addInitialComponents(newNode.id, this.initialComponents);
this.save().then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h6 i18n>Choose an assessment item:</h6>
mat-button
color="primary"
routerLink="../../choose-template"
[state]="{ nodeIdToInsertInsideOrAfter: nodeIdToInsertInsideOrAfter }"
[state]="{ targetId: targetId }"
i18n
>
Back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ActivatedRoute, Router } from '@angular/router';
export class ChooseAutomatedAssessmentComponent {
private importProjectId: number;
protected node: any;
protected nodeIdToInsertInsideOrAfter: string;
protected targetId: string;
private project: any;
protected projectItems: any;

Expand All @@ -21,7 +21,7 @@ export class ChooseAutomatedAssessmentComponent {
) {}

ngOnInit(): void {
this.nodeIdToInsertInsideOrAfter = history.state.nodeIdToInsertInsideOrAfter;
this.targetId = history.state.targetId;
this.importProjectId = this.projectService.getAutomatedAssessmentProjectId();
this.showAutomatedAssessmentProject();
}
Expand Down Expand Up @@ -50,7 +50,7 @@ export class ChooseAutomatedAssessmentComponent {
state: {
importProjectId: this.importProjectId,
node: this.node,
nodeIdToInsertInsideOrAfter: this.nodeIdToInsertInsideOrAfter
targetId: this.targetId
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ChooseNewNodeTemplate {
this.router.navigate(['..', ...template.route.split('/')], {
relativeTo: this.route,
state: {
nodeIdToInsertInsideOrAfter: history.state.nodeIdToInsertInsideOrAfter
targetId: history.state.targetId
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h5 i18n>Interactive Simulation</h5>
mat-button
color="primary"
routerLink="../../choose-template"
[state]="{ nodeIdToInsertInsideOrAfter: nodeIdToInsertInsideOrAfter }"
[state]="{ targetId: targetId }"
i18n
>
Back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h5 i18n>Customize Feedback (optional)</h5>
mat-button
color="primary"
routerLink="../choose-item"
[state]="{ nodeIdToInsertInsideOrAfter: nodeIdToInsertInsideOrAfter }"
[state]="{ targetId: targetId }"
i18n
>
Back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class ProjectAuthoringLessonComponent {
this.router.navigate(['add-node', 'choose-template'], {
relativeTo: this.route,
state: {
nodeIdToInsertInsideOrAfter: nodeId
targetId: nodeId
}
});
}
Expand Down
24 changes: 12 additions & 12 deletions src/assets/wise5/services/insertNodesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ export class InsertNodesService {
/**
* Insert nodes in specified location. Modifies project.
* @param nodes nodes to insert
* @param nodeIdToInsertInsideOrAfter id of node or group. If this is a group, we will make the
* @param targetId id of node or group. If this is a group, we will make the
* new step the first step in the group. If this is a step, we will place the new step after it.
*/
insertNodes(nodes: any[], nodeIdToInsertInsideOrAfter: string) {
if (nodeIdToInsertInsideOrAfter == null) {
insertNodes(nodes: any[], targetId: string) {
if (targetId == null) {
/*
* Insert the node after the last inactive node. If there
* are no inactive nodes it will just be placed in the
* inactive nodes section. In the latter case we do this by
* setting nodeIdToInsertInsideOrAfter to 'inactiveSteps'.
* setting targetId to 'inactiveSteps'.
*/
const inactiveNodes = this.ProjectService.getInactiveNodes();
if (inactiveNodes != null && inactiveNodes.length > 0) {
nodeIdToInsertInsideOrAfter = inactiveNodes[inactiveNodes.length - 1];
targetId = inactiveNodes[inactiveNodes.length - 1];
} else {
nodeIdToInsertInsideOrAfter = 'inactiveSteps';
targetId = 'inactiveSteps';
}
}

for (const node of nodes) {
if (this.ProjectService.isGroupNode(nodeIdToInsertInsideOrAfter)) {
this.ProjectService.createNodeInside(node, nodeIdToInsertInsideOrAfter);
if (this.ProjectService.isGroupNode(targetId)) {
this.ProjectService.createNodeInside(node, targetId);
} else {
this.ProjectService.createNodeAfter(node, nodeIdToInsertInsideOrAfter);
this.ProjectService.createNodeAfter(node, targetId);
}

/*
* Update the nodeIdToInsertInsideOrAfter so that when we are
* Update the targetId so that when we are
* importing multiple steps, the steps get placed in the correct
* order.
*
Expand All @@ -48,10 +48,10 @@ export class InsertNodesService {
* nodeB
*
* This means after we add nodeA, we must update
* nodeIdToInsertInsideOrAfter to be nodeA so that when we add
* targetId to be nodeA so that when we add
* nodeB, it will be placed after nodeA.
*/
nodeIdToInsertInsideOrAfter = node.id;
targetId = node.id;
}
}
}

0 comments on commit 7568dab

Please sign in to comment.