Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(AnnotationService): Move isThereAnyScoreAnnotation() to NodeInfo #1484

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ComponentTypeService } from '../../../../services/componentTypeService'
import { TeacherDataService } from '../../../../services/teacherDataService';
import { TeacherProjectService } from '../../../../services/teacherProjectService';
import { ComponentFactory } from '../../../../common/ComponentFactory';
import { isMatchingPeriods } from '../../../../common/period/period';

@Component({
selector: 'node-info',
Expand Down Expand Up @@ -49,7 +50,7 @@ export class NodeInfoComponent {
component.hasScoresSummary = this.summaryService.isScoresSummaryAvailableForComponentType(
component.type
);
component.hasScoreAnnotation = this.annotationService.isThereAnyScoreAnnotation(
component.hasScoreAnnotation = this.hasScoreAnnotation(
this.nodeId,
component.id,
this.periodId
Expand All @@ -66,6 +67,15 @@ export class NodeInfoComponent {
}
}

private hasScoreAnnotation(nodeId: string, componentId: string, periodId: number): boolean {
return this.annotationService
.getAnnotationsByNodeIdComponentId(nodeId, componentId)
.some((annotation) => {
isMatchingPeriods(annotation.periodId, periodId) &&
['score', 'autoScore'].includes(annotation.type);
});
}

private componentHasCorrectAnswer(component: any): boolean {
const service = this.componentServiceLookupService.getService(component.type);
return service.componentHasCorrectAnswer(component);
Expand Down
33 changes: 9 additions & 24 deletions src/assets/wise5/services/annotationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ProjectService } from './projectService';
import { ConfigService } from './configService';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, Subject } from 'rxjs';
import { isMatchingPeriods } from '../common/period/period';
import { generateRandomKey } from '../common/string/string';
import { Annotation } from '../common/Annotation';

Expand All @@ -32,6 +31,12 @@ export class AnnotationService {
return this.annotations.find((annotation) => annotation.id === annotationId) || null;
}

getAnnotationsByNodeIdComponentId(nodeId: string, componentId: string): Annotation[] {
return this.annotations.filter(
(annotation) => annotation.nodeId === nodeId && annotation.componentId === componentId
);
}

/**
* Get the latest annotation with the given params
* @param params an object containing the params to match
Expand Down Expand Up @@ -515,13 +520,10 @@ export class AnnotationService {
scoreType: 'score' | 'autoScore' | 'any' = 'any'
): Annotation {
return (
this.getAnnotations()
this.getAnnotationsByNodeIdComponentId(nodeId, componentId)
.filter(
(annotation) =>
annotation.nodeId == nodeId &&
annotation.componentId == componentId &&
annotation.toWorkgroupId == workgroupId &&
this.matchesScoreType(annotation, scoreType)
annotation.toWorkgroupId == workgroupId && this.matchesScoreType(annotation, scoreType)
)
.at(-1) || null
);
Expand All @@ -537,33 +539,16 @@ export class AnnotationService {
);
}

isThereAnyScoreAnnotation(nodeId, componentId, periodId) {
const annotations = this.getAnnotations();
for (const annotation of annotations) {
if (
annotation.nodeId === nodeId &&
annotation.componentId === componentId &&
isMatchingPeriods(annotation.periodId, periodId) &&
this.isScoreOrAutoScore(annotation)
) {
return true;
}
}
return false;
}

getLatestCommentAnnotation(
nodeId: string,
componentId: string,
workgroupId: number,
commentType: 'comment' | 'autoComment' | 'any' = 'any'
): Annotation {
return (
this.getAnnotations()
this.getAnnotationsByNodeIdComponentId(nodeId, componentId)
.filter(
(annotation) =>
annotation.nodeId == nodeId &&
annotation.componentId == componentId &&
annotation.toWorkgroupId == workgroupId &&
this.matchesCommentType(annotation, commentType)
)
Expand Down
Loading