diff --git a/src/assets/wise5/components/dialogGuidance/FeedbackRule.ts b/src/assets/wise5/components/dialogGuidance/FeedbackRule.ts index 9ea6793a5a2..98a54c4a7ab 100644 --- a/src/assets/wise5/components/dialogGuidance/FeedbackRule.ts +++ b/src/assets/wise5/components/dialogGuidance/FeedbackRule.ts @@ -4,6 +4,14 @@ export class FeedbackRule { feedback: string | string[]; static operatorPrecedences = { '!': 2, '&&': 1, '||': 1 }; + constructor(jsonObject: any = {}) { + for (const key of Object.keys(jsonObject)) { + if (jsonObject[key] != null) { + this[key] = jsonObject[key]; + } + } + } + static isSecondToLastSubmitRule(feedbackRule: FeedbackRule): boolean { return feedbackRule.expression === 'isSecondToLastSubmit'; } diff --git a/src/assets/wise5/components/dialogGuidance/dialog-guidance-authoring/dialog-guidance-authoring.component.html b/src/assets/wise5/components/dialogGuidance/dialog-guidance-authoring/dialog-guidance-authoring.component.html index 060aa5b6274..e3d72c6cce7 100644 --- a/src/assets/wise5/components/dialogGuidance/dialog-guidance-authoring/dialog-guidance-authoring.component.html +++ b/src/assets/wise5/components/dialogGuidance/dialog-guidance-authoring/dialog-guidance-authoring.component.html @@ -17,6 +17,8 @@ - + diff --git a/src/assets/wise5/components/dialogGuidance/dialogGuidanceService.ts b/src/assets/wise5/components/dialogGuidance/dialogGuidanceService.ts index 002e45673e3..f68dce40036 100644 --- a/src/assets/wise5/components/dialogGuidance/dialogGuidanceService.ts +++ b/src/assets/wise5/components/dialogGuidance/dialogGuidanceService.ts @@ -23,6 +23,7 @@ export class DialogGuidanceService extends ComponentService { component.feedbackRules = []; component.isComputerAvatarEnabled = false; component.computerAvatarSettings = this.getDefaultComputerAvatarSettings(); + component.version = 2; return component; } diff --git a/src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html b/src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html index 99986ec1559..17060f4729d 100644 --- a/src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html +++ b/src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html @@ -18,20 +18,60 @@ {{ruleIndex + 1}} drag_indicator - + Expression - - Feedback - + + + + + Feedback + 1" i18n>Feedback #{{feedbackIndex + 1}} + - + 1" + matTooltip="Delete feedback" + i18n-matTooltip + matTooltipPosition="before" + (click)="deleteFeedbackInRule(rule, feedbackIndex)"> + clear + + + + add_circle + + + + + + Feedback + + + + + { let fixture: ComponentFixture; beforeEach(async () => { await TestBed.configureTestingModule({ + imports: [UpgradeModule], declarations: [EditDialogGuidanceFeedbackRulesComponent], - providers: [{ provide: TeacherProjectService, useClass: MockTeacherProjectService }], + providers: [ + { provide: TeacherProjectService, useClass: MockTeacherProjectService }, + UtilService + ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); - }); - - beforeEach(() => { fixture = TestBed.createComponent(EditDialogGuidanceFeedbackRulesComponent); component = fixture.componentInstance; + component.version = 2; component.feedbackRules = [ - { expression: 'idea1', feedback: 'you hit idea1' }, - { expression: 'idea2', feedback: 'you hit idea2' } + new FeedbackRule({ id: '1111111111', expression: 'idea1', feedback: [feedbackString1] }), + new FeedbackRule({ id: '2222222222', expression: 'idea2', feedback: [feedbackString2] }) ]; nodeChangedSpy = spyOn(TestBed.inject(TeacherProjectService), 'nodeChanged'); fixture.detectChanges(); @@ -35,6 +43,8 @@ describe('EditDialogGuidanceFeedbackRulesComponent', () => { deleteRule(); moveUp(); moveDown(); + addNewFeedbackToRule(); + deleteFeedbackInRule(); }); function addNewRule() { @@ -50,12 +60,36 @@ function addNewRule() { expectFeedbackExpressions(['idea1', 'idea2', '']); expect(nodeChangedSpy).toHaveBeenCalled(); }); + + it('should create new rule with feedback version 1', () => { + component.version = 1; + component.feedbackRules = []; + component.addNewRule('beginning'); + expect(component.feedbackRules.length).toEqual(1); + const feedbackRule = component.feedbackRules[0]; + expect(feedbackRule.expression).toEqual(''); + expect(feedbackRule.feedback).toEqual(''); + expect(nodeChangedSpy).toHaveBeenCalled(); + }); + + it('should create new rule with feedback version 2', () => { + component.version = 2; + component.feedbackRules = []; + component.addNewRule('beginning'); + expect(component.feedbackRules.length).toEqual(1); + const feedbackRule = component.feedbackRules[0]; + expect(typeof feedbackRule.id).toEqual('string'); + expect(feedbackRule.expression).toEqual(''); + expect(feedbackRule.feedback).toEqual(['']); + expect(nodeChangedSpy).toHaveBeenCalled(); + }); }); } function deleteRule() { describe('deleteRule()', () => { it('should delete rule at specified index', () => { + spyOn(window, 'confirm').and.returnValue(true); component.deleteRule(0); expectFeedbackExpressions(['idea2']); expect(nodeChangedSpy).toHaveBeenCalled(); @@ -89,3 +123,27 @@ function expectFeedbackExpressions(expectedExpressionsInOrder: string[]): void { expect(component.feedbackRules[i].expression).toEqual(expectedExpressionsInOrder[i]); } } + +function addNewFeedbackToRule() { + describe('addNewFeedbackToRule', () => { + it('should add new feedback to rule', () => { + component.addNewFeedbackToRule(component.feedbackRules[0]); + expect(component.feedbackRules[0].feedback).toEqual([feedbackString1, '']); + }); + }); +} + +function deleteFeedbackInRule() { + describe('deleteFeedbackInRule', () => { + it('should delete feedback in rule', () => { + spyOn(window, 'confirm').and.returnValue(true); + const feedbackRule = new FeedbackRule({ + expression: '', + feedback: ['Hello', 'World'], + id: '1234567890' + }); + component.deleteFeedbackInRule(feedbackRule, 1); + expect(feedbackRule.feedback).toEqual(['Hello']); + }); + }); +} diff --git a/src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.ts b/src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.ts index 63e130216fb..5db6985d90a 100644 --- a/src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.ts +++ b/src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.ts @@ -3,6 +3,8 @@ import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; import { Subject, Subscription } from 'rxjs'; import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; import { TeacherProjectService } from '../../../services/teacherProjectService'; +import { UtilService } from '../../../services/utilService'; +import { FeedbackRule } from '../FeedbackRule'; @Component({ selector: 'edit-dialog-guidance-feedback-rules', @@ -10,11 +12,12 @@ import { TeacherProjectService } from '../../../services/teacherProjectService'; styleUrls: ['./edit-dialog-guidance-feedback-rules.component.scss'] }) export class EditDialogGuidanceFeedbackRulesComponent implements OnInit { - @Input() feedbackRules: any = []; + @Input() feedbackRules: FeedbackRule[] = []; inputChanged: Subject = new Subject(); subscriptions: Subscription = new Subscription(); + @Input() version: number; - constructor(private ProjectService: TeacherProjectService) {} + constructor(private ProjectService: TeacherProjectService, private utilService: UtilService) {} ngOnInit(): void { this.subscriptions.add( @@ -46,7 +49,7 @@ export class EditDialogGuidanceFeedbackRulesComponent implements OnInit { } addNewRule(position: string): void { - const newFeedbackRule = { expression: '', feedback: '' }; + const newFeedbackRule = this.createNewFeedbackRule(); if (position === 'beginning') { this.feedbackRules.unshift(newFeedbackRule); } else { @@ -55,8 +58,34 @@ export class EditDialogGuidanceFeedbackRulesComponent implements OnInit { this.ProjectService.nodeChanged(); } - deleteRule(ruleIndex: number): void { - this.feedbackRules.splice(ruleIndex, 1); + private createNewFeedbackRule(): any { + if (this.version === 1) { + return { expression: '', feedback: '' }; + } else { + return { id: this.utilService.generateKey(10), expression: '', feedback: [''] }; + } + } + + addNewFeedbackToRule(rule: FeedbackRule): void { + (rule.feedback as string[]).push(''); this.ProjectService.nodeChanged(); } + + deleteFeedbackInRule(rule: FeedbackRule, feedbackIndex: number): void { + if (confirm($localize`Are you sure you want to delete this feedback?`)) { + (rule.feedback as string[]).splice(feedbackIndex, 1); + this.ProjectService.nodeChanged(); + } + } + + deleteRule(ruleIndex: number): void { + if (confirm($localize`Are you sure you want to delete this feedback rule?`)) { + this.feedbackRules.splice(ruleIndex, 1); + this.ProjectService.nodeChanged(); + } + } + + customTrackBy(index: number): number { + return index; + } } diff --git a/src/messages.xlf b/src/messages.xlf index 5d8228c8aca..fe94df771da 100644 --- a/src/messages.xlf +++ b/src/messages.xlf @@ -11972,21 +11972,21 @@ Category Name: Discuss your answer with a thought buddy! src/assets/wise5/components/dialogGuidance/dialogGuidanceService.ts - 33 + 34 Hi there! It's nice to meet you. What do you think about... src/assets/wise5/components/dialogGuidance/dialogGuidanceService.ts - 34 + 35 Thought Buddy src/assets/wise5/components/dialogGuidance/dialogGuidanceService.ts - 39 + 40 @@ -12140,7 +12140,11 @@ Category Name: Feedback src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html - 27 + 36 + + + src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html + 66 src/assets/wise5/components/match/match-authoring/match-authoring.component.html @@ -12151,32 +12155,74 @@ Category Name: 199 + + Feedback # + + src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html + 37 + + + + Delete feedback + + src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html + 46 + + + + Add new feedback + + src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html + 55 + + + + add_circle + + src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html + 60 + + Delete rule src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html - 39 + 79 Move up src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html - 48 + 88 Move down src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html - 56 + 96 Add a new rule at the end src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.html - 69 + 109 + + + + Are you sure you want to delete this feedback? + + src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.ts + 75 + + + + Are you sure you want to delete this feedback rule? + + src/assets/wise5/components/dialogGuidance/edit-dialog-guidance-feedback-rules/edit-dialog-guidance-feedback-rules.component.ts + 82