1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2025-01-10 01:56:47 +09:00
vervis/src/Vervis/Form/Project.hs

103 lines
3.5 KiB
Haskell
Raw Normal View History

2016-02-23 17:28:25 +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/>.
-}
module Vervis.Form.Project
( NewProject (..)
, newProjectForm
, NewProjectCollab (..)
, newProjectCollabForm
, editProjectForm
2016-02-23 17:28:25 +09:00
)
where
import Vervis.Import hiding (on, isNothing)
import Database.Esqueleto hiding ((==.))
import qualified Database.Esqueleto as E ((==.))
2016-02-23 17:28:25 +09:00
import Vervis.Field.Project
import Vervis.Model
import Vervis.Model.Ident
import Vervis.Model.Repo
2016-02-23 17:28:25 +09:00
data NewProject = NewProject
{ npIdent :: PrjIdent
, npName :: Maybe Text
, npDesc :: Maybe Text
, npRole :: ProjectRoleId
}
newProjectAForm :: SharerId -> AForm Handler NewProject
newProjectAForm sid = NewProject
<$> areq (newProjectIdentField sid) "Identifier*" Nothing
<*> aopt textField "Name" Nothing
<*> aopt textField "Description" Nothing
<*> areq selectRole "Your role*" Nothing
where
selectRole =
selectField $
optionsPersistKey [ProjectRoleSharer ==. sid] [] $
rl2text . projectRoleIdent
2016-02-23 17:28:25 +09:00
newProjectForm :: SharerId -> Form NewProject
newProjectForm sid = renderDivs $ newProjectAForm sid
data NewProjectCollab = NewProjectCollab
{ ncPerson :: PersonId
, ncRole :: ProjectRoleId
}
newProjectCollabAForm
:: SharerId -> ProjectId -> AForm Handler NewProjectCollab
newProjectCollabAForm sid jid = NewProjectCollab
<$> areq selectPerson "Person*" Nothing
<*> areq selectRole "Role*" Nothing
where
selectPerson = selectField $ do
l <- runDB $ select $
from $ \ (collab `RightOuterJoin` person `InnerJoin` sharer) -> do
on $ person ^. PersonIdent E.==. sharer ^. SharerId
on $
collab ?. ProjectCollabProject E.==. just (val jid) &&.
collab ?. ProjectCollabPerson E.==. just (person ^. PersonId)
where_ $ isNothing $ collab ?. ProjectCollabId
return (sharer ^. SharerIdent, person ^. PersonId)
optionsPairs $ map (shr2text . unValue *** unValue) l
selectRole =
selectField $
optionsPersistKey [ProjectRoleSharer ==. sid] [] $
rl2text . projectRoleIdent
newProjectCollabForm :: SharerId -> ProjectId -> Form NewProjectCollab
newProjectCollabForm sid jid = renderDivs $ newProjectCollabAForm sid jid
editProjectAForm :: Entity Project -> AForm Handler Project
editProjectAForm (Entity jid project) = Project
<$> pure (projectIdent project)
<*> pure (projectSharer project)
<*> aopt textField "Name" (Just $ projectName project)
<*> aopt textField "Description" (Just $ projectDesc project)
<*> pure (projectNextTicket project)
<*> aopt selectWiki "Wiki" (Just $ projectWiki project)
where
selectWiki =
selectField $
optionsPersistKey [RepoProject ==. Just jid] [] $
rp2text . repoIdent
editProjectForm :: Entity Project -> Form Project
editProjectForm p = renderDivs $ editProjectAForm p