Skip to content

Commit

Permalink
refactor(TeacherProjectService): Move getNumberOfRubricsByNodeId() to…
Browse files Browse the repository at this point in the history
… Node (#1901)
  • Loading branch information
hirokiterashima authored Aug 20, 2024
1 parent 1465073 commit b610a42
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/app/classroom-monitor/step-info/step-info.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class StepInfoComponent {
? $localize`Has new alert(s)`
: $localize`Has dismissed alert(s)`;
}
this.hasRubrics = this.projectService.getNumberOfRubricsByNodeId(this.nodeId) > 0;
this.hasRubrics = this.projectService.getNode(this.nodeId).getNumRubrics() > 0;
this.rubricIconLabel = $localize`Step has rubrics/teaching tips`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class ProjectAuthoringStepComponent {
}

protected nodeHasRubric(nodeId: string): boolean {
return this.projectService.nodeHasRubric(nodeId);
return this.projectService.getNode(nodeId).getNumRubrics() > 0;
}

protected getConstraintDescriptions(nodeId: string): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class NodeGradingViewComponent implements OnInit {
this.canViewStudentNames = this.configService.getPermissions().canViewStudentNames;
this.setWorkgroupsById();
this.sortWorkgroups();
this.numRubrics = this.projectService.getNumberOfRubricsByNodeId(node.id);
this.numRubrics = node.getNumRubrics();
document.body.scrollTop = document.documentElement.scrollTop = 0;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TeacherProjectService } from '../../../../services/teacherProjectServic
import { ClassroomMonitorTestingModule } from '../../../classroom-monitor-testing.module';
import { NavItemComponent } from './nav-item.component';
import { NodeService } from '../../../../services/nodeService';
import { Node } from '../../../../common/Node';

class MockNotificationService {
getAlertNotifications() {
Expand Down Expand Up @@ -39,10 +40,9 @@ class MockTeacherProjectService {
nodeHasWork() {}
getMaxScoreForNode() {}
getNode() {
return { getIcon: () => {} };
return new Node();
}
getParentGroup() {}
getNumberOfRubricsByNodeId() {}
}

let component: NavItemComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class NavItemComponent implements OnInit {
this.parentGroupId = parentGroup.id;
}
this.getAlertNotifications();
this.hasRubrics = this.projectService.getNumberOfRubricsByNodeId(this.nodeId) > 0;
this.hasRubrics = this.projectService.getNode(this.nodeId).getNumRubrics() > 0;
this.alertIconLabel = $localize`Has new alert(s)`;
this.alertIconClass = 'warn';
this.alertIconName = 'notifications';
Expand Down
15 changes: 15 additions & 0 deletions src/assets/wise5/common/Node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('Node', () => {
replaceComponent();
getAllRelatedComponents();
deleteTransition();
getNumRubrics();
});

function copyComponents() {
Expand Down Expand Up @@ -214,3 +215,17 @@ function deleteTransition() {
});
});
}

function getNumRubrics() {
describe('getNumRubrics()', () => {
it("should return 0 when node and components don't have any rubric", () => {
expect(node.getNumRubrics()).toEqual(0);
});
it('should return total number of rubrics for the node and its components', () => {
node.rubric = 'node rubric';
node.components[0].rubric = 'component 1 rubric';
node.components[1].rubric = 'component 2 rubric';
expect(node.getNumRubrics()).toEqual(3);
});
});
}
11 changes: 11 additions & 0 deletions src/assets/wise5/common/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,15 @@ export class Node {
this.transitionLogic.maxPathsVisitable = null;
}
}

getNumRubrics(): number {
let numRubrics = 0;
if (this.rubric != null && this.rubric != '') {
numRubrics++;
}
numRubrics += this.components.filter(
(component) => component.rubric != null && component.rubric != ''
).length;
return numRubrics;
}
}
32 changes: 0 additions & 32 deletions src/assets/wise5/services/teacherProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,38 +366,6 @@ export class TeacherProjectService extends ProjectService {
return null;
}

nodeHasRubric(nodeId: string): boolean {
return this.getNumberOfRubricsByNodeId(nodeId) > 0;
}

/**
* Get the total number of rubrics (step + components) for the given nodeId
* @param nodeId the node id
* @return Number of rubrics for the node
*/
getNumberOfRubricsByNodeId(nodeId: string): number {
let numRubrics = 0;
const node = this.getNodeById(nodeId);
if (node) {
const nodeRubric = node.rubric;
if (nodeRubric != null && nodeRubric != '') {
numRubrics++;
}
const components = node.components;
if (components && components.length) {
for (let component of components) {
if (component) {
const componentRubric = component.rubric;
if (componentRubric != null && componentRubric != '') {
numRubrics++;
}
}
}
}
}
return numRubrics;
}

getBackgroundColor(nodeId: string): string {
const branchPathLetter = this.nodeIdToBranchPathLetter[nodeId];
if (branchPathLetter != null) {
Expand Down

0 comments on commit b610a42

Please sign in to comment.