We are getting close ...

This commit is contained in:
Aaron Fischer 2017-04-15 22:45:43 +02:00
parent d9d21b8bb2
commit b7ea1bb5f7
6 changed files with 57 additions and 42 deletions

View file

@ -25,6 +25,7 @@
[ring/ring-core "1.5.1"] [ring/ring-core "1.5.1"]
[ring/ring-defaults "0.2.3"] [ring/ring-defaults "0.2.3"]
[selmer "1.10.6"] [selmer "1.10.6"]
[hiccup "1.0.5"]
[image-resizer "0.1.9"] [image-resizer "0.1.9"]
[me.raynes/fs "1.4.6"] [me.raynes/fs "1.4.6"]
[digest "1.4.5"] [digest "1.4.5"]

View file

@ -39,6 +39,11 @@ UPDATE images
SET title = :title, description = :description SET title = :title, description = :description
WHERE id = :id WHERE id = :id
-- :name set-image-hash :! :1
UPDATE images
SET hash = :hash
WHERE id = :id
-- :name create-tag! :i! -- :name create-tag! :i!
INSERT OR IGNORE INTO tags (tagname) INSERT OR IGNORE INTO tags (tagname)

View file

@ -40,8 +40,8 @@
<hr> <hr>
<div class="detail-image"> <div class="detail-image">
<a href="/images/raw/{{ image.hash }}.png"> <a href="/images/raw/{{ image.hash }}">
<img class="card-img-top" src="/images/normal/{{ image.hash }}.png" alt="{{ image.title }}"/> <img class="card-img-top" src="/images/normal/{{ image.hash }}" alt="{{ image.title }}"/>
</a> </a>
</div> </div>
<hr> <hr>

View file

@ -1,40 +1,16 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% block content %} {% block content %}
{% if pages|count > 1 %}
<nav aria-label="Page navigation" class="pull-right clearfix">
<ul class="pagination">
<li class="page-item{% ifequal current-page 1 %} disabled{% endifequal %}">
<a class="page-link" href="/page/{{ current-page|dec }}">
<span class="fa fa-arrow-left"></span>
Zurück
</a>
</li>
{% for page in pages %}
<li class="page-item{% ifequal page current-page %} active{% endifequal %}">
<a class="page-link" href="/page/{{ page }}">{{ page }}</a>
</li>
{% endfor %}
<li class="page-item{% ifequal current-page pages|count %} disabled{% endifequal %}"> {% safe %}{{ pagination| }}{% endsafe %}
<a class="page-link" href="/page/{{ current-page|inc }}">
Weiter
<span class="fa fa-arrow-right"></span>
</a>
</li>
</ul>
</nav>
<div class="clearfix"></div>
<hr>
{% endif %}
<div class="clearfix d-flex justify-content-center flex-wrap"> <div class="clearfix d-flex justify-content-center flex-wrap">
{% for image in images %} {% for image in images %}
<a href="/show/{{ image.id }}" class="thumbnail-image"> <a href="/show/{{ image.id }}" class="thumbnail-image">
<img src="/images/thumbnails/{{ image.hash }}.png" alt="{{ image.title }}"> <img src="/images/thumbnails/{{ image.hash }}" alt="{{ image.title }}">
</a> </a>
{% endfor %} {% endfor %}
</div> </div>
{% endblock %} {% endblock %}

View file

@ -51,21 +51,24 @@
(let [file (exif/without-exif (io/file filepath))] (let [file (exif/without-exif (io/file filepath))]
(as-file ((apply fn params) file) (as-file ((apply fn params) file)
target-filepath target-filepath
:verbatim))) :verbatim)
(fs/delete file)))
(defn scale-image-and-save [filepath] (defn scale-image-and-save [filepath]
(let [image-hash (target-image-filename filepath) (let [image-hash (target-image-filename filepath)
file-extension (fs/extension filepath) file-extension (fs/extension filepath)
new-raw-file-name (str image-hash file-extension) new-file-name (str image-hash file-extension)]
new-file-name (str image-hash ".png")]
(fs/copy filepath (data-path "gallery" "raw" new-file-name)) (fs/copy filepath (data-path "gallery" "raw" new-file-name))
(save scale-normal [1024 768] filepath (data-path "gallery" "normal" new-file-name)) (try
(save scale-thumbnail [250] filepath (data-path "gallery" "thumbnails" new-file-name)) (do
image-hash)) (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] (defn process-image [filepath]
(let [image-hash (scale-image-and-save filepath)] (let [image-hash (scale-image-and-save filepath)]
(fs/delete filepath) ;;;(fs/delete filepath)
image-hash)) image-hash))
(defn process-all-images [] (defn process-all-images []

View file

@ -4,22 +4,47 @@
[ring.util.http-response :as response] [ring.util.http-response :as response]
[ring.util.response :refer [redirect file-response]] [ring.util.response :refer [redirect file-response]]
[yenu.helpers.images :as images] [yenu.helpers.images :as images]
[hiccup.core :as h]
[yenu.db.core :as db])) [yenu.db.core :as db]))
(defn number-of-pages [images-on-page] (defn number-of-pages [images-on-page]
(int (Math/ceil (int (Math/ceil
(/ (:count (db/get-image-count)) images-on-page)))) (/ (: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] (defn index-page [current-page request]
(let [image-count 15 (let [image-count 25
offset (* (dec current-page) image-count) offset (* (dec current-page) image-count)
pages (number-of-pages image-count) pages (number-of-pages image-count)
images (db/get-all-images {:offset offset :count image-count})] images (db/get-all-images {:offset offset :count image-count})]
(layout/render "index.html" (layout/render "index.html"
{:images images {:images images
:flash (:flash request)
:current-page current-page :current-page current-page
:pages (range 1 (inc pages)) :pagination (pagination pages current-page)})))
:flash (:flash request)})))
(defn detail-page [image-id request] (defn detail-page [image-id request]
(let [image (db/get-image {:id image-id}) (let [image (db/get-image {:id image-id})
@ -28,6 +53,7 @@
saved-author (get-in request [:cookies "author" :value])] saved-author (get-in request [:cookies "author" :value])]
(layout/render "detail.html" (layout/render "detail.html"
{:image image {:image image
:flash (:flash request)
:next-image next-img :next-image next-img
:prev-image prev-img :prev-image prev-img
:tags (db/get-tags-for-image {:id (:id image)}) :tags (db/get-tags-for-image {:id (:id image)})
@ -37,10 +63,14 @@
(defn add-comment! [image-id request] (defn add-comment! [image-id request]
(let [author (:author (:params request)) (let [author (:author (:params request))
comment (:comment (:params request))] comment (:comment (:params request))]
(db/create-comment! {:image_id image-id (if (not= comment "")
:author author (db/create-comment! {:image_id image-id
:comment comment}) :author author
:comment comment}))
(-> (redirect (str "/show/" image-id)) (-> (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"] (assoc-in [:cookies "author"]
{:value author {:value author
:path "/" :path "/"