@@ -3,79 +3,78 @@ import { Subscription } from 'rxjs';
33import { AnnotationService } from '../../../assets/wise5/services/annotationService' ;
44import { TeacherDataService } from '../../../assets/wise5/services/teacherDataService' ;
55import { Annotation } from '../../../assets/wise5/common/Annotation' ;
6+ import { CommonModule } from '@angular/common' ;
67
78@Component ( {
9+ imports : [ CommonModule ] ,
810 selector : 'component-new-work-badge' ,
9- template : `<span *ngIf="hasNewWork" class="badge badge--info" i18n>New</span>`
11+ standalone : true ,
12+ template : `@if (hasNewWork) {
13+ <span class="badge badge--info" i18n>New</span>
14+ }`
1015} )
1116export class ComponentNewWorkBadgeComponent {
12- annotationSavedToServerSubscription : Subscription ;
13-
14- @Input ( )
15- componentId : string ;
16-
17- hasNewWork : boolean = false ;
18-
19- @Input ( )
20- nodeId : string ;
21-
22- @Input ( )
23- workgroupId : number ;
17+ @Input ( ) componentId : string ;
18+ protected hasNewWork : boolean ;
19+ @Input ( ) nodeId : string ;
20+ private subscriptions : Subscription = new Subscription ( ) ;
21+ @Input ( ) workgroupId : number ;
2422
2523 constructor (
26- private AnnotationService : AnnotationService ,
27- private TeacherDataService : TeacherDataService
24+ private annotationService : AnnotationService ,
25+ private dataService : TeacherDataService
2826 ) { }
2927
30- ngOnInit ( ) {
28+ ngOnInit ( ) : void {
3129 this . checkHasNewWork ( ) ;
32- this . annotationSavedToServerSubscription = this . AnnotationService . annotationSavedToServer$ . subscribe (
33- ( annotation : Annotation ) => {
30+ this . subscriptions . add (
31+ this . annotationService . annotationSavedToServer$ . subscribe ( ( annotation : Annotation ) => {
3432 if ( annotation . nodeId === this . nodeId && annotation . componentId === this . componentId ) {
3533 this . checkHasNewWork ( ) ;
3634 }
37- }
35+ } )
3836 ) ;
3937 }
4038
41- ngOnDestroy ( ) {
42- this . annotationSavedToServerSubscription . unsubscribe ( ) ;
39+ ngOnDestroy ( ) : void {
40+ this . subscriptions . unsubscribe ( ) ;
4341 }
4442
45- checkHasNewWork ( ) {
46- const latestComponentState = this . TeacherDataService . getLatestComponentStateByWorkgroupIdNodeIdAndComponentId (
43+ private checkHasNewWork ( ) : void {
44+ this . hasNewWork = false ;
45+ const componentState = this . dataService . getLatestComponentStateByWorkgroupIdNodeIdAndComponentId (
4746 this . workgroupId ,
4847 this . nodeId ,
4948 this . componentId
5049 ) ;
51- const latestAnnotations = this . AnnotationService . getLatestComponentAnnotations (
50+ const annotations = this . annotationService . getLatestComponentAnnotations (
5251 this . nodeId ,
5352 this . componentId ,
5453 this . workgroupId ,
55- null ,
54+ 'any' ,
5655 'comment'
5756 ) ;
58- if ( latestComponentState ) {
59- let latestTeacherComment = null ;
60- if ( latestAnnotations && latestAnnotations . comment ) {
61- latestTeacherComment = latestAnnotations . comment ;
57+ if ( componentState ) {
58+ let teacherComment = null ;
59+ if ( annotations && annotations . comment ) {
60+ teacherComment = annotations . comment ;
6261 }
63- let latestTeacherScore = null ;
64- if ( latestAnnotations && latestAnnotations . score ) {
65- if ( latestAnnotations . score . type !== 'autoScore' ) {
66- latestTeacherScore = latestAnnotations . score ;
62+ let teacherScore = null ;
63+ if ( annotations && annotations . score ) {
64+ if ( annotations . score . type !== 'autoScore' ) {
65+ teacherScore = annotations . score ;
6766 }
6867 }
69- const commentSaveTime = latestTeacherComment ? latestTeacherComment . serverSaveTime : 0 ;
70- const scoreSaveTime = latestTeacherScore ? latestTeacherScore . serverSaveTime : 0 ;
71- let latestTeacherAnnotationTime = 0 ;
68+ const commentSaveTime = teacherComment ? teacherComment . serverSaveTime : 0 ;
69+ const scoreSaveTime = teacherScore ? teacherScore . serverSaveTime : 0 ;
70+ let teacherAnnotationTime = 0 ;
7271 if ( commentSaveTime >= scoreSaveTime ) {
73- latestTeacherAnnotationTime = commentSaveTime ;
72+ teacherAnnotationTime = commentSaveTime ;
7473 } else if ( scoreSaveTime > commentSaveTime ) {
75- latestTeacherAnnotationTime = scoreSaveTime ;
74+ teacherAnnotationTime = scoreSaveTime ;
7675 }
77- let latestComponentStateTime = latestComponentState . serverSaveTime ;
78- if ( latestComponentStateTime > latestTeacherAnnotationTime ) {
76+ let componentStateTime = componentState . serverSaveTime ;
77+ if ( componentStateTime > teacherAnnotationTime ) {
7978 this . hasNewWork = true ;
8079 }
8180 }
0 commit comments