2016-02-27 14:41:36 +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.Repo
|
2016-05-30 22:10:02 +09:00
|
|
|
( NewRepo (..)
|
|
|
|
, newRepoForm
|
2016-05-31 10:52:04 +09:00
|
|
|
, NewCollab (..)
|
|
|
|
, newCollabForm
|
2016-02-27 14:41:36 +09:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2016-05-03 09:33:49 +09:00
|
|
|
--import Prelude
|
|
|
|
|
2016-05-31 10:52:04 +09:00
|
|
|
import Database.Esqueleto hiding ((==.))
|
|
|
|
|
|
|
|
import qualified Database.Esqueleto as E ((==.))
|
|
|
|
|
|
|
|
import Vervis.Import hiding (isNothing, on)
|
2016-02-27 14:41:36 +09:00
|
|
|
import Vervis.Field.Repo
|
2016-05-30 22:10:02 +09:00
|
|
|
import Vervis.Model
|
|
|
|
import Vervis.Model.Ident
|
2016-05-03 08:51:53 +09:00
|
|
|
import Vervis.Model.Repo
|
2016-02-27 14:41:36 +09:00
|
|
|
|
2016-05-30 22:10:02 +09:00
|
|
|
data NewRepo = NewRepo
|
|
|
|
{ nrpIdent :: RpIdent
|
|
|
|
, nrpVcs :: VersionControlSystem
|
|
|
|
, nrpProj :: Maybe ProjectId
|
|
|
|
, nrpDesc :: Maybe Text
|
|
|
|
, nrpRole :: RoleId
|
|
|
|
}
|
|
|
|
|
|
|
|
newRepoAForm
|
|
|
|
:: PersonId -> SharerId -> Maybe ProjectId -> AForm Handler NewRepo
|
|
|
|
newRepoAForm pid sid mpid = NewRepo
|
2016-05-24 05:46:54 +09:00
|
|
|
<$> (text2rp <$> areq (mkIdentField sid) "Identifier*" Nothing)
|
2016-05-03 09:33:49 +09:00
|
|
|
<*> areq (selectFieldList vcsList) "Version control system*" Nothing
|
2016-05-14 22:05:29 +09:00
|
|
|
<*> aopt selectProject "Project" (Just mpid)
|
2016-02-27 14:41:36 +09:00
|
|
|
<*> aopt textField "Description" Nothing
|
2016-05-30 22:10:02 +09:00
|
|
|
<*> areq selectRole "Your role*" Nothing
|
2016-05-03 09:33:49 +09:00
|
|
|
where
|
|
|
|
vcsList :: [(Text, VersionControlSystem)]
|
|
|
|
vcsList =
|
|
|
|
[ ("Darcs", VCSDarcs)
|
|
|
|
, ("Git" , VCSGit)
|
|
|
|
]
|
2016-05-14 22:05:29 +09:00
|
|
|
selectProject =
|
|
|
|
selectField $
|
2016-05-24 05:46:54 +09:00
|
|
|
optionsPersistKey [ProjectSharer ==. sid] [Asc ProjectIdent] $
|
|
|
|
prj2text . projectIdent
|
2016-05-30 22:10:02 +09:00
|
|
|
selectRole =
|
|
|
|
selectField $
|
|
|
|
optionsPersistKey [RolePerson ==. pid] [] $
|
|
|
|
rl2text . roleIdent
|
2016-02-27 14:41:36 +09:00
|
|
|
|
2016-05-30 22:10:02 +09:00
|
|
|
newRepoForm :: PersonId -> SharerId -> Maybe ProjectId -> Form NewRepo
|
|
|
|
newRepoForm pid sid mpid = renderDivs $ newRepoAForm pid sid mpid
|
2016-05-31 10:52:04 +09:00
|
|
|
|
|
|
|
data NewCollab = NewCollab
|
|
|
|
{ ncPerson :: PersonId
|
|
|
|
, ncRole :: RoleId
|
|
|
|
}
|
|
|
|
|
|
|
|
newCollabAForm :: PersonId -> RepoId -> AForm Handler NewCollab
|
|
|
|
newCollabAForm pid rid = NewCollab
|
|
|
|
<$> 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 ?. CollabRepo E.==. just (val rid) &&.
|
|
|
|
collab ?. CollabPerson E.==. just (person ^. PersonId)
|
|
|
|
where_ $ isNothing $ collab ?. CollabId
|
|
|
|
return (sharer ^. SharerIdent, person ^. PersonId)
|
|
|
|
optionsPairs $ map (shr2text . unValue *** unValue) l
|
|
|
|
selectRole =
|
|
|
|
selectField $
|
|
|
|
optionsPersistKey [RolePerson ==. pid] [] $
|
|
|
|
rl2text . roleIdent
|
|
|
|
|
|
|
|
newCollabForm :: PersonId -> RepoId -> Form NewCollab
|
|
|
|
newCollabForm pid rid = renderDivs $ newCollabAForm pid rid
|