diff --git a/routes b/routes index 6df7b740c..133c66add 100644 --- a/routes +++ b/routes @@ -7,3 +7,6 @@ / HomeR GET POST /profile ProfileR GET + + +/assist/newcourse NewCourseR GET POST \ No newline at end of file diff --git a/src/Application.hs b/src/Application.hs index fbb444868..3815f9d35 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -20,7 +20,6 @@ module Application ) where import Control.Monad.Logger (liftLoc, runLoggingT) -import Database.Persist.Sql (runMigrationUnsafe) import Database.Persist.Postgresql (createPostgresqlPool, pgConnStr, pgPoolSize, runSqlPool) import Import @@ -42,6 +41,7 @@ import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet, import Handler.Common import Handler.Home import Handler.Profile +import Handler.Assist -- 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 @@ -80,7 +80,7 @@ makeFoundation appSettings = do (pgPoolSize $ appDatabaseConf appSettings) -- Perform database migration using our application's logging settings. - runLoggingT (runSqlPool (runMigrationUnsafe migrateAll) pool) logFunc + runLoggingT (runSqlPool (runMigration migrateAll) pool) logFunc -- Return the foundation return $ mkFoundation pool diff --git a/src/Foundation.hs b/src/Foundation.hs index 7fa6dd380..6e476daea 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -166,6 +166,8 @@ instance Yesod UniWorX where isAuthorized (StaticR _) _ = return Authorized isAuthorized ProfileR _ = isAuthenticated + -- TODO: change to Assistants + isAuthorized NewCourseR _ = return Authorized -- This function creates static content files in the static folder -- and names them based on a hash of their content. This allows diff --git a/src/Handler/Assist.hs b/src/Handler/Assist.hs new file mode 100644 index 000000000..2aeb965b7 --- /dev/null +++ b/src/Handler/Assist.hs @@ -0,0 +1,59 @@ +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE TypeFamilies #-} +module Handler.Assist where + +import Import +import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3) +-- import Text.Julius (RawJS (..)) + +data NewCourseForm = NewCourseForm + { ncf_name :: Text + , ncf_short :: Text + , ncf_capacity :: Maybe Int + } +-- Handler for Assistants + +getNewCourseR :: Handler Html +getNewCourseR = do + (formWidget, formEnctype) <- generateFormPost newCourseForm + defaultLayout $ do + setTitle "Neuen Kurs anlegen" + $(widgetFile "newcourse") + +postNewCourseR :: Handler Html +postNewCourseR = do + ((result, formWidget), formEnctype) <- runFormPost newCourseForm + case result of + FormSuccess res -> do + setMessage "Got something!" + redirect NewCourseR + _ -> redirect NewCourseR + +{- + defaultLayout $ do + let (commentFormId, commentTextareaId, commentListId) = commentIds + aDomId <- newIdent + setTitle "Welcome To Yesod!" + $(widgetFile "homepage") +-} + + + +newCourseForm :: Form NewCourseForm +newCourseForm = renderBootstrap3 BootstrapBasicForm $ NewCourseForm + <$> areq textField (set "Name des Kurses") Nothing + <*> areq textField (set "Kurs Kürzel (3-4 Zeichen)") Nothing + <*> aopt intField (set "Maximale Teilnehmer") Nothing + -- Add attributes like the placeholder and CSS classes. + where set txt = FieldSettings + { fsLabel = txt + , fsTooltip = Nothing + , fsId = Nothing + , fsName = Nothing + , fsAttrs = + [ ("class", "form-control") + ] + } diff --git a/templates/newcourse.hamlet b/templates/newcourse.hamlet new file mode 100644 index 000000000..7fe8aaf07 --- /dev/null +++ b/templates/newcourse.hamlet @@ -0,0 +1,20 @@ +
+
+
+
+
+

Neuen Kurs anlegen: + +

+ Bitte alles ausfüllen! + +

+
+
+
+ ^{formWidget} + +