Skip to content

Commit

Permalink
Extract duplicate getReferenceComponent() to ProjectService #1409
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima committed Sep 13, 2023
1 parent 10b4dff commit 093d531
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/app/services/studentPeerGroupService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function retrieveQuestionBankStudentData() {
describe('retrieveQuestionBankStudentData()', () => {
it('should retrieve question bank student data in preview', () => {
setIsPreview(true);
spyOn(projectService, 'getReferenceComponent').and.returnValue({
spyOn(projectService, 'getReferenceComponentForField').and.returnValue({
nodeId: nodeId1,
componentId: componentId1
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Observable } from 'rxjs';
import { PeerGroupService } from '../../../services/peerGroupService';
import { ProjectService } from '../../../services/projectService';
import { OpenResponseContent } from '../../openResponse/OpenResponseContent';
import { QuestionBank } from './QuestionBank';
import { Component as WISEComponent } from '../../../common/Component';
import { PeerGroupStudentData } from '../../../../../app/domain/peerGroupStudentData';
import { CRaterResponse } from '../../common/cRater/CRaterResponse';
Expand Down Expand Up @@ -35,7 +34,9 @@ export class PeerChatQuestionBankComponent implements OnInit {

ngOnInit(): void {
if (this.displayedQuestionBankRules == null) {
const referenceComponent = this.getReferenceComponent(this.content.questionBank);
const referenceComponent = this.projectService.getReferenceComponent(
this.content.questionBank
);
if (
this.content.questionBank.isPeerGroupingTagSpecified() &&
['OpenResponse', 'MultipleChoice'].includes(referenceComponent.content.type)
Expand All @@ -47,12 +48,6 @@ export class PeerChatQuestionBankComponent implements OnInit {
}
}

private getReferenceComponent(questionBank: QuestionBank): WISEComponent {
const nodeId = questionBank.getReferenceNodeId();
const componentId = questionBank.getReferenceComponentId();
return new WISEComponent(this.projectService.getComponent(nodeId, componentId), nodeId);
}

private evaluatePeerGroup(referenceComponent: WISEComponent): void {
this.getPeerGroupData(
this.content.questionBank.getPeerGroupingTag(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ProjectService } from '../../services/projectService';
import { StudentDataService } from '../../services/studentDataService';
import { DynamicPrompt } from './DynamicPrompt';
import { ConstraintService } from '../../services/constraintService';
import { Component as WISEComponent } from '../../common/Component';
import { DynamicPromptOpenResponseEvaluator } from './DynamicPromptOpenResponseEvaluator';
import { DynamicPromptMultipleChoiceEvaluator } from './DynamicPromptMultipleChoiceEvaluator';

Expand Down Expand Up @@ -44,17 +43,11 @@ export class DynamicPromptComponent implements OnInit {
}

ngOnInit(): void {
const referenceComponent = this.getReferenceComponent(this.dynamicPrompt);
const referenceComponent = this.projectService.getReferenceComponent(this.dynamicPrompt);
if (referenceComponent.content.type === 'OpenResponse') {
new DynamicPromptOpenResponseEvaluator(this).evaluate(referenceComponent);
} else if (referenceComponent.content.type === 'MultipleChoice') {
new DynamicPromptMultipleChoiceEvaluator(this).evaluate(referenceComponent);
}
}

private getReferenceComponent(dynamicPrompt: DynamicPrompt): WISEComponent {
const nodeId = dynamicPrompt.getReferenceNodeId();
const componentId = dynamicPrompt.getReferenceComponentId();
return new WISEComponent(this.projectService.getComponent(nodeId, componentId), nodeId);
}
}
13 changes: 11 additions & 2 deletions src/assets/wise5/services/projectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { MultipleChoiceContent } from '../components/multipleChoice/MultipleChoi
import { TransitionLogic } from '../common/TransitionLogic';
import { Transition } from '../common/Transition';
import { ReferenceComponent } from '../../../app/domain/referenceComponent';
import { QuestionBank } from '../components/peerChat/peer-chat-question-bank/QuestionBank';
import { DynamicPrompt } from '../directives/dynamic-prompt/DynamicPrompt';
import { Component } from '../common/Component';

@Injectable()
export class ProjectService {
Expand Down Expand Up @@ -1971,12 +1974,18 @@ export class ProjectService {
* }
* @returns the referenceComponent object from a component
*/
getReferenceComponent(
getReferenceComponentForField(
nodeId: string,
componentId: string,
fieldName: string
fieldName: 'dynamicPrompt' | 'questionBank'
): ReferenceComponent {
const component = this.getComponent(nodeId, componentId);
return component[fieldName]?.referenceComponent;
}

getReferenceComponent(content: QuestionBank | DynamicPrompt): Component {
const nodeId = content.getReferenceNodeId();
const componentId = content.getReferenceComponentId();
return new Component(this.getComponent(nodeId, componentId), nodeId);
}
}
6 changes: 3 additions & 3 deletions src/assets/wise5/services/studentPeerGroupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class StudentPeerGroupService extends PeerGroupService {
peerGroupId: number,
nodeId: string,
componentId: string,
fieldName: string,
fieldName: 'dynamicPrompt' | 'questionBank',
urlEnding: string
): Observable<PeerGroupStudentData[]> {
if (this.configService.isPreview()) {
Expand All @@ -90,9 +90,9 @@ export class StudentPeerGroupService extends PeerGroupService {
private getPreviewPeerGroupStudentData(
nodeId: string,
componentId: string,
fieldName: string
fieldName: 'dynamicPrompt' | 'questionBank'
): Observable<PeerGroupStudentData[]> {
const referenceComponent = this.projectService.getReferenceComponent(
const referenceComponent = this.projectService.getReferenceComponentForField(
nodeId,
componentId,
fieldName
Expand Down
32 changes: 16 additions & 16 deletions src/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -20767,112 +20767,112 @@ If this problem continues, let your teacher know and move on to the next activit
<source>Complete &lt;b&gt;<x id="PH" equiv-text="nodeTitle"/>&lt;/b&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1171</context>
<context context-type="linenumber">1174</context>
</context-group>
</trans-unit>
<trans-unit id="4750375498606149231" datatype="html">
<source>Visit &lt;b&gt;<x id="PH" equiv-text="nodeTitle"/>&lt;/b&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1177</context>
<context context-type="linenumber">1180</context>
</context-group>
</trans-unit>
<trans-unit id="6126058561630526429" datatype="html">
<source>Correctly answer &lt;b&gt;<x id="PH" equiv-text="nodeTitle"/>&lt;/b&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1183</context>
<context context-type="linenumber">1186</context>
</context-group>
</trans-unit>
<trans-unit id="7085241847460263487" datatype="html">
<source>Obtain a score of &lt;b&gt;<x id="PH" equiv-text="scoresString"/>&lt;/b&gt; on &lt;b&gt;<x id="PH_1" equiv-text="nodeTitle"/>&lt;/b&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1198</context>
<context context-type="linenumber">1201</context>
</context-group>
</trans-unit>
<trans-unit id="5469027549306748048" datatype="html">
<source>You must choose &quot;<x id="PH" equiv-text="choiceText"/>&quot; on &quot;<x id="PH_1" equiv-text="nodeTitle"/>&quot;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1206</context>
<context context-type="linenumber">1209</context>
</context-group>
</trans-unit>
<trans-unit id="6293177000168372990" datatype="html">
<source>Submit &lt;b&gt;<x id="PH" equiv-text="requiredSubmitCount"/>&lt;/b&gt; time on &lt;b&gt;<x id="PH_1" equiv-text="nodeTitle"/>&lt;/b&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1218</context>
<context context-type="linenumber">1221</context>
</context-group>
</trans-unit>
<trans-unit id="4693324974790890133" datatype="html">
<source>Submit &lt;b&gt;<x id="PH" equiv-text="requiredSubmitCount"/>&lt;/b&gt; times on &lt;b&gt;<x id="PH_1" equiv-text="nodeTitle"/>&lt;/b&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1220</context>
<context context-type="linenumber">1223</context>
</context-group>
</trans-unit>
<trans-unit id="8416169412912074869" datatype="html">
<source>Take the branch path from &lt;b&gt;<x id="PH" equiv-text="fromNodeTitle"/>&lt;/b&gt; to &lt;b&gt;<x id="PH_1" equiv-text="toNodeTitle"/>&lt;/b&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1227</context>
<context context-type="linenumber">1230</context>
</context-group>
</trans-unit>
<trans-unit id="8087029188038414167" datatype="html">
<source>Write &lt;b&gt;<x id="PH" equiv-text="requiredNumberOfWords"/>&lt;/b&gt; words on &lt;b&gt;<x id="PH_1" equiv-text="nodeTitle"/>&lt;/b&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1233</context>
<context context-type="linenumber">1236</context>
</context-group>
</trans-unit>
<trans-unit id="22049568725715518" datatype="html">
<source>&quot;<x id="PH" equiv-text="nodeTitle"/>&quot; is visible</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1239</context>
<context context-type="linenumber">1242</context>
</context-group>
</trans-unit>
<trans-unit id="5023130174506669799" datatype="html">
<source>&quot;<x id="PH" equiv-text="nodeTitle"/>&quot; is visitable</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1245</context>
<context context-type="linenumber">1248</context>
</context-group>
</trans-unit>
<trans-unit id="1185133360670447094" datatype="html">
<source>Add &lt;b&gt;<x id="PH" equiv-text="requiredNumberOfNotes"/>&lt;/b&gt; note on &lt;b&gt;<x id="PH_1" equiv-text="nodeTitle"/>&lt;/b&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1252</context>
<context context-type="linenumber">1255</context>
</context-group>
</trans-unit>
<trans-unit id="5985921753090789216" datatype="html">
<source>Add &lt;b&gt;<x id="PH" equiv-text="requiredNumberOfNotes"/>&lt;/b&gt; notes on &lt;b&gt;<x id="PH_1" equiv-text="nodeTitle"/>&lt;/b&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1254</context>
<context context-type="linenumber">1257</context>
</context-group>
</trans-unit>
<trans-unit id="4560070803879446782" datatype="html">
<source>You must fill in &lt;b&gt;<x id="PH" equiv-text="requiredNumberOfFilledRows"/>&lt;/b&gt; row in the &lt;b&gt;Table&lt;/b&gt; on &lt;b&gt;<x id="PH_1" equiv-text="nodeTitle"/>&lt;/b&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1261</context>
<context context-type="linenumber">1264</context>
</context-group>
</trans-unit>
<trans-unit id="2804292280751903227" datatype="html">
<source>You must fill in &lt;b&gt;<x id="PH" equiv-text="requiredNumberOfFilledRows"/>&lt;/b&gt; rows in the &lt;b&gt;Table&lt;/b&gt; on &lt;b&gt;<x id="PH_1" equiv-text="nodeTitle"/>&lt;/b&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1263</context>
<context context-type="linenumber">1266</context>
</context-group>
</trans-unit>
<trans-unit id="4171523921205906508" datatype="html">
<source>Wait for your teacher to unlock the item</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/projectService.ts</context>
<context context-type="linenumber">1266</context>
<context context-type="linenumber">1269</context>
</context-group>
</trans-unit>
<trans-unit id="8770055323459972095" datatype="html">
Expand Down

0 comments on commit 093d531

Please sign in to comment.