diff --git a/project.clj b/project.clj
index 2b19329..aad4283 100644
--- a/project.clj
+++ b/project.clj
@@ -25,6 +25,7 @@
[ring/ring-core "1.5.1"]
[ring/ring-defaults "0.2.3"]
[selmer "1.10.6"]
+ [hiccup "1.0.5"]
[image-resizer "0.1.9"]
[me.raynes/fs "1.4.6"]
[digest "1.4.5"]
diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql
index bf22c10..9f69fd3 100644
--- a/resources/sql/queries.sql
+++ b/resources/sql/queries.sql
@@ -39,6 +39,11 @@ UPDATE images
SET title = :title, description = :description
WHERE id = :id
+-- :name set-image-hash :! :1
+UPDATE images
+SET hash = :hash
+WHERE id = :id
+
-- :name create-tag! :i!
INSERT OR IGNORE INTO tags (tagname)
diff --git a/resources/templates/detail.html b/resources/templates/detail.html
index 4f0d2d8..2c28867 100644
--- a/resources/templates/detail.html
+++ b/resources/templates/detail.html
@@ -40,8 +40,8 @@
{% for image in images %}
-
+
{% endfor %}
+
{% endblock %}
diff --git a/src/clj/yenu/helpers/images.clj b/src/clj/yenu/helpers/images.clj
index 8fc6b7a..fe7db59 100644
--- a/src/clj/yenu/helpers/images.clj
+++ b/src/clj/yenu/helpers/images.clj
@@ -51,21 +51,24 @@
(let [file (exif/without-exif (io/file filepath))]
(as-file ((apply fn params) file)
target-filepath
- :verbatim)))
+ :verbatim)
+ (fs/delete file)))
(defn scale-image-and-save [filepath]
(let [image-hash (target-image-filename filepath)
file-extension (fs/extension filepath)
- new-raw-file-name (str image-hash file-extension)
- new-file-name (str image-hash ".png")]
+ new-file-name (str image-hash file-extension)]
(fs/copy filepath (data-path "gallery" "raw" new-file-name))
- (save scale-normal [1024 768] filepath (data-path "gallery" "normal" new-file-name))
- (save scale-thumbnail [250] filepath (data-path "gallery" "thumbnails" new-file-name))
- image-hash))
+ (try
+ (do
+ (save scale-normal [1024 768] filepath (data-path "gallery" "normal" new-file-name))
+ (save scale-thumbnail [250] filepath (data-path "gallery" "thumbnails" new-file-name)))
+ (catch Exception e (prn e)))
+ new-file-name))
(defn process-image [filepath]
(let [image-hash (scale-image-and-save filepath)]
- (fs/delete filepath)
+ ;;;(fs/delete filepath)
image-hash))
(defn process-all-images []
diff --git a/src/clj/yenu/routes/core.clj b/src/clj/yenu/routes/core.clj
index f4f36c6..2eef273 100644
--- a/src/clj/yenu/routes/core.clj
+++ b/src/clj/yenu/routes/core.clj
@@ -4,22 +4,47 @@
[ring.util.http-response :as response]
[ring.util.response :refer [redirect file-response]]
[yenu.helpers.images :as images]
+ [hiccup.core :as h]
[yenu.db.core :as db]))
(defn number-of-pages [images-on-page]
(int (Math/ceil
(/ (:count (db/get-image-count)) images-on-page))))
+(defn page [number is-current? additional-class content]
+ (h/html
+ [:li (if is-current? {:class (str "page-item " additional-class)} {:class "page-item"})
+ [:a.page-link {:href (str "/page/" number)} content]]))
+
+(defn dots []
+ (h/html [:li.page-item.disabled [:p.page-link "..."]]))
+
+(defn pagelist [from to current]
+ (for [p (range from (inc to))] (page p (= p current) "active" p)))
+
+(defn pagination [num current]
+ (h/html
+ [:nav.pull-right.clearfix {:aria-label "Page navigation"}
+ [:ul.pagination
+ (page (dec current) (= current 1) "disabled" (h/html [:span.fa.fa-arrow-left] " Zurück"))
+ (cond
+ (< num 13) (pagelist 1 num current)
+ (<= current 7) (h/html (pagelist 1 10 current) (dots) (pagelist (- num 1) num current))
+ (>= current (- num 6)) (h/html (pagelist 1 2 current) (dots) (pagelist (- num 9) num current))
+ :else (h/html (pagelist 1 2 current) (dots) (pagelist (- current 3) (+ current 3) current) (dots) (pagelist (- num 1) num current)))
+ (page (inc current) (= current num) "disabled" (h/html "Weiter " [:span.fa.fa-arrow-right]))]]
+ [:div.clearfix]))
+
(defn index-page [current-page request]
- (let [image-count 15
+ (let [image-count 25
offset (* (dec current-page) image-count)
pages (number-of-pages image-count)
images (db/get-all-images {:offset offset :count image-count})]
(layout/render "index.html"
{:images images
+ :flash (:flash request)
:current-page current-page
- :pages (range 1 (inc pages))
- :flash (:flash request)})))
+ :pagination (pagination pages current-page)})))
(defn detail-page [image-id request]
(let [image (db/get-image {:id image-id})
@@ -28,6 +53,7 @@
saved-author (get-in request [:cookies "author" :value])]
(layout/render "detail.html"
{:image image
+ :flash (:flash request)
:next-image next-img
:prev-image prev-img
:tags (db/get-tags-for-image {:id (:id image)})
@@ -37,10 +63,14 @@
(defn add-comment! [image-id request]
(let [author (:author (:params request))
comment (:comment (:params request))]
- (db/create-comment! {:image_id image-id
- :author author
- :comment comment})
+ (if (not= comment "")
+ (db/create-comment! {:image_id image-id
+ :author author
+ :comment comment}))
(-> (redirect (str "/show/" image-id))
+ (assoc :flash (if (not= comment "")
+ {:message "Danke für deinen Kommentar" :type "success"}
+ {:message "Der kommentar war leider leer." :type "danger"}))
(assoc-in [:cookies "author"]
{:value author
:path "/"