diff --git a/config/routes b/config/routes index 23af488..6ceafd7 100644 --- a/config/routes +++ b/config/routes @@ -103,7 +103,8 @@ /s/#ShrIdent/p/#PrjIdent/t/#Int/assign TicketAssignR GET POST /s/#ShrIdent/p/#PrjIdent/t/#Int/unassign TicketUnassignR POST /s/#ShrIdent/p/#PrjIdent/tcr ClaimRequestsProjectR GET -/s/#ShrIdent/p/#PrjIdent/t/#Int/cr ClaimRequestsTicketR GET +/s/#ShrIdent/p/#PrjIdent/t/#Int/cr ClaimRequestsTicketR GET POST +/s/#ShrIdent/p/#PrjIdent/t/#Int/cr/new ClaimRequestNewR GET /s/#ShrIdent/p/#PrjIdent/t/#Int/d TicketDiscussionR GET POST /s/#ShrIdent/p/#PrjIdent/t/#Int/d/#Int TicketMessageR GET POST /s/#ShrIdent/p/#PrjIdent/t/#Int/d/!reply TicketTopReplyR GET diff --git a/src/Vervis/Form/Ticket.hs b/src/Vervis/Form/Ticket.hs index a63189a..3ec5d81 100644 --- a/src/Vervis/Form/Ticket.hs +++ b/src/Vervis/Form/Ticket.hs @@ -18,6 +18,7 @@ module Vervis.Form.Ticket , newTicketForm , editTicketContentForm , assignTicketForm + , claimRequestForm , ticketFilterForm ) where @@ -88,6 +89,12 @@ assignTicketAForm pid jid = 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 (selectFieldList status) "Status*" (Just Nothing) diff --git a/src/Vervis/Foundation.hs b/src/Vervis/Foundation.hs index 316b685..a66f7c5 100644 --- a/src/Vervis/Foundation.hs +++ b/src/Vervis/Foundation.hs @@ -170,6 +170,9 @@ instance Yesod App where (TicketUnclaimR s j _ , _ ) -> projOp ProjOpUnclaimTicket s j (TicketAssignR s j _ , _ ) -> projOp ProjOpAssignTicket s j (TicketUnassignR s j _ , _ ) -> projOp ProjOpUnassignTicket s j + (ClaimRequestsTicketR s j _, True) -> projOp ProjOpRequestTicket s j + (ClaimRequestNewR s j _ , _ ) -> projOp ProjOpRequestTicket s j + (TicketUnassignR s j _ , _ ) -> projOp ProjOpUnassignTicket s j (TicketDiscussionR _ _ _ , True) -> personAny (TicketMessageR _ _ _ _ , True) -> personAny (TicketTopReplyR _ _ _ , _ ) -> personAny @@ -460,6 +463,10 @@ instance YesodBreadcrumbs App where ClaimRequestsTicketR shr prj num -> ( "Ticket Claim Requests" , Just $ TicketR shr prj num ) + ClaimRequestNewR shr prj num -> ( "New" + , Just $ + ClaimRequestsTicketR shr prj num + ) TicketDiscussionR shar proj num -> ( "Discussion" , Just $ TicketR shar proj num ) diff --git a/src/Vervis/Handler/Ticket.hs b/src/Vervis/Handler/Ticket.hs index c74b9c1..2a4b8a8 100644 --- a/src/Vervis/Handler/Ticket.hs +++ b/src/Vervis/Handler/Ticket.hs @@ -32,6 +32,8 @@ module Vervis.Handler.Ticket , getClaimRequestsPersonR , getClaimRequestsProjectR , getClaimRequestsTicketR + , postClaimRequestsTicketR + , getClaimRequestNewR , getTicketDiscussionR , postTicketDiscussionR , getTicketMessageR @@ -450,6 +452,40 @@ getClaimRequestsTicketR shr prj num = do return (sharer, tcr) defaultLayout $(widgetFile "ticket/claim-request/list") +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") + selectDiscussionId :: ShrIdent -> PrjIdent -> Int -> AppDB DiscussionId selectDiscussionId shar proj tnum = do Entity sid _sharer <- getBy404 $ UniqueSharer shar diff --git a/src/Vervis/Model/Role.hs b/src/Vervis/Model/Role.hs index 6de11ab..cc6bce4 100644 --- a/src/Vervis/Model/Role.hs +++ b/src/Vervis/Model/Role.hs @@ -28,7 +28,8 @@ data RepoOperation = RepoOpPush deriving (Eq, Show, Read, Enum, Bounded) derivePersistField "RepoOperation" data ProjectOperation - = ProjOpClaimTicket + = ProjOpRequestTicket + | ProjOpClaimTicket | ProjOpUnclaimTicket | ProjOpAssignTicket | ProjOpUnassignTicket diff --git a/templates/ticket/claim-request/new.hamlet b/templates/ticket/claim-request/new.hamlet new file mode 100644 index 0000000..c5d961e --- /dev/null +++ b/templates/ticket/claim-request/new.hamlet @@ -0,0 +1,17 @@ +$# This file is part of Vervis. +$# +$# Written in 2016 by fr33domlover . +$# +$# ♡ 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 +$# . + +
+ ^{widget} + diff --git a/templates/ticket/one.hamlet b/templates/ticket/one.hamlet index 6c28d29..d983816 100644 --- a/templates/ticket/one.hamlet +++ b/templates/ticket/one.hamlet @@ -39,6 +39,10 @@ $if not $ ticketDone ticket $nothing Not assigned. + Ask to have it assigned to you + + or +