Commit 9ad009ff authored by Björn Eyselein's avatar Björn Eyselein
Browse files

Reformat learn.{ts,scala.html}

parent 367de6ac
......@@ -9,7 +9,6 @@ function readSolution(cardType: CardType): undefined | Solution {
switch (cardType) {
case 'Vocable':
case 'Text':
case 'Blank':
const solution: string = document.querySelector<HTMLInputElement>('#translation_input').value;
if (solution.length === 0) {
......@@ -18,6 +17,10 @@ function readSolution(cardType: CardType): undefined | Solution {
return {solution, selectedAnswers: []};
case 'Blank':
throw cardType;
// return {solution: '', selectedAnswers: []};
case 'Choice':
const selectedAnswers: number[] = [];
......@@ -124,7 +127,6 @@ domReady(() => {
checkSolutionBtn = document.querySelector<HTMLButtonElement>('#checkSolutionBtn');
checkSolutionUrl = checkSolutionBtn.dataset['href'];
document.addEventListener('keypress', event => {
if (event.key === 'Enter') {
if (canSolve) {
......
......@@ -4,79 +4,79 @@
implicit requestHeader: RequestHeader, messagesProvider: MessagesProvider
)
@title = @{
"Lernen"
}
@scripts = {
<script src="@routes.Assets.versioned("learn.js")"></script>
}
@title = @{
"Lernen"
}
@choiceInputType = @{
flashcard.choiceAnswers.count(_.correctness != Correctness.Wrong) match {
case 1 => "radio"
case _ => "checkbox"
@scripts = {
<script src="@routes.Assets.versioned("scripts/learn.js")"></script>
}
}
@main(title, Some(user), scripts) {
@helper.CSRF.formField
@choiceInputType = @{
flashcard.choiceAnswers.count(_.correctness != Correctness.Wrong) match {
case 1 => "radio"
case _ => "checkbox"
}
}
<div class="row">
<div class="col s12 l8 offset-l2" id="flashcardDiv" data-cardtype="@flashcard.cardType">
<div class="card-panel">
<h4 class="center-align">@flashcard.question</h4>
</div>
@main(title, Some(user), scripts) {
@helper.CSRF.formField
<p class="center-align">
<code>
Stapel: @oldAnswer.map(_.bucket).getOrElse(1), Versuche: <span id="triesSpan">@oldAnswer.map(_.tries).getOrElse(0)</span></code>
</p>
<div class="row">
<div class="col s12 l8 offset-l2" id="flashcardDiv" data-cardtype="@flashcard.cardType">
<div class="card-panel">
<h4 class="center-align">@flashcard.question</h4>
</div>
@flashcard.cardType match {
case CardType.Text | CardType.Vocable => {
<div class="row">
<div class="input-field col s12">
<input type="text" id="translation_input" autofocus autocomplete="off">
<label for="translation_input">Übersetzung</label>
</div>
</div>
}
case CardType.Blank => {
<p class="center-align">
<code>
Stapel: @oldAnswer.map(_.bucket).getOrElse(1), Versuche: <span id="triesSpan">@oldAnswer.map(_.tries).getOrElse(0)</span></code>
</p>
@for(blanksAnswer <- flashcard.blanksAnswers) {
@flashcard.cardType match {
case CardType.Text | CardType.Vocable => {
<div class="row">
<div class="input-field col s12">
<input type="text" id="blanksInput_@blanksAnswer.answerId" autofocus autocomplete="off">
<label for="blanksInput_@blanksAnswer.answerId">Übersetzung</label>
<input type="text" id="translation_input" autofocus autocomplete="off">
<label for="translation_input">Übersetzung</label>
</div>
</div>
}
}
case CardType.Choice => {
@for(answer <- scala.util.Random.shuffle(flashcard.choiceAnswers)) {
<p>
<label for="choice_@answer.answerId">
<input id="choice_@answer.answerId" name="choice_answers" type="@choiceInputType" data-choiceid="@answer.answerId">
<span>@answer.answer</span>
</label>
</p>
case CardType.Blank => {
@for(blanksAnswer <- flashcard.blanksAnswers) {
<div class="row">
<div class="input-field col s12">
<input type="text" id="blanksInput_@blanksAnswer.answerId" autofocus autocomplete="off">
<label for="blanksInput_@blanksAnswer.answerId">Übersetzung</label>
</div>
</div>
}
}
case CardType.Choice => {
@for(answer <- scala.util.Random.shuffle(flashcard.choiceAnswers)) {
<p>
<label for="choice_@answer.answerId">
<input id="choice_@answer.answerId" name="choice_answers" type="@choiceInputType" data-choiceid="@answer.answerId">
<span>@answer.answer</span>
</label>
</p>
}
}
}
}
<p id="correctionTextPar">&nbsp;</p>
<p id="correctionTextPar">&nbsp;</p>
<button class="btn btn-large waves-effect green" onclick="checkSolution();" id="checkSolutionBtn"
data-href="@routes.HomeController.checkSolution(flashcard.courseId, flashcard.collId, flashcard.cardId)">
Lösung testen
</button>
<button class="btn btn-large waves-effect @primaryColor" onclick="checkSolution();" id="checkSolutionBtn"
data-href="@routes.HomeController.checkSolution(flashcard.courseId, flashcard.collId, flashcard.cardId)">
Lösung testen
</button>
<a href="@routes.HomeController.startLearning(flashcard.courseId, flashcard.collId, isRepeating)"
id="nextFlashcardBtn" class="btn btn-large waves-effect blue disabled">Weiter</a>
<a href="@routes.HomeController.startLearning(flashcard.courseId, flashcard.collId, isRepeating)"
id="nextFlashcardBtn" class="btn btn-large waves-effect @accentColor disabled">Weiter</a>
</div>
</div>
</div>
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment