2016-05-01 06:26:54 +09:00
|
|
|
{- 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.Form.Ticket
|
2016-05-18 18:15:11 +09:00
|
|
|
( NewTicket (..)
|
|
|
|
, newTicketForm
|
2016-05-02 18:15:10 +09:00
|
|
|
, editTicketForm
|
2016-05-01 06:26:54 +09:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Prelude
|
|
|
|
|
|
|
|
import Control.Monad.IO.Class (liftIO)
|
|
|
|
import Control.Monad.Trans.Class (lift)
|
2016-05-18 18:15:11 +09:00
|
|
|
import Data.Text (Text)
|
2016-05-02 18:15:10 +09:00
|
|
|
import Data.Time.Calendar (Day (..))
|
|
|
|
import Data.Time.Clock (getCurrentTime, UTCTime (..))
|
2016-05-01 06:26:54 +09:00
|
|
|
import Yesod.Form
|
|
|
|
|
|
|
|
import Vervis.Foundation (Form, Handler)
|
|
|
|
import Vervis.Model
|
|
|
|
|
|
|
|
--TODO use custom fields to ensure uniqueness or other constraints?
|
|
|
|
|
2016-05-02 18:15:10 +09:00
|
|
|
defTime :: UTCTime
|
|
|
|
defTime = UTCTime (ModifiedJulianDay 0) 0
|
|
|
|
|
|
|
|
now :: AForm Handler UTCTime
|
|
|
|
now = lift $ liftIO getCurrentTime
|
|
|
|
|
2016-05-18 18:15:11 +09:00
|
|
|
data NewTicket = NewTicket
|
|
|
|
{ ntTitle :: Text
|
|
|
|
, ntDesc :: Text
|
|
|
|
}
|
|
|
|
|
|
|
|
newTicketAForm :: AForm Handler NewTicket
|
|
|
|
newTicketAForm = NewTicket
|
|
|
|
<$> areq textField "Title*" Nothing
|
2016-05-02 18:15:10 +09:00
|
|
|
<*> ( maybe "" unTextarea <$>
|
|
|
|
aopt textareaField "Description (Markdown)" Nothing
|
|
|
|
)
|
2016-05-01 06:26:54 +09:00
|
|
|
|
2016-05-18 18:15:11 +09:00
|
|
|
newTicketForm :: Form NewTicket
|
|
|
|
newTicketForm = renderDivs newTicketAForm
|
2016-05-02 18:15:10 +09:00
|
|
|
|
|
|
|
editTicketAForm :: Ticket -> PersonId -> AForm Handler Ticket
|
|
|
|
editTicketAForm ticket pid = fmap fixDone $ Ticket
|
|
|
|
<$> pure (ticketProject ticket)
|
|
|
|
<*> pure (ticketNumber ticket)
|
|
|
|
<*> pure (ticketCreated ticket)
|
|
|
|
<*> pure (ticketCreator ticket)
|
|
|
|
<*> areq textField "Title*" (Just $ ticketTitle ticket)
|
|
|
|
<*> ( maybe "" unTextarea <$>
|
|
|
|
aopt
|
|
|
|
textareaField
|
|
|
|
"Description (Markdown)"
|
|
|
|
(Just $ Just $ Textarea $ ticketDesc ticket)
|
|
|
|
)
|
|
|
|
<*> areq checkBoxField "Done*" (Just $ ticketDone ticket)
|
|
|
|
<*> now
|
|
|
|
<*> pure (ticketCloser ticket)
|
2016-05-18 18:44:32 +09:00
|
|
|
<*> pure (ticketDiscuss ticket)
|
2016-05-02 18:15:10 +09:00
|
|
|
where
|
|
|
|
fixDone result = case (ticketDone ticket, ticketDone result) of
|
|
|
|
(True, True) -> result { ticketClosed = ticketClosed ticket }
|
|
|
|
(False, False) -> result { ticketClosed = ticketClosed ticket }
|
|
|
|
(False, True) -> result { ticketCloser = pid }
|
|
|
|
(True, False) -> result { ticketClosed = defTime
|
|
|
|
, ticketCloser = ticketCreator ticket
|
|
|
|
}
|
|
|
|
|
|
|
|
editTicketForm :: Ticket -> PersonId -> Form Ticket
|
|
|
|
editTicketForm t p = renderDivs $ editTicketAForm t p
|