Skip to content

Commit

Permalink
feat(GradingNodeService): Extract from NodeService and clean up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima committed Dec 10, 2024
1 parent 0925c18 commit 67d92dd
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 76 deletions.
4 changes: 3 additions & 1 deletion src/app/teacher/classroom-monitor.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { PreviewComponentComponent } from '../../assets/wise5/authoringTool/comp
import { ComponentGradingComponent } from '../../assets/wise5/classroomMonitor/classroomMonitorComponents/component-grading.component';
import { SelectPeriodComponent } from '../../assets/wise5/classroomMonitor/classroomMonitorComponents/select-period/select-period.component';
import { GradingStepToolsComponent } from '../../assets/wise5/classroomMonitor/classroomMonitorComponents/grading-step-tools/grading-step-tools.component';
import { GradingNodeService } from '../../assets/wise5/services/gradingNodeService';

@NgModule({
declarations: [
Expand Down Expand Up @@ -76,6 +77,7 @@ import { GradingStepToolsComponent } from '../../assets/wise5/classroomMonitor/c
StepInfoComponent,
StudentTeacherCommonModule,
TeacherSummaryDisplayComponent
]
],
providers: [GradingNodeService]
})
export class ClassroomMonitorModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { MilestoneReportService } from '../services/milestoneReportService';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { TeacherPauseScreenService } from '../services/teacherPauseScreenService';
import { RunStatusService } from '../services/runStatusService';
import { GradingNodeService } from '../services/gradingNodeService';

@NgModule({
imports: [
Expand All @@ -24,6 +25,7 @@ import { RunStatusService } from '../services/runStatusService';
],
providers: [
ClassroomStatusService,
GradingNodeService,
MilestoneService,
MilestoneReportService,
TeacherDataService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, ViewEncapsulation } from '@angular/core';
import { Directionality } from '@angular/cdk/bidi';
import { StepToolsComponent } from '../../../common/stepTools/step-tools.component';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
Expand All @@ -10,6 +11,9 @@ import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { NodeIconComponent } from '../../../vle/node-icon/node-icon.component';
import { TeacherDataService } from '../../../services/teacherDataService';
import { GradingNodeService } from '../../../services/gradingNodeService';
import { TeacherProjectService } from '../../../services/teacherProjectService';

@Component({
encapsulation: ViewEncapsulation.None,
Expand All @@ -31,6 +35,15 @@ import { NodeIconComponent } from '../../../vle/node-icon/node-icon.component';
styleUrl: '../../../common/stepTools/step-tools.component.scss'
})
export class GradingStepToolsComponent extends StepToolsComponent {
constructor(
protected dataService: TeacherDataService,
protected dir: Directionality,
protected nodeService: GradingNodeService,
protected projectService: TeacherProjectService
) {
super(dataService, dir, nodeService, projectService);
}

protected calculateNodeIds(): void {
this.nodeIds = Object.keys(this.projectService.idToOrder);
this.nodeIds = this.nodeIds.filter((nodeId) => {
Expand All @@ -39,22 +52,7 @@ export class GradingStepToolsComponent extends StepToolsComponent {
this.nodeIds.shift(); // remove the 'group0' master root node from consideration
}

protected getPrevNodeId(): string {
return this.nodeService.getPrevNodeIdWithWork(this.nodeId);
}

protected getNextNodeId(): Promise<any> {
return Promise.resolve(this.nodeService.getNextNodeIdWithWork(this.nodeId));
}

protected goToPrevNode(): void {
this.nodeService.goToPrevNodeWithWork();
this.nodeId = this.dataService.getCurrentNodeId();
}

protected goToNextNode(): void {
this.nodeService.goToNextNodeWithWork().then((nodeId: string) => {
this.nodeId = nodeId;
});
return Promise.resolve(this.nodeService.getNextNodeId(this.nodeId));
}
}
2 changes: 1 addition & 1 deletion src/assets/wise5/common/stepTools/step-tools.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class StepToolsComponent {

constructor(
protected dataService: TeacherDataService,
private dir: Directionality,
protected dir: Directionality,
protected nodeService: NodeService,
protected projectService: TeacherProjectService
) {}
Expand Down
62 changes: 62 additions & 0 deletions src/assets/wise5/services/gradingNodeService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Injectable } from '@angular/core';
import { TeacherNodeService } from './teacherNodeService';

@Injectable()
export class GradingNodeService extends TeacherNodeService {
/**
* Get the next node id in the project sequence that captures student work
* @param currentId (optional)
* @returns next node id
*/
getNextNodeId(currentId = null): Promise<string> {
return super.getNextNodeId(currentId).then((nextNodeId: string) => {
if (nextNodeId) {
if (this.ProjectService.nodeHasWork(nextNodeId)) {
return nextNodeId;
} else {
return this.getNextNodeId(nextNodeId);
}
} else {
return null;
}
});
}

/**
* Go to the next node that captures work
* @return a promise that will return the next node id
*/
goToNextNode(): Promise<string> {
return this.getNextNodeId().then((nextNodeId: string) => {
if (nextNodeId) {
this.setCurrentNode(nextNodeId);
}
return nextNodeId;
});
}

/**
* Go to the previous node that captures work
*/
goToPrevNode(): void {
this.setCurrentNode(this.getPrevNodeId());
}

/**
* Get the previous node id in the project sequence that captures student work
* @param currentId (optional)
* @returns next node id
*/
getPrevNodeId(currentId = null) {
const prevNodeId = super.getPrevNodeId(currentId);
if (prevNodeId) {
if (this.ProjectService.nodeHasWork(prevNodeId)) {
return prevNodeId;
} else {
return this.getPrevNodeId(prevNodeId);
}
} else {
return null;
}
}
}
58 changes: 0 additions & 58 deletions src/assets/wise5/services/nodeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,6 @@ export class NodeService {
return null;
}

/**
* Go to the next node that captures work
* @return a promise that will return the next node id
*/
goToNextNodeWithWork(): Promise<string> {
return this.getNextNodeIdWithWork().then((nextNodeId: string) => {
if (nextNodeId) {
this.setCurrentNode(nextNodeId);
}
return nextNodeId;
});
}

/**
* Get the next node id in the project sequence that captures student work
* @param currentId (optional)
* @returns next node id
*/
getNextNodeIdWithWork(currentId = null) {
return this.getNextNodeId(currentId).then((nextNodeId: string) => {
if (nextNodeId) {
if (this.ProjectService.nodeHasWork(nextNodeId)) {
return nextNodeId;
} else {
return this.getNextNodeIdWithWork(nextNodeId);
}
} else {
return null;
}
});
}

goToPrevNode() {
const prevNodeId = this.getPrevNodeId();
this.setCurrentNode(prevNodeId);
Expand Down Expand Up @@ -131,32 +99,6 @@ export class NodeService {
return prevNodeId;
}

/**
* Go to the previous node that captures work
*/
goToPrevNodeWithWork() {
const prevNodeId = this.getPrevNodeIdWithWork();
this.setCurrentNode(prevNodeId);
}

/**
* Get the previous node id in the project sequence that captures student work
* @param currentId (optional)
* @returns next node id
*/
getPrevNodeIdWithWork(currentId = null) {
const prevNodeId = this.getPrevNodeId(currentId);
if (prevNodeId) {
if (this.ProjectService.nodeHasWork(prevNodeId)) {
return prevNodeId;
} else {
return this.getPrevNodeIdWithWork(prevNodeId);
}
} else {
return null;
}
}

/**
* Close the current node (and open the current node's parent group)
*/
Expand Down

0 comments on commit 67d92dd

Please sign in to comment.