Home.hs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. {-# LANGUAGE NoImplicitPrelude #-}
  2. {-# LANGUAGE OverloadedStrings #-}
  3. {-# LANGUAGE TemplateHaskell #-}
  4. {-# LANGUAGE MultiParamTypeClasses #-}
  5. {-# LANGUAGE TypeFamilies #-}
  6. module Handler.Home where
  7. import Import
  8. import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3)
  9. import Text.Julius (RawJS (..))
  10. -- Define our data that will be used for creating the form.
  11. data FileForm = FileForm
  12. { fileInfo :: FileInfo
  13. , fileDescription :: Text
  14. }
  15. -- This is a handler function for the GET request method on the HomeR
  16. -- resource pattern. All of your resource patterns are defined in
  17. -- config/routes
  18. --
  19. -- The majority of the code you will write in Yesod lives in these handler
  20. -- functions. You can spread them across multiple files if you are so
  21. -- inclined, or create a single monolithic file.
  22. getHomeR :: Handler Html
  23. getHomeR = do
  24. -- allPosts <- runDB $ selectList [BlogPostTitle >=. "foo", BlogPostTitle !=. "foobar"] [Asc BlogPostId, LimitTo 5]
  25. -- error "todo"
  26. allPosts <- runDB $ selectList [] [Desc BlogPostId, LimitTo 50]
  27. defaultLayout $ do
  28. $(widgetFile "posts/index")
  29. -- getHomeR :: Handler Html
  30. -- getHomeR = do
  31. -- (formWidget, formEnctype) <- generateFormPost sampleForm
  32. -- let submission = Nothing :: Maybe FileForm
  33. -- handlerName = "getHomeR" :: Text
  34. -- allComments <- runDB $ getAllComments
  35. -- defaultLayout $ do
  36. -- let (commentFormId, commentTextareaId, commentListId) = commentIds
  37. -- aDomId <- newIdent
  38. -- setTitle "Welcome To Yesod!"
  39. -- $(widgetFile "homepage")
  40. -- postHomeR :: Handler Html
  41. -- postHomeR = do
  42. -- ((result, formWidget), formEnctype) <- runFormPost sampleForm
  43. -- let handlerName = "postHomeR" :: Text
  44. -- submission = case result of
  45. -- FormSuccess res -> Just res
  46. -- _ -> Nothing
  47. -- allComments <- runDB $ getAllComments
  48. -- defaultLayout $ do
  49. -- let (commentFormId, commentTextareaId, commentListId) = commentIds
  50. -- aDomId <- newIdent
  51. -- setTitle "Welcome To Yesod!"
  52. -- $(widgetFile "homepage")
  53. -- sampleForm :: Form FileForm
  54. -- sampleForm = renderBootstrap3 BootstrapBasicForm $ FileForm
  55. -- <$> fileAFormReq "Choose a file"
  56. -- <*> areq textField textSettings Nothing
  57. -- -- Add attributes like the placeholder and CSS classes.
  58. -- where textSettings = FieldSettings
  59. -- { fsLabel = "What's on the file?"
  60. -- , fsTooltip = Nothing
  61. -- , fsId = Nothing
  62. -- , fsName = Nothing
  63. -- , fsAttrs =
  64. -- [ ("class", "form-control")
  65. -- , ("placeholder", "File description")
  66. -- ]
  67. -- }
  68. -- commentIds :: (Text, Text, Text)
  69. -- commentIds = ("js-commentForm", "js-createCommentTextarea", "js-commentList")
  70. -- getAllComments :: DB [Entity Comment]
  71. -- getAllComments = selectList [] [Asc CommentId]