@@ -51,9 +51,8 @@ export class MatchAuthoring extends ComponentAuthoring {
5151 }
5252
5353 turnOnSubmitButtonIfFeedbackExists ( ) {
54- const show = this . componentHasFeedback ( ) ;
55- if ( show ) {
56- this . setShowSubmitButtonValue ( show ) ;
54+ if ( this . componentHasFeedback ( ) ) {
55+ this . setShowSubmitButtonValue ( true ) ;
5756 }
5857 }
5958
@@ -237,16 +236,10 @@ export class MatchAuthoring extends ComponentAuthoring {
237236 }
238237
239238 removeChoiceFromFeedback ( choiceId : string ) : void {
240- const feedback = this . authoringComponentContent . feedback ;
241- for ( const bucketFeedback of feedback ) {
242- const choices = bucketFeedback . choices ;
243- for ( let c = 0 ; c < choices . length ; c ++ ) {
244- const choice = choices [ c ] ;
245- if ( choiceId === choice . choiceId ) {
246- choices . splice ( c , 1 ) ;
247- break ;
248- }
249- }
239+ for ( const bucketFeedback of this . authoringComponentContent . feedback ) {
240+ bucketFeedback . choices = bucketFeedback . choices . filter ( ( choice ) => {
241+ return choice . choiceId !== choiceId ;
242+ } ) ;
250243 }
251244 }
252245
@@ -264,18 +257,20 @@ export class MatchAuthoring extends ComponentAuthoring {
264257 }
265258
266259 componentHasFeedback ( ) : boolean {
267- const feedback = this . authoringComponentContent . feedback ;
268- for ( const tempFeedback of feedback ) {
269- const tempChoices = tempFeedback . choices ;
270- for ( const tempChoice of tempChoices ) {
271- if ( tempChoice . isCorrect || ( tempChoice . feedback != null && tempChoice . feedback != '' ) ) {
260+ for ( const feedback of this . authoringComponentContent . feedback ) {
261+ for ( const choice of feedback . choices ) {
262+ if ( choice . isCorrect || this . isNonEmpty ( choice . feedback ) ) {
272263 return true ;
273264 }
274265 }
275266 }
276267 return false ;
277268 }
278269
270+ isNonEmpty ( str : string ) : boolean {
271+ return str != null && str != '' ;
272+ }
273+
279274 isCorrectClicked ( feedback : any ) : void {
280275 if ( ! feedback . isCorrect ) {
281276 delete feedback . position ;
@@ -286,25 +281,21 @@ export class MatchAuthoring extends ComponentAuthoring {
286281 }
287282
288283 chooseChoiceAsset ( choice : any ) : void {
289- const params = {
290- isPopup : true ,
291- nodeId : this . nodeId ,
292- componentId : this . componentId ,
293- target : 'choice' ,
294- targetObject : choice
295- } ;
296- this . openAssetChooser ( params ) ;
284+ this . openAssetChooserHelper ( 'choice' , choice ) ;
297285 }
298286
299287 chooseBucketAsset ( bucket : any ) : void {
300- const params = {
288+ this . openAssetChooserHelper ( 'bucket' , bucket ) ;
289+ }
290+
291+ openAssetChooserHelper ( target : string , targetObject : any ) : void {
292+ this . openAssetChooser ( {
301293 isPopup : true ,
302294 nodeId : this . nodeId ,
303295 componentId : this . componentId ,
304- target : 'bucket' ,
305- targetObject : bucket
306- } ;
307- this . openAssetChooser ( params ) ;
296+ target : target ,
297+ targetObject : targetObject
298+ } ) ;
308299 }
309300
310301 assetSelected ( { nodeId, componentId, assetItem, target, targetObject } ) : void {
0 commit comments