Add edit images #8
This commit is contained in:
parent
54c2e25b5b
commit
5274c8d8da
3 changed files with 46 additions and 6 deletions
|
@ -34,6 +34,11 @@ WHERE created_at < :image-date
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
|
|
||||||
|
-- :name edit-image! :! :1
|
||||||
|
UPDATE images
|
||||||
|
SET title = :title, description = :description
|
||||||
|
WHERE id = :id
|
||||||
|
|
||||||
|
|
||||||
-- :name create-tag! :i!
|
-- :name create-tag! :i!
|
||||||
INSERT OR IGNORE INTO tags (tagname)
|
INSERT OR IGNORE INTO tags (tagname)
|
||||||
|
|
|
@ -1,39 +1,53 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{% if image %}
|
||||||
|
<h1>Bild editieren</h1>
|
||||||
|
<p>Hier kann ein bestehendes Bild bearbeitet werden. Das Bild selbst kann nicht
|
||||||
|
verändert werden (hierzu muss das Bild gelöscht und neu angelegt werden)</p>
|
||||||
|
{% else %}
|
||||||
<h1>Bild hochladen</h1>
|
<h1>Bild hochladen</h1>
|
||||||
<p>Hier kann ein neues Bild der Gallerie hinzugefügt werden. Dabei sind alle
|
<p>Hier kann ein neues Bild der Gallerie hinzugefügt werden. Dabei sind alle
|
||||||
gängigen Bildformate und Auflösungen möglich. Das hochgeladene Bild wird
|
gängigen Bildformate und Auflösungen möglich. Das hochgeladene Bild wird
|
||||||
zugeschnitten (Thumbnail) und skaliert (Detailseite).</p>
|
zugeschnitten (Thumbnail) und skaliert (Detailseite).</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<form action="/upload" enctype="multipart/form-data" method="POST" class="form-horizontal">
|
<form action="{% if image %}/edit/{{ image.id }}{% else %}/upload{% endif %}" enctype="multipart/form-data" method="POST" class="form-horizontal">
|
||||||
{% csrf-field %}
|
{% csrf-field %}
|
||||||
|
|
||||||
|
{% if not image %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="file" class="sr-only">Bild</label>
|
<label for="file" class="sr-only">Bild</label>
|
||||||
<input id="file" class="form-control" name="file" type="file" />
|
<input id="file" class="form-control" name="file" type="file" />
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="title">Bildüberschrift</label>
|
<label for="title">Bildüberschrift</label>
|
||||||
<input type="text" name="title" class="form-control"
|
<input type="text" name="title" class="form-control"
|
||||||
|
value="{{ image.title }}"
|
||||||
placeholder="Leer lassen für Dateiname">
|
placeholder="Leer lassen für Dateiname">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="description">Beschreibung (optional)</label>
|
<label for="description">Beschreibung (optional)</label>
|
||||||
<textarea name="description" class="form-control" rows="4"></textarea>
|
<textarea name="description" class="form-control" rows="4">{{image.description }}</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="tags">Tags</label>
|
<label for="tags">Tags</label>
|
||||||
<input type="text" id="tags" name="tags" class="form-control"
|
<input type="text" id="tags" name="tags" class="form-control"
|
||||||
|
value="{% if tags %}{% for tag in tags %}{{ tag.tagname }} {% endfor %}{% endif %}"
|
||||||
placeholder="Trennen mit Leerzeichen oder Kommas">
|
placeholder="Trennen mit Leerzeichen oder Kommas">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-success">
|
<button type="submit" class="btn btn-success">
|
||||||
<span class="fa fa-floppy-o"></span>
|
<span class="fa fa-floppy-o"></span>
|
||||||
|
{% if image %}
|
||||||
|
Bild bearbeiten
|
||||||
|
{% else %}
|
||||||
Bild hochladen
|
Bild hochladen
|
||||||
|
{% endif %}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -28,11 +28,14 @@
|
||||||
(let [{tag-id :id} (db/get-tag {:tagname tag})]
|
(let [{tag-id :id} (db/get-tag {:tagname tag})]
|
||||||
(db/add-tag-to-image! {:imageid image-id :tagid tag-id})))
|
(db/add-tag-to-image! {:imageid image-id :tagid tag-id})))
|
||||||
|
|
||||||
|
(defn add-tags-for-image [image-id tag-string]
|
||||||
|
(let [all-tags (str/split tag-string, #"(\s*,\s*|\s+)")]
|
||||||
|
(run! #(add-tag image-id %) all-tags)))
|
||||||
|
|
||||||
(defn add-image-to-database [filehash title description tags]
|
(defn add-image-to-database [filehash title description tags]
|
||||||
(let [img (db/create-image! {:hash filehash :title title :description description})
|
(let [img (db/create-image! {:hash filehash :title title :description description})
|
||||||
image-id ((keyword "last_insert_rowid()") img)
|
image-id ((keyword "last_insert_rowid()") img)]
|
||||||
all-tags (str/split tags, #"(\s*,\s*|\s+)")]
|
(add-tags-for-image image-id tags)))
|
||||||
(run! #(add-tag image-id %) all-tags)))
|
|
||||||
|
|
||||||
(defn delete-image! [id request]
|
(defn delete-image! [id request]
|
||||||
(let [image (db/get-image {:id id})]
|
(let [image (db/get-image {:id id})]
|
||||||
|
@ -45,6 +48,16 @@
|
||||||
(let [comments (db/get-recent-comments {:num-comments 20})]
|
(let [comments (db/get-recent-comments {:num-comments 20})]
|
||||||
(layout/render "comments.html" {:comments comments})))
|
(layout/render "comments.html" {:comments comments})))
|
||||||
|
|
||||||
|
(defn edit-image-form [id request]
|
||||||
|
(let [image (db/get-image {:id id})
|
||||||
|
tags (db/get-tags-for-image {:id id})]
|
||||||
|
(layout/render "admin/upload.html" {:image image :tags tags})))
|
||||||
|
|
||||||
|
(defn edit-image! [id title description tags request]
|
||||||
|
(db/edit-image! {:id id :title title :description description})
|
||||||
|
(db/delete-image-tags! {:id id})
|
||||||
|
(add-tags-for-image id tags))
|
||||||
|
|
||||||
(defroutes admin-routes
|
(defroutes admin-routes
|
||||||
(GET "/upload" [:as request]
|
(GET "/upload" [:as request]
|
||||||
(-> (layout/render
|
(-> (layout/render
|
||||||
|
@ -60,7 +73,15 @@
|
||||||
(GET "/delete/:id" [id :as request]
|
(GET "/delete/:id" [id :as request]
|
||||||
(delete-image! id request)
|
(delete-image! id request)
|
||||||
(-> (redirect "/page/1")
|
(-> (redirect "/page/1")
|
||||||
(assoc :flash {:message "Bild wurde gelöscht" :type "success"})))
|
(assoc :flash {:message "Bild wurde gelöscht" :type "danger"})))
|
||||||
|
|
||||||
|
(GET "/edit/:id" [id :as request]
|
||||||
|
(edit-image-form id request))
|
||||||
|
|
||||||
|
(POST "/edit/:id" [id title description tags :as request]
|
||||||
|
(edit-image! id title description tags request)
|
||||||
|
(-> (redirect (str "/show/" id))
|
||||||
|
(assoc :flash {:message "Bild wurde bearbeitet" :type "success"})))
|
||||||
|
|
||||||
(GET "/statistics" []
|
(GET "/statistics" []
|
||||||
(layout/render "statistics.html"))
|
(layout/render "statistics.html"))
|
||||||
|
|
Loading…
Reference in a new issue