From d8c65930ca056847394496485a0af19a3ea7c6f6 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sun, 16 Oct 2022 23:44:16 +0000 Subject: [PATCH] UI, DB: Switch ticket filter to use TicketResolve instead of TicketStatus --- src/Vervis/Form/Ticket.hs | 13 ++--------- src/Vervis/Ticket.hs | 32 ++++++++++++++++---------- src/Vervis/TicketFilter.hs | 19 ++++++++------- src/Vervis/Widget/Ticket.hs | 4 ++-- templates/cloth/widget/summary.hamlet | 16 +++++-------- templates/ticket/widget/summary.hamlet | 16 +++++-------- 6 files changed, 45 insertions(+), 55 deletions(-) diff --git a/src/Vervis/Form/Ticket.hs b/src/Vervis/Form/Ticket.hs index 324490c..ca3c581 100644 --- a/src/Vervis/Form/Ticket.hs +++ b/src/Vervis/Form/Ticket.hs @@ -262,18 +262,9 @@ claimRequestForm = renderDivs claimRequestAForm -} ticketFilterAForm :: AForm Handler TicketFilter -ticketFilterAForm = mk - <$> areq checkBoxField "New" (Just True) - <*> areq checkBoxField "To-do" (Just True) +ticketFilterAForm = TicketFilter + <$> areq checkBoxField "Open" (Just True) <*> areq checkBoxField "Closed" (Just False) - where - mk new todo closed = - TicketFilter $ - catMaybes - [result new TSNew, result todo TSTodo, result closed TSClosed] - where - result False _ = Nothing - result True s = Just s ticketFilterForm :: Form TicketFilter ticketFilterForm = renderDivs ticketFilterAForm diff --git a/src/Vervis/Ticket.hs b/src/Vervis/Ticket.hs index f7607f1..600324b 100644 --- a/src/Vervis/Ticket.hs +++ b/src/Vervis/Ticket.hs @@ -97,7 +97,7 @@ import Vervis.Widget.Ticket -- | Get summaries of all the tickets in the given project. getTicketSummaries - :: Maybe (E.SqlExpr (Entity Ticket) -> E.SqlExpr (E.Value Bool)) + :: Maybe (E.SqlExpr (Maybe (Entity TicketResolve)) -> E.SqlExpr (E.Value Bool)) -> Maybe (E.SqlExpr (Entity Ticket) -> [E.SqlExpr E.OrderBy]) -> Maybe (Int, Int) -> DeckId @@ -108,12 +108,15 @@ getTicketSummaries mfilt morder offlim deckID = do `E.InnerJoin` td `E.LeftOuterJoin` (tal `E.InnerJoin` p `E.InnerJoin` a) `E.LeftOuterJoin` (tar `E.InnerJoin` ra `E.InnerJoin` ro `E.InnerJoin` i) + `E.LeftOuterJoin` tr `E.InnerJoin` d `E.LeftOuterJoin` m ) -> do E.on $ E.just (d E.^. DiscussionId) E.==. m E.?. MessageRoot E.on $ t E.^. TicketDiscuss E.==. d E.^. DiscussionId + E.on $ E.just (t E.^. TicketId) E.==. tr E.?. TicketResolveTicket + E.on $ ro E.?. RemoteObjectInstance E.==. i E.?. InstanceId E.on $ ra E.?. RemoteActorIdent E.==. ro E.?. RemoteObjectId E.on $ tar E.?. TicketAuthorRemoteAuthor E.==. ra E.?. RemoteActorId @@ -127,11 +130,12 @@ getTicketSummaries mfilt morder offlim deckID = do E.where_ $ td E.^. TicketDeckDeck E.==. E.val deckID E.groupBy - ( t E.^. TicketId, td E.^. TicketDeckId + ( (t E.^. TicketId, td E.^. TicketDeckId) + , tr E.?. TicketResolveId , tal E.?. TicketAuthorLocalId, p E.?. PersonId, a E.?. ActorId , ra E.?. RemoteActorId, ro E.?. RemoteObjectId, i E.?. InstanceId ) - for_ mfilt $ \ filt -> E.where_ $ filt t + for_ mfilt $ \ filt -> E.where_ $ filt tr for_ morder $ \ order -> E.orderBy $ order t for_ offlim $ \ (off, lim) -> do E.offset $ fromIntegral off @@ -144,12 +148,12 @@ getTicketSummaries mfilt morder offlim deckID = do , i, ro, ra , t E.^. TicketCreated , t E.^. TicketTitle - , t E.^. TicketStatus + , tr E.?. TicketResolveId , E.count $ m E.?. MessageId ) for tickets $ - \ (E.Value tid, E.Value tdid, mp, ma, mi, mro, mra, E.Value c, E.Value t, E.Value d, E.Value r) -> do + \ (E.Value tid, E.Value tdid, mp, ma, mi, mro, mra, E.Value c, E.Value t, E.Value mc, E.Value r) -> do labels <- E.select $ E.from $ \ (tpc `E.InnerJoin` wf) -> do E.on $ tpc E.^. TicketParamClassField E.==. wf E.^. WorkflowFieldId E.where_ $ tpc E.^. TicketParamClassTicket E.==. E.val tid @@ -166,12 +170,12 @@ getTicketSummaries mfilt morder offlim deckID = do , tsCreatedAt = c , tsTitle = t , tsLabels = map entityVal labels - , tsStatus = d + , tsClosed = isJust mc , tsComments = r } getClothSummaries - :: Maybe (E.SqlExpr (Entity Ticket) -> E.SqlExpr (E.Value Bool)) + :: Maybe (E.SqlExpr (Maybe (Entity TicketResolve)) -> E.SqlExpr (E.Value Bool)) -> Maybe (E.SqlExpr (Entity Ticket) -> [E.SqlExpr E.OrderBy]) -> Maybe (Int, Int) -> LoomId @@ -182,12 +186,15 @@ getClothSummaries mfilt morder offlim loomID = do `E.InnerJoin` tl `E.LeftOuterJoin` (tal `E.InnerJoin` p `E.InnerJoin` a) `E.LeftOuterJoin` (tar `E.InnerJoin` ra `E.InnerJoin` ro `E.InnerJoin` i) + `E.LeftOuterJoin` tr `E.InnerJoin` d `E.LeftOuterJoin` m ) -> do E.on $ E.just (d E.^. DiscussionId) E.==. m E.?. MessageRoot E.on $ t E.^. TicketDiscuss E.==. d E.^. DiscussionId + E.on $ E.just (t E.^. TicketId) E.==. tr E.?. TicketResolveTicket + E.on $ ro E.?. RemoteObjectInstance E.==. i E.?. InstanceId E.on $ ra E.?. RemoteActorIdent E.==. ro E.?. RemoteObjectId E.on $ tar E.?. TicketAuthorRemoteAuthor E.==. ra E.?. RemoteActorId @@ -201,11 +208,12 @@ getClothSummaries mfilt morder offlim loomID = do E.where_ $ tl E.^. TicketLoomLoom E.==. E.val loomID E.groupBy - ( t E.^. TicketId, tl E.^. TicketLoomId + ( (t E.^. TicketId, tl E.^. TicketLoomId) + , tr E.?. TicketResolveId , tal E.?. TicketAuthorLocalId, p E.?. PersonId, a E.?. ActorId , ra E.?. RemoteActorId, ro E.?. RemoteObjectId, i E.?. InstanceId ) - for_ mfilt $ \ filt -> E.where_ $ filt t + for_ mfilt $ \ filt -> E.where_ $ filt tr for_ morder $ \ order -> E.orderBy $ order t for_ offlim $ \ (off, lim) -> do E.offset $ fromIntegral off @@ -218,12 +226,12 @@ getClothSummaries mfilt morder offlim loomID = do , i, ro, ra , t E.^. TicketCreated , t E.^. TicketTitle - , t E.^. TicketStatus + , tr E.?. TicketResolveId , E.count $ m E.?. MessageId ) for tickets $ - \ (E.Value tid, E.Value tlid, mp, ma, mi, mro, mra, E.Value c, E.Value t, E.Value d, E.Value r) -> do + \ (E.Value tid, E.Value tlid, mp, ma, mi, mro, mra, E.Value c, E.Value t, E.Value mc, E.Value r) -> do labels <- E.select $ E.from $ \ (tpc `E.InnerJoin` wf) -> do E.on $ tpc E.^. TicketParamClassField E.==. wf E.^. WorkflowFieldId E.where_ $ tpc E.^. TicketParamClassTicket E.==. E.val tid @@ -240,7 +248,7 @@ getClothSummaries mfilt morder offlim loomID = do , csCreatedAt = c , csTitle = t , csLabels = map entityVal labels - , csStatus = d + , csClosed = isJust mc , csComments = r } diff --git a/src/Vervis/TicketFilter.hs b/src/Vervis/TicketFilter.hs index aa5f21c..f469dc6 100644 --- a/src/Vervis/TicketFilter.hs +++ b/src/Vervis/TicketFilter.hs @@ -1,6 +1,6 @@ {- This file is part of Vervis. - - - Written in 2016, 2018, 2019 by fr33domlover . + - Written in 2016, 2018, 2019, 2022 by fr33domlover . - - ♡ Copying is an act of love. Please copy, reuse and share. - @@ -26,19 +26,18 @@ import Vervis.Model import Vervis.Model.Ticket data TicketFilter = TicketFilter - { tfStatus :: [TicketStatus] + { tfOpen :: Bool + , tfClosed :: Bool } instance Default TicketFilter where - def = TicketFilter - { tfStatus = [] - } + def = TicketFilter True True filterTickets :: Esqueleto q e b => TicketFilter - -> Maybe (e (Entity Ticket) -> e (Value Bool)) -filterTickets (TicketFilter s) = - if null s - then Nothing - else Just $ \ t -> t ^. TicketStatus `in_` valList s + -> Maybe (e (Maybe (Entity TicketResolve)) -> e (Value Bool)) +filterTickets (TicketFilter False False) = Just $ \ _ -> val (0::Int) ==. val 1 +filterTickets (TicketFilter False True) = Just $ \ t -> not_ $ isNothing $ t ?. TicketResolveId +filterTickets (TicketFilter True False) = Just $ \ t -> isNothing $ t ?. TicketResolveId +filterTickets (TicketFilter True True) = Nothing diff --git a/src/Vervis/Widget/Ticket.hs b/src/Vervis/Widget/Ticket.hs index d75d1cd..1aa9e91 100644 --- a/src/Vervis/Widget/Ticket.hs +++ b/src/Vervis/Widget/Ticket.hs @@ -61,7 +61,7 @@ data TicketSummary = TicketSummary , tsCreatedAt :: UTCTime , tsTitle :: Text , tsLabels :: [WorkflowField] - , tsStatus :: TicketStatus + , tsClosed :: Bool , tsComments :: Int } @@ -73,7 +73,7 @@ data ClothSummary = ClothSummary , csCreatedAt :: UTCTime , csTitle :: Text , csLabels :: [WorkflowField] - , csStatus :: TicketStatus + , csClosed :: Bool , csComments :: Int } diff --git a/templates/cloth/widget/summary.hamlet b/templates/cloth/widget/summary.hamlet index 8b33269..f27d72a 100644 --- a/templates/cloth/widget/summary.hamlet +++ b/templates/cloth/widget/summary.hamlet @@ -13,16 +13,12 @@ $# with this software. If not, see $# . - $case csStatus cs - $of TSNew - - ⬚ - $of TSTodo - - ☐ - $of TSClosed - - ☒ + $if csClosed cs + + ☒ + $else + + ☐ diff --git a/templates/ticket/widget/summary.hamlet b/templates/ticket/widget/summary.hamlet index 43ef993..2b2aa38 100644 --- a/templates/ticket/widget/summary.hamlet +++ b/templates/ticket/widget/summary.hamlet @@ -13,16 +13,12 @@ $# with this software. If not, see $# . - $case tsStatus ts - $of TSNew - - ⬚ - $of TSTodo - - ☐ - $of TSClosed - - ☒ + $if tsClosed ts + + ☒ + $else + + ☐