From e4f2a73538facd5f29ce3f0131866dd723d6b84f Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Tue, 26 Nov 2024 15:04:06 -0800 Subject: [PATCH] Add starter choices for MC authoring --- .../services/multipleChoiceService.spec.ts | 10 ++++---- .../wise5/components/multipleChoice/Choice.ts | 9 +++++++- .../multiple-choice-authoring.component.ts | 9 ++------ .../multipleChoice/multipleChoiceService.ts | 12 ++++++---- src/messages.xlf | 23 ++++++++++++++++++- 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/app/services/multipleChoiceService.spec.ts b/src/app/services/multipleChoiceService.spec.ts index 8436185bb72..43bcfda25bd 100644 --- a/src/app/services/multipleChoiceService.spec.ts +++ b/src/app/services/multipleChoiceService.spec.ts @@ -26,8 +26,8 @@ let componentId1: string = 'abcdefghij'; describe('MultipleChoiceService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [], - providers: [ + imports: [], + providers: [ AnnotationService, ConfigService, MultipleChoiceService, @@ -37,8 +37,8 @@ describe('MultipleChoiceService', () => { TagService, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting() - ] -}); + ] + }); service = TestBed.inject(MultipleChoiceService); choice1 = createChoice(choiceId1, choiceText1, '', false); choice2 = createChoice(choiceId2, choiceText2, '', false); @@ -58,7 +58,7 @@ function createComponent() { const component = service.createComponent(); expect(component.type).toEqual('MultipleChoice'); expect(component.choiceType).toEqual('radio'); - expect(component.choices).toEqual([]); + expect(component.choices.length).toEqual(2); expect(component.showFeedback).toEqual(true); }); } diff --git a/src/assets/wise5/components/multipleChoice/Choice.ts b/src/assets/wise5/components/multipleChoice/Choice.ts index b67cb81099e..9efd95b19b2 100644 --- a/src/assets/wise5/components/multipleChoice/Choice.ts +++ b/src/assets/wise5/components/multipleChoice/Choice.ts @@ -1,6 +1,13 @@ -export interface Choice { +export class Choice { feedbackToShow: string; id: string; isCorrect: boolean; text: string; + + constructor(id: string, text: string, isCorrect: boolean, feedbackToShow: string) { + this.id = id; + this.text = text; + this.isCorrect = isCorrect; + this.feedbackToShow = feedbackToShow; + } } diff --git a/src/assets/wise5/components/multipleChoice/multiple-choice-authoring/multiple-choice-authoring.component.ts b/src/assets/wise5/components/multipleChoice/multiple-choice-authoring/multiple-choice-authoring.component.ts index 7c42677139e..07fe3236d98 100644 --- a/src/assets/wise5/components/multipleChoice/multiple-choice-authoring/multiple-choice-authoring.component.ts +++ b/src/assets/wise5/components/multipleChoice/multiple-choice-authoring/multiple-choice-authoring.component.ts @@ -18,6 +18,7 @@ import { FlexLayoutModule } from '@angular/flex-layout'; import { EditComponentPrompt } from '../../../../../app/authoring-tool/edit-component-prompt/edit-component-prompt.component'; import { TranslatableAssetChooserComponent } from '../../../authoringTool/components/translatable-asset-chooser/translatable-asset-chooser.component'; import { TranslatableInputComponent } from '../../../authoringTool/components/translatable-input/translatable-input.component'; +import { Choice } from '../Choice'; @Component({ imports: [ @@ -80,13 +81,7 @@ export class MultipleChoiceAuthoring extends AbstractComponentAuthoring { } protected addChoice(): void { - const newChoice = { - id: generateRandomKey(), - text: '', - feedback: '', - isCorrect: false - }; - this.componentContent.choices.push(newChoice); + this.componentContent.choices.push(new Choice(generateRandomKey(), '', false, '')); this.componentChanged(); } diff --git a/src/assets/wise5/components/multipleChoice/multipleChoiceService.ts b/src/assets/wise5/components/multipleChoice/multipleChoiceService.ts index 3f139e7852b..902cd798f04 100644 --- a/src/assets/wise5/components/multipleChoice/multipleChoiceService.ts +++ b/src/assets/wise5/components/multipleChoice/multipleChoiceService.ts @@ -1,8 +1,8 @@ -'use strict'; - import { ComponentService } from '../componentService'; import { Injectable } from '@angular/core'; import { arraysContainSameValues } from '../../common/array/array'; +import { Choice } from './Choice'; +import { generateRandomKey } from '../../common/string/string'; @Injectable() export class MultipleChoiceService extends ComponentService { @@ -10,11 +10,15 @@ export class MultipleChoiceService extends ComponentService { return $localize`Multiple Choice`; } - createComponent() { + createComponent(): any { const component: any = super.createComponent(); component.type = 'MultipleChoice'; + component.prompt = $localize`Choose an option from below`; component.choiceType = 'radio'; - component.choices = []; + component.choices = [ + new Choice(generateRandomKey(), $localize`Choice 1`, false, ''), + new Choice(generateRandomKey(), $localize`Choice 2`, false, '') + ]; component.showFeedback = true; return component; } diff --git a/src/messages.xlf b/src/messages.xlf index a90c4c1bcd6..b466772fe4d 100644 --- a/src/messages.xlf +++ b/src/messages.xlf @@ -19593,7 +19593,7 @@ Warning: This will delete all existing choices and buckets in this component. src/assets/wise5/components/multipleChoice/multiple-choice-authoring/multiple-choice-authoring.component.ts - 94 + 89 @@ -19829,6 +19829,27 @@ Warning: This will delete all existing choices in this component. 25,28 + + Choose an option from below + + src/assets/wise5/components/multipleChoice/multipleChoiceService.ts + 16 + + + + Choice 1 + + src/assets/wise5/components/multipleChoice/multipleChoiceService.ts + 19 + + + + Choice 2 + + src/assets/wise5/components/multipleChoice/multipleChoiceService.ts + 20 + + Students type a response to a question or prompt.