1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-29 00:34:54 +09:00

If a repo belongs to a project, pick repo team from project team

This commit is contained in:
fr33domlover 2016-06-05 13:59:48 +00:00
parent 7e0abe20b8
commit 72def092b2
2 changed files with 35 additions and 15 deletions

View file

@ -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

View file

@ -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