Skip to content

Commit

Permalink
Added safeguarding for qb value on wordPair deletion and save
Browse files Browse the repository at this point in the history
  • Loading branch information
dmols committed Aug 26, 2024
1 parent a3a7695 commit 2da86c8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/controllers/creator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ angular.module 'matching', ['ngAnimate']
$scope.addWordPair = (q=null, a=null, media=[0,0], id='') ->
$scope.widget.wordPairs.push {question:q, answer:a, media:media, id:id}

$scope.removeWordPair = (index) -> $scope.widget.wordPairs.splice(index, 1)
$scope.removeWordPair = (index) ->
$scope.widget.wordPairs.splice(index, 1)

# Update the question bank value if it's greater than the number of word pairs
if($scope.enableQuestionBank && $scope.questionBankVal > $scope.widget.wordPairs.length)
$scope.questionBankVal = $scope.questionBankValTemp = $scope.widget.wordPairs.length

$scope.removeAudio = (index, which) -> $scope.widget.wordPairs[index].media.splice(which, 1, 0)

Expand Down Expand Up @@ -128,11 +133,19 @@ angular.module 'matching', ['ngAnimate']
assets

_buildSaveData = ->

# Update question bank value in case it happens to be greater than the number of word pairs, to avoid errors on player side
if $scope.questionBankVal > $scope.widget.wordPairs.length then $scope.questionBankVal = $scope.questionBankValTemp = $scope.widget.wordPairs.length

_qset.items = []
_qset.options = {caseSensitive: null, enableQuestionBank: $scope.enableQuestionBank, questionBankVal: $scope.questionBankVal}
_qset.items[0] =
name: "null"
items: []

_qset.options =
enableQuestionBank: $scope.enableQuestionBank
questionBankVal: $scope.questionBankVal

wordPairs = $scope.widget.wordPairs

return false if not wordPairs.length
Expand Down

0 comments on commit 2da86c8

Please sign in to comment.