Add page for a course

Also added a relation between courses and challenges
This commit is contained in:
Filip Gralinski 2022-01-17 21:58:09 +01:00
parent e3981717c9
commit 36ad24dba5
7 changed files with 50 additions and 0 deletions

View File

@ -63,6 +63,7 @@ import Handler.Evaluate
import Handler.Swagger import Handler.Swagger
import Handler.Team import Handler.Team
import Handler.Announcements import Handler.Announcements
import Handler.Course
-- This line actually creates our YesodDispatch instance. It is the second half -- This line actually creates our YesodDispatch instance. It is the second half
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the -- of the call to mkYesodData which occurs in Foundation.hs. Please see the

View File

@ -233,6 +233,8 @@ instance Yesod App where
isAuthorized (CompareFormR _ _) _ = regularAuthorization isAuthorized (CompareFormR _ _) _ = regularAuthorization
isAuthorized (CourseR _) _ = regularAuthorization
isAuthorized MyTeamsR _ = isTrustedAuthorized isAuthorized MyTeamsR _ = isTrustedAuthorized
isAuthorized CreateTeamR _ = isTrustedAuthorized isAuthorized CreateTeamR _ = isTrustedAuthorized

38
Handler/Course.hs Normal file
View File

@ -0,0 +1,38 @@
module Handler.Course where
import Import
import Handler.Shared
import Handler.ListChallenges
import qualified Database.Esqueleto as E
import Database.Esqueleto ((^.))
data CourseInfo = CourseInfo {
courseInfoCourse :: Course,
courseInfoChallenges :: [Entity Challenge]
}
getCourseR :: Text -> Handler Html
getCourseR courseCode = do
courseInfo <- fetchCourseInfo courseCode
defaultLayout $ do
setTitle "Course"
$(widgetFile "course")
fetchCourseInfo :: Text -> Handler CourseInfo
fetchCourseInfo courseCode = do
(Entity courseId course) <- runDB $ getBy404 $ UniqueCourseCode courseCode
challenges <- runDB $ E.select $ E.from $ \(challenge, course_challenge) -> do
E.where_ (course_challenge ^. CourseChallengeCourse E.==. E.val courseId
E.&&. course_challenge ^. CourseChallengeChallenge E.==. challenge ^. ChallengeId)
E.orderBy [E.asc (challenge ^. ChallengeName)]
return challenge
return $ CourseInfo {
courseInfoCourse = course,
courseInfoChallenges = filter (\ch -> (challengeArchived $ entityVal ch) /= Just True) challenges
}

View File

@ -212,6 +212,10 @@ Teacher
user UserId user UserId
course CourseId course CourseId
UniqueTeacherCourse user course UniqueTeacherCourse user course
CourseChallenge
challenge ChallengeId
course CourseId
UniqueCourseChallenge challenge course
-- for "KPI" dashboard -- for "KPI" dashboard
Indicator Indicator
test TestId test TestId

View File

@ -15,6 +15,7 @@
/test-progress/#Int/#Int TestProgressR GET /test-progress/#Int/#Int TestProgressR GET
/api/test-progress/#Int/#Int TestProgressJsonR GET /api/test-progress/#Int/#Int TestProgressJsonR GET
/list-challenges ListChallengesR GET /list-challenges ListChallengesR GET
/course/#Text CourseR GET
/test-announcements TestAnnouncementsR GET /test-announcements TestAnnouncementsR GET

View File

@ -65,6 +65,7 @@ library
Handler.Team Handler.Team
Handler.Announcements Handler.Announcements
Web.Announcements Web.Announcements
Handler.Course
if flag(dev) || flag(library-only) if flag(dev) || flag(library-only)
cpp-options: -DDEVELOPMENT cpp-options: -DDEVELOPMENT

3
templates/course.hamlet Normal file
View File

@ -0,0 +1,3 @@
<h1>#{courseName $ courseInfoCourse courseInfo}
^{listChallengesCore $ courseInfoChallenges courseInfo}