2016-02-18 06:53:53 +09:00
|
|
|
{- This file is part of Vervis.
|
|
|
|
-
|
|
|
|
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
|
|
|
-
|
|
|
|
- ♡ Copying is an act of love. Please copy, reuse and share.
|
|
|
|
-
|
|
|
|
- The author(s) have dedicated all copyright and related and neighboring
|
|
|
|
- rights to this software to the public domain worldwide. This software is
|
|
|
|
- distributed without any warranty.
|
|
|
|
-
|
|
|
|
- You should have received a copy of the CC0 Public Domain Dedication along
|
|
|
|
- with this software. If not, see
|
|
|
|
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
-}
|
|
|
|
|
2016-02-23 17:45:03 +09:00
|
|
|
module Vervis.Handler.Project
|
2016-02-18 06:53:53 +09:00
|
|
|
( getProjectsR
|
2016-02-25 12:10:30 +09:00
|
|
|
, postProjectsR
|
|
|
|
, getProjectNewR
|
2016-02-18 06:53:53 +09:00
|
|
|
, getProjectR
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2016-02-23 17:45:03 +09:00
|
|
|
import Vervis.Import hiding ((==.))
|
2016-02-18 06:53:53 +09:00
|
|
|
--import Prelude
|
|
|
|
|
2016-03-07 09:39:07 +09:00
|
|
|
import Text.Blaze.Html (toHtml)
|
2016-02-18 06:53:53 +09:00
|
|
|
import Database.Esqueleto
|
|
|
|
--import Model
|
|
|
|
--import Yesod.Core (Handler)
|
2016-02-25 12:10:30 +09:00
|
|
|
import Vervis.Form.Project
|
2016-02-18 06:53:53 +09:00
|
|
|
|
|
|
|
getProjectsR :: Text -> Handler Html
|
|
|
|
getProjectsR ident = do
|
|
|
|
projects <- runDB $ select $ from $ \ (sharer, project) -> do
|
|
|
|
where_ $
|
|
|
|
sharer ^. SharerIdent ==. val ident &&.
|
|
|
|
sharer ^. SharerId ==. project ^. ProjectSharer
|
|
|
|
orderBy [asc $ project ^. ProjectIdent]
|
|
|
|
return $ project ^. ProjectIdent
|
2016-05-14 07:11:46 +09:00
|
|
|
defaultLayout $(widgetFile "project/list")
|
2016-02-18 06:53:53 +09:00
|
|
|
|
2016-02-25 12:10:30 +09:00
|
|
|
postProjectsR :: Text -> Handler Html
|
|
|
|
postProjectsR ident = do
|
|
|
|
Entity _pid person <- requireAuth
|
|
|
|
let sid = personIdent person
|
|
|
|
((result, widget), enctype) <- runFormPost $ newProjectForm sid
|
|
|
|
case result of
|
|
|
|
FormSuccess project -> do
|
|
|
|
runDB $ insert_ project
|
|
|
|
setMessage "Project added."
|
2016-05-14 07:07:56 +09:00
|
|
|
redirect HomeR
|
2016-02-25 12:10:30 +09:00
|
|
|
FormMissing -> do
|
|
|
|
setMessage "Field(s) missing"
|
2016-05-14 07:11:46 +09:00
|
|
|
defaultLayout $(widgetFile "project/new")
|
2016-05-14 07:07:56 +09:00
|
|
|
FormFailure _l -> do
|
2016-05-14 07:06:23 +09:00
|
|
|
setMessage "Project creation failed, see below"
|
2016-05-14 07:11:46 +09:00
|
|
|
defaultLayout $(widgetFile "project/new")
|
2016-02-25 12:10:30 +09:00
|
|
|
|
|
|
|
getProjectNewR :: Text -> Handler Html
|
|
|
|
getProjectNewR ident = do
|
|
|
|
Entity _pid person <- requireAuth
|
|
|
|
let sid = personIdent person
|
|
|
|
((_result, widget), enctype) <- runFormPost $ newProjectForm sid
|
2016-05-14 07:11:46 +09:00
|
|
|
defaultLayout $(widgetFile "project/new")
|
2016-02-25 12:10:30 +09:00
|
|
|
|
2016-02-18 06:53:53 +09:00
|
|
|
getProjectR :: Text -> Text -> Handler Html
|
|
|
|
getProjectR user proj = do
|
2016-03-03 17:35:29 +09:00
|
|
|
project <- runDB $ do
|
|
|
|
Entity sid _s <- getBy404 $ UniqueSharerIdent user
|
|
|
|
Entity _pid p <- getBy404 $ UniqueProject proj sid
|
|
|
|
return p
|
2016-05-14 07:11:46 +09:00
|
|
|
defaultLayout $(widgetFile "project/one")
|