Commit 3c60525b authored by Björn Eyselein's avatar Björn Eyselein
Browse files

Fix ts for new model

parent daa6d26c
......@@ -71,7 +71,7 @@ final case class Flashcard(
case _ => JsError()
})
def backs: Seq[String] = convertFromJson(frontsJson, {
def backs: Seq[String] = convertFromJson(backsJson, {
case JsString(value) => JsSuccess(value)
case _ => JsError()
})
......
......@@ -25,7 +25,7 @@
<div class="row">
@for(flashcard <- flashcardGroup) {
<div class="col m@colWidth s12">
<div class="card-panel">@flashcard.cardId: @flashcard.fs</div>
<div class="card-panel">@flashcard.cardId: @flashcard.fronts</div>
</div>
}
</div>
......
@import model.{User, Flashcard, CardType, Collection}
@import model.{User, Flashcard, CardType, Collection, Consts}
@(user: User, courseId: Int, collection: Collection, cards: Seq[Flashcard], readErrors: Seq[String])
@title = @{
"Vorschau importierte Karteikarten"
}
@title = @{
"Vorschau importierte Karteikarten"
}
@cardsPerRow = @{
3
}
@cardsPerRow = @{
3
}
@colWidth = @{
12 / cardsPerRow
}
@colWidth = @{
12 / cardsPerRow
}
@main(title, Some(user)) {
@if(cards.nonEmpty) {
@main(title, Some(user)) {
@if(cards.nonEmpty) {
<div class="row">
<div class="col s12">
<a href="@routes.AdminController.collectionAdmin(courseId, collection.id)" class="btn btn-large waves-effect waves-block @accentColor">
Zurück zur Sammlung
</a>
<div class="row">
<div class="col s12">
<a href="@routes.AdminController.collectionAdmin(courseId, collection.id)" class="btn btn-large waves-effect waves-block @accentColor">
Zurück zur Sammlung
</a>
</div>
</div>
</div>
@for(completeCardGroup <- cards.grouped(cardsPerRow)) {
<div class="row">
@for(completeCard <- completeCardGroup) {
<div class="col m@colWidth s12">
<div class="card-panel">
<p><b>ID</b>:
@completeCard.cardId</p>
<p><b>Vorderseite</b>: @completeCard.fronts</p>
<p><b>Hinwies Vorderseite:</b>
@completeCard.frontHint.map(fh => Html(s"<i>$fh</i>")).getOrElse("--")</p>
@completeCard.cardType match {
case CardType.Word | CardType.Text => {
<p>
<b>Rückseite</b>: @completeCard.backs
</p>
<p>
<b>Hinwies Rückseite:</b>
@completeCard.backHint.map(fh => Html(s"<i>$fh</i>")).getOrElse("--")
</p>
}
case CardType.Blank => {
<hr>
@for(flashcardGroup <- cards.grouped(cardsPerRow)) {
<div class="row">
@for(flashcard <- flashcardGroup) {
<div class="col m@colWidth s12">
<div class="card-panel">
<p>
<b>ID</b>:
@flashcard.cardId
</p>
<div>
<b>Vorderseite</b>: @flashcard.fronts.mkString(Consts.multipleSolutionsSplitChar)
</div>
<p>
<b>Hinwies Vorderseite:</b>
@flashcard.frontHint.map(fh => Html(s"<i>$fh</i>")).getOrElse("--")
</p>
@flashcard.cardType match {
case CardType.Word | CardType.Text => {
<div>
<b>Rückseite</b>: @flashcard.backs.mkString(Consts.multipleSolutionsSplitChar)
</div>
<p>
<b>Hinwies Rückseite:</b>
@flashcard.backHint.map(fh => Html(s"<i>$fh</i>")).getOrElse("--")
</p>
}
case CardType.Blank => {
<hr>
@for(answer <- completeCard.blanksAnswerFragments) {
<p>@answer.answer</p>
@for(answer <- flashcard.blanksAnswerFragments) {
<p>@answer.answer</p>
}
}
}
case CardType.Choice => {
<hr>
@for(answerGroup <- completeCard.choiceAnswers.grouped(2)) {
<div class="row">
@for(answer <- answerGroup) {
<div class="col m6 s12">
<b>@if(answer.correctness != model.Correctness.Wrong) {
+
} else {
-
}</b>
@answer.answer
</div>
case CardType.Choice => {
<hr>
@for(answerGroup <- flashcard.choiceAnswers.grouped(2)) {
<div class="row">
@for(answer <- answerGroup) {
<div class="col m6 s12">
<b>@if(answer.correctness != model.Correctness.Wrong) {
+
} else {
-
}</b>
@answer.answer
</div>
}
</div>
}
</div>
}
}
}
</div>
</div>
}
</div>
}
</div>
}
} else {
<p class="red-text">Konnte keine Karteikarten importieren!</p>
} else {
<p class="red-text">Konnte keine Karteikarten importieren!</p>
}
}
}
......@@ -2,46 +2,46 @@
@(user: User, courseId: Int, collection: Collection, flashcardCount: Int, toLearnCount: Int)
@alreadyLearnedCount = @{
flashcardCount - toLearnCount
}
@alreadyLearnedCount = @{
flashcardCount - toLearnCount
}
@progress = @{
Math.round(alreadyLearnedCount * 100 / flashcardCount.toDouble) + "%"
}
@progress = @{
s"${Math.round(alreadyLearnedCount * 100 / flashcardCount.toDouble)}%"
}
@title = @{
s"Sammlung '${collection.name}'"
}
@title = @{
s"Sammlung '${collection.name}'"
}
@main(title, Some(user)) {
<h4 class="center-align">@title</h4>
@main(title, Some(user)) {
<h4 class="center-align">@title</h4>
<hr>
<hr>
<p>Diese Sammlung enthält insgesamt @flashcardCount Karteikarten.</p>
<p>Diese Sammlung enthält insgesamt @flashcardCount Karteikarten.</p>
<p>
@if(toLearnCount == 0) {
Sie haben alle Karteikarten gelernt.
} else {
Es existieren noch @toLearnCount neue Karteikarten.
}
</p>
<p>
@if(toLearnCount == 0) {
Sie haben alle Karteikarten gelernt.
} else {
Es existieren noch @toLearnCount neue Karteikarten.
}
</p>
<br>
<br>
<h5 class="center-align">Fortschritt</h5>
<h5 class="center-align">Fortschritt</h5>
<p class="center">@alreadyLearnedCount / @flashcardCount</p>
<p class="center">@alreadyLearnedCount / @flashcardCount</p>
<div class="progress">
<div class="determinate" style="width: @progress"></div>
</div>
<div class="progress">
<div class="determinate" style="width: @progress"></div>
</div>
<br>
<br>
@if(toLearnCount > 0) {
<a href="@routes.HomeController.learn(courseId, collection.id)" class="btn btn-block @accentColor">Lernen</a>
}
@if(toLearnCount > 0) {
<a href="@routes.HomeController.learn(courseId, collection.id)" class="btn btn-block @accentColor">Lernen</a>
}
}
......@@ -211,16 +211,12 @@ function checkSolution(): void {
}
function updateReadQuestionButton(readQuestionButton: HTMLButtonElement): void {
const numOfFoundVoices: number = window.speechSynthesis.getVoices().length;
if (numOfFoundVoices > 0) {
console.info("Found " + numOfFoundVoices + " voices!");
if (window.speechSynthesis.getVoices().length > 0) {
readQuestionButton.classList.remove('hide');
readQuestionButton.disabled = false;
readQuestionButton.onclick = () => {
const toRead: string[] = currentFlashcard.frontToBack ? currentFlashcard.flashcard.fronts : currentFlashcard.flashcard.backs;
const toRead: string[] = currentFlashcard.frontToBack ? currentFlashcard.flashcard.frontsJson : currentFlashcard.flashcard.backsJson;
toRead.forEach((front) => {
const utterance = new SpeechSynthesisUtterance(front);
......@@ -228,8 +224,6 @@ function updateReadQuestionButton(readQuestionButton: HTMLButtonElement): void {
window.speechSynthesis.speak(utterance);
});
};
} else {
console.warn("Could not find any voices for Speech synthesis!");
}
}
......
......@@ -39,14 +39,13 @@ interface Flashcard {
cardType: CardType;
fronts: string[];
frontsJson: string[];
frontHint: string | undefined;
backs: string[];
backsJson: string[];
backHint: string | undefined;
blanksAnswers: BlanksAnswerFragment[];
choiceAnswers: ChoiceAnswer[];
blanksAnswerFragmentsJson: BlanksAnswerFragment[];
choiceAnswersJson: ChoiceAnswer[];
}
interface FlashcardToAnswer {
......
......@@ -41,9 +41,9 @@ function updateView(flashcard: FlashcardToAnswer): void {
// Update question text
let questionText: string;
if (flashcard.frontToBack) {
questionText = flashcard.flashcard.fronts.join('/') + (flashcard.flashcard.frontHint !== undefined ? ` <i>${flashcard.flashcard.frontHint}</i>` : '');
questionText = flashcard.flashcard.frontsJson.join('/') + (flashcard.flashcard.frontHint !== undefined ? ` <i>${flashcard.flashcard.frontHint}</i>` : '');
} else {
questionText = flashcard.flashcard.backs.join('/') + (flashcard.flashcard.backHint !== undefined ? ` <i>${flashcard.flashcard.backHint}</i>` : '');
questionText = flashcard.flashcard.backsJson.join('/') + (flashcard.flashcard.backHint !== undefined ? ` <i>${flashcard.flashcard.backHint}</i>` : '');
}
document.querySelector<HTMLHeadingElement>('#questionDiv').innerHTML = questionText;
......@@ -62,16 +62,16 @@ function updateView(flashcard: FlashcardToAnswer): void {
switch (flashcard.flashcard.cardType) {
case 'Text':
case 'Word' :
answerDiv.innerHTML = buildTextAnswerInput(flashcard.frontToBack ? flashcard.flashcard.backs : flashcard.flashcard.fronts);
answerDiv.innerHTML = buildTextAnswerInput(flashcard.frontToBack ? flashcard.flashcard.backsJson : flashcard.flashcard.frontsJson);
document.querySelector<HTMLInputElement>('#translation_input_0').focus();
break;
case 'Blank':
answerDiv.innerHTML = buildAnswerFragments(flashcard.flashcard.blanksAnswers);
answerDiv.innerHTML = buildAnswerFragments(flashcard.flashcard.blanksAnswerFragmentsJson);
break;
case 'Choice':
answerDiv.innerHTML = buildChoiceAnswers(flashcard.flashcard.choiceAnswers);
answerDiv.innerHTML = buildChoiceAnswers(flashcard.flashcard.choiceAnswersJson);
break;
}
}
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