From f6903364f41772be0a726d43e96dfba22e28bcfd Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sun, 23 Feb 2020 13:22:32 +0000 Subject: [PATCH] getTicketsR: Deduce ticket URLs correctly for JSON output --- src/Vervis/Handler/Ticket.hs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Vervis/Handler/Ticket.hs b/src/Vervis/Handler/Ticket.hs index ac5cfa1..6a84641 100644 --- a/src/Vervis/Handler/Ticket.hs +++ b/src/Vervis/Handler/Ticket.hs @@ -181,7 +181,19 @@ getTicketsR shr prj = selectRep $ do , OffsetBy off , LimitTo lim ] - selectKeysList [LocalTicketTicket <-. tids] [Desc LocalTicketTicket] + E.select $ E.from $ \ (lt `E.LeftOuterJoin` (tal `E.InnerJoin` p `E.InnerJoin` s `E.LeftOuterJoin` tup)) -> do + E.on $ tal E.?. TicketAuthorLocalId E.==. tup E.?. TicketUnderProjectAuthor + E.on $ p E.?. PersonIdent E.==. s E.?. SharerId + E.on $ tal E.?. TicketAuthorLocalAuthor E.==. p E.?. PersonId + E.on $ E.just (lt E.^. LocalTicketId) E.==. tal E.?. TicketAuthorLocalTicket + E.where_ $ lt E.^. LocalTicketTicket `E.in_` E.valList tids + E.orderBy [E.desc $ lt E.^. LocalTicketTicket] + return + ( lt E.^. LocalTicketId + , tal E.?. TicketAuthorLocalId + , s E.?. SharerIdent + , tup E.?. TicketUnderProjectId + ) getPageAndNavCount countAllTickets selectTickets encodeRouteHome <- getEncodeRouteHome @@ -189,8 +201,8 @@ getTicketsR shr prj = selectRep $ do encodeRoutePageLocal <- getEncodeRoutePageLocal let pageUrl = encodeRoutePageLocal here host <- asksSite siteInstanceHost - encodeTicketKey <- getEncodeKeyHashid - let ticketUrl = TicketR shr prj . encodeTicketKey + encodeLT <- getEncodeKeyHashid + encodeTAL <- getEncodeKeyHashid return $ case mpage of @@ -223,11 +235,18 @@ getTicketsR shr prj = selectRep $ do else Nothing , collectionPageStartIndex = Nothing , collectionPageItems = - map (encodeRouteHome . ticketUrl) tickets + map (encodeRouteHome . ticketRoute encodeLT encodeTAL) + tickets } where here = TicketsR shr prj encodeStrict = BL.toStrict . encode + ticketRoute encodeLT encodeTAL (E.Value ltid, E.Value mtalid, E.Value mshr, E.Value mtupid) = + case (mtalid, mshr, mtupid) of + (Nothing, Nothing, Nothing) -> TicketR shr prj $ encodeLT ltid + (Just talid, Just shrA, Nothing) -> SharerTicketR shrA $ encodeTAL talid + (Just _, Just _, Just _) -> TicketR shr prj $ encodeLT ltid + _ -> error "Impossible" getTicketTreeR :: ShrIdent -> PrjIdent -> Handler Html getTicketTreeR shr prj = do