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
|
|
|
|
( newProjectForm
|
2016-06-01 17:52:14 +09:00
|
|
|
, NewProjectCollab (..)
|
|
|
|
, newProjectCollabForm
|
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-02-25 12:10:30 +09:00
|
|
|
newProjectAForm :: SharerId -> AForm Handler Project
|
|
|
|
newProjectAForm sid = Project
|
2016-05-24 05:46:54 +09:00
|
|
|
<$> (text2prj <$> areq (mkIdentField sid) "Identifier*" Nothing)
|
2016-02-25 12:10:30 +09:00
|
|
|
<*> pure sid
|
|
|
|
<*> aopt textField "Name" Nothing
|
|
|
|
<*> aopt textField "Description" Nothing
|
2016-05-01 20:05:56 +09:00
|
|
|
<*> pure 1
|
2016-06-04 15:57:54 +09:00
|
|
|
<*> pure Nothing
|
2016-02-23 17:28:25 +09:00
|
|
|
|
2016-02-25 12:10:30 +09:00
|
|
|
newProjectForm :: SharerId -> Form Project
|
|
|
|
newProjectForm = renderDivs . newProjectAForm
|
2016-06-01 17:52:14 +09:00
|
|
|
|
|
|
|
data NewProjectCollab = NewProjectCollab
|
|
|
|
{ ncPerson :: PersonId
|
|
|
|
, ncRole :: ProjectRoleId
|
|
|
|
}
|
|
|
|
|
|
|
|
newProjectCollabAForm
|
|
|
|
:: PersonId -> ProjectId -> AForm Handler NewProjectCollab
|
|
|
|
newProjectCollabAForm pid rid = 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 rid) &&.
|
|
|
|
collab ?. ProjectCollabPerson E.==. just (person ^. PersonId)
|
|
|
|
where_ $ isNothing $ collab ?. ProjectCollabId
|
|
|
|
return (sharer ^. SharerIdent, person ^. PersonId)
|
|
|
|
optionsPairs $ map (shr2text . unValue *** unValue) l
|
|
|
|
selectRole =
|
|
|
|
selectField $
|
|
|
|
optionsPersistKey [ProjectRolePerson ==. pid] [] $
|
|
|
|
rl2text . projectRoleIdent
|
|
|
|
|
|
|
|
newProjectCollabForm :: PersonId -> ProjectId -> Form NewProjectCollab
|
|
|
|
newProjectCollabForm pid rid = renderDivs $ newProjectCollabAForm pid rid
|