Turn boolean ticketDone into TicketStatus enum

This commit is contained in:
fr33domlover 2016-08-11 00:44:11 +00:00
parent 26624404ca
commit 3329b49b2e
16 changed files with 140 additions and 76 deletions

View file

@ -172,7 +172,6 @@ WorkflowField
enm WorkflowFieldEnumId Maybe enm WorkflowFieldEnumId Maybe
required Bool required Bool
constant Bool constant Bool
-- filter TicketStatusFilterId
UniqueWorkflowField workflow ident UniqueWorkflowField workflow ident
@ -213,7 +212,7 @@ Ticket
title Text title Text
desc Text -- Assume this is Pandoc Markdown desc Text -- Assume this is Pandoc Markdown
assignee PersonId Maybe assignee PersonId Maybe
done Bool status TicketStatus
closed UTCTime closed UTCTime
closer PersonId closer PersonId
discuss DiscussionId discuss DiscussionId

View file

@ -129,7 +129,7 @@ editTicketContentAForm ticket = Ticket
(Just $ Just $ Textarea $ ticketDesc ticket) (Just $ Just $ Textarea $ ticketDesc ticket)
) )
<*> pure (ticketAssignee ticket) <*> pure (ticketAssignee ticket)
<*> pure (ticketDone ticket) <*> pure (ticketStatus ticket)
<*> pure (ticketClosed ticket) <*> pure (ticketClosed ticket)
<*> pure (ticketCloser ticket) <*> pure (ticketCloser ticket)
<*> pure (ticketDiscuss ticket) <*> pure (ticketDiscuss ticket)
@ -210,10 +210,7 @@ claimRequestForm = renderDivs claimRequestAForm
ticketFilterAForm :: AForm Handler TicketFilter ticketFilterAForm :: AForm Handler TicketFilter
ticketFilterAForm = TicketFilter ticketFilterAForm = TicketFilter
<$> areq (selectFieldList status) "Status*" (Just Nothing) <$> aopt (selectField optionsEnum) "Status*" (Just Nothing)
where
status :: [(Text, Maybe Bool)]
status = [("Open", Just False), ("Closed", Just True), ("All", Nothing)]
ticketFilterForm :: Form TicketFilter ticketFilterForm :: Form TicketFilter
ticketFilterForm = renderDivs ticketFilterAForm ticketFilterForm = renderDivs ticketFilterAForm

View file

