Commits

Luke Plant committed 89c760c

Added 'edit posts' admin page

Comments (0)

Files changed (5)

src/Blog/Model.hs

     [] -> return Nothing
     (postdata:_) -> return $ Just $ makePost postdata
 
-getRecentPosts :: (IConnection conn) => conn -> Int -> IO ([P.Post], Bool)
-getRecentPosts cn page = do
-  (res,more) <- pagedQuery cn getRecentPostsQuery [] page Settings.post_page_size
+getRecentPosts :: (IConnection conn) => conn -> Int -> Int -> IO ([P.Post], Bool)
+getRecentPosts cn page pagesize = do
+  (res,more) <- pagedQuery cn getRecentPostsQuery [] page pagesize
   return (map makePost res, more)
 
 getPostsForCategory :: (IConnection conn) => conn -> Ct.Category -> Int -> IO ([P.Post], Bool)

src/Blog/Templates.hs

                                   , ("full", ToSElemD $ P.post_formatted p)
                                   , ("url", ToSElemD $ postUrl p)
                                   , ("commentsOpen", ToSElemD $ P.comments_open p)
+                                  , ("adminUrl", ToSElemD $ adminEditPostUrl p)
                                   ]
 
 categoryTemplateInfo :: C.Category -> Map.Map String ToSElemD

src/Blog/Views.hs

 mainIndex req = do
   let curpage = getPage req
   cn <- connect
-  (posts,more) <- getRecentPosts cn curpage
+  (posts,more) <- getRecentPosts cn curpage Settings.post_page_size
   cats <- getCategoriesBulk cn posts
   t <- get_template "index"
   return $ Just $ standardResponseTT req $
 -- Category editing is very simple and doesn't require
 -- much validation.
 
+adminMenu :: View
 adminMenu req = do
   t <- get_template "admin_menu"
   return $ Just $ standardResponseTT req $
           ("adminCategoriesUrl", Links.adminCategoriesUrl)
          )
 
-adminPosts = undefined
-
+adminPosts req = do
+  t <- get_template "admin_posts"
+  let curpage = getPage req
+  cn <- connect
+  (posts,more) <- getRecentPosts cn curpage Settings.admin_post_page_size
+  return $ Just $ standardResponseTT req $
+             (renderf t
+              ("pagetitle", "Edit posts")
+              ("posts", map postTemplateInfo posts)
+              ("paginglinks", pagingLinks Links.adminPostsUrl curpage more)
+             )
 
 -- | View that handles all editing of categories (add/edit/delete)
 adminCategories req = do

src/Blog/settingslocal.hs

 admin_usernames = [blog_author_name]
 
 post_page_size = 20 :: Int
+admin_post_page_size = 100 :: Int
 domain = "lukeplant_local"
 
 secret = "123"

src/templates/admin_posts.st

+$pagestart()$
+<h1>$pagetitle$</h1>
+
+$posts:{
+<div><a href="$it.adminUrl$">$it.title$</a></div>
+}$
+
+$paginglinks:noescape()$
+
+$pageend()$