Luke Plant avatar Luke Plant committed 40868dc

Added HTML 'all comments' page

Comments (0)

Files changed (7)

src/Blog/Links.hs

 allPostsFeedUrl        = Settings.root_url ++ "atom/"
 postCommentFeedUrl   p = Settings.root_url ++ "posts/" ++ (UTF8.toString $ P.slug p) ++ "/atom/"
 categoryPostsFeedUrl c = Settings.root_url ++ "categories/" ++ (UTF8.toString $ C.slug c) ++ "/atom/"
+allCommentsUrl         = Settings.root_url ++ "comments/"
 allCommentsFeedUrl     = Settings.root_url ++ "comments/atom/"
 
 commentUrl cm p        = postUrl p ++ "#comment" ++ (show $ Cm.uid cm)

src/Blog/Model.hs

 getCommentByIdQuery      = "SELECT id, post_id, timestamp, name, email, text_raw, text_formatted, format_id, hidden, response FROM comments WHERE id = ?;"
 getCommentsForPostQuery  = "SELECT id, '',      timestamp, name, email, '',       text_formatted, '',        hidden, response FROM comments WHERE post_id = ? ORDER BY timestamp ASC;"
 
-getRecentCommentsQuery   = "SELECT c.id, c.post_id, c.timestamp, c.name, c.email, '',       c.text_formatted, '',        c.hidden, c.response, p.slug as post_slug, p.title as post_title FROM comments as c INNER JOIN posts as p ON c.post_id = p.id ORDER BY c.timestamp DESC;"
+getRecentCommentsQuery   = "SELECT c.id, c.post_id, c.timestamp, c.name, c.email, '',       c.text_formatted, '',        c.hidden, c.response, p.slug as post_slug, p.title as post_title FROM comments as c INNER JOIN posts as p ON c.post_id = p.id ORDER BY c.timestamp DESC $LIMITOFFSET ;"
 
 getPasswordForUsernameQuery = "SELECT password FROM users WHERE username = ?;"
 setPasswordForUsernameQuery = "UPDATE users SET password = ? WHERE username = ?;"
   return (map makePost res, more)
 
 -- | Returns all recent comments, paired with the Post they are from
--- Contains only enough information to generate the feed.
-getRecentComments :: (IConnection conn) => conn -> Int -> Int -> IO [(Cm.Comment, P.Post)]
+-- Contains only enough information to generate the feed and the 'Recent comments' page
+getRecentComments :: (IConnection conn) => conn -> Int -> Int -> IO ([(Cm.Comment, P.Post)],Bool)
 getRecentComments cn page pagesize = do
   (res, more) <- pagedQuery cn getRecentCommentsQuery [] page pagesize
   let comments = map makeComment res
   let posts = map (\row -> minimalPost (fromSql $ row !! 10) (fromSql $ row !! 11)) res
-  return $ zip comments posts
+  return $ (zip comments posts, more)
 
 getCategoryBySlug :: (IConnection conn) => conn -> String -> IO (Maybe Ct.Category)
 getCategoryBySlug cn slug = do

src/Blog/Routes.hs

          , "categories/" <+/> empty                   //-> categoriesView         $ []
          , "categories/" <+/> anyParam                //-> categoryView           $ []
          , "categories/" <+/> stringParam</+>"atom/"  //-> categoryPostsFeedView  $ []
+         , "comments/" <+/> empty                     //-> allCommentsView        $ []
          , "comments/atom/" <+/> empty                //-> allCommentsFeedView    $ []
          , "login/" <+/> empty                        //-> loginView              $ []
          , "logout/" <+/> empty                       //-> logoutView             $ []

src/Blog/Views.hs

   feedResponse $ allPostsFeed posts
 
 
+allCommentsView req = do
+  let curpage = getPage req
+  cn <- connect
+  (commentsAndPosts,more) <- getRecentComments cn curpage Settings.comment_page_size
+  t <- get_template "comments"
+  return $ Just $ standardResponseTT req $
+                      (renderf t
+                       ("comments", map (commentTemplateInfo . fst) commentsAndPosts)
+                       ("urls", map (uncurry commentUrl) commentsAndPosts)
+                       ("titles", map (P.title . snd) commentsAndPosts)
+                       ("paginglinks", pagingLinks allCommentsUrl curpage more)
+                       ("atomfeedurl", allCommentsFeedUrl)
+                      )
+
 allCommentsFeedView req = do
   cn <- connect
-  comments <- getRecentComments cn 1 Settings.feed_comment_page_size
-  feedResponse $ allCommentsFeed comments
+  (commentsAndPosts,more) <- getRecentComments cn 1 Settings.feed_comment_page_size
+  feedResponse $ allCommentsFeed commentsAndPosts
 
 -- | View to help with debugging
 debug :: String -> View

src/Blog/settingslive.hs

 admin_usernames = [blog_author_name]
 
 post_page_size = 20 :: Int
+comment_page_size = 30 :: Int
 admin_post_page_size = 100 :: Int
 feed_post_page_size = 8 :: Int
 feed_comment_page_size = 15 :: Int

src/Blog/settingslocal.hs

 admin_usernames = [blog_author_name]
 
 post_page_size = 20 :: Int
+comment_page_size = 30 :: Int
 admin_post_page_size = 100 :: Int
 feed_post_page_size = 8 :: Int
 feed_comment_page_size = 15 :: Int

src/templates/comments.st

+$pagestart(pagetitle="Recent comments")$
+<h1>Recent comments</h1>
+<div class="comments">
+$comments,urls,titles:{ c,u,t |
+<div><a href="$u$">$t$</a></div> $comment(comment=c)$ }$
+</div>
+$paginglinks:noescape()$
+$pageend()$
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.