@ -86,6 +86,7 @@ import Vervis.GraphProxy (ticketDepGraph)
import Vervis.MediaType (MediaType (Markdown)) import Vervis.MediaType (MediaType (Markdown))
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Ticket
import Vervis.Model.Workflow import Vervis.Model.Workflow
import Vervis.Render (renderSourceT) import Vervis.Render (renderSourceT)
import Vervis.Settings (widgetFile) import Vervis.Settings (widgetFile)
@ -116,7 +117,7 @@ getTicketsR shar proj = do
( ticket ^. TicketNumber ( ticket ^. TicketNumber
, sharer , sharer
, ticket ^. TicketTitle , ticket ^. TicketTitle
, ticket ^. TicketDone , ticket ^. TicketStatus
) )
defaultLayout $(widgetFile "ticket/list") defaultLayout $(widgetFile "ticket/list")
@ -145,7 +146,7 @@ postTicketsR shar proj = do
, ticketTitle = ntTitle nt , ticketTitle = ntTitle nt
, ticketDesc = ntDesc nt , ticketDesc = ntDesc nt
, ticketAssignee = Nothing , ticketAssignee = Nothing
, ticketDone = False , ticketStatus = TSNew
, ticketClosed = UTCTime (ModifiedJulianDay 0) 0 , ticketClosed = UTCTime (ModifiedJulianDay 0) 0
, ticketCloser = author , ticketCloser = author
, ticketDiscuss = did , ticketDiscuss = did
@ -221,11 +222,11 @@ getTicketR shar proj num = do
sharer <- get404 $ personIdent person sharer <- get404 $ personIdent person
return (sharer, fromMaybe False $ (== apid) <$> mpid) return (sharer, fromMaybe False $ (== apid) <$> mpid)
closer <- closer <-
if ticketDone ticket case ticketStatus ticket of
then do TSClosed -> do
person <- get404 $ ticketCloser ticket person <- get404 $ ticketCloser ticket
get404 $ personIdent person get404 $ personIdent person
else return author _ -> return author
tparams <- getTicketTextParams tid wid tparams <- getTicketTextParams tid wid
eparams <- getTicketEnumParams tid wid eparams <- getTicketEnumParams tid wid
deps <- select $ from $ \ (dep `InnerJoin` t) -> do deps <- select $ from $ \ (dep `InnerJoin` t) -> do
@ -331,12 +332,12 @@ postTicketCloseR shr prj num = do
Entity s _ <- getBy404 $ UniqueSharer shr Entity s _ <- getBy404 $ UniqueSharer shr
Entity p _ <- getBy404 $ UniqueProject prj s Entity p _ <- getBy404 $ UniqueProject prj s
getBy404 $ UniqueTicket p num getBy404 $ UniqueTicket p num
if ticketDone ticket case ticketStatus ticket of
then return False TSClosed -> return False
else do _ -> do
update tid update tid
[ TicketAssignee =. Nothing [ TicketAssignee =. Nothing
, TicketDone =. True , TicketStatus =. TSClosed
, TicketClosed =. now , TicketClosed =. now
, TicketCloser =. pid , TicketCloser =. pid
] ]
@ -356,14 +357,14 @@ postTicketOpenR shr prj num = do
Entity s _ <- getBy404 $ UniqueSharer shr Entity s _ <- getBy404 $ UniqueSharer shr
Entity p _ <- getBy404 $ UniqueProject prj s Entity p _ <- getBy404 $ UniqueProject prj s
getBy404 $ UniqueTicket p num getBy404 $ UniqueTicket p num
if ticketDone ticket case ticketStatus ticket of
then do TSClosed -> do
update tid update tid
[ TicketDone =. False [ TicketStatus =. TSTodo
, TicketCloser =. ticketCreator ticket , TicketCloser =. ticketCreator ticket
] ]
return True return True
else return False _ -> return False
setMessage $ setMessage $
if succ if succ
then "Ticket reopened" then "Ticket reopened"
@ -378,14 +379,17 @@ postTicketClaimR shr prj num = do
Entity s _ <- getBy404 $ UniqueSharer shr Entity s _ <- getBy404 $ UniqueSharer shr
Entity p _ <- getBy404 $ UniqueProject prj s Entity p _ <- getBy404 $ UniqueProject prj s
getBy404 $ UniqueTicket p num getBy404 $ UniqueTicket p num
case (ticketDone ticket, ticketAssignee ticket) of case (ticketStatus ticket, ticketAssignee ticket) of
(True, _) -> (TSNew, _) ->
return $
Just "The ticket isnt accepted yet. Cant claim it."
(TSClosed, _) ->
return $ return $
Just "The ticket is closed. Cant claim closed tickets." Just "The ticket is closed. Cant claim closed tickets."
(False, Just _) -> (TSTodo, Just _) ->
return $ return $
Just "The ticket is already assigned to someone." Just "The ticket is already assigned to someone."
(False, Nothing) -> do (TSTodo, Nothing) -> do
update tid [TicketAssignee =. Just pid] update tid [TicketAssignee =. Just pid]
return Nothing return Nothing
setMessage $ fromMaybe "The ticket is now assigned to you." mmsg setMessage $ fromMaybe "The ticket is now assigned to you." mmsg
@ -399,16 +403,20 @@ postTicketUnclaimR shr prj num = do
Entity s _ <- getBy404 $ UniqueSharer shr Entity s _ <- getBy404 $ UniqueSharer shr
Entity p _ <- getBy404 $ UniqueProject prj s Entity p _ <- getBy404 $ UniqueProject prj s
getBy404 $ UniqueTicket p num getBy404 $ UniqueTicket p num
case ((== pid) <$> ticketAssignee ticket, ticketDone ticket) of case ((== pid) <$> ticketAssignee ticket, ticketStatus ticket) of
(Nothing, _) -> (Nothing, _) ->
return $ Just "The ticket is already unassigned." return $ Just "The ticket is already unassigned."
(Just False, _) -> (Just False, _) ->
return $ Just "The ticket is assigned to someone else." return $ Just "The ticket is assigned to someone else."
(Just True, True) -> do (Just True, TSNew) -> do
$logWarn "Found a new claimed ticket, this is invalid"
return $
Just "The ticket isnt accepted yet. Cant unclaim it."
(Just True, TSClosed) -> do
$logWarn "Found a closed claimed ticket, this is invalid" $logWarn "Found a closed claimed ticket, this is invalid"
return $ return $
Just "The ticket is closed. Cant unclaim closed tickets." Just "The ticket is closed. Cant unclaim closed tickets."
(Just True, False) -> do (Just True, TSTodo) -> do
update tid [TicketAssignee =. Nothing] update tid [TicketAssignee =. Nothing]
return Nothing return Nothing
setMessage $ fromMaybe "The ticket is now unassigned." mmsg setMessage $ fromMaybe "The ticket is now unassigned." mmsg
@ -425,10 +433,11 @@ getTicketAssignR shr prj num = do
let msg t = do let msg t = do
setMessage t setMessage t
redirect $ TicketR shr prj num redirect $ TicketR shr prj num
case (ticketDone ticket, ticketAssignee ticket) of case (ticketStatus ticket, ticketAssignee ticket) of
(True, _) -> msg "The ticket is closed. Cant assign closed tickets." (TSNew, _) -> msg "The ticket isnt accepted yet. Cant assign it."
(False, Just _) -> msg "The ticket is already assigned to someone." (TSClosed, _) -> msg "The ticket is closed. Cant assign it."
(False, Nothing) -> do (TSTodo, Just _) -> msg "The ticket is already assigned to someone."
(TSTodo, Nothing) -> do
((_result, widget), enctype) <- ((_result, widget), enctype) <-
runFormPost $ assignTicketForm vpid jid runFormPost $ assignTicketForm vpid jid
defaultLayout $(widgetFile "ticket/assign") defaultLayout $(widgetFile "ticket/assign")
@ -444,10 +453,11 @@ postTicketAssignR shr prj num = do
let msg t = do let msg t = do
setMessage t setMessage t
redirect $ TicketR shr prj num redirect $ TicketR shr prj num
case (ticketDone ticket, ticketAssignee ticket) of case (ticketStatus ticket, ticketAssignee ticket) of
(True, _) -> msg "The ticket is closed. Cant assign closed tickets." (TSNew, _) -> msg "The ticket isnt accepted yet. Cant assign it."
(False, Just _) -> msg "The ticket is already assigned to someone." (TSClosed, _) -> msg "The ticket is closed. Cant assign it."
(False, Nothing) -> do (TSTodo, Just _) -> msg "The ticket is already assigned to someone."
(TSTodo, Nothing) -> do
((result, widget), enctype) <- ((result, widget), enctype) <-
runFormPost $ assignTicketForm vpid jid runFormPost $ assignTicketForm vpid jid
case result of case result of
@ -474,16 +484,20 @@ postTicketUnassignR shr prj num = do
Entity s _ <- getBy404 $ UniqueSharer shr Entity s _ <- getBy404 $ UniqueSharer shr
Entity p _ <- getBy404 $ UniqueProject prj s Entity p _ <- getBy404 $ UniqueProject prj s
getBy404 $ UniqueTicket p num getBy404 $ UniqueTicket p num
case ((== pid) <$> ticketAssignee ticket, ticketDone ticket) of case ((== pid) <$> ticketAssignee ticket, ticketStatus ticket) of
(Nothing, _) -> (Nothing, _) ->
return $ Just "The ticket is already unassigned." return $ Just "The ticket is already unassigned."
(Just True, _) -> (Just True, _) ->
return $ Just "The ticket is assigned to you, unclaim instead." return $ Just "The ticket is assigned to you, unclaim instead."
(Just False, True) -> do (Just False, TSNew) -> do
$logWarn "Found a new claimed ticket, this is invalid"
return $
Just "The ticket isnt accepted yet. Cant unclaim it."
(Just False, TSClosed) -> do
$logWarn "Found a closed claimed ticket, this is invalid" $logWarn "Found a closed claimed ticket, this is invalid"
return $ return $
Just "The ticket is closed. Cant unclaim closed tickets." Just "The ticket is closed. Cant unclaim closed tickets."
(Just False, False) -> do (Just False, TSTodo) -> do
update tid [TicketAssignee =. Nothing] update tid [TicketAssignee =. Nothing]
return Nothing return Nothing
setMessage $ fromMaybe "The ticket is now unassigned." mmsg setMessage $ fromMaybe "The ticket is now unassigned." mmsg
@ -658,7 +672,7 @@ getTicketDeps forward shr prj num = do
( ticket ^. TicketNumber ( ticket ^. TicketNumber
, sharer , sharer
, ticket ^. TicketTitle , ticket ^. TicketTitle
, ticket ^. TicketDone , ticket ^. TicketStatus
) )
defaultLayout $(widgetFile "ticket/dep/list") defaultLayout $(widgetFile "ticket/dep/list")

