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/>.
|
|
|
|
-}
|
|
|
|
|
2016-02-25 12:10:30 +09:00
|
|
|
module Vervis.Form.Project
|
2016-06-06 15:48:59 +09:00
|
|
|
( NewProject (..)
|
|
|
|
, newProjectForm
|
2016-06-01 17:52:14 +09:00
|
|
|
, NewProjectCollab (..)
|
|
|
|
, newProjectCollabForm
|
2016-06-05 19:43:28 +09:00
|
|
|
, editProjectForm
|
2016-02-23 17:28:25 +09:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2016-06-01 17:52:14 +09:00
|
|
|
import Vervis.Import hiding (on, isNothing)
|
|
|
|
|
|
|
|
import Database.Esqueleto hiding ((==.))
|
|
|
|
|
|
|
|
import qualified Database.Esqueleto as E ((==.))
|
2016-02-23 17:28:25 +09:00
|
|
|
|
2016-02-25 12:10:30 +09:00
|
|
|
import Vervis.Field.Project
|
2016-06-01 17:52:14 +09:00
|
|
|
import Vervis.Model
|
|
|
|
import Vervis.Model.Ident
|
|
|
|
import Vervis.Model.Repo
|
2016-02-23 17:28:25 +09:00
|
|
|
|
2016-06-06 15:48:59 +09:00
|
|
|
data NewProject = NewProject
|
|
|
|
{ npIdent :: PrjIdent
|
|
|
|
, npName :: Maybe Text
|
|
|
|
, npDesc :: Maybe Text
|
|
|
|
, npRole :: ProjectRoleId
|
|
|
|
}
|
|
|
|
|
2016-06-07 02:29:54 +09:00
|
|
|
newProjectAForm :: SharerId -> AForm Handler NewProject
|
|
|
|
newProjectAForm sid = NewProject
|
2016-06-06 15:48:59 +09:00
|
|
|
<$> areq (newProjectIdentField sid) "Identifier*" Nothing
|
|
|
|
<*> aopt textField "Name" Nothing
|
|
|
|
<*> aopt textField "Description" Nothing
|
|
|
|
<*> areq selectRole "Your role*" Nothing
|
|
|
|
where
|
|
|
|
selectRole =
|
|
|
|
selectField $
|
2016-06-07 02:29:54 +09:00
|
|
|
optionsPersistKey [ProjectRoleSharer ==. sid] [] $
|
2016-06-06 15:48:59 +09:00
|
|
|
rl2text . projectRoleIdent
|
2016-02-23 17:28:25 +09:00
|
|
|
|
2016-06-07 02:29:54 +09:00
|
|
|
newProjectForm :: SharerId -> Form NewProject
|
|
|
|
newProjectForm sid = renderDivs $ newProjectAForm sid
|
2016-06-01 17:52:14 +09:00
|
|
|
|
|
|
|
data NewProjectCollab = NewProjectCollab
|
|
|
|
{ ncPerson :: PersonId
|
|
|
|
, ncRole :: ProjectRoleId
|
|
|
|
}
|
|
|
|
|
|
|
|
newProjectCollabAForm
|
2016-06-07 02:29:54 +09:00
|
|
|
:: SharerId -> ProjectId -> AForm Handler NewProjectCollab
|
|
|
|
newProjectCollabAForm sid jid = NewProjectCollab
|
2016-06-01 17:52:14 +09:00
|
|
|
<$> 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 $
|
2016-06-07 02:29:54 +09:00
|
|
|
collab ?. ProjectCollabProject E.==. just (val jid) &&.
|
2016-06-01 17:52:14 +09:00
|
|
|
collab ?. ProjectCollabPerson E.==. just (person ^. PersonId)
|
|
|
|
where_ $ isNothing $ collab ?. ProjectCollabId
|
|
|
|
return (sharer ^. SharerIdent, person ^. PersonId)
|
|
|
|
optionsPairs $ map (shr2text . unValue *** unValue) l
|
|
|
|
selectRole =
|
|
|
|
selectField $
|
2016-06-07 02:29:54 +09:00
|
|
|
optionsPersistKey [ProjectRoleSharer ==. sid] [] $
|
2016-06-01 17:52:14 +09:00
|
|
|
rl2text . projectRoleIdent
|
|
|
|
|
2016-06-07 02:29:54 +09:00
|
|
|
newProjectCollabForm :: SharerId -> ProjectId -> Form NewProjectCollab
|
|
|
|
newProjectCollabForm sid jid = renderDivs $ newProjectCollabAForm sid jid
|
2016-06-05 19:43:28 +09:00
|
|
|
|
|
|
|
editProjectAForm :: Entity Project -> AForm Handler Project
|
|
|
|
editProjectAForm (Entity jid project) = Project
|
2016-06-07 02:29:54 +09:00
|
|
|
<$> 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)
|
2016-06-05 19:43:28 +09:00
|
|
|
where
|
|
|
|
selectWiki =
|
|
|
|
selectField $
|
|
|
|
optionsPersistKey [RepoProject ==. Just jid] [] $
|
|
|
|
rp2text . repoIdent
|
|
|
|
|
|
|
|
editProjectForm :: Entity Project -> Form Project
|
|
|
|
editProjectForm p = renderDivs $ editProjectAForm p
|