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-06-01 16:35:22 +09:00
|
|
|
, NewRepoCollab (..)
|
|
|
|
, newRepoCollabForm
|
2016-06-06 06:11:05 +09:00
|
|
|
, editRepoForm
|
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
|
2016-06-01 16:35:22 +09:00
|
|
|
, nrpRole :: RepoRoleId
|
2016-05-30 22:10:02 +09:00
|
|
|
}
|
|
|
|
|
2016-06-07 02:29:54 +09:00
|
|
|
newRepoAForm :: SharerId -> Maybe ProjectId -> AForm Handler NewRepo
|
|
|
|
newRepoAForm sid mjid = 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-06-07 02:29:54 +09:00
|
|
|
<*> aopt (selectProjectForNew sid) "Project" (Just mjid)
|
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-30 22:10:02 +09:00
|
|
|
selectRole =
|
|
|
|
selectField $
|
2016-06-07 02:29:54 +09:00
|
|
|
optionsPersistKey [RepoRoleSharer ==. sid] [] $
|
2016-06-01 16:35:22 +09:00
|
|
|
rl2text . repoRoleIdent
|
2016-02-27 14:41:36 +09:00
|
|
|
|
2016-06-07 02:29:54 +09:00
|
|
|
newRepoForm :: SharerId -> Maybe ProjectId -> Form NewRepo
|
|
|
|
newRepoForm sid mjid = renderDivs $ newRepoAForm sid mjid
|
2016-05-31 10:52:04 +09:00
|
|
|
|
2016-06-01 16:35:22 +09:00
|
|
|
data NewRepoCollab = NewRepoCollab
|
2016-05-31 10:52:04 +09:00
|
|
|
{ ncPerson :: PersonId
|
2016-06-01 16:35:22 +09:00
|
|
|
, ncRole :: RepoRoleId
|
2016-05-31 10:52:04 +09:00
|
|
|
}
|
|
|
|
|
2016-06-05 22:59:48 +09:00
|
|
|
newRepoCollabAForm
|
2016-06-07 02:29:54 +09:00
|
|
|
:: SharerId -> Maybe ProjectId -> RepoId -> AForm Handler NewRepoCollab
|
|
|
|
newRepoCollabAForm sid mjid rid = NewRepoCollab
|
2016-06-05 22:59:48 +09:00
|
|
|
<$> areq (selectPerson mjid) "Person*" Nothing
|
|
|
|
<*> areq selectRole "Role*" Nothing
|
2016-05-31 10:52:04 +09:00
|
|
|
where
|
2016-06-06 15:03:42 +09:00
|
|
|
selectPerson Nothing = selectCollabFromAll rid
|
|
|
|
selectPerson (Just jid) = selectCollabFromProject jid rid
|
2016-05-31 10:52:04 +09:00
|
|
|
selectRole =
|
|
|
|
selectField $
|
2016-06-07 02:29:54 +09:00
|
|
|
optionsPersistKey [RepoRoleSharer ==. sid] [] $
|
2016-06-01 16:35:22 +09:00
|
|
|
rl2text . repoRoleIdent
|
2016-05-31 10:52:04 +09:00
|
|
|
|
2016-06-05 22:59:48 +09:00
|
|
|
newRepoCollabForm
|
2016-06-07 02:29:54 +09:00
|
|
|
:: SharerId -> Maybe ProjectId -> RepoId -> Form NewRepoCollab
|
|
|
|
newRepoCollabForm sid mjid rid = renderDivs $ newRepoCollabAForm sid mjid rid
|
2016-06-06 06:11:05 +09:00
|
|
|
|
|
|
|
editRepoAForm :: Entity Repo -> AForm Handler Repo
|
|
|
|
editRepoAForm (Entity rid repo) = Repo
|
|
|
|
<$> pure (repoIdent repo)
|
|
|
|
<*> pure (repoSharer repo)
|
|
|
|
<*> pure (repoVcs repo)
|
|
|
|
<*> aopt selectProject' "Project" (Just $ repoProject repo)
|
|
|
|
<*> aopt textField "Description" (Just $ repoDesc repo)
|
|
|
|
<*> let b = repoMainBranch repo
|
|
|
|
in case repoVcs repo of
|
|
|
|
VCSDarcs -> pure b
|
|
|
|
VCSGit -> areq textField "Main branch*" (Just b)
|
|
|
|
where
|
|
|
|
selectProject' = selectProjectForExisting (repoSharer repo) rid
|
|
|
|
|
|
|
|
editRepoForm :: Entity Repo -> Form Repo
|
|
|
|
editRepoForm r = renderDivs $ editRepoAForm r
|