View file

@ -29,6 +29,7 @@ import Vervis.Model.Group
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Repo import Vervis.Model.Repo
import Vervis.Model.Role import Vervis.Model.Role
import Vervis.Model.Ticket
import Vervis.Model.Workflow import Vervis.Model.Workflow
-- You can define all of your database entities in the entities file. -- You can define all of your database entities in the entities file.

View file

@ -0,0 +1,28 @@
{- 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.Model.Ticket
( TicketStatus (..)
)
where
import Prelude
import Database.Persist.TH
data TicketStatus = TSNew | TSTodo | TSClosed
deriving (Eq, Show, Read, Bounded, Enum)
derivePersistField "TicketStatus"

View file

@ -48,7 +48,7 @@ getTicketSummaries jid = do
, tsCreatedBy = s , tsCreatedBy = s
, tsCreatedAt = c , tsCreatedAt = c
, tsTitle = t , tsTitle = t
, tsDone = d , tsStatus = d
, tsComments = r , tsComments = r
} }
fmap (map toSummary) $ select $ from $ fmap (map toSummary) $ select $ from $
@ -62,7 +62,7 @@ getTicketSummaries jid = do
, s , s
, t ^. TicketCreated , t ^. TicketCreated
, t ^. TicketTitle , t ^. TicketTitle
, t ^. TicketDone , t ^. TicketStatus
, d ^. DiscussionNextMessage -. val 1 , d ^. DiscussionNextMessage -. val 1
) )

