From 72def092b2d41d0fc18194be1963f1ebb9a54c9c Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sun, 5 Jun 2016 13:59:48 +0000 Subject: [PATCH] If a repo belongs to a project, pick repo team from project team --- src/Vervis/Form/Repo.hs | 33 ++++++++++++++++++++++++++------- src/Vervis/Handler/Repo.hs | 17 +++++++++-------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/Vervis/Form/Repo.hs b/src/Vervis/Form/Repo.hs index 4d3e2ab..e2f8547 100644 --- a/src/Vervis/Form/Repo.hs +++ b/src/Vervis/Form/Repo.hs @@ -72,12 +72,13 @@ data NewRepoCollab = NewRepoCollab , ncRole :: RepoRoleId } -newRepoCollabAForm :: PersonId -> RepoId -> AForm Handler NewRepoCollab -newRepoCollabAForm pid rid = NewRepoCollab - <$> areq selectPerson "Person*" Nothing - <*> areq selectRole "Role*" Nothing +newRepoCollabAForm + :: PersonId -> Maybe ProjectId -> RepoId -> AForm Handler NewRepoCollab +newRepoCollabAForm pid mjid rid = NewRepoCollab + <$> areq (selectPerson mjid) "Person*" Nothing + <*> areq selectRole "Role*" Nothing where - selectPerson = selectField $ do + selectPerson Nothing = selectField $ do l <- runDB $ select $ from $ \ (collab `RightOuterJoin` person `InnerJoin` sharer) -> do on $ person ^. PersonIdent E.==. sharer ^. SharerId @@ -87,10 +88,28 @@ newRepoCollabAForm pid rid = NewRepoCollab where_ $ isNothing $ collab ?. RepoCollabId return (sharer ^. SharerIdent, person ^. PersonId) optionsPairs $ map (shr2text . unValue *** unValue) l + selectPerson (Just jid) = selectField $ do + l <- runDB $ select $ from $ + \ ( pcollab `InnerJoin` + person `LeftOuterJoin` + rcollab `InnerJoin` + sharer + ) -> do + on $ person ^. PersonIdent E.==. sharer ^. SharerId + on $ + rcollab ?. RepoCollabRepo E.==. just (val rid) &&. + rcollab ?. RepoCollabPerson E.==. just (person ^. PersonId) + on $ + pcollab ^. ProjectCollabProject E.==. val jid &&. + pcollab ^. ProjectCollabPerson E.==. person ^. PersonId + where_ $ isNothing $ rcollab ?. RepoCollabId + return (sharer ^. SharerIdent, person ^. PersonId) + optionsPairs $ map (shr2text . unValue *** unValue) l selectRole = selectField $ optionsPersistKey [RepoRolePerson ==. pid] [] $ rl2text . repoRoleIdent -newRepoCollabForm :: PersonId -> RepoId -> Form NewRepoCollab -newRepoCollabForm pid rid = renderDivs $ newRepoCollabAForm pid rid +newRepoCollabForm + :: PersonId -> Maybe ProjectId -> RepoId -> Form NewRepoCollab +newRepoCollabForm pid mjid rid = renderDivs $ newRepoCollabAForm pid mjid rid diff --git a/src/Vervis/Handler/Repo.hs b/src/Vervis/Handler/Repo.hs index bfbd3b1..106fadc 100644 --- a/src/Vervis/Handler/Repo.hs +++ b/src/Vervis/Handler/Repo.hs @@ -237,12 +237,12 @@ getRepoDevsR shr rp = do postRepoDevsR :: ShrIdent -> RpIdent -> Handler Html postRepoDevsR shr rp = do - (pid, rid) <- runDB $ do + (pid, mjid, rid) <- runDB $ do Entity s _ <- getBy404 $ UniqueSharer shr Entity p _ <- getBy404 $ UniquePersonIdent s - Entity r _ <- getBy404 $ UniqueRepo rp s - return (p, r) - ((result, widget), enctype) <- runFormPost $ newRepoCollabForm pid rid + Entity r repository <- getBy404 $ UniqueRepo rp s + return (p, repoProject repository, r) + ((result, widget), enctype) <- runFormPost $ newRepoCollabForm pid mjid rid case result of FormSuccess nc -> do runDB $ do @@ -263,12 +263,13 @@ postRepoDevsR shr rp = do getRepoDevNewR :: ShrIdent -> RpIdent -> Handler Html getRepoDevNewR shr rp = do - (pid, rid) <- runDB $ do + (pid, mjid, rid) <- runDB $ do Entity s _ <- getBy404 $ UniqueSharer shr Entity p _ <- getBy404 $ UniquePersonIdent s - Entity r _ <- getBy404 $ UniqueRepo rp s - return (p, r) - ((_result, widget), enctype) <- runFormPost $ newRepoCollabForm pid rid + Entity r repository <- getBy404 $ UniqueRepo rp s + return (p, repoProject repository, r) + ((_result, widget), enctype) <- + runFormPost $ newRepoCollabForm pid mjid rid defaultLayout $(widgetFile "repo/collab/new") getRepoDevR :: ShrIdent -> RpIdent -> ShrIdent -> Handler Html