{- 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 , NewCollab (..) , newCollabForm ) 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 :: RoleId } newRepoAForm :: PersonId -> SharerId -> Maybe ProjectId -> AForm Handler NewRepo newRepoAForm pid sid mpid = NewRepo <$> (text2rp <$> areq (mkIdentField sid) "Identifier*" Nothing) <*> areq (selectFieldList vcsList) "Version control system*" Nothing <*> aopt selectProject "Project" (Just mpid) <*> aopt textField "Description" Nothing <*> areq selectRole "Your role*" Nothing where vcsList :: [(Text, VersionControlSystem)] vcsList = [ ("Darcs", VCSDarcs) , ("Git" , VCSGit) ] selectProject = selectField $ optionsPersistKey [ProjectSharer ==. sid] [Asc ProjectIdent] $ prj2text . projectIdent selectRole = selectField $ optionsPersistKey [RolePerson ==. pid] [] $ rl2text . roleIdent newRepoForm :: PersonId -> SharerId -> Maybe ProjectId -> Form NewRepo newRepoForm pid sid mpid = renderDivs $ newRepoAForm pid sid mpid 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