Eventually-decentralized project hosting and management platform
Clone
HTTPS:
darcs clone https://vervis.peers.community/repos/WvWbo
SSH:
darcs clone USERNAME@vervis.peers.community:WvWbo
Tags
TODO
Ticket.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | {- This file is part of Vervis.
-
- Written in 2016, 2019, 2020, 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.Ticket
( fedUriField
, NewTicket (..)
, NewCloth (..)
, newTicketForm
, newClothForm
--, editTicketContentForm
--, assignTicketForm
--, claimRequestForm
, ticketFilterForm
--, ticketDepForm
)
where
import Control.Applicative (liftA2, liftA3)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Class (lift)
import Data.Bool
import Data.Maybe
import Data.Text (Text)
import Data.Time.Calendar (Day (..))
import Data.Time.Clock (getCurrentTime, UTCTime (..))
import Data.Traversable
import Database.Persist
import Yesod.Core
import Yesod.Form
import Yesod.Persist.Core (runDB)
import qualified Data.Text as T
import Development.PatchMediaType
import Network.FedURI
import Web.Text
import Vervis.FedURI
import Vervis.Foundation (App, Form, Handler)
import Vervis.Model
import Vervis.Model.Ticket
import Vervis.Model.Workflow
import Vervis.Ticket
import Vervis.TicketFilter (TicketFilter (..))
fedUriField
:: (Monad m, RenderMessage (HandlerSite m) FormMessage) => Field m FedURI
fedUriField = Field
{ fieldParse = parseHelper $ \ t ->
case parseObjURI t of
Left e -> Left $ MsgInvalidUrl $ T.pack e <> ": " <> t
Right u -> Right u
, fieldView = \theId name attrs val isReq ->
[whamlet|<input ##{theId} name=#{name} *{attrs} type=url :isReq:required value=#{either id renderObjURI val}>|]
, fieldEnctype = UrlEncoded
}
--TODO use custom fields to ensure uniqueness or other constraints?
data NewTicket = NewTicket
{ ntTitle :: Text
, ntDesc :: PandocMarkdown
--, ntTParams :: [(WorkflowFieldId, Text)]
--, ntEParams :: [(WorkflowFieldId, WorkflowEnumCtorId)]
--, ntCParams :: [WorkflowFieldId]
}
data NewCloth = NewCloth
{ ncTitle :: Text
, ncDesc :: PandocMarkdown
, ncTarget :: Maybe Text
, ncOrigin :: Maybe (FedURI, Maybe Text)
, ncPatch :: Maybe (PatchMediaType, FileInfo)
}
{-
fieldSettings :: Text -> Bool -> FieldSettings App
fieldSettings name req =
fieldSettingsLabel $
if req
then name `T.snoc` '*'
else name
tfield :: Entity WorkflowField -> AForm Handler (Maybe (WorkflowFieldId, Text))
tfield (Entity fid f) =
let sets = fieldSettings (workflowFieldName f) (workflowFieldRequired f)
in fmap (fid, ) <$>
if workflowFieldRequired f
then Just <$> areq textField sets Nothing
else aopt textField sets Nothing
efield
:: Entity WorkflowField
-> Maybe (AForm Handler (Maybe (WorkflowFieldId, WorkflowEnumCtorId)))
efield (Entity fid f) =
case workflowFieldEnm f of
Nothing -> Nothing
Just eid -> Just $
let sets =
fieldSettings
(workflowFieldName f)
(workflowFieldRequired f)
sel =
selectField $
optionsPersistKey
[WorkflowEnumCtorEnum ==. eid]
[]
workflowEnumCtorName
in fmap (fid, ) <$>
if workflowFieldRequired f
then Just <$> areq sel sets Nothing
else aopt sel sets Nothing
cfield :: Entity WorkflowField -> AForm Handler (Maybe WorkflowFieldId)
cfield (Entity fid f) =
let sets = fieldSettings (workflowFieldName f) (workflowFieldRequired f)
mkval False = Nothing
mkval True = Just fid
in if workflowFieldRequired f
then mkval <$> areq checkBoxField sets Nothing
else mkval . fromMaybe False <$> aopt checkBoxField sets Nothing
-}
newTicketForm :: WorkflowId -> Form NewTicket
newTicketForm wid html = do
{-
(tfs, efs, cfs) <- lift $ runDB $ do
tfs <- selectList
[ WorkflowFieldWorkflow ==. wid
, WorkflowFieldType ==. WFTText
, WorkflowFieldEnm ==. Nothing
, WorkflowFieldFilterNew ==. True
]
[]
efs <- selectList
[ WorkflowFieldWorkflow ==. wid
, WorkflowFieldType ==. WFTEnum
, WorkflowFieldFilterNew ==. True
]
[]
cfs <- selectList
[ WorkflowFieldWorkflow ==. wid
, WorkflowFieldType ==. WFTClass
, WorkflowFieldEnm ==. Nothing
, WorkflowFieldFilterNew ==. True
]
[]
return (tfs, efs, cfs)
-}
flip renderDivs html $ NewTicket
<$> (areq textField "Title*" Nothing)
<*> ( pandocMarkdownFromText . T.filter (/= '\r') . unTextarea <$>
areq textareaField "Description (Markdown)*" Nothing
)
-- <*> (catMaybes <$> traverse tfield tfs)
-- <*> (fmap catMaybes $ sequenceA $ mapMaybe efield efs)
-- <*> (catMaybes <$> traverse cfield cfs)
newClothForm :: Form NewCloth
newClothForm = renderDivs $ mk
<$> (areq textField "Title*" Nothing)
<*> ( pandocMarkdownFromText . T.filter (/= '\r') . unTextarea <$>
areq textareaField "Description (Markdown)*" Nothing
)
<*> aopt textField "Target branch" Nothing
<*> aopt fedUriField "Origin repo" Nothing
<*> aopt textField "Origin branch" Nothing
<*> aopt (selectFieldList typeList) "Patch type" Nothing
<*> aopt fileField "Patch file" Nothing
where
typeList :: [(Text, PatchMediaType)]
typeList =
[ ("Darcs", PatchMediaTypeDarcs)
, ("Git" , PatchMediaTypeGit)
]
mk title desc targetBranch originRepo originBranch typ file =
NewCloth
title desc targetBranch
((,originBranch) <$> originRepo) ((,) <$> typ <*> file)
{-
editTicketContentAForm :: Ticket -> AForm Handler Ticket
editTicketContentAForm ticket = Ticket
<$> pure (ticketNumber ticket)
<*> pure (ticketCreated ticket)
<*> ( sanitizeBalance <$>
areq textField "Title*" (Just $ ticketTitle ticket)
)
<*> ( maybe "" (T.filter (/= '\r') . unTextarea) <$>
aopt
textareaField
"Description (Markdown)"
(Just $ Just $ Textarea $
T.intercalate "\r\n" $ T.lines $ ticketSource ticket
)
)
<*> pure (ticketDescription ticket)
<*> pure (ticketAssignee ticket)
<*> pure (ticketStatus ticket)
tEditField
:: TicketTextParam
-> AForm Handler (Maybe TicketParamTextId, Maybe (WorkflowFieldId, Text))
tEditField (TicketTextParam (WorkflowFieldSummary fid _ name req _ _) mv) =
let sets = fieldSettings name req
in (ttpvId <$> mv, ) . fmap (fid, ) <$>
if req
then Just <$> areq textField sets (ttpvVal <$> mv)
else aopt textField sets (Just . ttpvVal <$> mv)
eEditField
:: TicketEnumParam
-> AForm
Handler
( Maybe TicketParamEnumId
, Maybe (WorkflowFieldId, WorkflowEnumCtorId)
)
eEditField (TicketEnumParam (WorkflowFieldSummary fid _ name req _ _) e mv) =
let sets = fieldSettings name req
sel =
selectField $
optionsPersistKey
[WorkflowEnumCtorEnum ==. wesId e]
[]
workflowEnumCtorName
in (tepvId <$> mv, ) . fmap (fid, ) <$>
if req
then Just <$> areq sel sets (tepvVal <$> mv)
else aopt sel sets (Just . tepvVal <$> mv)
cEditField
:: TicketClassParam
-> AForm Handler (Maybe TicketParamClassId, Maybe WorkflowFieldId)
cEditField (TicketClassParam (WorkflowFieldSummary fid _ name req _ _) mv) =
let sets = fieldSettings name req
in (mv,) . bool Nothing (Just fid) <$> areq checkBoxField sets (Just $ isJust mv)
editableField :: Ticket -> WorkflowFieldSummary -> Bool
editableField t f =
not (wfsConstant f) &&
case ticketStatus t of
TSNew -> wffNew $ wfsFilter f
TSTodo -> wffTodo $ wfsFilter f
TSClosed -> wffClosed $ wfsFilter f
editTicketContentForm
:: TicketId
-> Ticket
-> WorkflowId
-> Form
( Ticket
, [ ( Maybe TicketParamTextId
, Maybe (WorkflowFieldId, Text)
)
]
, [ ( Maybe TicketParamEnumId
, Maybe (WorkflowFieldId, WorkflowEnumCtorId)
)
]
, [ ( Maybe TicketParamClassId
, Maybe WorkflowFieldId
)
]
)
editTicketContentForm tid t wid html = do
(tfs, efs, cfs) <-
lift $ runDB $
liftA3 (,,)
( filter (editableField t . ttpField) <$>
getTicketTextParams tid wid
)
( filter (editableField t . tepField) <$>
getTicketEnumParams tid wid
)
( filter (editableField t . tcpField) <$>
getTicketClasses tid wid
)
flip renderDivs html $
(,,,)
<$> editTicketContentAForm t
<*> traverse tEditField tfs
<*> traverse eEditField efs
<*> traverse cEditField cfs
-}
{-
assignTicketAForm :: PersonId -> ProjectId -> AForm Handler PersonId
assignTicketAForm pid jid =
areq (selectAssigneeFromProject pid jid) "Assignee*" Nothing
assignTicketForm :: PersonId -> ProjectId -> Form PersonId
assignTicketForm pid jid = renderDivs $ assignTicketAForm pid jid
-}
{-
claimRequestAForm :: AForm Handler Text
claimRequestAForm = unTextarea <$> areq textareaField "Message*" Nothing
claimRequestForm :: Form Text
claimRequestForm = renderDivs claimRequestAForm
-}
ticketFilterAForm :: AForm Handler TicketFilter
ticketFilterAForm = TicketFilter
<$> areq checkBoxField "Open" (Just True)
<*> areq checkBoxField "Closed" (Just False)
ticketFilterForm :: Form TicketFilter
ticketFilterForm = renderDivs ticketFilterAForm
{-
ticketDepAForm :: ProjectId -> TicketId -> AForm Handler TicketId
ticketDepAForm jid tid = areq (selectTicketDep jid tid) "Dependency" Nothing
ticketDepForm :: ProjectId -> TicketId -> Form TicketId
ticketDepForm jid tid = renderDivs $ ticketDepAForm jid tid
-}
|