Add forward and back buttons and detail view

This commit is contained in:
Aaron Fischer 2017-03-20 23:16:58 +01:00
parent 3ad4a284ec
commit 257436a884
4 changed files with 51 additions and 8 deletions

View file

@ -22,6 +22,18 @@ LIMIT :count OFFSET :offset
-- :name get-image-count :? :1
SELECT COUNT(id) as count FROM images
-- :name get-next-image :? :1
SELECT * FROM images
WHERE created_at > :image-date
ORDER BY created_at ASC
LIMIT 1
-- :name get-prev-image :? :1
SELECT * FROM images
WHERE created_at < :image-date
ORDER BY created_at DESC
LIMIT 1
-- :name create-tag! :i!
INSERT OR IGNORE INTO tags (tagname)

View file

@ -0,0 +1,20 @@
{% extends "layout.html" %}
{% block content %}
{% if next-image %}
<a class="btn btn-primary" href="/show/{{ next-image.id }}">Weiter</a>
{% endif %}
{% if prev-image %}
<a class="btn btn-primary" href="/show/{{ prev-image.id }}">Zurück</a>
{% endif %}
<h1>{{ image.title }}</h1>
<img class="col-md-12" src="/images/normal/{{ image.hash }}.png" alt="{{ image.title }}"/>
{% if image.description|length > 0 %}
<p>{{ image.description }}</p>
{% endif %}
{% endblock %}

View file

@ -1,6 +1,14 @@
{% extends "layout.html" %}
{% block content %}
<div>
{% for image in images %}
<a href="/show/{{ image.id }}" class="thumbnail-image">
<img src="/images/thumbnails/{{ image.hash }}.png" alt="{{ image.title }}">
</a>
{% endfor %}
</div>
<div class="clearfix"></div>
{% if pages|count > 1 %}
<nav aria-label="Page navigation" class="pull-right">
@ -23,12 +31,4 @@
<div class="clearfix"></div>
{% endif %}
<div>
{% for image in images %}
<a href="/show/{{ image.hash }}" class="thumbnail-image">
<img src="/images/thumbnails/{{ image.hash }}.png" alt="{{ image.title }}">
</a>
{% endfor %}
</div>
<div class="clearfix"></div>
{% endblock %}

View file

@ -20,6 +20,15 @@
:current-page current-page
:pages (range 1 (inc pages))})))
(defn detail-page [image-id]
(let [image (db/get-image {:id image-id})
next-img (db/get-next-image {:image-date (:created_at image)})
prev-img (db/get-prev-image {:image-date (:created_at image)})]
(layout/render "detail.html"
{:image image
:next-image next-img
:prev-image prev-img})))
(defn image-file [type hash ext]
(let [filename (str hash "." ext)]
(file-response (images/data-path "gallery" type filename))))
@ -29,6 +38,8 @@
(redirect "/page/1"))
(GET "/page/:page-number" [page-number]
(index-page (Integer. page-number)))
(GET "/show/:image-id" [image-id]
(detail-page image-id))
(GET ["/images/:type/:hash.:ext"
;;:type #"(normal|raw|thumbnails)"
;;:hash #"[0-9]+-[^.]+"