1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-29 01:34:52 +09:00

Ticket view page

This commit is contained in:
fr33domlover 2016-05-01 09:58:55 +00:00
parent eaadbc050c
commit 7a4b211617
5 changed files with 82 additions and 18 deletions

View file

@ -68,6 +68,7 @@ Ticket
project ProjectId project ProjectId
number Int number Int
created UTCTime created UTCTime
creator PersonId
title Text title Text
desc Text -- Assume this is Pandoc Markdown desc Text -- Assume this is Pandoc Markdown
done Bool done Bool

View file

@ -32,14 +32,15 @@ import Vervis.Model
--TODO stuff like number and created - do I generate them here using monadic --TODO stuff like number and created - do I generate them here using monadic
-- form or do I rely on handler to provide? which approach is better? -- form or do I rely on handler to provide? which approach is better?
newTicketAForm :: ProjectId -> Int -> AForm Handler Ticket newTicketAForm :: ProjectId -> Int -> PersonId -> AForm Handler Ticket
newTicketAForm pid number = Ticket newTicketAForm pid number author = Ticket
<$> pure pid <$> pure pid
<*> pure number <*> pure number
<*> lift (liftIO getCurrentTime) <*> lift (liftIO getCurrentTime)
<*> pure author
<*> areq textField "Title*" Nothing <*> areq textField "Title*" Nothing
<*> (maybe "" unTextarea <$> aopt textareaField "Description (Markdown)" Nothing) <*> (maybe "" unTextarea <$> aopt textareaField "Description (Markdown)" Nothing)
<*> pure False <*> pure False
newTicketForm :: ProjectId -> Int -> Form Ticket newTicketForm :: ProjectId -> Int -> PersonId -> Form Ticket
newTicketForm pid number = renderDivs $ newTicketAForm pid number newTicketForm pid number author = renderDivs $ newTicketAForm pid number author

View file

@ -23,16 +23,21 @@ where
import Prelude import Prelude
import Data.Maybe (fromMaybe)
import Data.Text (Text) import Data.Text (Text)
import Data.Time.Format (formatTime, defaultTimeLocale)
import Database.Esqueleto hiding ((==.))
import Database.Persist import Database.Persist
import Text.Blaze.Html (Html, toHtml) import Text.Blaze.Html (Html, toHtml)
import Yesod.Auth (requireAuthId)
import Yesod.Core (defaultLayout) import Yesod.Core (defaultLayout)
import Yesod.Core.Handler (notFound) import Yesod.Core.Handler (notFound)
import Yesod.Core.Widget (setTitle) import Yesod.Core.Widget (setTitle)
import Yesod.Form.Functions (runFormPost) import Yesod.Form.Functions (runFormPost)
import Yesod.Persist.Core (runDB, getBy404) import Yesod.Persist.Core (runDB, get404, getBy404)
import qualified Data.Text as T (intercalate) import qualified Data.Text as T (intercalate, pack)
import qualified Database.Esqueleto as E ((==.))
import Vervis.Form.Ticket import Vervis.Form.Ticket
import Vervis.Foundation import Vervis.Foundation
@ -41,10 +46,22 @@ import Vervis.Settings (widgetFile)
getTicketsR :: Text -> Text -> Handler Html getTicketsR :: Text -> Text -> Handler Html
getTicketsR shar proj = do getTicketsR shar proj = do
tickets <- runDB $ do --tickets <- runDB $ do
Entity sid _sharer <- getBy404 $ UniqueSharerIdent shar -- Entity sid _sharer <- getBy404 $ UniqueSharerIdent shar
Entity pid _project <- getBy404 $ UniqueProject proj sid -- Entity pid _project <- getBy404 $ UniqueProject proj sid
selectList [TicketProject ==. pid] [Asc TicketNumber] -- selectList [TicketProject ==. pid] [Asc TicketNumber]
rows <- runDB $ select $ from $ \ (ticket, person, sharer) -> do
where_ $
ticket ^. TicketCreator E.==. person ^. PersonId &&.
person ^. PersonIdent E.==. sharer ^. SharerId
orderBy [asc $ ticket ^. TicketNumber]
return
( ticket ^. TicketNumber
, sharer ^. SharerIdent
, sharer ^. SharerName
, ticket ^. TicketTitle
, ticket ^. TicketDone
)
defaultLayout $ do defaultLayout $ do
setTitle $ toHtml $ T.intercalate " :: " [shar, proj, "Tickes"] setTitle $ toHtml $ T.intercalate " :: " [shar, proj, "Tickes"]
$(widgetFile "ticket/list") $(widgetFile "ticket/list")
@ -58,10 +75,22 @@ getTicketNewR shar proj = do
Entity sid _sharer <- getBy404 $ UniqueSharerIdent shar Entity sid _sharer <- getBy404 $ UniqueSharerIdent shar
getBy404 $ UniqueProject proj sid getBy404 $ UniqueProject proj sid
let next = projectNextTicket project let next = projectNextTicket project
((_result, widget), enctype) <- runFormPost $ newTicketForm pid next author <- requireAuthId
((_result, widget), enctype) <- runFormPost $ newTicketForm pid next author
defaultLayout $ do defaultLayout $ do
setTitle $ toHtml $ T.intercalate " :: " [shar, proj, "New ticket"] setTitle $ toHtml $ T.intercalate " :: " [shar, proj, "New ticket"]
$(widgetFile "ticket/new") $(widgetFile "ticket/new")
getTicketR :: Text -> Text -> Int -> Handler Html getTicketR :: Text -> Text -> Int -> Handler Html
getTicketR shar proj num = notFound getTicketR shar proj num = do
(author, ticket) <- runDB $ do
Entity sid _sharer <- getBy404 $ UniqueSharerIdent shar
Entity pid _project <- getBy404 $ UniqueProject proj sid
Entity _tid ticket <- getBy404 $ UniqueTicket pid num
person <- get404 $ ticketCreator ticket
author <- get404 $ personIdent person
return (author, ticket)
defaultLayout $ do
setTitle $ toHtml $ T.intercalate " :: "
[shar, proj, "Tickets", T.pack ('#' : show num)]
$(widgetFile "ticket/one")

View file

@ -20,15 +20,18 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<table> <table>
<tr> <tr>
<th>Number <th>Number
<th>Author
<th>Title <th>Title
<th>Done <th>Done
$forall Entity _tid ticket <- tickets $forall
(Value number, Value authorIdent, Value mAuthorName, Value title, Value done)
<- rows
<tr> <tr>
<td> <td>
<a href=@{TicketR shar proj $ ticketNumber ticket}> <a href=@{TicketR shar proj number}>#{number}
#{ticketNumber ticket}
<td> <td>
<a href=@{TicketR shar proj $ ticketNumber ticket}> <a href=@{PersonR authorIdent}>#{fromMaybe authorIdent mAuthorName}
#{ticketTitle ticket}
<td> <td>
#{ticketDone ticket} <a href=@{TicketR shar proj number}>#{title}
<td>
#{done}

View file

@ -0,0 +1,30 @@
$# 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/>.
<h1>#{shar} :: #{proj} :: Tickets :: ##{num}
<p>
Created on #{formatTime defaultTimeLocale "%F" $ ticketCreated ticket} by
#{fromMaybe (sharerIdent author) $ sharerName author}
<p>Done: #{ticketDone ticket}
<h2>#{ticketTitle ticket}
<p>
Below is the ticket description. Its supposed to be rendered as Markdown,
but for now, temporarily, its shown here as plain text.
<code>
<pre>#{ticketDesc ticket}