2016-05-01 07:32:22 +09:00
|
|
|
|
{- This file is part of Vervis.
|
|
|
|
|
-
|
2019-03-16 01:36:02 +09:00
|
|
|
|
- Written in 2016, 2018, 2019 by fr33domlover <fr33domlover@riseup.net>.
|
2016-05-01 07:32:22 +09:00
|
|
|
|
-
|
|
|
|
|
- ♡ 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.Handler.Ticket
|
|
|
|
|
( getTicketsR
|
|
|
|
|
, postTicketsR
|
2016-08-04 16:36:24 +09:00
|
|
|
|
, getTicketTreeR
|
2016-05-01 07:32:22 +09:00
|
|
|
|
, getTicketNewR
|
2016-05-01 08:02:44 +09:00
|
|
|
|
, getTicketR
|
2016-05-02 15:13:57 +09:00
|
|
|
|
, putTicketR
|
|
|
|
|
, deleteTicketR
|
2016-05-02 20:34:11 +09:00
|
|
|
|
, postTicketR
|
2016-05-02 15:13:57 +09:00
|
|
|
|
, getTicketEditR
|
2016-08-11 16:58:51 +09:00
|
|
|
|
, postTicketAcceptR
|
2016-06-02 04:50:41 +09:00
|
|
|
|
, postTicketCloseR
|
|
|
|
|
, postTicketOpenR
|
2016-06-06 18:03:49 +09:00
|
|
|
|
, postTicketClaimR
|
|
|
|
|
, postTicketUnclaimR
|
2016-06-07 16:33:19 +09:00
|
|
|
|
, getTicketAssignR
|
|
|
|
|
, postTicketAssignR
|
|
|
|
|
, postTicketUnassignR
|
2016-06-08 01:31:55 +09:00
|
|
|
|
, getClaimRequestsPersonR
|
|
|
|
|
, getClaimRequestsProjectR
|
|
|
|
|
, getClaimRequestsTicketR
|
2016-06-08 10:28:18 +09:00
|
|
|
|
, postClaimRequestsTicketR
|
|
|
|
|
, getClaimRequestNewR
|
2016-05-20 01:58:23 +09:00
|
|
|
|
, getTicketDiscussionR
|
2016-05-22 05:01:31 +09:00
|
|
|
|
, postTicketDiscussionR
|
2019-03-23 05:46:42 +09:00
|
|
|
|
, getMessageR
|
2016-05-20 07:07:25 +09:00
|
|
|
|
, postTicketMessageR
|
|
|
|
|
, getTicketTopReplyR
|
|
|
|
|
, getTicketReplyR
|
2016-06-08 05:16:15 +09:00
|
|
|
|
, getTicketDepsR
|
2016-07-29 01:40:10 +09:00
|
|
|
|
, postTicketDepsR
|
|
|
|
|
, getTicketDepNewR
|
|
|
|
|
, postTicketDepR
|
|
|
|
|
, deleteTicketDepR
|
2016-07-27 17:35:50 +09:00
|
|
|
|
, getTicketReverseDepsR
|
2019-04-11 22:44:44 +09:00
|
|
|
|
, getTicketParticipantsR
|
|
|
|
|
, getTicketTeamR
|
2016-05-01 07:32:22 +09:00
|
|
|
|
)
|
|
|
|
|
where
|
|
|
|
|
|
|
|
|
|
import Prelude
|
|
|
|
|
|
2016-08-04 16:36:24 +09:00
|
|
|
|
import Control.Applicative (liftA2)
|
2016-05-18 18:15:11 +09:00
|
|
|
|
import Control.Monad.IO.Class (liftIO)
|
2016-06-06 18:03:49 +09:00
|
|
|
|
import Control.Monad.Logger (logWarn)
|
2016-08-11 18:27:30 +09:00
|
|
|
|
import Data.Bool (bool)
|
2016-05-22 23:31:56 +09:00
|
|
|
|
import Data.Default.Class (def)
|
2016-08-11 03:52:26 +09:00
|
|
|
|
import Data.Foldable (traverse_)
|
2016-05-01 18:58:55 +09:00
|
|
|
|
import Data.Maybe (fromMaybe)
|
2016-06-07 16:33:19 +09:00
|
|
|
|
import Data.Monoid ((<>))
|
2016-05-01 07:32:22 +09:00
|
|
|
|
import Data.Text (Text)
|
2016-05-18 18:15:11 +09:00
|
|
|
|
import Data.Time.Calendar (Day (..))
|
|
|
|
|
import Data.Time.Clock (UTCTime (..), getCurrentTime)
|
2016-05-01 18:58:55 +09:00
|
|
|
|
import Data.Time.Format (formatTime, defaultTimeLocale)
|
2016-06-02 01:20:19 +09:00
|
|
|
|
import Data.Traversable (for)
|
2016-08-09 20:36:14 +09:00
|
|
|
|
import Database.Esqueleto hiding ((=.), (+=.), update, delete)
|
|
|
|
|
import Database.Persist hiding ((==.))
|
2018-07-11 17:15:19 +09:00
|
|
|
|
import Network.HTTP.Types (StdMethod (DELETE, POST))
|
2016-05-01 07:32:22 +09:00
|
|
|
|
import Text.Blaze.Html (Html, toHtml)
|
2016-06-06 19:00:05 +09:00
|
|
|
|
import Yesod.Auth (requireAuthId, maybeAuthId)
|
2019-03-23 05:46:42 +09:00
|
|
|
|
import Yesod.Core
|
2019-03-16 01:36:02 +09:00
|
|
|
|
import Yesod.Core.Handler
|
2016-05-22 23:31:56 +09:00
|
|
|
|
import Yesod.Form.Functions (runFormGet, runFormPost)
|
2016-05-01 19:15:38 +09:00
|
|
|
|
import Yesod.Form.Types (FormResult (..))
|
2016-05-01 18:58:55 +09:00
|
|
|
|
import Yesod.Persist.Core (runDB, get404, getBy404)
|
2016-05-01 07:32:22 +09:00
|
|
|
|
|
2016-05-03 06:20:25 +09:00
|
|
|
|
import qualified Data.Text as T (filter, intercalate, pack)
|
2016-05-01 18:58:55 +09:00
|
|
|
|
import qualified Database.Esqueleto as E ((==.))
|
2016-05-01 07:32:22 +09:00
|
|
|
|
|
2016-07-29 01:40:10 +09:00
|
|
|
|
import Database.Persist.Sql.Graph.TransitiveReduction (trrFix)
|
2019-03-29 12:25:32 +09:00
|
|
|
|
import Yesod.Hashids
|
|
|
|
|
|
|
|
|
|
import Data.Maybe.Local (partitionMaybePairs)
|
|
|
|
|
|
2016-05-01 07:32:22 +09:00
|
|
|
|
import Vervis.Form.Ticket
|
|
|
|
|
import Vervis.Foundation
|
2016-05-20 01:58:23 +09:00
|
|
|
|
import Vervis.Handler.Discussion
|
2016-07-29 01:40:10 +09:00
|
|
|
|
import Vervis.GraphProxy (ticketDepGraph)
|
2016-05-03 06:20:25 +09:00
|
|
|
|
import Vervis.MediaType (MediaType (Markdown))
|
2016-05-01 07:32:22 +09:00
|
|
|
|
import Vervis.Model
|
2016-05-24 05:46:54 +09:00
|
|
|
|
import Vervis.Model.Ident
|
2016-08-11 09:44:11 +09:00
|
|
|
|
import Vervis.Model.Ticket
|
2016-08-09 05:51:58 +09:00
|
|
|
|
import Vervis.Model.Workflow
|
2016-05-03 06:20:25 +09:00
|
|
|
|
import Vervis.Render (renderSourceT)
|
2019-04-21 06:34:45 +09:00
|
|
|
|
import Vervis.Settings
|
2016-08-11 18:27:30 +09:00
|
|
|
|
import Vervis.Style
|
2016-08-04 16:36:24 +09:00
|
|
|
|
import Vervis.Ticket
|
2016-05-22 23:31:56 +09:00
|
|
|
|
import Vervis.TicketFilter (filterTickets)
|
2016-06-06 16:26:58 +09:00
|
|
|
|
import Vervis.Time (showDate)
|
2018-07-11 17:15:19 +09:00
|
|
|
|
import Vervis.Widget (buttonW)
|
2016-05-18 19:26:19 +09:00
|
|
|
|
import Vervis.Widget.Discussion (discussionW)
|
2016-05-25 06:48:21 +09:00
|
|
|
|
import Vervis.Widget.Sharer (personLinkW)
|
2016-07-04 18:58:25 +09:00
|
|
|
|
import Vervis.Widget.Ticket
|
2016-05-01 07:32:22 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketsR :: ShrIdent -> PrjIdent -> Handler Html
|
2018-05-26 17:02:07 +09:00
|
|
|
|
getTicketsR shr prj = do
|
2016-05-22 23:31:56 +09:00
|
|
|
|
((filtResult, filtWidget), filtEnctype) <- runFormGet ticketFilterForm
|
|
|
|
|
let tf =
|
|
|
|
|
case filtResult of
|
|
|
|
|
FormSuccess filt -> filt
|
|
|
|
|
FormMissing -> def
|
|
|
|
|
FormFailure l ->
|
|
|
|
|
error $ "Ticket filter form failed: " ++ show l
|
2018-05-26 17:02:07 +09:00
|
|
|
|
rows <- runDB $ do
|
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity jid _ <- getBy404 $ UniqueProject prj sid
|
2018-06-17 19:29:51 +09:00
|
|
|
|
getTicketSummaries
|
|
|
|
|
(filterTickets tf)
|
|
|
|
|
(Just $ \ t -> [asc $ t ^. TicketNumber])
|
|
|
|
|
jid
|
2016-05-18 18:38:48 +09:00
|
|
|
|
defaultLayout $(widgetFile "ticket/list")
|
2016-05-01 07:32:22 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
postTicketsR :: ShrIdent -> PrjIdent -> Handler Html
|
2016-05-01 19:15:38 +09:00
|
|
|
|
postTicketsR shar proj = do
|
2016-08-09 08:36:39 +09:00
|
|
|
|
Entity pid project <- runDB $ do
|
|
|
|
|
Entity sid _sharer <- getBy404 $ UniqueSharer shar
|
|
|
|
|
getBy404 $ UniqueProject proj sid
|
|
|
|
|
((result, widget), enctype) <-
|
|
|
|
|
runFormPost $ newTicketForm $ projectWorkflow project
|
2016-05-01 19:15:38 +09:00
|
|
|
|
case result of
|
2016-05-18 18:15:11 +09:00
|
|
|
|
FormSuccess nt -> do
|
|
|
|
|
author <- requireAuthId
|
|
|
|
|
now <- liftIO getCurrentTime
|
|
|
|
|
tnum <- runDB $ do
|
2016-05-18 18:44:32 +09:00
|
|
|
|
update pid [ProjectNextTicket +=. 1]
|
2019-03-19 05:18:25 +09:00
|
|
|
|
did <- insert Discussion
|
2019-04-11 22:26:57 +09:00
|
|
|
|
fsid <- insert FollowerSet
|
2016-05-18 18:15:11 +09:00
|
|
|
|
let ticket = Ticket
|
2016-06-02 01:20:19 +09:00
|
|
|
|
{ ticketProject = pid
|
|
|
|
|
, ticketNumber = projectNextTicket project
|
|
|
|
|
, ticketCreated = now
|
|
|
|
|
, ticketCreator = author
|
|
|
|
|
, ticketTitle = ntTitle nt
|
|
|
|
|
, ticketDesc = ntDesc nt
|
|
|
|
|
, ticketAssignee = Nothing
|
2016-08-11 09:44:11 +09:00
|
|
|
|
, ticketStatus = TSNew
|
2016-06-02 01:20:19 +09:00
|
|
|
|
, ticketClosed = UTCTime (ModifiedJulianDay 0) 0
|
|
|
|
|
, ticketCloser = author
|
|
|
|
|
, ticketDiscuss = did
|
2019-04-11 22:26:57 +09:00
|
|
|
|
, ticketFollowers = fsid
|
2016-05-18 18:15:11 +09:00
|
|
|
|
}
|
2016-08-09 08:36:39 +09:00
|
|
|
|
tid <- insert ticket
|
2016-08-09 21:34:03 +09:00
|
|
|
|
let mktparam (fid, v) = TicketParamText
|
2016-08-09 08:36:39 +09:00
|
|
|
|
{ ticketParamTextTicket = tid
|
|
|
|
|
, ticketParamTextField = fid
|
|
|
|
|
, ticketParamTextValue = v
|
|
|
|
|
}
|
2016-08-09 21:34:03 +09:00
|
|
|
|
insertMany_ $ map mktparam $ ntTParams nt
|
|
|
|
|
let mkeparam (fid, v) = TicketParamEnum
|
|
|
|
|
{ ticketParamEnumTicket = tid
|
|
|
|
|
, ticketParamEnumField = fid
|
|
|
|
|
, ticketParamEnumValue = v
|
|
|
|
|
}
|
|
|
|
|
insertMany_ $ map mkeparam $ ntEParams nt
|
2016-05-18 18:15:11 +09:00
|
|
|
|
return $ ticketNumber ticket
|
2016-05-01 19:15:38 +09:00
|
|
|
|
setMessage "Ticket created."
|
2016-05-18 18:15:11 +09:00
|
|
|
|
redirect $ TicketR shar proj tnum
|
2016-05-01 19:15:38 +09:00
|
|
|
|
FormMissing -> do
|
|
|
|
|
setMessage "Field(s) missing."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/new")
|
|
|
|
|
FormFailure _l -> do
|
|
|
|
|
setMessage "Ticket creation failed, see errors below."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/new")
|
2016-05-01 07:32:22 +09:00
|
|
|
|
|
2016-08-04 16:36:24 +09:00
|
|
|
|
getTicketTreeR :: ShrIdent -> PrjIdent -> Handler Html
|
|
|
|
|
getTicketTreeR shr prj = do
|
|
|
|
|
(summaries, deps) <- runDB $ do
|
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity jid _ <- getBy404 $ UniqueProject prj sid
|
|
|
|
|
liftA2 (,)
|
2018-06-17 19:29:51 +09:00
|
|
|
|
(getTicketSummaries Nothing Nothing jid)
|
2016-08-04 16:36:24 +09:00
|
|
|
|
(getTicketDepEdges jid)
|
|
|
|
|
defaultLayout $ ticketTreeDW shr prj summaries deps
|
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketNewR :: ShrIdent -> PrjIdent -> Handler Html
|
2016-05-01 07:32:22 +09:00
|
|
|
|
getTicketNewR shar proj = do
|
2016-08-09 08:36:39 +09:00
|
|
|
|
wid <- runDB $ do
|
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shar
|
|
|
|
|
Entity _ j <- getBy404 $ UniqueProject proj sid
|
|
|
|
|
return $ projectWorkflow j
|
|
|
|
|
((_result, widget), enctype) <- runFormPost $ newTicketForm wid
|
2016-05-18 18:15:11 +09:00
|
|
|
|
defaultLayout $(widgetFile "ticket/new")
|
2016-05-01 08:02:44 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-01 18:58:55 +09:00
|
|
|
|
getTicketR shar proj num = do
|
2016-06-06 19:00:05 +09:00
|
|
|
|
mpid <- maybeAuthId
|
2016-08-09 20:36:14 +09:00
|
|
|
|
( wshr, wfl,
|
|
|
|
|
author, massignee, closer, ticket, tparams, eparams, deps, rdeps) <-
|
2016-08-09 05:51:58 +09:00
|
|
|
|
runDB $ do
|
|
|
|
|
(jid, wshr, wid, wfl) <- do
|
|
|
|
|
Entity s sharer <- getBy404 $ UniqueSharer shar
|
|
|
|
|
Entity p project <- getBy404 $ UniqueProject proj s
|
|
|
|
|
w <- get404 $ projectWorkflow project
|
|
|
|
|
wsharer <-
|
|
|
|
|
if workflowSharer w == s
|
|
|
|
|
then return sharer
|
|
|
|
|
else get404 $ workflowSharer w
|
|
|
|
|
return
|
|
|
|
|
( p
|
|
|
|
|
, sharerIdent wsharer
|
|
|
|
|
, projectWorkflow project
|
|
|
|
|
, workflowIdent w
|
|
|
|
|
)
|
|
|
|
|
Entity tid ticket <- getBy404 $ UniqueTicket jid num
|
|
|
|
|
author <- do
|
|
|
|
|
person <- get404 $ ticketCreator ticket
|
|
|
|
|
get404 $ personIdent person
|
|
|
|
|
massignee <- for (ticketAssignee ticket) $ \ apid -> do
|
|
|
|
|
person <- get404 apid
|
|
|
|
|
sharer <- get404 $ personIdent person
|
|
|
|
|
return (sharer, fromMaybe False $ (== apid) <$> mpid)
|
|
|
|
|
closer <-
|
2016-08-11 09:44:11 +09:00
|
|
|
|
case ticketStatus ticket of
|
|
|
|
|
TSClosed -> do
|
2016-08-09 05:51:58 +09:00
|
|
|
|
person <- get404 $ ticketCloser ticket
|
|
|
|
|
get404 $ personIdent person
|
2016-08-11 09:44:11 +09:00
|
|
|
|
_ -> return author
|
2016-08-11 03:52:26 +09:00
|
|
|
|
tparams <- getTicketTextParams tid wid
|
|
|
|
|
eparams <- getTicketEnumParams tid wid
|
2016-08-09 05:51:58 +09:00
|
|
|
|
deps <- select $ from $ \ (dep `InnerJoin` t) -> do
|
2016-08-09 20:36:14 +09:00
|
|
|
|
on $ dep ^. TicketDependencyChild ==. t ^. TicketId
|
|
|
|
|
where_ $ dep ^. TicketDependencyParent ==. val tid
|
2016-08-09 05:51:58 +09:00
|
|
|
|
return t
|
|
|
|
|
rdeps <- select $ from $ \ (dep `InnerJoin` t) -> do
|
2016-08-09 20:36:14 +09:00
|
|
|
|
on $ dep ^. TicketDependencyParent ==. t ^. TicketId
|
|
|
|
|
where_ $ dep ^. TicketDependencyChild ==. val tid
|
2016-08-09 05:51:58 +09:00
|
|
|
|
return t
|
|
|
|
|
return
|
|
|
|
|
( wshr, wfl
|
2016-08-09 20:36:14 +09:00
|
|
|
|
, author, massignee, closer, ticket, tparams, eparams
|
|
|
|
|
, deps, rdeps
|
2016-08-09 05:51:58 +09:00
|
|
|
|
)
|
2019-03-29 12:25:32 +09:00
|
|
|
|
encodeHid <- getEncodeKeyHashid
|
2016-05-03 06:20:25 +09:00
|
|
|
|
let desc = renderSourceT Markdown $ T.filter (/= '\r') $ ticketDesc ticket
|
2016-05-22 06:27:12 +09:00
|
|
|
|
discuss =
|
|
|
|
|
discussionW
|
|
|
|
|
(return $ ticketDiscuss ticket)
|
|
|
|
|
(TicketTopReplyR shar proj num)
|
2019-03-29 12:25:32 +09:00
|
|
|
|
(TicketReplyR shar proj num . encodeHid)
|
2016-08-11 18:27:30 +09:00
|
|
|
|
cRelevant <- newIdent
|
|
|
|
|
cIrrelevant <- newIdent
|
|
|
|
|
let relevant filt =
|
|
|
|
|
bool cIrrelevant cRelevant $
|
|
|
|
|
case ticketStatus ticket of
|
|
|
|
|
TSNew -> wffNew filt
|
|
|
|
|
TSTodo -> wffTodo filt
|
|
|
|
|
TSClosed -> wffClosed filt
|
2016-05-20 01:58:23 +09:00
|
|
|
|
defaultLayout $(widgetFile "ticket/one")
|
2016-05-02 15:13:57 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
putTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-02 18:15:10 +09:00
|
|
|
|
putTicketR shar proj num = do
|
2016-08-11 03:52:26 +09:00
|
|
|
|
(tid, ticket, wid) <- runDB $ do
|
2016-05-24 05:46:54 +09:00
|
|
|
|
Entity sid _sharer <- getBy404 $ UniqueSharer shar
|
2016-08-11 03:52:26 +09:00
|
|
|
|
Entity pid project <- getBy404 $ UniqueProject proj sid
|
|
|
|
|
Entity tid ticket <- getBy404 $ UniqueTicket pid num
|
|
|
|
|
return (tid, ticket, projectWorkflow project)
|
|
|
|
|
((result, widget), enctype) <-
|
|
|
|
|
runFormPost $ editTicketContentForm tid ticket wid
|
2016-05-02 18:15:10 +09:00
|
|
|
|
case result of
|
2016-08-11 03:52:26 +09:00
|
|
|
|
FormSuccess (ticket', tparams, eparams) -> do
|
|
|
|
|
runDB $ do
|
|
|
|
|
replace tid ticket'
|
|
|
|
|
let (tdel, tins, tupd) = partitionMaybePairs tparams
|
|
|
|
|
deleteWhere [TicketParamTextId <-. tdel]
|
|
|
|
|
let mktparam (fid, v) = TicketParamText
|
|
|
|
|
{ ticketParamTextTicket = tid
|
|
|
|
|
, ticketParamTextField = fid
|
|
|
|
|
, ticketParamTextValue = v
|
|
|
|
|
}
|
|
|
|
|
insertMany_ $ map mktparam tins
|
|
|
|
|
traverse_
|
|
|
|
|
(\ (aid, (_fid, v)) ->
|
|
|
|
|
update aid [TicketParamTextValue =. v]
|
|
|
|
|
)
|
|
|
|
|
tupd
|
|
|
|
|
let (edel, eins, eupd) = partitionMaybePairs eparams
|
|
|
|
|
deleteWhere [TicketParamEnumId <-. edel]
|
|
|
|
|
let mkeparam (fid, v) = TicketParamEnum
|
|
|
|
|
{ ticketParamEnumTicket = tid
|
|
|
|
|
, ticketParamEnumField = fid
|
|
|
|
|
, ticketParamEnumValue = v
|
|
|
|
|
}
|
|
|
|
|
insertMany_ $ map mkeparam eins
|
|
|
|
|
traverse_
|
|
|
|
|
(\ (aid, (_fid, v)) ->
|
|
|
|
|
update aid [TicketParamEnumValue =. v]
|
|
|
|
|
)
|
|
|
|
|
eupd
|
2016-05-02 20:33:30 +09:00
|
|
|
|
setMessage "Ticket updated."
|
2016-05-02 18:15:10 +09:00
|
|
|
|
redirect $ TicketR shar proj num
|
|
|
|
|
FormMissing -> do
|
|
|
|
|
setMessage "Field(s) missing."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/edit")
|
|
|
|
|
FormFailure _l -> do
|
|
|
|
|
setMessage "Ticket update failed, see errors below."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/edit")
|
2016-05-02 15:13:57 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
deleteTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-02 18:15:10 +09:00
|
|
|
|
deleteTicketR shar proj num =
|
|
|
|
|
--TODO: I can easily implement this, but should it even be possible to
|
|
|
|
|
--delete tickets?
|
|
|
|
|
error "Not implemented"
|
2016-05-02 15:13:57 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
postTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-02 20:34:11 +09:00
|
|
|
|
postTicketR shar proj num = do
|
|
|
|
|
mmethod <- lookupPostParam "_method"
|
|
|
|
|
case mmethod of
|
|
|
|
|
Just "PUT" -> putTicketR shar proj num
|
|
|
|
|
Just "DELETE" -> deleteTicketR shar proj num
|
|
|
|
|
_ -> notFound
|
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketEditR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-02 18:15:10 +09:00
|
|
|
|
getTicketEditR shar proj num = do
|
2016-08-11 03:52:26 +09:00
|
|
|
|
(tid, ticket, wid) <- runDB $ do
|
2016-05-24 05:46:54 +09:00
|
|
|
|
Entity sid _sharer <- getBy404 $ UniqueSharer shar
|
2016-08-11 03:52:26 +09:00
|
|
|
|
Entity pid project <- getBy404 $ UniqueProject proj sid
|
|
|
|
|
Entity tid ticket <- getBy404 $ UniqueTicket pid num
|
|
|
|
|
return (tid, ticket, projectWorkflow project)
|
|
|
|
|
((_result, widget), enctype) <-
|
|
|
|
|
runFormPost $ editTicketContentForm tid ticket wid
|
2016-05-20 01:58:23 +09:00
|
|
|
|
defaultLayout $(widgetFile "ticket/edit")
|
|
|
|
|
|
2016-08-11 16:58:51 +09:00
|
|
|
|
postTicketAcceptR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketAcceptR shr prj num = do
|
|
|
|
|
succ <- runDB $ do
|
|
|
|
|
Entity tid ticket <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity p _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
getBy404 $ UniqueTicket p num
|
|
|
|
|
case ticketStatus ticket of
|
|
|
|
|
TSNew -> do
|
|
|
|
|
update tid [TicketStatus =. TSTodo]
|
|
|
|
|
return True
|
|
|
|
|
_ -> return False
|
|
|
|
|
setMessage $
|
|
|
|
|
if succ
|
|
|
|
|
then "Ticket accepted."
|
|
|
|
|
else "Ticket is already accepted."
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
|
2016-06-02 04:50:41 +09:00
|
|
|
|
postTicketCloseR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketCloseR shr prj num = do
|
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
now <- liftIO getCurrentTime
|
|
|
|
|
succ <- runDB $ do
|
|
|
|
|
Entity tid ticket <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity p _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
getBy404 $ UniqueTicket p num
|
2016-08-11 09:44:11 +09:00
|
|
|
|
case ticketStatus ticket of
|
|
|
|
|
TSClosed -> return False
|
|
|
|
|
_ -> do
|
2016-06-02 04:50:41 +09:00
|
|
|
|
update tid
|
2016-06-06 16:44:00 +09:00
|
|
|
|
[ TicketAssignee =. Nothing
|
2016-08-11 09:44:11 +09:00
|
|
|
|
, TicketStatus =. TSClosed
|
2016-06-06 16:44:00 +09:00
|
|
|
|
, TicketClosed =. now
|
|
|
|
|
, TicketCloser =. pid
|
2016-06-02 04:50:41 +09:00
|
|
|
|
]
|
|
|
|
|
return True
|
|
|
|
|
setMessage $
|
|
|
|
|
if succ
|
|
|
|
|
then "Ticket closed."
|
|
|
|
|
else "Ticket is already closed."
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
|
|
|
|
|
postTicketOpenR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketOpenR shr prj num = do
|
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
now <- liftIO getCurrentTime
|
|
|
|
|
succ <- runDB $ do
|
|
|
|
|
Entity tid ticket <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity p _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
getBy404 $ UniqueTicket p num
|
2016-08-11 09:44:11 +09:00
|
|
|
|
case ticketStatus ticket of
|
|
|
|
|
TSClosed -> do
|
2016-06-02 04:50:41 +09:00
|
|
|
|
update tid
|
2016-08-11 09:44:11 +09:00
|
|
|
|
[ TicketStatus =. TSTodo
|
2016-06-02 04:50:41 +09:00
|
|
|
|
, TicketCloser =. ticketCreator ticket
|
|
|
|
|
]
|
|
|
|
|
return True
|
2016-08-11 09:44:11 +09:00
|
|
|
|
_ -> return False
|
2016-06-02 04:50:41 +09:00
|
|
|
|
setMessage $
|
|
|
|
|
if succ
|
|
|
|
|
then "Ticket reopened"
|
|
|
|
|
else "Ticket is already open."
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
|
2016-06-06 18:03:49 +09:00
|
|
|
|
postTicketClaimR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketClaimR shr prj num = do
|
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
mmsg <- runDB $ do
|
|
|
|
|
Entity tid ticket <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity p _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
getBy404 $ UniqueTicket p num
|
2016-08-11 09:44:11 +09:00
|
|
|
|
case (ticketStatus ticket, ticketAssignee ticket) of
|
|
|
|
|
(TSNew, _) ->
|
|
|
|
|
return $
|
|
|
|
|
Just "The ticket isn’t accepted yet. Can’t claim it."
|
|
|
|
|
(TSClosed, _) ->
|
2016-06-06 18:03:49 +09:00
|
|
|
|
return $
|
|
|
|
|
Just "The ticket is closed. Can’t claim closed tickets."
|
2016-08-11 09:44:11 +09:00
|
|
|
|
(TSTodo, Just _) ->
|
2016-06-06 18:03:49 +09:00
|
|
|
|
return $
|
|
|
|
|
Just "The ticket is already assigned to someone."
|
2016-08-11 09:44:11 +09:00
|
|
|
|
(TSTodo, Nothing) -> do
|
2016-06-06 18:03:49 +09:00
|
|
|
|
update tid [TicketAssignee =. Just pid]
|
|
|
|
|
return Nothing
|
|
|
|
|
setMessage $ fromMaybe "The ticket is now assigned to you." mmsg
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
|
|
|
|
|
postTicketUnclaimR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketUnclaimR shr prj num = do
|
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
mmsg <- runDB $ do
|
|
|
|
|
Entity tid ticket <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity p _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
getBy404 $ UniqueTicket p num
|
2016-08-11 09:44:11 +09:00
|
|
|
|
case ((== pid) <$> ticketAssignee ticket, ticketStatus ticket) of
|
2016-06-06 18:03:49 +09:00
|
|
|
|
(Nothing, _) ->
|
|
|
|
|
return $ Just "The ticket is already unassigned."
|
|
|
|
|
(Just False, _) ->
|
|
|
|
|
return $ Just "The ticket is assigned to someone else."
|
2016-08-11 09:44:11 +09:00
|
|
|
|
(Just True, TSNew) -> do
|
|
|
|
|
$logWarn "Found a new claimed ticket, this is invalid"
|
|
|
|
|
return $
|
|
|
|
|
Just "The ticket isn’t accepted yet. Can’t unclaim it."
|
|
|
|
|
(Just True, TSClosed) -> do
|
2016-06-06 18:03:49 +09:00
|
|
|
|
$logWarn "Found a closed claimed ticket, this is invalid"
|
|
|
|
|
return $
|
|
|
|
|
Just "The ticket is closed. Can’t unclaim closed tickets."
|
2016-08-11 09:44:11 +09:00
|
|
|
|
(Just True, TSTodo) -> do
|
2016-06-06 18:03:49 +09:00
|
|
|
|
update tid [TicketAssignee =. Nothing]
|
|
|
|
|
return Nothing
|
|
|
|
|
setMessage $ fromMaybe "The ticket is now unassigned." mmsg
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
|
2016-06-07 16:33:19 +09:00
|
|
|
|
getTicketAssignR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
getTicketAssignR shr prj num = do
|
|
|
|
|
vpid <- requireAuthId
|
|
|
|
|
(jid, Entity tid ticket) <- runDB $ do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity j _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
et <- getBy404 $ UniqueTicket j num
|
|
|
|
|
return (j, et)
|
|
|
|
|
let msg t = do
|
|
|
|
|
setMessage t
|
|
|
|
|
redirect $ TicketR shr prj num
|
2016-08-11 09:44:11 +09:00
|
|
|
|
case (ticketStatus ticket, ticketAssignee ticket) of
|
|
|
|
|
(TSNew, _) -> msg "The ticket isn’t accepted yet. Can’t assign it."
|
|
|
|
|
(TSClosed, _) -> msg "The ticket is closed. Can’t assign it."
|
|
|
|
|
(TSTodo, Just _) -> msg "The ticket is already assigned to someone."
|
|
|
|
|
(TSTodo, Nothing) -> do
|
2016-06-07 16:33:19 +09:00
|
|
|
|
((_result, widget), enctype) <-
|
|
|
|
|
runFormPost $ assignTicketForm vpid jid
|
|
|
|
|
defaultLayout $(widgetFile "ticket/assign")
|
|
|
|
|
|
|
|
|
|
postTicketAssignR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketAssignR shr prj num = do
|
|
|
|
|
vpid <- requireAuthId
|
|
|
|
|
(jid, Entity tid ticket) <- runDB $ do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity j _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
et <- getBy404 $ UniqueTicket j num
|
|
|
|
|
return (j, et)
|
|
|
|
|
let msg t = do
|
|
|
|
|
setMessage t
|
|
|
|
|
redirect $ TicketR shr prj num
|
2016-08-11 09:44:11 +09:00
|
|
|
|
case (ticketStatus ticket, ticketAssignee ticket) of
|
|
|
|
|
(TSNew, _) -> msg "The ticket isn’t accepted yet. Can’t assign it."
|
|
|
|
|
(TSClosed, _) -> msg "The ticket is closed. Can’t assign it."
|
|
|
|
|
(TSTodo, Just _) -> msg "The ticket is already assigned to someone."
|
|
|
|
|
(TSTodo, Nothing) -> do
|
2016-06-07 16:33:19 +09:00
|
|
|
|
((result, widget), enctype) <-
|
|
|
|
|
runFormPost $ assignTicketForm vpid jid
|
|
|
|
|
case result of
|
|
|
|
|
FormSuccess pid -> do
|
|
|
|
|
sharer <- runDB $ do
|
|
|
|
|
update tid [TicketAssignee =. Just pid]
|
|
|
|
|
person <- getJust pid
|
|
|
|
|
getJust $ personIdent person
|
|
|
|
|
let si = sharerIdent sharer
|
|
|
|
|
msg $ toHtml $
|
|
|
|
|
"The ticket is now assigned to " <> shr2text si <> "."
|
|
|
|
|
FormMissing -> do
|
|
|
|
|
setMessage "Field(s) missing."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/assign")
|
|
|
|
|
FormFailure _l -> do
|
|
|
|
|
setMessage "Ticket assignment failed, see errors below."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/assign")
|
|
|
|
|
|
|
|
|
|
postTicketUnassignR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketUnassignR shr prj num = do
|
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
mmsg <- runDB $ do
|
|
|
|
|
Entity tid ticket <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity p _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
getBy404 $ UniqueTicket p num
|
2016-08-11 09:44:11 +09:00
|
|
|
|
case ((== pid) <$> ticketAssignee ticket, ticketStatus ticket) of
|
2016-06-07 16:33:19 +09:00
|
|
|
|
(Nothing, _) ->
|
|
|
|
|
return $ Just "The ticket is already unassigned."
|
|
|
|
|
(Just True, _) ->
|
|
|
|
|
return $ Just "The ticket is assigned to you, unclaim instead."
|
2016-08-11 09:44:11 +09:00
|
|
|
|
(Just False, TSNew) -> do
|
|
|
|
|
$logWarn "Found a new claimed ticket, this is invalid"
|
|
|
|
|
return $
|
|
|
|
|
Just "The ticket isn’t accepted yet. Can’t unclaim it."
|
|
|
|
|
(Just False, TSClosed) -> do
|
2016-06-07 16:33:19 +09:00
|
|
|
|
$logWarn "Found a closed claimed ticket, this is invalid"
|
|
|
|
|
return $
|
|
|
|
|
Just "The ticket is closed. Can’t unclaim closed tickets."
|
2016-08-11 09:44:11 +09:00
|
|
|
|
(Just False, TSTodo) -> do
|
2016-06-07 16:33:19 +09:00
|
|
|
|
update tid [TicketAssignee =. Nothing]
|
|
|
|
|
return Nothing
|
|
|
|
|
setMessage $ fromMaybe "The ticket is now unassigned." mmsg
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
|
2016-06-08 00:29:26 +09:00
|
|
|
|
-- | The logged-in user gets a list of the ticket claim requests they have
|
|
|
|
|
-- opened, in any project.
|
2016-06-08 01:31:55 +09:00
|
|
|
|
getClaimRequestsPersonR :: Handler Html
|
|
|
|
|
getClaimRequestsPersonR = do
|
2016-06-07 19:01:57 +09:00
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
rqs <- runDB $ select $ from $
|
|
|
|
|
\ (tcr `InnerJoin` ticket `InnerJoin` project `InnerJoin` sharer) -> do
|
2016-08-09 20:36:14 +09:00
|
|
|
|
on $ project ^. ProjectSharer ==. sharer ^. SharerId
|
|
|
|
|
on $ ticket ^. TicketProject ==. project ^. ProjectId
|
|
|
|
|
on $ tcr ^. TicketClaimRequestTicket ==. ticket ^. TicketId
|
|
|
|
|
where_ $ tcr ^. TicketClaimRequestPerson ==. val pid
|
2016-06-07 19:01:57 +09:00
|
|
|
|
orderBy [desc $ tcr ^. TicketClaimRequestCreated]
|
|
|
|
|
return
|
|
|
|
|
( sharer ^. SharerIdent
|
|
|
|
|
, project ^. ProjectIdent
|
|
|
|
|
, ticket ^. TicketNumber
|
|
|
|
|
, ticket ^. TicketTitle
|
|
|
|
|
, tcr ^. TicketClaimRequestCreated
|
|
|
|
|
)
|
|
|
|
|
defaultLayout $(widgetFile "person/claim-requests")
|
|
|
|
|
|
2016-06-08 00:29:26 +09:00
|
|
|
|
-- | Get a list of ticket claim requests for a given project.
|
2016-06-08 01:31:55 +09:00
|
|
|
|
getClaimRequestsProjectR :: ShrIdent -> PrjIdent -> Handler Html
|
|
|
|
|
getClaimRequestsProjectR shr prj = do
|
2016-06-08 00:29:26 +09:00
|
|
|
|
rqs <- runDB $ do
|
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity jid _ <- getBy404 $ UniqueProject prj sid
|
|
|
|
|
select $ from $
|
|
|
|
|
\ ( tcr `InnerJoin`
|
|
|
|
|
ticket `InnerJoin`
|
|
|
|
|
person `InnerJoin`
|
|
|
|
|
sharer
|
|
|
|
|
) -> do
|
2016-08-09 20:36:14 +09:00
|
|
|
|
on $ person ^. PersonIdent ==. sharer ^. SharerId
|
|
|
|
|
on $ tcr ^. TicketClaimRequestPerson ==. person ^. PersonId
|
|
|
|
|
on $ tcr ^. TicketClaimRequestTicket ==. ticket ^. TicketId
|
|
|
|
|
where_ $ ticket ^. TicketProject ==. val jid
|
2016-06-08 00:29:26 +09:00
|
|
|
|
orderBy [desc $ tcr ^. TicketClaimRequestCreated]
|
|
|
|
|
return
|
|
|
|
|
( sharer
|
|
|
|
|
, ticket ^. TicketNumber
|
|
|
|
|
, ticket ^. TicketTitle
|
|
|
|
|
, tcr ^. TicketClaimRequestCreated
|
|
|
|
|
)
|
2016-06-08 01:31:55 +09:00
|
|
|
|
defaultLayout $(widgetFile "project/claim-request/list")
|
|
|
|
|
|
|
|
|
|
-- | Get a list of ticket claim requests for a given ticket.
|
|
|
|
|
getClaimRequestsTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
getClaimRequestsTicketR shr prj num = do
|
|
|
|
|
rqs <- runDB $ do
|
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity jid _ <- getBy404 $ UniqueProject prj sid
|
|
|
|
|
Entity tid _ <- getBy404 $ UniqueTicket jid num
|
|
|
|
|
select $ from $ \ (tcr `InnerJoin` person `InnerJoin` sharer) -> do
|
2016-08-09 20:36:14 +09:00
|
|
|
|
on $ person ^. PersonIdent ==. sharer ^. SharerId
|
|
|
|
|
on $ tcr ^. TicketClaimRequestPerson ==. person ^. PersonId
|
|
|
|
|
where_ $ tcr ^. TicketClaimRequestTicket ==. val tid
|
2016-06-08 01:31:55 +09:00
|
|
|
|
orderBy [desc $ tcr ^. TicketClaimRequestCreated]
|
|
|
|
|
return (sharer, tcr)
|
2016-06-08 00:29:26 +09:00
|
|
|
|
defaultLayout $(widgetFile "ticket/claim-request/list")
|
|
|
|
|
|
2016-06-08 10:28:18 +09:00
|
|
|
|
getClaimRequestNewR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
getClaimRequestNewR shr prj num = do
|
|
|
|
|
((_result, widget), etype) <- runFormPost claimRequestForm
|
|
|
|
|
defaultLayout $(widgetFile "ticket/claim-request/new")
|
|
|
|
|
|
|
|
|
|
postClaimRequestsTicketR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postClaimRequestsTicketR shr prj num = do
|
|
|
|
|
((result, widget), etype) <- runFormPost claimRequestForm
|
|
|
|
|
case result of
|
|
|
|
|
FormSuccess msg -> do
|
|
|
|
|
now <- liftIO getCurrentTime
|
|
|
|
|
pid <- requireAuthId
|
|
|
|
|
runDB $ do
|
|
|
|
|
tid <- do
|
|
|
|
|
Entity s _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity j _ <- getBy404 $ UniqueProject prj s
|
|
|
|
|
Entity t _ <- getBy404 $ UniqueTicket j num
|
|
|
|
|
return t
|
|
|
|
|
let cr = TicketClaimRequest
|
|
|
|
|
{ ticketClaimRequestPerson = pid
|
|
|
|
|
, ticketClaimRequestTicket = tid
|
|
|
|
|
, ticketClaimRequestMessage = msg
|
|
|
|
|
, ticketClaimRequestCreated = now
|
|
|
|
|
}
|
|
|
|
|
insert_ cr
|
|
|
|
|
setMessage "Ticket claim request opened."
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
FormMissing -> do
|
|
|
|
|
setMessage "Field(s) missing."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/claim-request/new")
|
|
|
|
|
FormFailure _l -> do
|
|
|
|
|
setMessage "Submission failed, see errors below."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/claim-request/new")
|
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
selectDiscussionId :: ShrIdent -> PrjIdent -> Int -> AppDB DiscussionId
|
2016-05-20 07:07:25 +09:00
|
|
|
|
selectDiscussionId shar proj tnum = do
|
2016-05-24 05:46:54 +09:00
|
|
|
|
Entity sid _sharer <- getBy404 $ UniqueSharer shar
|
2016-05-20 07:07:25 +09:00
|
|
|
|
Entity pid _project <- getBy404 $ UniqueProject proj sid
|
|
|
|
|
Entity _tid ticket <- getBy404 $ UniqueTicket pid tnum
|
|
|
|
|
return $ ticketDiscuss ticket
|
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketDiscussionR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2019-03-16 01:36:02 +09:00
|
|
|
|
getTicketDiscussionR shar proj num = do
|
2019-03-29 12:25:32 +09:00
|
|
|
|
encodeHid <- getEncodeKeyHashid
|
2016-05-20 07:40:54 +09:00
|
|
|
|
getDiscussion
|
2019-03-29 12:25:32 +09:00
|
|
|
|
(TicketReplyR shar proj num . encodeHid)
|
2016-05-22 06:27:12 +09:00
|
|
|
|
(TicketTopReplyR shar proj num)
|
2016-05-20 07:40:54 +09:00
|
|
|
|
(selectDiscussionId shar proj num)
|
2016-05-20 01:58:23 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
postTicketDiscussionR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2019-04-21 06:34:45 +09:00
|
|
|
|
postTicketDiscussionR shr prj num = do
|
|
|
|
|
hLocal <- getsYesod $ appInstanceHost . appSettings
|
2016-05-22 05:01:31 +09:00
|
|
|
|
postTopReply
|
2019-04-21 06:34:45 +09:00
|
|
|
|
hLocal
|
|
|
|
|
[ ProjectR shr prj
|
|
|
|
|
, TicketParticipantsR shr prj num
|
|
|
|
|
, TicketTeamR shr prj num
|
|
|
|
|
]
|
|
|
|
|
(TicketR shr prj num)
|
|
|
|
|
(TicketDiscussionR shr prj num)
|
|
|
|
|
(const $ TicketR shr prj num)
|
2016-05-22 05:01:31 +09:00
|
|
|
|
|
2019-03-29 12:25:32 +09:00
|
|
|
|
getMessageR :: ShrIdent -> KeyHashid LocalMessage -> Handler TypedContent
|
2019-03-23 05:46:42 +09:00
|
|
|
|
getMessageR shr hid = do
|
2019-03-29 12:25:32 +09:00
|
|
|
|
lmid <- decodeKeyHashid404 hid
|
2019-03-23 05:46:42 +09:00
|
|
|
|
getDiscussionMessage shr lmid
|
2019-03-16 01:36:02 +09:00
|
|
|
|
|
2019-03-29 12:25:32 +09:00
|
|
|
|
postTicketMessageR :: ShrIdent -> PrjIdent -> Int -> KeyHashid Message -> Handler Html
|
2019-04-21 06:34:45 +09:00
|
|
|
|
postTicketMessageR shr prj num mkhid = do
|
2019-03-29 12:25:32 +09:00
|
|
|
|
encodeHid <- getEncodeKeyHashid
|
2019-04-21 06:34:45 +09:00
|
|
|
|
mid <- decodeKeyHashid404 mkhid
|
|
|
|
|
hLocal <- getsYesod $ appInstanceHost . appSettings
|
2016-05-20 07:07:25 +09:00
|
|
|
|
postReply
|
2019-04-21 06:34:45 +09:00
|
|
|
|
hLocal
|
|
|
|
|
[ ProjectR shr prj
|
|
|
|
|
, TicketParticipantsR shr prj num
|
|
|
|
|
, TicketTeamR shr prj num
|
|
|
|
|
]
|
|
|
|
|
(TicketR shr prj num)
|
|
|
|
|
(TicketReplyR shr prj num . encodeHid)
|
|
|
|
|
(TicketMessageR shr prj num . encodeHid)
|
|
|
|
|
(const $ TicketR shr prj num)
|
|
|
|
|
(selectDiscussionId shr prj num)
|
2019-03-16 01:36:02 +09:00
|
|
|
|
mid
|
2016-05-20 07:07:25 +09:00
|
|
|
|
|
2016-05-23 21:24:14 +09:00
|
|
|
|
getTicketTopReplyR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
2016-05-22 05:01:31 +09:00
|
|
|
|
getTicketTopReplyR shar proj num =
|
|
|
|
|
getTopReply $ TicketDiscussionR shar proj num
|
2016-05-20 07:07:25 +09:00
|
|
|
|
|
2019-03-29 12:25:32 +09:00
|
|
|
|
getTicketReplyR :: ShrIdent -> PrjIdent -> Int -> KeyHashid Message -> Handler Html
|
2019-03-16 01:36:02 +09:00
|
|
|
|
getTicketReplyR shar proj tnum hid = do
|
2019-03-29 12:25:32 +09:00
|
|
|
|
encodeHid <- getEncodeKeyHashid
|
|
|
|
|
mid <- decodeKeyHashid404 hid
|
2016-05-20 07:07:25 +09:00
|
|
|
|
getReply
|
2019-03-29 12:25:32 +09:00
|
|
|
|
(TicketReplyR shar proj tnum . encodeHid)
|
|
|
|
|
(TicketMessageR shar proj tnum . encodeHid)
|
2016-05-20 07:40:54 +09:00
|
|
|
|
(selectDiscussionId shar proj tnum)
|
2019-03-16 01:36:02 +09:00
|
|
|
|
mid
|
2016-06-08 05:16:15 +09:00
|
|
|
|
|
2016-07-27 17:35:50 +09:00
|
|
|
|
getTicketDeps :: Bool -> ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
getTicketDeps forward shr prj num = do
|
|
|
|
|
let from' =
|
|
|
|
|
if forward then TicketDependencyParent else TicketDependencyChild
|
|
|
|
|
to' =
|
|
|
|
|
if forward then TicketDependencyChild else TicketDependencyParent
|
2016-06-08 05:16:15 +09:00
|
|
|
|
rows <- runDB $ do
|
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity jid _ <- getBy404 $ UniqueProject prj sid
|
|
|
|
|
Entity tid _ <- getBy404 $ UniqueTicket jid num
|
|
|
|
|
select $ from $
|
|
|
|
|
\ ( td `InnerJoin`
|
|
|
|
|
ticket `InnerJoin`
|
|
|
|
|
person `InnerJoin`
|
|
|
|
|
sharer
|
|
|
|
|
) -> do
|
2016-08-09 20:36:14 +09:00
|
|
|
|
on $ person ^. PersonIdent ==. sharer ^. SharerId
|
|
|
|
|
on $ ticket ^. TicketCreator ==. person ^. PersonId
|
|
|
|
|
on $ td ^. to' ==. ticket ^. TicketId
|
|
|
|
|
where_ $ td ^. from' ==. val tid
|
2016-06-08 05:16:15 +09:00
|
|
|
|
orderBy [asc $ ticket ^. TicketNumber]
|
|
|
|
|
return
|
|
|
|
|
( ticket ^. TicketNumber
|
|
|
|
|
, sharer
|
|
|
|
|
, ticket ^. TicketTitle
|
2016-08-11 09:44:11 +09:00
|
|
|
|
, ticket ^. TicketStatus
|
2016-06-08 05:16:15 +09:00
|
|
|
|
)
|
|
|
|
|
defaultLayout $(widgetFile "ticket/dep/list")
|
2016-07-27 17:35:50 +09:00
|
|
|
|
|
|
|
|
|
getTicketDepsR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
getTicketDepsR = getTicketDeps True
|
|
|
|
|
|
2016-07-29 01:40:10 +09:00
|
|
|
|
postTicketDepsR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
postTicketDepsR shr prj num = do
|
|
|
|
|
(jid, tid) <- runDB $ do
|
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity jid _ <- getBy404 $ UniqueProject prj sid
|
|
|
|
|
Entity tid _ <- getBy404 $ UniqueTicket jid num
|
|
|
|
|
return (jid, tid)
|
|
|
|
|
((result, widget), enctype) <- runFormPost $ ticketDepForm jid tid
|
|
|
|
|
case result of
|
|
|
|
|
FormSuccess ctid -> do
|
|
|
|
|
runDB $ do
|
|
|
|
|
let td = TicketDependency
|
|
|
|
|
{ ticketDependencyParent = tid
|
|
|
|
|
, ticketDependencyChild = ctid
|
|
|
|
|
}
|
|
|
|
|
insert_ td
|
|
|
|
|
trrFix td ticketDepGraph
|
|
|
|
|
setMessage "Ticket dependency added."
|
|
|
|
|
redirect $ TicketR shr prj num
|
|
|
|
|
FormMissing -> do
|
|
|
|
|
setMessage "Field(s) missing."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/dep/new")
|
|
|
|
|
FormFailure _l -> do
|
|
|
|
|
setMessage "Submission failed, see errors below."
|
|
|
|
|
defaultLayout $(widgetFile "ticket/dep/new")
|
|
|
|
|
|
|
|
|
|
getTicketDepNewR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
getTicketDepNewR shr prj num = do
|
|
|
|
|
(jid, tid) <- runDB $ do
|
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity jid _ <- getBy404 $ UniqueProject prj sid
|
|
|
|
|
Entity tid _ <- getBy404 $ UniqueTicket jid num
|
|
|
|
|
return (jid, tid)
|
|
|
|
|
((_result, widget), enctype) <- runFormPost $ ticketDepForm jid tid
|
|
|
|
|
defaultLayout $(widgetFile "ticket/dep/new")
|
|
|
|
|
|
|
|
|
|
postTicketDepR :: ShrIdent -> PrjIdent -> Int -> Int -> Handler Html
|
|
|
|
|
postTicketDepR shr prj pnum cnum = do
|
|
|
|
|
mmethod <- lookupPostParam "_method"
|
|
|
|
|
case mmethod of
|
|
|
|
|
Just "DELETE" -> deleteTicketDepR shr prj pnum cnum
|
|
|
|
|
_ -> notFound
|
|
|
|
|
|
|
|
|
|
deleteTicketDepR :: ShrIdent -> PrjIdent -> Int -> Int -> Handler Html
|
|
|
|
|
deleteTicketDepR shr prj pnum cnum = do
|
|
|
|
|
runDB $ do
|
|
|
|
|
Entity sid _ <- getBy404 $ UniqueSharer shr
|
|
|
|
|
Entity jid _ <- getBy404 $ UniqueProject prj sid
|
|
|
|
|
Entity ptid _ <- getBy404 $ UniqueTicket jid pnum
|
|
|
|
|
Entity ctid _ <- getBy404 $ UniqueTicket jid cnum
|
|
|
|
|
Entity tdid _ <- getBy404 $ UniqueTicketDependency ptid ctid
|
|
|
|
|
delete tdid
|
|
|
|
|
setMessage "Ticket dependency removed."
|
|
|
|
|
redirect $ TicketDepsR shr prj pnum
|
|
|
|
|
|
2016-07-27 17:35:50 +09:00
|
|
|
|
getTicketReverseDepsR :: ShrIdent -> PrjIdent -> Int -> Handler Html
|
|
|
|
|
getTicketReverseDepsR = getTicketDeps False
|
2019-04-11 22:44:44 +09:00
|
|
|
|
|
|
|
|
|
getTicketParticipantsR :: ShrIdent -> PrjIdent -> Int -> Handler TypedContent
|
|
|
|
|
getTicketParticipantsR = error "TODO implement getTicketParticipantsR"
|
|
|
|
|
|
|
|
|
|
getTicketTeamR :: ShrIdent -> PrjIdent -> Int -> Handler TypedContent
|
|
|
|
|
getTicketTeamR = error "TODO implement getTicketTeamR"
|