mirror of
https://code.sup39.dev/repos/Wqawg
synced 2025-01-08 21:36:46 +09:00
72 lines
2.5 KiB
Haskell
72 lines
2.5 KiB
Haskell
|
{- This file is part of Vervis.
|
||
|
-
|
||
|
- Written in 2016 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.Ticket
|
||
|
( getTicketSummaries
|
||
|
, getTicketDepEdges
|
||
|
)
|
||
|
where
|
||
|
|
||
|
import Prelude
|
||
|
|
||
|
import Control.Arrow ((***))
|
||
|
import Database.Esqueleto
|
||
|
|
||
|
import Vervis.Foundation (AppDB)
|
||
|
import Vervis.Model
|
||
|
import Vervis.Widget.Ticket (TicketSummary (..))
|
||
|
|
||
|
-- | Get summaries of all the tickets in the given project.
|
||
|
getTicketSummaries :: ProjectId -> AppDB [TicketSummary]
|
||
|
getTicketSummaries jid = do
|
||
|
let toSummary (Value n, Entity _ s, Value c, Value t, Value d, Value r) =
|
||
|
TicketSummary
|
||
|
{ tsNumber = n
|
||
|
, tsCreatedBy = s
|
||
|
, tsCreatedAt = c
|
||
|
, tsTitle = t
|
||
|
, tsDone = d
|
||
|
, tsComments = r
|
||
|
}
|
||
|
fmap (map toSummary) $ select $ from $
|
||
|
\ (t `InnerJoin` p `InnerJoin` s `InnerJoin` d) -> do
|
||
|
on $ t ^. TicketDiscuss ==. d ^. DiscussionId
|
||
|
on $ p ^. PersonIdent ==. s ^. SharerId
|
||
|
on $ t ^. TicketCreator ==. p ^. PersonId
|
||
|
where_ $ t ^. TicketProject ==. val jid
|
||
|
return
|
||
|
( t ^. TicketNumber
|
||
|
, s
|
||
|
, t ^. TicketCreated
|
||
|
, t ^. TicketTitle
|
||
|
, t ^. TicketDone
|
||
|
, d ^. DiscussionNextMessage -. val 1
|
||
|
)
|
||
|
|
||
|
-- | Get the child-parent ticket number pairs of all the ticket dependencies
|
||
|
-- in the given project, in ascending order by child, and then ascending order
|
||
|
-- by parent.
|
||
|
getTicketDepEdges :: ProjectId -> AppDB [(Int, Int)]
|
||
|
getTicketDepEdges jid =
|
||
|
fmap (map $ unValue *** unValue) $
|
||
|
select $ from $ \ (t1 `InnerJoin` td `InnerJoin` t2) -> do
|
||
|
on $ t2 ^. TicketId ==. td ^. TicketDependencyParent
|
||
|
on $ t1 ^. TicketId ==. td ^. TicketDependencyChild
|
||
|
where_ $
|
||
|
t1 ^. TicketProject ==. val jid &&.
|
||
|
t2 ^. TicketProject ==. val jid
|
||
|
orderBy [asc $ t1 ^. TicketNumber, asc $ t2 ^. TicketNumber]
|
||
|
return (t1 ^. TicketNumber, t2 ^. TicketNumber)
|