Eventually-decentralized project hosting and management platform

[[ 🗃 ^WvWbo vervis ]] :: [📥 Inbox] [📤 Outbox] [🐤 Followers] [🤝 Collaborators] [🛠 Changes]

Clone

HTTPS: darcs clone https://vervis.peers.community/repos/WvWbo

SSH: darcs clone USERNAME@vervis.peers.community:WvWbo

Tags

TODO

src / Vervis / Form /

Repo.hs

{- This file is part of Vervis.
 -
 - Written in 2016, 2019, 2022 by fr33domlover <fr33domlover@riseup.net>.
 -
 - ♡ 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
 - <http://creativecommons.org/publicdomain/zero/1.0/>.
 -}

module Vervis.Form.Repo
    ( NewRepo (..)
    , newRepoForm
    --, NewRepoCollab (..)
    --, newRepoCollabForm
    --, editRepoForm
    )
where

import Data.Text (Text)
import Yesod.Form.Fields
import Yesod.Form.Functions
import Yesod.Form.Types

import Development.PatchMediaType

import Vervis.Foundation
import Vervis.Model

data NewRepo = NewRepo
    { nrpName :: Text
    , nrpDesc :: Text
    , nrpVcs  :: VersionControlSystem
    }

newRepoForm :: Form NewRepo
newRepoForm = renderDivs $ NewRepo
    <$> areq textField                 "Name*"                   Nothing
    <*> areq textField                 "Description"             Nothing
    <*> areq (selectFieldList vcsList) "Version control system*" Nothing
    where
    vcsList :: [(Text, VersionControlSystem)]
    vcsList =
        [ ("Darcs", VCSDarcs)
        , ("Git"  , VCSGit)
        ]

{-
data NewRepoCollab = NewRepoCollab
    { ncPerson :: PersonId
    , ncRole   :: Maybe RoleId
    }

newRepoCollabAForm
    :: SharerId -> Maybe ProjectId -> RepoId -> AForm Handler NewRepoCollab
newRepoCollabAForm sid mjid rid = NewRepoCollab
    <$> areq (selectPerson mjid) "Person*"     Nothing
    <*> aopt selectRole          "Custom role" Nothing
    where
    selectPerson Nothing    = selectCollabFromAll rid
    selectPerson (Just jid) = selectCollabFromProject jid rid
    selectRole =
        selectField $
        optionsPersistKey [RoleSharer ==. sid] [] $
        rl2text . roleIdent

newRepoCollabForm
    :: SharerId -> Maybe ProjectId -> RepoId -> Form NewRepoCollab
newRepoCollabForm sid mjid rid = renderDivs $ newRepoCollabAForm sid mjid rid

editRepoAForm :: SharerId -> Entity Repo -> AForm Handler Repo
editRepoAForm sid (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)
        )
    <*> aopt selectRole "User role"  (Just $ repoCollabUser repo)
    <*> aopt selectRole "Guest role" (Just $ repoCollabAnon repo)
    <*> pure (repoInbox repo)
    <*> pure (repoOutbox repo)
    <*> pure (repoFollowers repo)
    where
    selectProject' = selectProjectForExisting (repoSharer repo) rid
    selectRole =
        selectField $
        optionsPersistKey [RoleSharer ==. sid] [] $
        rl2text . roleIdent

editRepoForm :: SharerId -> Entity Repo -> Form Repo
editRepoForm s r = renderDivs $ editRepoAForm s r
-}
[See repo JSON]