diff of cf9cc7487ea8cf4703e93db15353943242a4deb0
cf9cc7487ea8cf4703e93db15353943242a4deb0
diff --git a/elm-frontti/src/Ajax_cmds.elm b/elm-frontti/src/Ajax_cmds.elm
index 7d2845e..5536ab4 100644
--- a/elm-frontti/src/Ajax_cmds.elm
+++ b/elm-frontti/src/Ajax_cmds.elm
@@ -20,10 +20,9 @@ getEditablePosts =
{ url = "/api/posts/all-titles"
, expect = Http.expectJson EditableTitlesReceived (Json.list Article.sidebarTitleDecoder) }
-getPage : Int -> Cmd Msg
getPage page_id =
Http.get
- { url = "/api/posts/page/" ++ (String.fromInt page_id) ++ "/page-size/6"
+ { url = "/api/posts/page/" ++ (String.fromInt page_id)
, expect = Http.expectJson PageReceived Page.pageDecoder}
getPost : Int -> Cmd Msg
diff --git a/elm-frontti/src/Main.elm b/elm-frontti/src/Main.elm
index 937e042..35a0816 100644
--- a/elm-frontti/src/Main.elm
+++ b/elm-frontti/src/Main.elm
@@ -633,9 +633,14 @@ view model =
post_elements
else
[ div [class "post"] [ text "There are no posts in this instance"]])
- , [footer [(attribute "data-testid" "page-changer")] (if page.id > 1 then [ a [href ("/blog/page/" ++ fromInt (page.id + 1))] [text "Older posts"]
- , a [href ("/blog/page/" ++ fromInt (page.id - 1)), class "newer-post"] [text "Newer posts"]]
- else [a [href ("/blog/page/" ++ fromInt (page.id + 1))] [text "Next page"]])]])
+ , [footer [ attribute "data-testid" "page-changer"
+ , class "page-changer" ]
+ (if page.id > 1 then
+ [ a [href ("/blog/page/" ++ fromInt (page.id + 1))] [text "Older posts"]
+ , a [href ("/blog/page/" ++ fromInt (page.id - 1)), class "newer-post"] [text "Newer posts"]]
+
+ else
+ [a [href ("/blog/page/" ++ fromInt (page.id + 1))] [text "Older posts"]])]])
ShowError err ->
[pre [] [text err]]
PostEditorList titles -> [ PostsAdmin.view titles ]
diff --git a/resources/css/murja.css b/resources/css/murja.css
index feefc04..a449fc8 100644
--- a/resources/css/murja.css
+++ b/resources/css/murja.css
@@ -274,6 +274,12 @@ header {
display: block;
}
+.page-changer {
+ display: flex;
+ justify-content: space-between;
+ width: 100%;
+}
+
@media only screen and (max-device-width:480px)
{
body {
diff --git a/src/posts/post-db.lisp b/src/posts/post-db.lisp
index d2ad49a..b9b4b85 100644
--- a/src/posts/post-db.lisp
+++ b/src/posts/post-db.lisp
@@ -37,8 +37,12 @@
post)
(defun get-page (page page-size &key allow-hidden?)
- (let ((resulting-page (coerce
- (get-page* page page-size allow-hidden?) 'list)))
+ (let ((page (if (< page 1)
+ 1
+ page))
+ (resulting-page (coerce
+ (get-page* (* (1- page) page-size)
+ page-size allow-hidden?) 'list)))
(mapcar #'fix-post
resulting-page)))
diff --git a/src/routes/post-routes.lisp b/src/routes/post-routes.lisp
index ec72136..f99eb27 100644
--- a/src/routes/post-routes.lisp
+++ b/src/routes/post-routes.lisp
@@ -1,5 +1,6 @@
(defpackage murja.routes.post-routes
(:use :cl)
+ (:import-from :murja.routes.settings-routes :get-settings)
(:import-from :lisp-fixup :partial)
(:import-from :com.inuoe.jzon :stringify :parse)
(:import-from :murja.middleware.db :@transaction)
@@ -22,20 +23,20 @@
(let ((titles (get-titles-by-year :allow-hidden? t)))
(stringify titles)))
-(defroute get-page-route ("/api/posts/page/:page/page-size/:page-size" :method :get
- :decorators (@json @transaction))
- (&path (page 'integer)
- &path (page-size 'integer))
- (let* ((page (1- page))
- (posts (or (murja.posts.post-db:get-page page page-size) #()))
- (id page)
- (last-page? (zerop (length (murja.posts.post-db:get-page (1+ page) page-size))))
- (result (make-hash-table)))
- (setf (gethash "id" result) id)
- (setf (gethash "posts" result) posts)
- (setf (gethash "last-page?" result) last-page?)
+(defroute get-page-route ("/api/posts/page/:page" :method :get
+ :decorators (@json @transaction))
+ (&path (page 'integer))
+ (let* ((settings (get-settings))
+ (page-size (gethash "recent-post-count" settings)))
+ (let* ((id page)
+ (posts (or (murja.posts.post-db:get-page page page-size) #()))
+ (last-page? (zerop (length (murja.posts.post-db:get-page (1+ page) page-size))))
+ (result (make-hash-table)))
+ (setf (gethash "id" result) id)
+ (setf (gethash "posts" result) posts)
+ (setf (gethash "last-page?" result) last-page?)
- (com.inuoe.jzon:stringify result)))
+ (com.inuoe.jzon:stringify result))))
(defroute hidden-post ("/api/posts/post/:id/allow-hidden/:hidden" :method :get
:decorators (@json
diff --git a/src/routes/root-routes.lisp b/src/routes/root-routes.lisp
index 1efabb1..b10713b 100644
--- a/src/routes/root-routes.lisp
+++ b/src/routes/root-routes.lisp
@@ -114,3 +114,7 @@
(defroute ddddddd ("/blog/settings" :method :get) ()
*root*)
+
+
+(defroute ddddddd ("/blog/page/:page" :method :get) ()
+ *root*)
diff --git a/src/routes/settings-routes.lisp b/src/routes/settings-routes.lisp
index 593b40f..f0608e7 100644
--- a/src/routes/settings-routes.lisp
+++ b/src/routes/settings-routes.lisp
@@ -4,21 +4,25 @@
(:import-from :murja.middleware.auth :@authenticated :*user* :@can?)
(:import-from :murja.middleware.json :@json)
(:import-from :murja.middleware.db :@transaction)
- (:import-from :easy-routes :defroute))
+ (:import-from :easy-routes :defroute)
+ (:export :get-settings))
(in-package :murja.routes.settings-routes)
+(defun get-settings ()
+ (reduce (lambda (acc pair)
+ (destructuring-bind (k v) pair
+ (setf (gethash k acc) (com.inuoe.jzon:parse v))
+ acc))
+ (postmodern:query "SELECT key, value FROM blog.Settings")
+
+ :initial-value (make-hash-table :test 'equal)))
+
(defroute client-settings ("/api/settings/client-settings" :method :get
:decorators (@transaction
@json)) ()
(com.inuoe.jzon:stringify
- (reduce (lambda (acc pair)
- (destructuring-bind (k v) pair
- (setf (gethash k acc) (com.inuoe.jzon:parse v))
- acc))
- (postmodern:query "SELECT key, value FROM blog.Settings")
-
- :initial-value (make-hash-table))))
+ (get-settings)))
(defroute update-setting ("/api/settings/client-settings" :method :put
:decorators (@transaction
diff --git a/test/tests.lisp b/test/tests.lisp
index 71fb4c0..a65f302 100644
--- a/test/tests.lisp
+++ b/test/tests.lisp
@@ -112,38 +112,55 @@
(is (equalp 2 (length existing-unlisted-posts))))
(literal
- A simple grep of the repository tells us that the interesting functions to test are":"
- "feuer@vivacia aggressive-murja % grep -iR hidden src |grep -i defun" =>
- - "src/posts/post-db.lisp:(defun get-titles-by-year (&key allow-hidden?)"
- - "src/posts/post-db.lisp:(defun get-page (page page-size &key allow-hidden?)"
- - "src/posts/post-db.lisp:(defun get-post (id &key allow-hidden?)"
- - "src/posts/post-db.lisp:(defun get-tagged (tag &key allow-hidden?)"
-
- !L
- (let ((titles (murja.posts.post-db:get-titles-by-year :allow-hidden? nil))
- (first-page (murja.posts.post-db:get-page 1 555 :allow-hidden? nil))
- (hidden-post (murja.posts.post-db:get-post hidden-post-id :allow-hidden? nil))
- (unlisted-post (murja.posts.post-db:get-post unlisted-post-id :allow-hidden? nil))
- (test-hidden-tagged-posts (murja.posts.post-db:get-tagged "test-hidden" :allow-hidden? nil)))
-
- (is (null hidden-post))
- (is (null test-hidden-tagged-posts))
-
- ;; unlisted posts should be always visible
- (is (atom unlisted-post))
- ;; just missing from the sidebar titles
- (is (not (member unlisted-post-id
- (mapcar (lambda (title) (gethash "Id" title)) titles)
- :test 'equal)))
-
-
- ;; test sidebar titles
- (is (not (member "Hidden title" (mapcar (lambda (title) (gethash "Title" title)) titles) :test 'equal)))
- (is (not (member "Unlisted title" (mapcar (lambda (title) (gethash "Title" title)) titles) :test 'equal)))
-
- ;; test the page
- (is (not (member "Hidden title" (mapcar (lambda (title) (gethash "Title" title)) first-page) :test 'equal)))
- (is (not (member "Unlisted title" (mapcar (lambda (title) (gethash "Title" title)) first-page) :test 'equal))))))))))
+ A simple grep of the repository tells us that the interesting functions to test are":"
+ "feuer@vivacia aggressive-murja % grep -iR hidden src |grep -i defun" =>
+ - "src/posts/post-db.lisp:(defun get-titles-by-year (&key allow-hidden?)"
+ - "src/posts/post-db.lisp:(defun get-page (page page-size &key allow-hidden?)"
+ - "src/posts/post-db.lisp:(defun get-post (id &key allow-hidden?)"
+ - "src/posts/post-db.lisp:(defun get-tagged (tag &key allow-hidden?)"
+
+ !L
+ (let ((titles (murja.posts.post-db:get-titles-by-year :allow-hidden? nil))
+ (first-page (murja.posts.post-db:get-page 1 555 :allow-hidden? nil))
+ (count-of-posts (caar (postmodern:query "SELECT COUNT(*) FROM blog.Post")))
+ (hidden-post (murja.posts.post-db:get-post hidden-post-id :allow-hidden? nil))
+ (unlisted-post (murja.posts.post-db:get-post unlisted-post-id :allow-hidden? nil))
+ (test-hidden-tagged-posts (murja.posts.post-db:get-tagged "test-hidden" :allow-hidden? nil)))
+
+ (is (null hidden-post))
+ (is (null test-hidden-tagged-posts))
+
+ ;; unlisted posts should be always visible
+ (is (atom unlisted-post))
+ ;; just missing from the sidebar titles
+ (is (not (member unlisted-post-id
+ (mapcar (lambda (title) (gethash "Id" title)) titles)
+ :test 'equal)))
+
+
+ ;; test sidebar titles
+ (is (not (member "Hidden title" (mapcar (lambda (title) (gethash "Title" title)) titles) :test 'equal)))
+ (is (not (member "Unlisted title" (mapcar (lambda (title) (gethash "Title" title)) titles) :test 'equal)))
+
+ ;; test the page
+ (is (not (member "Hidden title" (mapcar (lambda (title) (gethash "Title" title)) first-page) :test 'equal)))
+ (is (not (member "Unlisted title" (mapcar (lambda (title) (gethash "Title" title)) first-page) :test 'equal)))
+
+ ;; test the page really badly
+ (is (equalp 4
+ count-of-posts))
+
+ (literal
+ There are now 4 posts in the db. Let's read it in 2 two post pages and make sure they do not share posts.
+
+ !L
+ (let ((pages (mapcar (lambda (p) (gethash "id" p))
+ (concatenate 'list
+ (murja.posts.post-db:get-page 1 2 :allow-hidden? t)
+ (murja.posts.post-db:get-page 2 2 :allow-hidden? t)))))
+ (format t "pages: ~a~%" pages)
+ (is (equalp 4
+ (length (remove-duplicates pages)))))))))))))
;; (setf fiveam:*run-test-when-defined* t)