Skip to content

Commit ba94664

Browse files
refactor(NodeComponent): Convert to standalone (#1888)
1 parent bac6e61 commit ba94664

File tree

8 files changed

+125
-138
lines changed

8 files changed

+125
-138
lines changed

src/app/student/vle/student-vle.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { ProjectService } from '../../../assets/wise5/services/projectService';
1414
import { StudentDataService } from '../../../assets/wise5/services/studentDataService';
1515
import { NavigationComponent } from '../../../assets/wise5/themes/default/navigation/navigation.component';
1616
import { StepToolsComponent } from '../../../assets/wise5/themes/default/themeComponents/stepTools/step-tools.component';
17-
import { NodeModule } from '../../../assets/wise5/vle/node/node.module';
1817
import { StudentAssetsDialogModule } from '../../../assets/wise5/vle/studentAsset/student-assets-dialog/student-assets-dialog.module';
1918
import { VLEComponent } from '../../../assets/wise5/vle/vle.component';
2019
import { VLEProjectService } from '../../../assets/wise5/vle/vleProjectService';
@@ -34,6 +33,7 @@ import { StudentPeerGroupService } from '../../../assets/wise5/services/studentP
3433
import { PeerGroupService } from '../../../assets/wise5/services/peerGroupService';
3534
import { TopBarComponent } from '../top-bar/top-bar.component';
3635
import { NodeStatusIconComponent } from '../../../assets/wise5/themes/default/themeComponents/nodeStatusIcon/node-status-icon.component';
36+
import { NodeComponent } from '../../../assets/wise5/vle/node/node.component';
3737

3838
@NgModule({
3939
declarations: [
@@ -50,7 +50,7 @@ import { NodeStatusIconComponent } from '../../../assets/wise5/themes/default/th
5050
ComponentStudentModule,
5151
MatDialogModule,
5252
NavigationComponent,
53-
NodeModule,
53+
NodeComponent,
5454
NodeStatusIconComponent,
5555
RunEndedAndLockedMessageComponent,
5656
SimpleDialogModule,

src/assets/wise5/vle/node/node.component.html

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,64 @@
44
style="border-color: {{ nodeStatus?.icon?.color }}; position: relative;"
55
fxLayout="row wrap"
66
>
7-
<div
8-
*ngIf="showRubric"
9-
class="node-content__rubric"
10-
fxLayout="row"
11-
fxLayoutAlign="center center"
12-
>
13-
<help-icon [content]="node.rubric" label="Step Info" i18n-label icon="info" />
14-
</div>
15-
<div
16-
*ngFor="let component of components"
17-
id="component_{{ component.id }}"
18-
class="component"
19-
fxFlex="100"
20-
fxFlex.gt-sm="{{ component.componentWidth ? component.componentWidth : 100 }}"
21-
>
22-
<component
23-
*ngIf="componentToVisible[component.id]"
24-
[nodeId]="node.id"
25-
[componentId]="component.id"
26-
[componentState]="getComponentStateByComponentId(component.id)"
27-
[workgroupId]="workgroupId"
28-
(saveComponentStateEvent)="saveComponentState($event)"
29-
/>
30-
</div>
7+
@if (showRubric) {
8+
<div class="node-content__rubric" fxLayout="row" fxLayoutAlign="center center">
9+
<help-icon [content]="node.rubric" label="Step Info" i18n-label icon="info" />
10+
</div>
11+
}
12+
@for (component of components; track component.id) {
13+
<div
14+
id="component_{{ component.id }}"
15+
class="component"
16+
fxFlex="100"
17+
fxFlex.gt-sm="{{ component.componentWidth ? component.componentWidth : 100 }}"
18+
>
19+
@if (componentToVisible[component.id]) {
20+
<component
21+
[nodeId]="node.id"
22+
[componentId]="component.id"
23+
[componentState]="getComponentStateByComponentId(component.id)"
24+
[workgroupId]="workgroupId"
25+
(saveComponentStateEvent)="saveComponentState($event)"
26+
/>
27+
}
28+
</div>
29+
}
3130
<div
3231
class="node-content__actions"
3332
fxLayout="row"
3433
fxLayoutAlign="start center"
3534
fxLayoutGap="12px"
3635
>
37-
<button
38-
*ngIf="node.showSaveButton"
39-
mat-raised-button
40-
color="primary"
41-
(click)="saveButtonClicked()"
42-
[disabled]="isDisabled || !dirtyComponentIds.length"
43-
aria-label="Save"
44-
i18n-aria-label
45-
i18n
46-
>
47-
Save
48-
</button>
49-
<button
50-
*ngIf="node.showSubmitButton"
51-
mat-raised-button
52-
color="primary"
53-
(click)="submitButtonClicked()"
54-
[disabled]="isDisabled || !dirtySubmitComponentIds.length"
55-
aria-label="Submit"
56-
i18n-aria-label
57-
i18n
58-
>
59-
Submit
60-
</button>
61-
<component-state-info
62-
*ngIf="latestComponentState && (node.showSaveButton || node.showSubmitButton)"
63-
[componentState]="latestComponentState"
64-
></component-state-info>
36+
@if (node.showSaveButton) {
37+
<button
38+
mat-raised-button
39+
color="primary"
40+
(click)="save()"
41+
[disabled]="disabled || !dirtyComponentIds.length"
42+
aria-label="Save"
43+
i18n-aria-label
44+
i18n
45+
>
46+
Save
47+
</button>
48+
}
49+
@if (node.showSubmitButton) {
50+
<button
51+
mat-raised-button
52+
color="primary"
53+
(click)="submit()"
54+
[disabled]="disabled || !dirtySubmitComponentIds.length"
55+
aria-label="Submit"
56+
i18n-aria-label
57+
i18n
58+
>
59+
Submit
60+
</button>
61+
}
62+
@if (latestComponentState && (node.showSaveButton || node.showSubmitButton)) {
63+
<component-state-info [componentState]="latestComponentState" />
64+
}
6565
</div>
6666
</div>
6767
</div>

src/assets/wise5/vle/node/node.component.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { provideHttpClientTesting } from '@angular/common/http/testing';
21
import { ComponentFixture, TestBed } from '@angular/core/testing';
3-
import { MatDialogModule } from '@angular/material/dialog';
42
import { ConfigService } from '../../services/configService';
53
import { StudentDataService } from '../../services/studentDataService';
64
import { VLEProjectService } from '../vleProjectService';
@@ -15,9 +13,8 @@ let fixture: ComponentFixture<NodeComponent>;
1513
describe('NodeComponent', () => {
1614
beforeEach(async () => {
1715
await TestBed.configureTestingModule({
18-
declarations: [NodeComponent],
19-
imports: [MatDialogModule, StudentTeacherCommonServicesModule],
20-
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()]
16+
imports: [NodeComponent, StudentTeacherCommonServicesModule],
17+
providers: [provideHttpClient(withInterceptorsFromDi())]
2118
}).compileComponents();
2219
});
2320

src/assets/wise5/vle/node/node.component.ts

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,41 @@ import { SessionService } from '../../services/sessionService';
1313
import { StudentDataService } from '../../services/studentDataService';
1414
import { VLEProjectService } from '../vleProjectService';
1515
import { copy } from '../../common/object/object';
16+
import { CommonModule } from '@angular/common';
17+
import { FlexLayoutModule } from '@angular/flex-layout';
18+
import { ComponentComponent } from '../../components/component/component.component';
19+
import { MatButtonModule } from '@angular/material/button';
20+
import { ComponentStateInfoComponent } from '../../common/component-state-info/component-state-info.component';
21+
import { HelpIconComponent } from '../../themes/default/themeComponents/helpIcon/help-icon.component';
1622

1723
@Component({
24+
imports: [
25+
CommonModule,
26+
ComponentComponent,
27+
ComponentStateInfoComponent,
28+
FlexLayoutModule,
29+
HelpIconComponent,
30+
MatButtonModule
31+
],
1832
selector: 'node',
19-
templateUrl: './node.component.html',
20-
styleUrls: ['./node.component.scss']
33+
standalone: true,
34+
styleUrl: './node.component.scss',
35+
templateUrl: './node.component.html'
2136
})
2237
export class NodeComponent implements OnInit {
23-
autoSaveInterval: number = 60000; // in milliseconds;
24-
autoSaveIntervalId: any;
25-
components: any[];
26-
componentToVisible = {};
27-
dirtyComponentIds: any = [];
28-
dirtySubmitComponentIds: any = [];
29-
isDisabled: boolean;
38+
private autoSaveInterval: number = 60000; // in milliseconds;
39+
private autoSaveIntervalId: any;
40+
protected components: any[];
41+
protected componentToVisible = {};
42+
protected dirtyComponentIds: any = [];
43+
protected dirtySubmitComponentIds: any = [];
44+
protected disabled: boolean;
45+
protected latestComponentState: ComponentState;
3046
@Input() node: Node;
31-
nodeContent: any;
32-
nodeStatus: any;
33-
latestComponentState: ComponentState;
34-
showRubric: boolean;
35-
submit: boolean = false;
36-
subscriptions: Subscription = new Subscription();
37-
teacherWorkgroupId: number;
38-
workComponents: string[] = [
47+
protected nodeStatus: any;
48+
protected showRubric: boolean;
49+
private subscriptions: Subscription = new Subscription();
50+
private workComponents: string[] = [
3951
'Animation',
4052
'AudioOscillator',
4153
'ConceptMap',
@@ -52,7 +64,7 @@ export class NodeComponent implements OnInit {
5264
'Summary',
5365
'Table'
5466
];
55-
workgroupId: number;
67+
protected workgroupId: number;
5668

5769
constructor(
5870
private componentService: ComponentService,
@@ -72,8 +84,7 @@ export class NodeComponent implements OnInit {
7284

7385
ngOnInit(): void {
7486
this.workgroupId = this.configService.getWorkgroupId();
75-
this.teacherWorkgroupId = this.configService.getTeacherWorkgroupId();
76-
this.isDisabled = !this.configService.isRunActive();
87+
this.disabled = !this.configService.isRunActive();
7788

7889
this.initializeNode();
7990
this.startAutoSaveInterval();
@@ -82,18 +93,15 @@ export class NodeComponent implements OnInit {
8293
this.subscriptions.add(
8394
this.studentDataService.componentSaveTriggered$.subscribe(({ nodeId, componentId }) => {
8495
if (nodeId == this.node.id && this.node.hasComponent(componentId)) {
85-
const isAutoSave = false;
86-
this.createAndSaveComponentData(isAutoSave, componentId);
96+
this.createAndSaveComponentData(false, componentId);
8797
}
8898
})
8999
);
90100

91101
this.subscriptions.add(
92102
this.studentDataService.componentSubmitTriggered$.subscribe(({ nodeId, componentId }) => {
93103
if (nodeId == this.node.id && this.node.hasComponent(componentId)) {
94-
const isAutoSave = false;
95-
const isSubmit = true;
96-
this.createAndSaveComponentData(isAutoSave, componentId, isSubmit);
104+
this.createAndSaveComponentData(false, componentId, true);
97105
}
98106
})
99107
);
@@ -155,9 +163,8 @@ export class NodeComponent implements OnInit {
155163
);
156164
}
157165

158-
initializeNode(): void {
166+
private initializeNode(): void {
159167
this.clearLatestComponentState();
160-
this.nodeContent = this.projectService.getNodeById(this.node.id);
161168
this.components = this.getComponents();
162169
this.nodeStatus = this.nodeStatusService.getNodeStatusByNodeId(this.node.id);
163170
this.dirtyComponentIds = [];
@@ -178,7 +185,8 @@ export class NodeComponent implements OnInit {
178185
this.showRubric = this.node.rubric != null && this.node.rubric != '';
179186
}
180187

181-
const script = this.nodeContent.script;
188+
const nodeContent = this.projectService.getNodeById(this.node.id);
189+
const script = nodeContent.script;
182190
if (script != null) {
183191
this.projectService.retrieveScript(script).then((script: string) => {
184192
new Function(script).call(this);
@@ -198,21 +206,18 @@ export class NodeComponent implements OnInit {
198206
this.subscriptions.unsubscribe();
199207
}
200208

201-
saveButtonClicked(): void {
202-
const isAutoSave = false;
203-
this.createAndSaveComponentData(isAutoSave);
209+
protected save(): void {
210+
this.createAndSaveComponentData(false);
204211
}
205212

206-
submitButtonClicked(): void {
213+
protected submit(): void {
207214
this.nodeService.broadcastNodeSubmitClicked({ nodeId: this.node.id });
208-
const isAutoSave = false;
209-
const isSubmit = true;
210-
this.createAndSaveComponentData(isAutoSave, null, isSubmit);
215+
this.createAndSaveComponentData(false, null, true);
211216
}
212217

213218
private getComponents(): any[] {
214219
return this.node.components.map((component) => {
215-
if (this.isDisabled) {
220+
if (this.disabled) {
216221
component.isDisabled = true;
217222
}
218223
return component;
@@ -226,8 +231,7 @@ export class NodeComponent implements OnInit {
226231
private startAutoSaveInterval(): void {
227232
this.autoSaveIntervalId = setInterval(() => {
228233
if (this.dirtyComponentIds.length) {
229-
const isAutoSave = true;
230-
this.createAndSaveComponentData(isAutoSave);
234+
this.createAndSaveComponentData(true);
231235
}
232236
}, this.autoSaveInterval);
233237
}
@@ -247,7 +251,7 @@ export class NodeComponent implements OnInit {
247251
* that needs saving
248252
*/
249253
private createAndSaveComponentData(
250-
isAutoSave,
254+
isAutoSave: boolean,
251255
componentId = null,
252256
isSubmit = null
253257
): Promise<any> {
@@ -256,7 +260,11 @@ export class NodeComponent implements OnInit {
256260
);
257261
}
258262

259-
private createComponentStatesResponseHandler(isAutoSave, componentId = null, isSubmit = null) {
263+
private createComponentStatesResponseHandler(
264+
isAutoSave: boolean,
265+
componentId: string = null,
266+
isSubmit: boolean = null
267+
) {
260268
return (componentStates) => {
261269
const componentAnnotations = this.getAnnotationsFromComponentStates(componentStates);
262270
componentStates.forEach((componentState: any) => {
@@ -400,7 +408,7 @@ export class NodeComponent implements OnInit {
400408
): any {
401409
componentState.runId = this.configService.getRunId();
402410
componentState.periodId = this.configService.getPeriodId();
403-
componentState.workgroupId = this.configService.getWorkgroupId();
411+
componentState.workgroupId = this.workgroupId;
404412
componentState.isAutoSave = isAutoSave === true;
405413
componentState.isSubmit ??= isSubmit;
406414
}
@@ -429,7 +437,7 @@ export class NodeComponent implements OnInit {
429437
}
430438
}
431439

432-
getComponentStateByComponentId(componentId: string): any {
440+
protected getComponentStateByComponentId(componentId: string): any {
433441
return this.studentDataService.getLatestComponentStateByNodeIdAndComponentId(
434442
this.node.id,
435443
componentId
@@ -444,7 +452,7 @@ export class NodeComponent implements OnInit {
444452
);
445453
}
446454

447-
saveComponentState($event: any): Promise<any> {
455+
protected saveComponentState($event: any): Promise<any> {
448456
return Promise.all([$event.componentStatePromise]).then(
449457
this.createComponentStatesResponseHandler(true)
450458
);

src/assets/wise5/vle/node/node.module.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)