View file

@ -25,9 +25,10 @@ import Data.Default.Class
import Database.Esqueleto import Database.Esqueleto
import Vervis.Model import Vervis.Model
import Vervis.Model.Ticket
data TicketFilter = TicketFilter data TicketFilter = TicketFilter
{ tfStatus :: Maybe Bool { tfStatus :: Maybe TicketStatus
} }
instance Default TicketFilter where instance Default TicketFilter where
@ -43,7 +44,7 @@ ticketFilter
ticketFilter tf ticket = ticketFilter tf ticket =
case tfStatus tf of case tfStatus tf of
Nothing -> Nothing Nothing -> Nothing
Just t -> Just $ ticket ^. TicketDone ==. val t Just t -> Just $ ticket ^. TicketStatus ==. val t
filterTickets filterTickets
:: Esqueleto q e b :: Esqueleto q e b

View file

@ -41,6 +41,7 @@ import Data.Graph.DirectedAcyclic.View.Tree
import Vervis.Foundation import Vervis.Foundation
import Vervis.Model import Vervis.Model
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Ticket
import Vervis.Settings (widgetFile) import Vervis.Settings (widgetFile)
import Vervis.Style import Vervis.Style
import Vervis.Time (showDate) import Vervis.Time (showDate)
@ -51,14 +52,15 @@ data TicketSummary = TicketSummary
, tsCreatedBy :: Sharer , tsCreatedBy :: Sharer
, tsCreatedAt :: UTCTime , tsCreatedAt :: UTCTime
, tsTitle :: Text , tsTitle :: Text
, tsDone :: Bool , tsStatus :: TicketStatus
, tsComments :: Int , tsComments :: Int
} }
ticketDepW :: ShrIdent -> PrjIdent -> Ticket -> Widget ticketDepW :: ShrIdent -> PrjIdent -> Ticket -> Widget
ticketDepW shr prj ticket = do ticketDepW shr prj ticket = do
cNew <- newIdent
cTodo <- newIdent cTodo <- newIdent
cDone <- newIdent cClosed <- newIdent
$(widgetFile "ticket/widget/dep") $(widgetFile "ticket/widget/dep")
ticketSummaryW ticketSummaryW
@ -68,8 +70,9 @@ ticketSummaryW
-> Maybe (HashMap Int Int) -> Maybe (HashMap Int Int)
-> Widget -> Widget
ticketSummaryW shr prj ts mcs = do ticketSummaryW shr prj ts mcs = do
cNew <- newIdent
cTodo <- newIdent cTodo <- newIdent
cDone <- newIdent cClosed <- newIdent
let tshow = T.pack . show let tshow = T.pack . show
mparams = map (tshow *** tshow) . M.toList <$> mcs mparams = map (tshow *** tshow) . M.toList <$> mcs
mroute <- getCurrentRoute mroute <- getCurrentRoute

View file

@ -17,10 +17,10 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<th>Number <th>Number
<th>Author <th>Author
<th>Title <th>Title
<th>Done <th>Status
$if forward $if forward
<th>Remove dependency <th>Remove dependency
$forall (Value number, Entity _ author, Value title, Value done) <- rows $forall (Value number, Entity _ author, Value title, Value status) <- rows
<tr> <tr>
<td> <td>
<a href=@{TicketR shr prj number}>#{number} <a href=@{TicketR shr prj number}>#{number}
@ -29,7 +29,7 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<td> <td>
<a href=@{TicketR shr prj number}>#{title} <a href=@{TicketR shr prj number}>#{title}
<td> <td>
#{done} #{show status}
$if forward $if forward
<td> <td>
<form method=POST action=@{TicketDepR shr prj num number}> <form method=POST action=@{TicketDepR shr prj num number}>

