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

Small updates, add script for docker moodle

parent 4534170d
......@@ -8,7 +8,7 @@ ADD --chown=wuekabel:wuekabel target/universal/wuekabel.tgz /home/wuekabel/
WORKDIR /home/wuekabel/wuekabel
COPY --chown=wuekabel:wuekabel conf/docker_entrypoint.sh .
COPY --chown=wuekabel:wuekabel other_resources/docker_entrypoint.sh .
EXPOSE 9000
......
......@@ -63,14 +63,13 @@ function readSolution(cardType: string): Solution | null {
function onCorrectionSuccess(result: CorrectionResult): void {
// console.info(JSON.stringify(result, null, 2));
correctionTextPar.text('Ihre Lösung war ' + (result.correct ? '' : 'nicht ') + 'korrekt.');
correctionTextPar.text('Ihre Lösung war ' + (result.correct ? '' : 'nicht ') + 'korrekt.')
.removeClass(result.correct ? 'red-text' : 'green-text').addClass(result.correct ? 'green-text' : 'red-text');
if (result.correct) {
checkSolutionBtn.prop('disabled', true);
checkSolutionBtn.prop('disabled', result.correct);
if (result.correct) {
$('#nextFlashcardBtn').removeClass('disabled');
} else {
}
switch (result.cardType) {
......
......@@ -2,10 +2,9 @@ package controllers
import javax.inject.{Inject, Singleton}
import model._
import play.api.libs.json.{JsError, JsSuccess}
import play.api.mvc._
import scala.concurrent.ExecutionContext
import scala.concurrent.{ExecutionContext, Future}
@Singleton
class HomeController @Inject()(cc: ControllerComponents, protected val tableDefs: TableDefs)(implicit protected val ec: ExecutionContext)
......@@ -64,48 +63,36 @@ class HomeController @Inject()(cc: ControllerComponents, protected val tableDefs
}
def startLearning(langId: Int, collId: Int): EssentialAction =
def startLearning(langId: Int, collId: Int, isRepeating: Boolean): EssentialAction =
futureWithUserAndCollection(adminRightsRequired = false, langId, collId) { (user, _, collection) =>
implicit request =>
tableDefs.futureMaybeIdentifierNextFlashcardToLearn(user, collection) map {
case None => Redirect(routes.HomeController.collection(langId, collId))
case Some(identifier) => Redirect(routes.HomeController.learn(identifier.langId, identifier.collId, identifier.cardId))
}
}
def learn(langId: Int, collId: Int, cardId: Int): EssentialAction =
withUserAndCompleteFlashcard(adminRightsRequired = false, langId, collId, cardId) { (user, _, _, completeFlashcard) =>
implicit request => Ok(views.html.learn(user, completeFlashcard, isRepeating = false))
}
val futureFlashcard = if (isRepeating)
tableDefs.futureMaybeIdentifierNextFlashcardToRepeat(user, collection)
else
tableDefs.futureMaybeIdentifierNextFlashcardToLearn(user, collection)
def startRepeating(langId: Int, collId: Int): EssentialAction =
futureWithUserAndCollection(adminRightsRequired = false, langId, collId) { (user, _, collection) =>
implicit request =>
tableDefs.futureMaybeIdentifierNextFlashcardToRepeat(user, collection) map {
futureFlashcard map {
case None => Redirect(routes.HomeController.collection(langId, collId))
case Some(identifier) => Redirect(routes.HomeController.repeat(identifier.langId, identifier.collId, identifier.cardId))
case Some(identifier) => Redirect(routes.HomeController.learn(identifier.langId, identifier.collId, identifier.cardId, isRepeating))
}
}
def repeat(langId: Int, collId: Int, cardId: Int): EssentialAction =
def learn(langId: Int, collId: Int, cardId: Int, isRepeating: Boolean): EssentialAction =
withUserAndCompleteFlashcard(adminRightsRequired = false, langId, collId, cardId) { (user, _, _, completeFlashcard) =>
implicit request => Ok(views.html.learn(user, completeFlashcard, isRepeating = false))
implicit request => Ok(views.html.learn(user, completeFlashcard, isRepeating))
}
def checkSolution(langId: Int, collId: Int, cardId: Int): EssentialAction =
futureWithUserAndCompleteFlashcard(adminRightsRequired = false, langId, collId, cardId) { (user, _, _, completeFlashcard) =>
implicit request =>
request.body.asJson match {
case None => ???
case Some(json) => JsonFormats.solutionFormat.reads(json) match {
case JsError(_) => ???
case JsSuccess(solution, _) =>
val correctionResult = Corrector.correct(completeFlashcard, solution)
tableDefs.futureInsertOrUpdateUserAnswer(user, completeFlashcard.flashcard, correctionResult.correct) map {
_ => Ok(JsonFormats.correctionResultWrites.writes(correctionResult))
}
}
request.body.asJson flatMap (json => JsonFormats.solutionFormat.reads(json).asOpt) match {
case None => Future(BadRequest("Could not read solution..."))
case Some(solution) =>
val correctionResult = Corrector.correct(completeFlashcard, solution)
tableDefs.futureInsertOrUpdateUserAnswer(user, completeFlashcard.flashcard, correctionResult.correct) map {
_ => Ok(JsonFormats.correctionResultWrites.writes(correctionResult))
}
}
}
......
......@@ -2,48 +2,47 @@
@(user: User, language: Language, collection: Collection, flashcardCount: Int, toLearnCount: Int, toRepeatCount: Int)
@title = {
Sammlung '@collection.name'
}
@main(title.toString(), Some(user)) {
<h2 class="center-align">@title</h2>
<hr>
<h5 class="center-align">Diese Sammlung enthält insgesamt @flashcardCount Karteikarten.</h5>
<br>
<div class="row">
<div class="col s12">
@if(toLearnCount == 0) {
<a class="btn btn-large waves-effect waves-block white">
<span class="green-text">Sie haben alle Karteikarten gelernt.</span>
</a>
} else {
<a href="@routes.HomeController.startLearning(language.id, collection.id)"
class="btn btn-large waves-effect waves-block red">
Es existieren noch @toLearnCount neue Karteikarten.
</a>
}
@title = @{
s"Sammlung '${collection.name}'"
}
@main(title, Some(user)) {
<h2 class="center-align">@title</h2>
<hr>
<h5 class="center-align">Diese Sammlung enthält insgesamt @flashcardCount Karteikarten.</h5>
<br>
<div class="row">
<div class="col s12">
@if(toLearnCount == 0) {
<a class="btn btn-large waves-effect waves-block white">
<span class="green-text">Sie haben alle Karteikarten gelernt.</span>
</a>
} else {
<a href="@routes.HomeController.startLearning(language.id, collection.id, isRepeating = false)"
class="btn btn-large waves-effect waves-block red">
Es existieren noch @toLearnCount neue Karteikarten.
</a>
}
</div>
</div>
</div>
<div class="row">
<div class="col s12">
@if(toRepeatCount == 0) {
<a class="btn btn-large waves-effect waves-block white">
<span class="green-text">Sie haben alle Karteikarten wiederholt.</span>
</a>
} else {
<a href="@routes.HomeController.startRepeating(language.id, collection.id)"
class="btn btn-large waves-effect waves-block red">
Es existieren noch @toRepeatCount nicht wiederholte Karteikarten.
</a>
}
<div class="row">
<div class="col s12">
@if(toRepeatCount == 0) {
<a class="btn btn-large waves-effect waves-block white">
<span class="green-text">Sie haben alle Karteikarten wiederholt.</span>
</a>
} else {
<a href="@routes.HomeController.startLearning(language.id, collection.id, isRepeating = true)"
class="btn btn-large waves-effect waves-block red">
Es existieren noch @toRepeatCount nicht wiederholte Karteikarten.
</a>
}
</div>
</div>
</div>
}
\ No newline at end of file
}
\ No newline at end of file
......@@ -37,9 +37,6 @@
<label for="translation_input">Übersetzung</label>
</div>
</div>
<p id="correctionTextPar">&nbsp;</p>
}
case CardType.SingleChoice | CardType.MultipleChoice => {
@for(answer <- scala.util.Random.shuffle(completeFlashcard.choiceAnswers)) {
......@@ -53,6 +50,8 @@
}
}
<p id="correctionTextPar">&nbsp;</p>
</section>
<br>
......@@ -62,12 +61,7 @@
data-href="@routes.HomeController.checkSolution(completeFlashcard.flashcard.langId, completeFlashcard.flashcard.collId, completeFlashcard.flashcard.id)">
Lösung testen
</button>
<a
@if(isRepeating) {
href="@routes.HomeController.startRepeating(completeFlashcard.flashcard.langId, completeFlashcard.flashcard.collId)"
} else {
href="@routes.HomeController.startLearning(completeFlashcard.flashcard.langId, completeFlashcard.flashcard.collId)"
}
<a href="@routes.HomeController.startLearning(completeFlashcard.flashcard.langId, completeFlashcard.flashcard.collId, isRepeating)"
id="nextFlashcardBtn" class="btn btn-large waves-effect blue disabled">Weiter</a>
</div>
}
......
# Routes
GET / controllers.HomeController.index
GET / controllers.HomeController.index
# User management
GET /registerForm controllers.LoginController.registerForm
POST /register controllers.LoginController.register
GET /loginForm controllers.LoginController.loginForm
POST /login controllers.LoginController.login
GET /logout controllers.LoginController.logout
GET /registerForm controllers.LoginController.registerForm
POST /register controllers.LoginController.register
GET /loginForm controllers.LoginController.loginForm
POST /login controllers.LoginController.login
GET /logout controllers.LoginController.logout
# Languages
GET /languages controllers.HomeController.allLanguages
GET /languages/:langId controllers.HomeController.language(langId: Int)
GET /languages controllers.HomeController.allLanguages
GET /languages/:langId controllers.HomeController.language(langId: Int)
GET /selectLanguage/:langId controllers.HomeController.selectLanguage(langId: Int)
GET /deselectLanguage/:langId controllers.HomeController.deselectLanguage(langId: Int)
GET /selectLanguage/:langId controllers.HomeController.selectLanguage(langId: Int)
GET /deselectLanguage/:langId controllers.HomeController.deselectLanguage(langId: Int)
GET /languages/:langId/collections/:collId controllers.HomeController.collection(langId: Int, collId: Int)
GET /languages/:langId/collections/:collId controllers.HomeController.collection(langId: Int, collId: Int)
GET /languages/:langId/collections/:collId/startLearning controllers.HomeController.startLearning(langId: Int, collId: Int)
GET /languages/:langId/collections/:collId/cards/:cardId/learn controllers.HomeController.learn(langId: Int, collId: Int, cardId:Int)
GET /languages/:langId/collections/:collId/startLearning/:isRepeating controllers.HomeController.startLearning(langId: Int, collId: Int, isRepeating: Boolean)
GET /languages/:langId/collections/:collId/startRepeating controllers.HomeController.startRepeating(langId: Int, collId: Int)
GET /languages/:langId/collections/:collId/cards/:cardId/repeat controllers.HomeController.repeat(langId: Int, collId: Int, cardId:Int)
GET /languages/:langId/collections/:collId/cards/:cardId/learn/:isRepeating controllers.HomeController.learn(langId: Int, collId: Int, cardId:Int, isRepeating: Boolean)
POST /languages/:langId/collections/:collId/cards/:cardId/checkSolution controllers.HomeController.checkSolution(langId:Int, collId: Int, cardId: Int)
#GET /languages/:langId/collections/:collId/cards/:cardId/repeat controllers.HomeController.repeat(langId: Int, collId: Int, cardId:Int)
POST /languages/:langId/collections/:collId/cards/:cardId/checkSolution controllers.HomeController.checkSolution(langId:Int, collId: Int, cardId: Int)
# Admin routes
GET /admin controllers.AdminController.index
GET /admin controllers.AdminController.index
POST /newLanguage controllers.AdminController.newLanguage
POST /newLanguage controllers.AdminController.newLanguage
GET /languages/:langId/admin controllers.AdminController.languageAdmin(langId: Int)
GET /languages/:langId/admin controllers.AdminController.languageAdmin(langId: Int)
POST /languages/:langId/newCollection controllers.AdminController.newCollection(langId: Int)
POST /languages/:langId/newCollection controllers.AdminController.newCollection(langId: Int)
GET /languages/:langId/collections/:collId/admin controllers.AdminController.collectionAdmin(langId: Int, collId: Int)
GET /languages/:langId/collections/:collId/admin controllers.AdminController.collectionAdmin(langId: Int, collId: Int)
POST /languages/:langId/collection/:collId/uploadCardsFile controllers.AdminController.uploadCardsFile(langId: Int, collId: Int)
POST /languages/:langId/collection/:collId/uploadCardsFile controllers.AdminController.uploadCardsFile(langId: Int, collId: Int)
#GET /languages/:langId/collections/:collId/importForm controllers.AdminController.importForm(langId: Int, collId: Int)
#GET /languages/:langId/collections/:collId/import controllers.AdminController.performImport(langId: Int, collId: Int)
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
......@@ -5,7 +5,7 @@ services:
image: mariadb
restart: always
volumes:
- ./conf/create_all.sql:/docker-entrypoint-initdb.d/00_create_all.sql
- ./other_resources/create_all.sql:/docker-entrypoint-initdb.d/00_create_all.sql
environment:
- MYSQL_ROOT_PASSWORD=12344321
......
#!/usr/bin/env bash
# TODO: wait for mysql db...
# wait for mysql db startup completed ...
while ! mysqladmin ping -h wuekabel_db --silent; do
echo "Could not ping mysql server, waiting..."
sleep 1
......
#!/usr/bin/env bash
MOODLE_PORT=8080
docker run -d --name DB -e MYSQL_DATABASE=moodle -e MYSQL_ROOT_PASSWORD=moodle -e MYSQL_USER=moodle -e MYSQL_PASSWORD=moodle mysql:5
docker run -d -P --name moodle --link DB:DB -e MOODLE_URL=http://localhost:${MOODLE_PORT} -p ${MOODLE_PORT}:80 jhardison/moodle
\ No newline at end of file
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