Skip to content

Commit

Permalink
feat(Constraint Removal Authoring): Filter MC components (#1227)
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima authored May 4, 2023
1 parent 7d7933a commit bb19b00
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@
<mat-option [value]="''">
<span class="red" i18n>Please Choose a Component</span>
</mat-option>
<mat-option
<ng-container
*ngFor="let component of getComponents(criteria.params.nodeId); index as componentIndex"
[value]="component.id"
>
<span i18n
>{{ componentIndex + 1 }}. {{ component.type }} (Prompt: {{ component.prompt }})</span
>
</mat-option>
<mat-option *ngIf="componentIdToIsSelectable[component.id]" [value]="component.id">
<span i18n
>{{ componentIndex + 1 }}. {{ component.type }} (Prompt: {{ component.prompt }})</span
>
</mat-option>
</ng-container>
</mat-select>
</mat-form-field>
<required-error-label *ngIf="criteria.params.componentId === ''"> </required-error-label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ describe('EditConstraintRemovalCriteriaComponent', () => {
});

beforeEach(() => {
removalCriteria = [
{
name: '',
params: {}
}
];
removalCriteria = {
name: '',
params: {}
};
component.criteria = removalCriteria;
component.constraint = new Constraint({
id: 'node1Constraint1',
action: '',
removalConditional: 'any',
removalCriteria: removalCriteria
removalCriteria: [removalCriteria]
});
component.node = { id: 'node1' };
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import { MultipleChoiceContent } from '../../../components/multipleChoice/Multip
templateUrl: './edit-constraint-removal-criteria.component.html'
})
export class EditConstraintRemovalCriteriaComponent implements OnInit {
@Input() constraint: any;
@Input() criteria: any;
@Input() node: any;
nodeIds: string[];

private allNodeIds: string[];
private componentIdToIsSelectable: { [componentId: string]: boolean } = {};
private componentParam: RemovalCriteriaParam = new RemovalCriteriaParam(
'componentId',
$localize`Component`
);
@Input() constraint: any;
@Input() criteria: any;
@Input() node: any;
nodeIds: string[];
private stepParam: RemovalCriteriaParam = new RemovalCriteriaParam('nodeId', $localize`Step`);

protected removalCriteria = [
Expand Down Expand Up @@ -81,7 +82,20 @@ export class EditConstraintRemovalCriteriaComponent implements OnInit {
constructor(private projectService: TeacherProjectService) {}

ngOnInit(): void {
this.nodeIds = this.projectService.getFlattenedProjectAsNodeIds(true);
this.allNodeIds = this.projectService.getFlattenedProjectAsNodeIds(true);
this.setNodeIds();
this.calculateSelectableComponents();
}

private setNodeIds(): void {
this.nodeIds =
this.criteria.name === 'choiceChosen'
? this.allNodeIds.filter((nodeId) =>
this.projectService
.getNode(nodeId)
.components.some((component) => component.type === 'MultipleChoice')
)
: this.allNodeIds;
}

deleteRemovalCriteria(): void {
Expand All @@ -102,6 +116,8 @@ export class EditConstraintRemovalCriteriaComponent implements OnInit {
criteria.params[value] = this.node.id;
}
}
this.setNodeIds();
this.calculateSelectableComponents();
this.saveProject();
}

Expand All @@ -116,9 +132,23 @@ export class EditConstraintRemovalCriteriaComponent implements OnInit {

protected nodeIdChanged(criteria: any): void {
criteria.params.componentId = '';
this.calculateSelectableComponents();
this.saveProject();
}

private calculateSelectableComponents(): void {
const components = this.projectService.getComponents(this.criteria.params.nodeId);
if (this.criteria.name === 'choiceChosen') {
components.forEach((component) => {
this.componentIdToIsSelectable[component.id] = component.type === 'MultipleChoice';
});
} else {
components.forEach((component) => {
this.componentIdToIsSelectable[component.id] = true;
});
}
}

protected getNodePosition(nodeId: string): string {
return this.projectService.getNodePositionById(nodeId);
}
Expand Down
16 changes: 8 additions & 8 deletions src/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -9017,43 +9017,43 @@ Click &quot;Cancel&quot; to keep the invalid JSON open so you can fix it.</sourc
<source>Please Select a From Step</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/constraint/edit-constraint-removal-criteria/edit-constraint-removal-criteria.component.html</context>
<context context-type="linenumber">84</context>
<context context-type="linenumber">85</context>
</context-group>
</trans-unit>
<trans-unit id="20cee39940010d8e8bd5c2bf5871a1e6bf445356" datatype="html">
<source>Please Select a To Step</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/constraint/edit-constraint-removal-criteria/edit-constraint-removal-criteria.component.html</context>
<context context-type="linenumber">106</context>
<context context-type="linenumber">107</context>
</context-group>
</trans-unit>
<trans-unit id="337685d80c312b75cbb9b507173f51f559c7f4ae" datatype="html">
<source>Please Select a Choice</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/constraint/edit-constraint-removal-criteria/edit-constraint-removal-criteria.component.html</context>
<context context-type="linenumber">177</context>
<context context-type="linenumber">178</context>
</context-group>
</trans-unit>
<trans-unit id="331a731f82078e496dfeddc5399c38bd40f7ffaa" datatype="html">
<source><x id="INTERPOLATION" equiv-text="{{ param.text }}"/></source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/constraint/edit-constraint-removal-criteria/edit-constraint-removal-criteria.component.html</context>
<context context-type="linenumber">222</context>
<context context-type="linenumber">223</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/constraint/edit-constraint-removal-criteria/edit-constraint-removal-criteria.component.html</context>
<context context-type="linenumber">245</context>
<context context-type="linenumber">246</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/constraint/edit-constraint-removal-criteria/edit-constraint-removal-criteria.component.html</context>
<context context-type="linenumber">268</context>
<context context-type="linenumber">269</context>
</context-group>
</trans-unit>
<trans-unit id="5847302460276630595" datatype="html">
<source>Component</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/constraint/edit-constraint-removal-criteria/edit-constraint-removal-criteria.component.ts</context>
<context context-type="linenumber">21</context>
<context context-type="linenumber">17</context>
</context-group>
</trans-unit>
<trans-unit id="8980375993935541237" datatype="html">
Expand Down Expand Up @@ -9259,7 +9259,7 @@ Click &quot;Cancel&quot; to keep the invalid JSON open so you can fix it.</sourc
<source>Are you sure you want to delete this removal criteria?</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/authoringTool/constraint/edit-constraint-removal-criteria/edit-constraint-removal-criteria.component.ts</context>
<context context-type="linenumber">88</context>
<context context-type="linenumber">101</context>
</context-group>
</trans-unit>
<trans-unit id="8564983557318479146" datatype="html">
Expand Down

0 comments on commit bb19b00

Please sign in to comment.