Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Question Bank Functionality #36

Merged
merged 11 commits into from
Apr 22, 2024
11 changes: 8 additions & 3 deletions src/creator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Hangman.directive('focusMe', ['$timeout', '$parse', ($timeout, $parse) ->
])

Hangman.factory 'Resource', ['$sanitize', ($sanitize) ->
buildQset: (title, items, partial, attempts, random) ->
buildQset: (title, items, partial, attempts, random, enableQuestionBank, questionBankVal) ->
qsetItems = []
qset = {}

Expand All @@ -47,7 +47,7 @@ Hangman.factory 'Resource', ['$sanitize', ($sanitize) ->
Materia.CreatorCore.cancelSave 'Word #'+(i+1)+' needs to contain at least one letter or number.'
return false

qset.options = {partial: partial, attempts: attempts, random: random}
qset.options = {partial: partial, attempts: attempts, random: random, enableQuestionBank: enableQuestionBank, questionBankVal: questionBankVal}
qset.assets = []
qset.rand = false
qset.name = title
Expand Down Expand Up @@ -97,6 +97,9 @@ Hangman.controller 'HangmanCreatorCtrl', ['$timeout', '$scope', '$sanitize', 'Re
$scope.partial = false
$scope.random = false
$scope.attempts = 5
$scope.questionBankDialog = false
$scope.enableQuestionBank = false
$scope.questionBankVal = 1

# for use with paginating results
$scope.currentPage = 0;
Expand Down Expand Up @@ -202,12 +205,14 @@ Hangman.controller 'HangmanCreatorCtrl', ['$timeout', '$scope', '$sanitize', 'Re
$scope.attempts = ~~qset.options.attempts or 5
$scope.partial = qset.options.partial
$scope.random = qset.options.random
$scope.enableQuestionBank = if qset.options.enableQuestionBank then qset.options.enableQuestionBank else false
$scope.questionBankVal = if qset.options.questionBankVal then qset.options.questionBankVal else 1
$scope.onQuestionImportComplete qset.items[0].items

$scope.$apply()

$scope.onSaveClicked = (mode = 'save') ->
qset = Resource.buildQset $sanitize($scope.title), $scope.items, $scope.partial, $scope.attempts, $scope.random
qset = Resource.buildQset $sanitize($scope.title), $scope.items, $scope.partial, $scope.attempts, $scope.random, $scope.enableQuestionBank, $scope.questionBankVal
if qset then Materia.CreatorCore.save $sanitize($scope.title), qset

$scope.onSaveComplete = (title, widget, qset, version) -> true
Expand Down
26 changes: 25 additions & 1 deletion src/creator.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<div class="logo"></div>
<h1 id="title" ng-bind="title" ng-click="showTitleDialog = true"></h1>
<div ng-click="showTitleDialog = true" class="link">Edit...</div>
<button class= "questionBankButton" ng-click="questionBankDialog = !questionBankDialog">Question Bank</button>
<span class="attempts">
<p>Incorrect guesses per phrase</p>
<div class="slide-btn">
Expand Down Expand Up @@ -169,7 +170,30 @@ <h3>Phrase</h3>
<span>{{currentPage+1}}/{{numberOfPages()}}</span>
<button ng-disabled="currentPage >= numberOfPages() - 1" ng-click="currentPage=currentPage+1">Next</button>
</div>

<div ng-show= "questionBankDialog" class="overlay"></div>
<div class="questionBankDialog-wrapper" ng-show= "questionBankDialog">
<div class="questionBankDialog">
<div class="enable-qb-question">
<strong>Enable question bank? </strong>
<div>
<span>
<input type="radio" ng-model="enableQuestionBank" ng-value=false> No</input>
<input type="radio" ng-model="enableQuestionBank" ng-value=true> Yes</input>
</span>
</div>
</div>
<div>
<span ng-show="enableQuestionBank" >
<strong>How many questions to ask? </strong>
<div>
<input class="numInput" type="number" ng-model="questionBankVal" ng-attr-min="{{items.length < 1 ? items.length : 1}}" ng-attr-max="{{items.length}}" step="1">
<span> out of {{items.length}} </span>
</div>
</span>
</div>
</div>
<button class="dialogCloseButton" ng-click="(questionBankVal <= items.length && questionBankVal > 0) && (questionBankDialog = !questionBankDialog)">Okay</button>
</div>
<div ng-show="!items.length &amp;&amp; step" class="arrow-box">
<span>Click here to add your first question</span>
</div>
Expand Down
59 changes: 59 additions & 0 deletions src/creator.scss
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,14 @@ button.add-question {
top: 28px;
background: #fff;
}

.questionBankButton {
position: absolute;
background-color: #5a5a5a;
right: 550px;
top: 35px;
}

.attempts {
position: absolute;
right: 355px;
Expand Down Expand Up @@ -772,6 +780,57 @@ button.add-question {
}
}

.questionBankDialog-wrapper {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: 5px solid greenyellow;
border-radius: 5px;
background-color: white;
color: black;
height: 300px;
width: 250px;
z-index: 10000;
display: flex;
justify-content: center;
align-items: center;

.questionBankDialog {
margin: 15px;

.numInput {
width: 30px;
margin-top: 10px;
}

.enable-qb-question {
margin-top: 15px;
margin-bottom: 15px;
}

}

.dialogCloseButton {
position: absolute;
bottom: 10px;
background-color: rgb(26, 244, 171);
color: black;
}

}

// To blur the background while the dialog is open
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 9000;
backdrop-filter: blur(5px);
}

.question-tip {
position: absolute;
right: 28px;
Expand Down
12 changes: 10 additions & 2 deletions src/player.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ HangmanEngine.controller 'HangmanEngineCtrl', ['$scope', '$timeout', 'Parse', 'R
Hangman.Draw.playAnimation 'torso', 'pander'
$scope.anvilStage = 1

$scope.prepareQuestionBank = (qsetArr, questionBankVal) ->
return _shuffle(qsetArr.items).slice(0, questionBankVal)

$scope.startQuestion = ->

$scope.$apply ->
Expand Down Expand Up @@ -323,10 +326,10 @@ HangmanEngine.controller 'HangmanEngineCtrl', ['$scope', '$timeout', 'Parse', 'R
$scope.max = Reset.attempts ~~_qset.options.attempts
$scope.keyboard = Reset.keyboard()
), 500


_shuffle = (a) ->
for i in [1...a.length]
for i in [0...a.length]
j = Math.floor Math.random() * (a.length)
[a[i], a[j]] = [a[j], a[i]]
a
Expand All @@ -344,6 +347,11 @@ HangmanEngine.controller 'HangmanEngineCtrl', ['$scope', '$timeout', 'Parse', 'R
if _qset.options.random
_qset.items[0].items = _shuffle _qset.items[0].items

if(_qset.options.random and _qset.options.enableQuestionBank)
_qset.items[0].items = _qset.items[0].items.slice(0, _qset.options.questionBankVal)
else if(qset.options.enableQuestionBank)
_qset.items[0].items = window.scope.prepareQuestionBank(qset.items[0], qset.options.questionBankVal)

$scope.total = _qset.items[0].items.length
$scope.max = Reset.attempts ~~_qset.options.attempts
$scope.keyboard = Reset.keyboard()
Expand Down
Loading