Skip to content

Commit

Permalink
Merge pull request #27 from MatsMoll/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
MatsMoll authored Feb 14, 2020
2 parents 14b9f5f + f4583b5 commit 1771b00
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Public/assets/js/flash-card/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function editFlashCard() {
}
})
.then(function (json) {
window.location.href = "/tasks/flash-card/" + json.id;
window.location.href = "/creator/tasks/flash-card/" + json.id + "/edit?wasUpdated=true";
})
.catch(function (error) {
presentErrorMessage(error.message);
Expand Down
8 changes: 7 additions & 1 deletion Sources/App/Subject Test/SubjectTestWebController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,18 @@ class SubjectTestWebController<API: SubjectTestAPIControlling>: SubjectTestWebCo
.map { _ in
req.redirect(to: "results")
}
.catchMap { error in
switch error {
case SubjectTest.DatabaseRepository.Errors.alreadyEnded: return req.redirect(to: "results")
default: throw error
}
}
}

static func results(on req: Request) throws -> EventLoopFuture<HTTPResponse> {

let user = try req.requireAuthenticated(User.self)

return try API.results(on: req)
.map { results in

Expand Down
41 changes: 23 additions & 18 deletions Sources/App/Task/Flash Card/FlashCardTask+RenderPracticing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,32 @@ extension FlashCardTask: RenderTaskPracticing {
.content(for: self, on: req)
.flatMap { preview in

try PracticeSession.DatabaseRepository
.goalProgress(in: session, on: req)
.flatMap { progress in
try TaskSessionAnswer.DatabaseRepository
.flashCardAnswers(in: session.requireID(), taskID: preview.task.requireID(), on: req)
.flatMap { answer in

try TaskResult.DatabaseRepository
.getLastResult(for: preview.task.requireID(), by: user.userId, on: req)
.map { lastResult in
try PracticeSession.DatabaseRepository
.goalProgress(in: session, on: req)
.flatMap { progress in

try req.renderer()
.render(
FlashCardTask.Templates.Execute.self,
with: .init(
taskPreview: preview,
user: user,
currentTaskIndex: index,
practiceProgress: progress,
session: session,
lastResult: lastResult?.content,
numberOfTasks: 0
try TaskResult.DatabaseRepository
.getLastResult(for: preview.task.requireID(), by: user.userId, on: req)
.map { lastResult in

try req.renderer()
.render(
FlashCardTask.Templates.Execute.self,
with: .init(
taskPreview: preview,
user: user,
currentTaskIndex: index,
practiceProgress: progress,
session: session,
lastResult: lastResult?.content,
prevAnswer: answer
)
)
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,45 @@ extension MultipleChoiseTask: RenderTaskPracticing {

try TaskResult.DatabaseRepository
.getLastResult(for: preview.task.requireID(), by: user.userId, on: req)
.map { lastResult in

try req.renderer()
.render(
MultipleChoiseTask.Templates.Execute.self,
with: .init(
multiple: content,
taskContent: preview,
user: user,
currentTaskIndex: index,
session: session,
lastResult: lastResult?.content,
practiceProgress: progress
.flatMap { lastResult in

if lastResult != nil {
return try TaskSessionAnswer.DatabaseRepository
.multipleChoiseAnswers(in: session.requireID(), taskID: content.task.requireID(), on: req)
.map { selectedChoises in

try req.renderer()
.render(
MultipleChoiseTask.Templates.Execute.self,
with: .init(
multiple: content,
taskContent: preview,
user: user,
currentTaskIndex: index,
session: session,
lastResult: lastResult?.content,
practiceProgress: progress,
selectedChoises: selectedChoises.map { $0.choiseID }
)
)
}
} else {
return req.future().map {
try req.renderer()
.render(
MultipleChoiseTask.Templates.Execute.self,
with: .init(
multiple: content,
taskContent: preview,
user: user,
currentTaskIndex: index,
session: session,
lastResult: lastResult?.content,
practiceProgress: progress
)
)
)
}
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions Sources/App/User/UserWebController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ import KognitaViews
import Mailgun
import FluentPostgreSQL
import KognitaAPI
import Authentication

final class UserWebController: RouteCollection {

func boot(router: Router) {

let redirectMiddle = router.grouped(RedirectMiddleware<User>(path: "/login"))

redirectMiddle.get("profile", use: profilePage)

router.get("signup", use: signupForm)
router.get("login", use: loginForm)
router.get("start-reset-password", use: startResetPasswordForm)
Expand All @@ -29,13 +34,32 @@ final class UserWebController: RouteCollection {
router.post("signup", use: create)
router.post("start-reset-password", use: startResetPassword)
router.post("reset-password", use: resetPassword)

}

func signupForm(_ req: Request) throws -> EventLoopFuture<View> {
User.Templates.Signup()
.render(with: .init(), for: req)
}

func profilePage(_ req: Request) throws -> EventLoopFuture<View> {
let user = try req.requireAuthenticated(User.self)

return try Subject.DatabaseRepository
.allActive(for: user, on: req)
.map { subjects in

try req.renderer()
.render(
view: User.Templates.Profile.self,
with: .init(
user: user,
subjects: subjects
)
)
}
}

func loginForm(_ req: Request) throws -> EventLoopFuture<Response> {

if try req.authenticated(User.self) != nil {
Expand Down

0 comments on commit 1771b00

Please sign in to comment.