Warning: some routes renamed; otherwise minor commit.
This commit is contained in:
parent
77e7e77e74
commit
3fbeed2682
5
routes
5
routes
@ -12,8 +12,9 @@
|
|||||||
/term/edit TermEditR GET POST
|
/term/edit TermEditR GET POST
|
||||||
/term/#TermIdentifier/edit TermEditExistR GET
|
/term/#TermIdentifier/edit TermEditExistR GET
|
||||||
|
|
||||||
/course/ CourseShowR GET
|
/course/ CourseListR GET
|
||||||
!/course/edit CourseEditR GET POST
|
!/course/edit CourseEditR GET POST
|
||||||
!/course/#TermIdentifier CourseShowTermR GET
|
!/course/#TermIdentifier CourseListTermR GET
|
||||||
/course/#TermIdentifier/#Text/edit CourseEditExistR GET
|
/course/#TermIdentifier/#Text/edit CourseEditExistR GET
|
||||||
|
/course/#TermIdentifier/#Text/show CourseShowR GET
|
||||||
|
|
||||||
|
|||||||
@ -169,8 +169,9 @@ instance Yesod UniWorX where
|
|||||||
|
|
||||||
-- TODO: all?
|
-- TODO: all?
|
||||||
isAuthorized TermShowR _ = return Authorized
|
isAuthorized TermShowR _ = return Authorized
|
||||||
isAuthorized CourseShowR _ = return Authorized
|
isAuthorized CourseListR _ = return Authorized
|
||||||
isAuthorized (CourseShowTermR _) _ = return Authorized
|
isAuthorized (CourseShowR _ _) _ = return Authorized
|
||||||
|
isAuthorized (CourseListTermR _) _ = return Authorized
|
||||||
-- TODO: change to Assistants
|
-- TODO: change to Assistants
|
||||||
isAuthorized TermEditR _ = return Authorized
|
isAuthorized TermEditR _ = return Authorized
|
||||||
isAuthorized (TermEditExistR _) _ = return Authorized
|
isAuthorized (TermEditExistR _) _ = return Authorized
|
||||||
|
|||||||
@ -20,11 +20,11 @@ import Colonnade
|
|||||||
import Yesod.Colonnade
|
import Yesod.Colonnade
|
||||||
|
|
||||||
|
|
||||||
getCourseShowR :: Handler TypedContent
|
getCourseListR :: Handler TypedContent
|
||||||
getCourseShowR = redirect TermShowR
|
getCourseListR = redirect TermShowR
|
||||||
|
|
||||||
getCourseShowTermR :: TermIdentifier -> Handler Html
|
getCourseListTermR :: TermIdentifier -> Handler Html
|
||||||
getCourseShowTermR tidini = do
|
getCourseListTermR tidini = do
|
||||||
(term,courses) <- runDB $ do
|
(term,courses) <- runDB $ do
|
||||||
term <- get $ TermKey tidini
|
term <- get $ TermKey tidini
|
||||||
courses <- selectList [CourseTermId ==. TermKey tidini] [Asc CourseShorthand]
|
courses <- selectList [CourseTermId ==. TermKey tidini] [Asc CourseShorthand]
|
||||||
@ -35,24 +35,34 @@ getCourseShowTermR tidini = do
|
|||||||
let colonnadeTerms = mconcat
|
let colonnadeTerms = mconcat
|
||||||
[ headed "Kürzel" $ (\c ->
|
[ headed "Kürzel" $ (\c ->
|
||||||
let shd = courseShorthand c
|
let shd = courseShorthand c
|
||||||
(TermKey tid) = courseTermId c
|
tid = unTermKey $ courseTermId c
|
||||||
|
in [whamlet| <a href=@{CourseShowR tid shd}>#{shd} |] )
|
||||||
|
-- , headed "Institut" $ [shamlet| #{course} |]
|
||||||
|
, headed "Beginn Anmeldung" $ fromString.(maybe "" formatTimeGerWD).courseRegisterFrom
|
||||||
|
, headed "Ende Anmeldung" $ fromString.(maybe "" formatTimeGerWD).courseRegisterTo
|
||||||
|
, headed " " $ (\c ->
|
||||||
|
let shd = courseShorthand c
|
||||||
|
tid = unTermKey $ courseTermId c
|
||||||
in do
|
in do
|
||||||
adminLink <- handlerToWidget $ isAuthorized (CourseEditExistR tid shd ) False
|
adminLink <- handlerToWidget $ isAuthorized (CourseEditExistR tid shd ) False
|
||||||
[whamlet|
|
[whamlet|
|
||||||
$if adminLink == Authorized
|
$if adminLink == Authorized
|
||||||
<a href=@{CourseEditExistR tid shd}>
|
<a href=@{CourseEditExistR tid shd}>
|
||||||
#{shd}
|
editieren
|
||||||
$else
|
|] )
|
||||||
#{shd}
|
|
||||||
|] )
|
|
||||||
-- , headed "Institut" $ [shamlet| #{course} |]
|
|
||||||
, headed "Beginn Anmeldung" $ fromString.(maybe "" formatTimeGerWD).courseRegisterFrom
|
|
||||||
, headed "Ende Anmeldung" $ fromString.(maybe "" formatTimeGerWD).courseRegisterTo
|
|
||||||
]
|
]
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
setTitle "Semesterkurse"
|
setTitle "Semesterkurse"
|
||||||
encodeHeadedWidgetTable tableDefault colonnadeTerms (map entityVal courses)
|
encodeHeadedWidgetTable tableDefault colonnadeTerms (map entityVal courses)
|
||||||
|
|
||||||
|
getCourseShowR :: TermIdentifier -> Text -> Handler Html
|
||||||
|
getCourseShowR tid csh = do
|
||||||
|
courseEnt <- runDB $ getBy404 $ CourseTermShort (TermKey tid) csh
|
||||||
|
let course = entityVal courseEnt
|
||||||
|
defaultLayout $ do
|
||||||
|
setTitle $ [shamlet| #{termToText tid} - #{csh}|]
|
||||||
|
$(widgetFile "course")
|
||||||
|
|
||||||
|
|
||||||
getCourseEditR :: Handler Html
|
getCourseEditR :: Handler Html
|
||||||
getCourseEditR = do
|
getCourseEditR = do
|
||||||
@ -82,7 +92,7 @@ courseEditHandler course = do
|
|||||||
runDB $ delete cid -- TODO Sicherheitsabfrage einbauen!
|
runDB $ delete cid -- TODO Sicherheitsabfrage einbauen!
|
||||||
let cti = termToText $ cfTerm res
|
let cti = termToText $ cfTerm res
|
||||||
setMessage $ [shamlet| Kurs #{cti}/#{cfShort res} wurde gelöscht! |]
|
setMessage $ [shamlet| Kurs #{cti}/#{cfShort res} wurde gelöscht! |]
|
||||||
redirect $ CourseShowTermR $ cfTerm res
|
redirect $ CourseListTermR $ cfTerm res
|
||||||
| fAct == formActionSave
|
| fAct == formActionSave
|
||||||
, Just cid <- cfCourseId res -> do
|
, Just cid <- cfCourseId res -> do
|
||||||
actTime <- liftIO getCurrentTime
|
actTime <- liftIO getCurrentTime
|
||||||
@ -100,7 +110,7 @@ courseEditHandler course = do
|
|||||||
]
|
]
|
||||||
let cti = termToText $ cfTerm res
|
let cti = termToText $ cfTerm res
|
||||||
setMessage $ [shamlet| Kurs #{cti}/#{cfShort res} wurde geändert. |]
|
setMessage $ [shamlet| Kurs #{cti}/#{cfShort res} wurde geändert. |]
|
||||||
redirect $ CourseShowTermR $ cfTerm res
|
redirect $ CourseListTermR $ cfTerm res
|
||||||
| fAct == formActionSave
|
| fAct == formActionSave
|
||||||
, Nothing <- cfCourseId res -> do
|
, Nothing <- cfCourseId res -> do
|
||||||
actTime <- liftIO getCurrentTime
|
actTime <- liftIO getCurrentTime
|
||||||
@ -124,7 +134,7 @@ courseEditHandler course = do
|
|||||||
runDB $ insert_ $ Lecturer aid cid
|
runDB $ insert_ $ Lecturer aid cid
|
||||||
let cti = termToText $ cfTerm res
|
let cti = termToText $ cfTerm res
|
||||||
setMessage $ [shamlet| Kurs #{cti}/#{cfShort res} wurde angelegt. |]
|
setMessage $ [shamlet| Kurs #{cti}/#{cfShort res} wurde angelegt. |]
|
||||||
redirect $ CourseShowTermR $ cfTerm res
|
redirect $ CourseListTermR $ cfTerm res
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
let cti = termToText $ cfTerm res
|
let cti = termToText $ cfTerm res
|
||||||
setMessage $ [shamlet|
|
setMessage $ [shamlet|
|
||||||
|
|||||||
@ -41,7 +41,7 @@ getTermShowR = do
|
|||||||
, headed "Kursliste" $ (\t -> let tn = termName t in do
|
, headed "Kursliste" $ (\t -> let tn = termName t in do
|
||||||
numCourses <- handlerToWidget $ runDB $ count [CourseTermId ==. TermKey tn ]
|
numCourses <- handlerToWidget $ runDB $ count [CourseTermId ==. TermKey tn ]
|
||||||
[whamlet|
|
[whamlet|
|
||||||
<a href=@{CourseShowTermR tn}>
|
<a href=@{CourseListTermR tn}>
|
||||||
#{show numCourses} Kurse
|
#{show numCourses} Kurse
|
||||||
|] )
|
|] )
|
||||||
, headed "Semesteranfang" $ fromString.formatTimeGerWD.termStart
|
, headed "Semesteranfang" $ fromString.formatTimeGerWD.termStart
|
||||||
|
|||||||
40
templates/course.hamlet
Normal file
40
templates/course.hamlet
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<div .masthead>
|
||||||
|
<div .container>
|
||||||
|
<div .row>
|
||||||
|
<h1 .header>
|
||||||
|
#{courseName course}
|
||||||
|
|
||||||
|
<div .container>
|
||||||
|
<div .bs-docs-section>
|
||||||
|
<div .row>
|
||||||
|
<div .col-lg-12>
|
||||||
|
<div .page-header>
|
||||||
|
<h1 #start>Beschreibung
|
||||||
|
|
||||||
|
$maybe descr <- courseDescription course
|
||||||
|
<p> #{descr}
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
You can also use this scaffolded site to explore some concepts, and best practices.
|
||||||
|
|
||||||
|
|
||||||
|
<li .list-group-item>
|
||||||
|
We can link to other handlers, like the <a href="@{ProfileR}">Profile</a>.
|
||||||
|
Try it out as an anonymous user and see the access denied.
|
||||||
|
Then, try to <a href="@{AuthR LoginR}">login</a> with the dummy authentication added
|
||||||
|
while in development.
|
||||||
|
|
||||||
|
<li .list-group-item>
|
||||||
|
The HTML you are seeing now is actually composed by a number of <em>widgets</em>, #
|
||||||
|
most of them are brought together by the <tt>defaultLayout</tt> function which #
|
||||||
|
is defined in the <tt>Foundation.hs</tt> module,
|
||||||
|
All the files for templates and wigdets are in <tt>templates</tt>.
|
||||||
|
|
||||||
|
<li .list-group-item>
|
||||||
|
A Widget's Html, Css and Javascript are separated in three files with the
|
||||||
|
<tt>.hamlet</tt>, <tt>.lucius</tt> and <tt>.julius</tt> extensions.
|
||||||
|
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user