Skip to content

Commit

Permalink
refactor(AnnotationService): getLatestCommentAnnotation()
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima committed Oct 19, 2023
1 parent b528bb8 commit 6d32a43
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 75 deletions.
105 changes: 33 additions & 72 deletions src/assets/wise5/services/annotationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,28 +440,15 @@ export class AnnotationService {
* @return object containing the component's latest score and comment annotations
*/
getLatestComponentAnnotations(
nodeId,
componentId,
workgroupId,
nodeId: string,
componentId: string,
workgroupId: number,
scoreType: 'score' | 'autoScore' | 'any' = 'any',
commentType = null
) {
let latestScoreAnnotation = this.getLatestScoreAnnotation(
nodeId,
componentId,
workgroupId,
scoreType
);
let latestCommentAnnotation = this.getLatestCommentAnnotation(
nodeId,
componentId,
workgroupId,
commentType
);

commentType: 'comment' | 'autoComment' | 'any' = 'any'
): any {
return {
score: latestScoreAnnotation,
comment: latestCommentAnnotation
score: this.getLatestScoreAnnotation(nodeId, componentId, workgroupId, scoreType),
comment: this.getLatestCommentAnnotation(nodeId, componentId, workgroupId, commentType)
};
}

Expand Down Expand Up @@ -574,59 +561,33 @@ export class AnnotationService {
return false;
}

/**
* Get the latest comment annotation
* @param nodeId the node id
* @param componentId the component id
* @param workgroupId the workgroup id
* @param commentType (optional) the type of comment
* e.g.
* 'autoComment' for auto graded comment
* 'comment' for teacher graded comment
* 'any' for auto graded comment or teacher graded comment
* @returns the latest comment annotation
*/
getLatestCommentAnnotation(nodeId, componentId, workgroupId, commentType) {
let annotation = null;
const annotations = this.getAnnotations();

if (commentType == null) {
commentType = 'any';
}

for (let a = annotations.length - 1; a >= 0; a--) {
const tempAnnotation = annotations[a];
if (tempAnnotation != null) {
let acceptAnnotation = false;
const tempNodeId = tempAnnotation.nodeId;
const tempComponentId = tempAnnotation.componentId;
const tempToWorkgroupId = tempAnnotation.toWorkgroupId;
const tempAnnotationType = tempAnnotation.type;

if (
nodeId == tempNodeId &&
componentId == tempComponentId &&
workgroupId == tempToWorkgroupId
) {
if (
commentType === 'any' &&
(tempAnnotationType === 'autoComment' || tempAnnotationType === 'comment')
) {
acceptAnnotation = true;
} else if (commentType === 'autoComment' && tempAnnotationType === 'autoComment') {
acceptAnnotation = true;
} else if (commentType === 'comment' && tempAnnotationType === 'comment') {
acceptAnnotation = true;
}
getLatestCommentAnnotation(
nodeId: string,
componentId: string,
workgroupId: number,
commentType: 'comment' | 'autoComment' | 'any' = 'any'
): Annotation {
return (
this.getAnnotations()
.filter(
(annotation) =>
annotation.nodeId == nodeId &&
annotation.componentId == componentId &&
annotation.toWorkgroupId == workgroupId &&
this.matchesCommentType(annotation, commentType)
)
.at(-1) || null
);
}

if (acceptAnnotation) {
annotation = tempAnnotation;
break;
}
}
}
}
return annotation;
private matchesCommentType(
annotation: Annotation,
commentType: 'comment' | 'autoComment' | 'any'
): boolean {
return (
(commentType === 'any' && ['autoComment', 'comment'].includes(annotation.type)) ||
annotation.type === commentType
);
}

getScoreValueFromScoreAnnotation(scoreAnnotation: any): number {
Expand Down
6 changes: 3 additions & 3 deletions src/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -20968,21 +20968,21 @@ If this problem continues, let your teacher know and move on to the next activit
<source>Sorry, you cannot view this item yet.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/studentNodeService.ts</context>
<context context-type="linenumber">39</context>
<context context-type="linenumber">40</context>
</context-group>
</trans-unit>
<trans-unit id="2738912629247967660" datatype="html">
<source>Item Locked</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/studentNodeService.ts</context>
<context context-type="linenumber">43</context>
<context context-type="linenumber">44</context>
</context-group>
</trans-unit>
<trans-unit id="685273827497092928" datatype="html">
<source>&lt;p&gt;To visit &lt;b&gt;<x id="PH" equiv-text="nodeTitle"/>&lt;/b&gt; you need to:&lt;/p&gt;&lt;ul&gt;</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/studentNodeService.ts</context>
<context context-type="linenumber">50</context>
<context context-type="linenumber">51</context>
</context-group>
</trans-unit>
<trans-unit id="8725215606116054825" datatype="html">
Expand Down

0 comments on commit 6d32a43

Please sign in to comment.