{- This file is part of Vervis. - - Written in 2016 by fr33domlover . - - ♡ 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 - . -} module Vervis.Form.Repo ( NewRepo (..) , newRepoForm , NewRepoCollab (..) , newRepoCollabForm , editRepoForm ) where --import Prelude import Database.Esqueleto hiding ((==.)) import qualified Database.Esqueleto as E ((==.)) import Vervis.Import hiding (isNothing, on) import Vervis.Field.Repo import Vervis.Model import Vervis.Model.Ident import Vervis.Model.Repo data NewRepo = NewRepo { nrpIdent :: RpIdent , nrpVcs :: VersionControlSystem , nrpProj :: Maybe ProjectId , nrpDesc :: Maybe Text , nrpRole :: RepoRoleId } newRepoAForm :: SharerId -> Maybe ProjectId -> AForm Handler NewRepo newRepoAForm sid mjid = NewRepo <$> (text2rp <$> areq (mkIdentField sid) "Identifier*" Nothing) <*> areq (selectFieldList vcsList) "Version control system*" Nothing <*> aopt (selectProjectForNew sid) "Project" (Just mjid) <*> aopt textField "Description" Nothing <*> areq selectRole "Your role*" Nothing where vcsList :: [(Text, VersionControlSystem)] vcsList = [ ("Darcs", VCSDarcs) , ("Git" , VCSGit) ] selectRole = selectField $ optionsPersistKey [RepoRoleSharer ==. sid] [] $ rl2text . repoRoleIdent newRepoForm :: SharerId -> Maybe ProjectId -> Form NewRepo newRepoForm sid mjid = renderDivs $ newRepoAForm sid mjid data NewRepoCollab = NewRepoCollab { ncPerson :: PersonId , ncRole :: RepoRoleId } newRepoCollabAForm :: SharerId -> Maybe ProjectId -> RepoId -> AForm Handler NewRepoCollab newRepoCollabAForm sid mjid rid = NewRepoCollab <$> areq (selectPerson mjid) "Person*" Nothing <*> areq selectRole "Role*" Nothing where selectPerson Nothing = selectCollabFromAll rid selectPerson (Just jid) = selectCollabFromProject jid rid selectRole = selectField $ optionsPersistKey [RepoRoleSharer ==. sid] [] $ rl2text . repoRoleIdent newRepoCollabForm :: SharerId -> Maybe ProjectId -> RepoId -> Form NewRepoCollab newRepoCollabForm sid mjid rid = renderDivs $ newRepoCollabAForm sid mjid rid 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