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

Small refactorings

parent df324dc1
......@@ -41,6 +41,8 @@ interface Flashcard {
front: string;
frontHint: string | undefined;
back: string;
backHint: string | undefined;
frontToBack: boolean;
......
......@@ -31,21 +31,26 @@ function buildChoiceAnswers(choiceAnswers: ChoiceAnswer[]): string {
</p>`.trim()).join('\n');
}
function updateQuestionText(flashcard: Flashcard): void {
let questionText = flashcard.front;
if (flashcard.frontHint !== undefined) {
questionText += ` <i>${flashcard.frontHint}</i>`;
}
function updateView(flashcard: Flashcard): void {
document.querySelector<HTMLHeadingElement>('#questionDiv').innerHTML = questionText;
}
console.info(JSON.stringify(flashcard, null, 2));
function updateView(flashcard: Flashcard): void {
// Update question text
let questionText: string;
if (flashcard.frontToBack) {
questionText = flashcard.front + (flashcard.frontHint !== undefined ? ` <i>${flashcard.frontHint}</i>` : '');
} else {
questionText = flashcard.back + (flashcard.backHint !== undefined ? ` <i>${flashcard.backHint}</i>` : '');
}
updateQuestionText(flashcard);
console.warn(questionText);
document.querySelector<HTMLHeadingElement>('#questionDiv').innerHTML = questionText;
// Update tries counter
document.querySelector<HTMLSpanElement>('#triesSpan').innerText = flashcard.currentTries.toFixed(0);
// Update bucket counter
if (flashcard.currentBucket !== undefined) {
document.querySelector<HTMLSpanElement>('#bucketSpan').innerText = flashcard.currentBucket.toFixed(0);
} else {
......
......@@ -11,6 +11,8 @@ final case class FlashcardToAnswer(
cardType: CardType,
front: String,
frontHint: Option[String],
back: String,
backHint: Option[String],
frontToBack: Boolean,
blanksAnswerFragments: Seq[BlanksAnswerFragment] = Seq.empty,
choiceAnswers: Seq[ChoiceAnswer] = Seq.empty,
......
......@@ -80,16 +80,20 @@ case object Correctness extends PlayEnum[Correctness] {
}
final case class FlashcardIdentifier(cardId: Int, collId: Int, courseId: Int) {
def asString = s"$courseId.$collId.$cardId"
}
// User answered flashcard
final case class UserAnsweredFlashcard(username: String, cardId: Int, collId: Int, courseId: Int, cardType: CardType,
bucket: Int, dateAnswered: LocalDate, correct: Boolean, wrongTries: Int, frontToBack: Boolean) {
final case class UserAnsweredFlashcard(
username: String,
cardId: Int,
collId: Int,
courseId: Int,
cardType: CardType,
bucket: Int,
dateAnswered: LocalDate,
correct: Boolean,
wrongTries: Int,
frontToBack: Boolean
) {
lazy val isActive: Boolean = dateAnswered.until(LocalDate.now(), ChronoUnit.DAYS) < Math.pow(3, bucket - 1)
......
......@@ -29,9 +29,6 @@ trait CoursesCollectionsFlashcardsTableQueries {
def futureCourseById(id: Int): Future[Option[Course]] = db.run(coursesTQ.filter(_.id === id).result.headOption)
// def futureCourseByShortName(shortName: String): Future[Option[Course]] =
// db.run(coursesTQ.filter(_.shortName === shortName).result.headOption)
def futureInsertCourse(course: Course): Future[Boolean] = db.run(coursesTQ += course).transform(_ == 1, identity)
......
......@@ -86,7 +86,6 @@ class TableDefs @Inject()(override protected val dbConfigProvider: DatabaseConfi
class FlashcardsToLearnView(tag: Tag) extends FlashcardToDoView(tag, "flashcards_to_learn")
class FlashcardsToRepeatView(tag: Tag) extends FlashcardToDoView(tag, "flashcards_to_repeat")
}
......@@ -42,13 +42,12 @@ trait TableQueries {
for {
maybeOldAnswer <- futureUserAnswerForFlashcard(user, cardId, collId, courseId, frontToBack)
} yield {
val frontToSend = if (frontToBack) front else back
val frontHintToSend = if (frontToBack) frontHint else backHint
FlashcardToAnswer(
cardId, collId, courseId, cardType,
frontToSend,
frontHintToSend,
front,
frontHint,
back,
backHint,
frontToBack,
blanksAnswerFragments,
choiceAnswers,
......
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