{- 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.Project ( newProjectForm , NewProjectCollab (..) , newProjectCollabForm , editProjectForm ) where import Vervis.Import hiding (on, isNothing) import Database.Esqueleto hiding ((==.)) import qualified Database.Esqueleto as E ((==.)) import Vervis.Field.Project import Vervis.Model import Vervis.Model.Ident import Vervis.Model.Repo newProjectAForm :: SharerId -> AForm Handler Project newProjectAForm sid = Project <$> (text2prj <$> areq (mkIdentField sid) "Identifier*" Nothing) <*> pure sid <*> aopt textField "Name" Nothing <*> aopt textField "Description" Nothing <*> pure 1 <*> pure Nothing newProjectForm :: SharerId -> Form Project newProjectForm = renderDivs . newProjectAForm data NewProjectCollab = NewProjectCollab { ncPerson :: PersonId , ncRole :: ProjectRoleId } newProjectCollabAForm :: PersonId -> ProjectId -> AForm Handler NewProjectCollab newProjectCollabAForm pid rid = NewProjectCollab <$> 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 ?. ProjectCollabProject E.==. just (val rid) &&. collab ?. ProjectCollabPerson E.==. just (person ^. PersonId) where_ $ isNothing $ collab ?. ProjectCollabId return (sharer ^. SharerIdent, person ^. PersonId) optionsPairs $ map (shr2text . unValue *** unValue) l selectRole = selectField $ optionsPersistKey [ProjectRolePerson ==. pid] [] $ rl2text . projectRoleIdent newProjectCollabForm :: PersonId -> ProjectId -> Form NewProjectCollab newProjectCollabForm pid rid = renderDivs $ newProjectCollabAForm pid rid editProjectAForm :: Entity Project -> AForm Handler Project editProjectAForm (Entity jid project) = Project <$> pure (projectIdent project) <*> pure (projectSharer project) <*> aopt textField "Name" (Just $ projectName project) <*> aopt textField "Description" (Just $ projectDesc project) <*> pure (projectNextTicket project) <*> aopt selectWiki "Wiki" (Just $ projectWiki project) where selectWiki = selectField $ optionsPersistKey [RepoProject ==. Just jid] [] $ rp2text . repoIdent editProjectForm :: Entity Project -> Form Project editProjectForm p = renderDivs $ editProjectAForm p