Skip to content

Commit a708481

Browse files
refactor(ComponentNewWorkBadgeComponent): Convert to standalone (#1874)
1 parent 8208a98 commit a708481

File tree

6 files changed

+47
-49
lines changed

6 files changed

+47
-49
lines changed

src/app/classroom-monitor/component-new-work-badge/component-new-work-badge.component.ts

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,78 @@ import { Subscription } from 'rxjs';
33
import { AnnotationService } from '../../../assets/wise5/services/annotationService';
44
import { TeacherDataService } from '../../../assets/wise5/services/teacherDataService';
55
import { 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
})
1116
export 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
}

src/app/teacher/classroom-monitor.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import { StepToolsComponent } from '../../assets/wise5/common/stepTools/step-too
4242
declarations: [
4343
AlertStatusCornerComponent,
4444
ClassroomMonitorComponent,
45-
ComponentNewWorkBadgeComponent,
4645
ComponentSelectComponent,
4746
NavItemComponent,
4847
NodeInfoComponent,
@@ -63,8 +62,8 @@ import { StepToolsComponent } from '../../assets/wise5/common/stepTools/step-too
6362
ViewComponentRevisionsComponent
6463
],
6564
imports: [
66-
StudentTeacherCommonModule,
6765
ComponentGradingModule,
66+
ComponentNewWorkBadgeComponent,
6867
ComponentStudentModule,
6968
DataExportModule,
7069
GradingCommonModule,
@@ -79,7 +78,8 @@ import { StepToolsComponent } from '../../assets/wise5/common/stepTools/step-too
7978
SaveIndicatorComponent,
8079
SelectPeriodModule,
8180
StepInfoComponent,
82-
StepToolsComponent
81+
StepToolsComponent,
82+
StudentTeacherCommonModule
8383
]
8484
})
8585
export class ClassroomMonitorModule {}

src/assets/wise5/classroomMonitor/classroomMonitorComponents/milestones/milestone-workgroup-item/milestone-workgroup-item.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ <h3 class="accent-1 gray-lightest-bg component__header">
7777
[componentId]="firstComponentId"
7878
[workgroupId]="workgroupId"
7979
[nodeId]="firstNodeId"
80-
></component-new-work-badge>
80+
/>
8181
</h3>
8282
<workgroup-component-grading
8383
[componentId]="firstComponentId"
@@ -99,7 +99,7 @@ <h3 class="accent-1 gray-lightest-bg component__header">
9999
[componentId]="lastComponentId"
100100
[workgroupId]="workgroupId"
101101
[nodeId]="lastNodeId"
102-
></component-new-work-badge>
102+
/>
103103
</h3>
104104
<workgroup-component-grading
105105
[componentId]="lastComponentId"

src/assets/wise5/classroomMonitor/classroomMonitorComponents/nodeGrading/workgroup-item/workgroup-item.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ <h3 class="accent-1 gray-lightest-bg component__header">
4848
[componentId]="component.id"
4949
[workgroupId]="workgroupId"
5050
[nodeId]="nodeId"
51-
></component-new-work-badge>
51+
/>
5252
</h3>
5353
<workgroup-component-grading
5454
class="component--grading__response__content"

src/assets/wise5/classroomMonitor/classroomMonitorComponents/studentGrading/step-item/step-item.component.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ <h3 class="accent-1 strong gray-lightest-bg component__header">
4646
[componentId]="component.id"
4747
[workgroupId]="workgroupId"
4848
[nodeId]="nodeId"
49-
>
50-
</component-new-work-badge>
49+
/>
5150
</h3>
5251
<workgroup-component-grading
5352
class="component--grading__response__content"

src/messages.xlf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,7 @@ Click &quot;Cancel&quot; to keep the invalid JSON open so you can fix it.</sourc
17241724
<source>New</source>
17251725
<context-group purpose="location">
17261726
<context context-type="sourcefile">src/app/classroom-monitor/component-new-work-badge/component-new-work-badge.component.ts</context>
1727-
<context context-type="linenumber">9</context>
1727+
<context context-type="linenumber">13</context>
17281728
</context-group>
17291729
<context-group purpose="location">
17301730
<context context-type="sourcefile">src/app/classroom-monitor/step-info/step-info.component.html</context>

0 commit comments

Comments
 (0)