View file

@ -27,8 +27,8 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<th>Number <th>Number
<th>Author <th>Author
<th>Title <th>Title
<th>Done <th>Status
$forall (Value number, Entity _ author, Value title, Value done) <- rows $forall (Value number, Entity _ author, Value title, Value status) <- rows
<tr> <tr>
<td> <td>
<a href=@{TicketR shar proj number}>#{number} <a href=@{TicketR shar proj number}>#{number}
@ -37,4 +37,4 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<td> <td>
<a href=@{TicketR shar proj number}>#{title} <a href=@{TicketR shar proj number}>#{title}
<td> <td>
#{done} #{show status}

View file

@ -45,7 +45,7 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
Created on #{showDate $ ticketCreated ticket} by Created on #{showDate $ ticketCreated ticket} by
^{personLinkW author} ^{personLinkW author}
$if not $ ticketDone ticket $if ticketStatus ticket /= TSClosed
<p> <p>
$maybe (assignee, me) <- massignee $maybe (assignee, me) <- massignee
$if me $if me
@ -84,17 +84,23 @@ $if not $ ticketDone ticket
<p> <p>
Status: # Status: #
$if ticketDone ticket $case ticketStatus ticket
Closed on #{showDate $ ticketClosed ticket} by $of TSNew
^{personLinkW closer}. Open, new.
<form method=POST action=@{TicketOpenR shar proj num}> <form method=POST action=@{TicketCloseR shar proj num}>
<input type=submit value="Reopen this ticket"> <input type=submit value="Close this ticket">
$else $of TSTodo
Open. Open, to do.
<form method=POST action=@{TicketCloseR shar proj num}> <form method=POST action=@{TicketCloseR shar proj num}>
<input type=submit value="Close this ticket"> <input type=submit value="Close this ticket">
$of TSClosed
Closed on #{showDate $ ticketClosed ticket} by
^{personLinkW closer}.
<form method=POST action=@{TicketOpenR shar proj num}>
<input type=submit value="Reopen this ticket">
<h2>#{ticketTitle ticket} <h2>#{ticketTitle ticket}

View file

@ -13,8 +13,11 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>. * <http://creativecommons.org/publicdomain/zero/1.0/>.
*/ */
.#{cNew}
color: #{dark yellow}
.#{cTodo} .#{cTodo}
color: #{dark red} color: #{dark red}
.#{cDone} .#{cClosed}
color: #{dark green} color: #{dark green}

View file

@ -12,11 +12,15 @@ $# You should have received a copy of the CC0 Public Domain Dedication along
$# with this software. If not, see $# with this software. If not, see
$# <http://creativecommons.org/publicdomain/zero/1.0/>. $# <http://creativecommons.org/publicdomain/zero/1.0/>.
$if ticketDone ticket $case ticketStatus ticket
<span .#{cDone}> $of TSNew
<span .#{cNew}>
$else
<span .#{cTodo}> $of TSTodo
<span .#{cTodo}>
$of TSClosed
<span .#{cClosed}>
<a href=@{TicketR shr prj $ ticketNumber ticket}> <a href=@{TicketR shr prj $ ticketNumber ticket}>
#{ticketTitle ticket} #{ticketTitle ticket}

View file

@ -13,8 +13,11 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>. * <http://creativecommons.org/publicdomain/zero/1.0/>.
*/ */
.#{cNew}
color: #{dark yellow}
.#{cTodo} .#{cTodo}
color: #{dark red} color: #{dark red}
.#{cDone} .#{cClosed}
color: #{dark green} color: #{dark green}

View file

@ -13,12 +13,16 @@ $# with this software. If not, see
$# <http://creativecommons.org/publicdomain/zero/1.0/>. $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<div> <div>
$if tsDone ts $case tsStatus ts
<span .#{cDone}> $of TSNew
<span .#{cNew}>
$else
<span .#{cTodo}> $of TSTodo
<span .#{cTodo}>
$of TSClosed
<span .#{cClosed}>
<a href=@{TicketR shr prj $ tsNumber ts}> <a href=@{TicketR shr prj $ tsNumber ts}>
#{tsNumber ts} #{tsNumber ts}

View file

@ -149,6 +149,7 @@ library
Vervis.Model.Ident Vervis.Model.Ident
Vervis.Model.Repo Vervis.Model.Repo
Vervis.Model.Role Vervis.Model.Role
Vervis.Model.Ticket
Vervis.Model.Workflow Vervis.Model.Workflow
Vervis.Paginate Vervis.Paginate
Vervis.Palette Vervis.Palette