From fcec208936f74b52e1d19b7272a5c26ecf092d8f Mon Sep 17 00:00:00 2001 From: SJost Date: Fri, 6 Oct 2017 11:22:43 +0200 Subject: [PATCH] termField stub created, needs to be moved to common utils --- models | 3 + src/Foundation.hs | 1 + src/Handler/Assist.hs | 61 +++++-- src/Model/Types.hs | 6 + uniworx.sublime-workspace | 332 ++++++++++++++++++++++++++++++-------- 5 files changed, 324 insertions(+), 79 deletions(-) diff --git a/models b/models index e115ddd5e..7736ff9de 100644 --- a/models +++ b/models @@ -1,6 +1,7 @@ User plugin Text ident Text + matrikelnummer Text UniqueAuthentication plugin ident Term json name TermIdentifier @@ -27,6 +28,8 @@ DegreeCourse json Course json name Text shorthand Text + description Textarea + linkexternal Text owner UserId schoolId SchoolId termId TermId -- TermId ist jetzt Text als Typ diff --git a/src/Foundation.hs b/src/Foundation.hs index 6e476daea..b31b50669 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -245,6 +245,7 @@ instance YesodAuth UniWorX where Nothing -> Authenticated <$> insert User { userPlugin = credsPlugin , userIdent = credsIdent + , userMatrikelnummer = "DummyMatrikel" } -- You can add other plugins like Google Email, email or OAuth here diff --git a/src/Handler/Assist.hs b/src/Handler/Assist.hs index 2aeb965b7..89823a678 100644 --- a/src/Handler/Assist.hs +++ b/src/Handler/Assist.hs @@ -1,36 +1,64 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} module Handler.Assist where import Import +import qualified Data.Text as T import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3) -- import Text.Julius (RawJS (..)) data NewCourseForm = NewCourseForm - { ncf_name :: Text - , ncf_short :: Text - , ncf_capacity :: Maybe Int - } + { ncf_user :: UserId + , ncf_term :: TermIdentifier + , ncf_name :: Text + , ncf_short :: Text + , ncf_description :: Textarea + , ncf_homepage :: Maybe Text + , ncf_html :: Html + , ncf_capacity :: Maybe Int + } -- Handler for Assistants +getShowCourseR :: CourseId -> Handler Html +getShowCourseR courseId = do + defaultLayout $ do + [whamlet| + TODO unfinished + |] + getNewCourseR :: Handler Html getNewCourseR = do - (formWidget, formEnctype) <- generateFormPost newCourseForm + aid <- requireAuthId + (formWidget, formEnctype) <- generateFormPost $ newCourseForm aid defaultLayout $ do setTitle "Neuen Kurs anlegen" + [whamlet| + User: #{show aid} + |] $(widgetFile "newcourse") postNewCourseR :: Handler Html postNewCourseR = do - ((result, formWidget), formEnctype) <- runFormPost newCourseForm + aid <- requireAuthId + ((result, formWidget), formEnctype) <- runFormPost $ newCourseForm aid case result of - FormSuccess res -> do + FormSuccess res -> defaultLayout $ do setMessage "Got something!" - redirect NewCourseR - _ -> redirect NewCourseR + $(widgetFile "newcourse") + FormMissing -> defaultLayout $ do + setMessage "Keine Daten erhalten." + $(widgetFile "newcourse") + FormFailure errorMsgs -> defaultLayout $ do + setMessage [shamlet| Fehler: +