Skip to content

Commit

Permalink
refactor(TeacherProjectService): Move branch description functions to…
Browse files Browse the repository at this point in the history
… ProjectAuthoringStepComponent (#1906)
  • Loading branch information
hirokiterashima authored Aug 22, 2024
1 parent f32035e commit 0b7b271
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,39 @@ export class ProjectAuthoringStepComponent {
}

protected getNumberOfBranchPaths(nodeId: string): number {
return this.projectService.getNumberOfBranchPaths(nodeId);
return this.projectService.getTransitionsByFromNodeId(nodeId).length;
}

/**
* If this step is a branch point, we will return the criteria that is used
* to determine which path the student gets assigned to.
* @param nodeId The node id of the branch point.
* @returns A human readable string containing the criteria of how students
* are assigned branch paths on this branch point.
*/
protected getBranchCriteriaDescription(nodeId: string): string {
return this.projectService.getBranchCriteriaDescription(nodeId);
const transitionLogic = this.projectService.getNode(nodeId).getTransitionLogic();
for (const transition of transitionLogic.transitions) {
if (transition.criteria != null && transition.criteria.length > 0) {
for (const singleCriteria of transition.criteria) {
if (singleCriteria.name === 'choiceChosen') {
return 'multiple choice';
} else if (singleCriteria.name === 'score') {
return 'score';
}
}
}
}

/*
* None of the transitions had a specific criteria so the branching is just
* based on the howToChooseAmongAvailablePaths field.
*/
if (transitionLogic.howToChooseAmongAvailablePaths === 'workgroupId') {
return 'workgroup ID';
} else if (transitionLogic.howToChooseAmongAvailablePaths === 'random') {
return 'random assignment';
}
}

protected getStepBackgroundColor(nodeId: string): string {
Expand Down
45 changes: 0 additions & 45 deletions src/assets/wise5/services/teacherProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,51 +310,6 @@ export class TeacherProjectService extends ProjectService {
this.project.rubric = html;
}

/**
* Get the number of branch paths. This is assuming the node is a branch point.
* @param nodeId The node id of the branch point node.
* @return The number of branch paths for this branch point.
*/
getNumberOfBranchPaths(nodeId) {
const transitions = this.getTransitionsByFromNodeId(nodeId);
if (transitions != null) {
return transitions.length;
}
return 0;
}

/**
* If this step is a branch point, we will return the criteria that is used
* to determine which path the student gets assigned to.
* @param nodeId The node id of the branch point.
* @returns A human readable string containing the criteria of how students
* are assigned branch paths on this branch point.
*/
getBranchCriteriaDescription(nodeId) {
const transitionLogic = this.getNode(nodeId).getTransitionLogic();
for (const transition of transitionLogic.transitions) {
if (transition.criteria != null && transition.criteria.length > 0) {
for (const singleCriteria of transition.criteria) {
if (singleCriteria.name === 'choiceChosen') {
return 'multiple choice';
} else if (singleCriteria.name === 'score') {
return 'score';
}
}
}
}

/*
* None of the transitions had a specific criteria so the branching is just
* based on the howToChooseAmongAvailablePaths field.
*/
if (transitionLogic.howToChooseAmongAvailablePaths === 'workgroupId') {
return 'workgroup ID';
} else if (transitionLogic.howToChooseAmongAvailablePaths === 'random') {
return 'random assignment';
}
}

setProjectScriptFilename(scriptFilename) {
this.project.script = scriptFilename;
}
Expand Down
2 changes: 1 addition & 1 deletion src/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -12809,7 +12809,7 @@ Click &quot;Cancel&quot; to keep the invalid JSON open so you can fix it.</sourc
<source>Are you sure you want to delete this step?</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/project-authoring-step/project-authoring-step.component.ts</context>
<context context-type="linenumber">112</context>
<context context-type="linenumber">140</context>
</context-group>
</trans-unit>
<trans-unit id="57cf305f9bfd681c70dc26e914108d06384ade9f" datatype="html">
Expand Down

0 comments on commit 0b7b271

Please sign in to comment.