tag deleting

integration-tests
Josha von Gizycki 5 years ago
parent fe9c48f405
commit 074f83536f

@ -305,8 +305,11 @@ table {
} }
.tag-list li { .tag-list li {
display: inline-block;
margin-right: .5rem; margin-right: .5rem;
display: inline-block;
}
.single-tag {
border: 1px solid @ci-color; border: 1px solid @ci-color;
border-left: .5rem solid @ci-blue; border-left: .5rem solid @ci-blue;
border-radius: .5rem; border-radius: .5rem;

@ -54,7 +54,6 @@
{:pre [(spec/assert ::tuple-query-list tuples)]} {:pre [(spec/assert ::tuple-query-list tuples)]}
(db/with-transaction @conn tx (db/with-transaction @conn tx
(doseq [tuple tuples] (doseq [tuple tuples]
(println tuple)
(let [qry (first tuple) (let [qry (first tuple)
params (second tuple)] params (second tuple)]
(devmode/send-to-bar (devmode/send-to-bar

@ -225,6 +225,10 @@
:link-uuid (:uuid link)})] :link-uuid (:uuid link)})]
(anti-forgery-field) (anti-forgery-field)
(view/delete-btn))]])]]]) (view/delete-btn))]])]]])
(when (seq (:tags instance))
[:section.tags
[:h2 "Tags"]
(view-tag/tag-table instance)])
[:section.link-instance [:section.link-instance
[:h2 "Link Instance with Instance of Schema..."] [:h2 "Link Instance with Instance of Schema..."]
[:ul [:ul

@ -54,6 +54,16 @@
(merge-tag-tuples (list "a" "b") (merge-tag-tuples (list "a" "b")
(neo4j/uuid) (neo4j/uuid)
(neo4j/uuid)))) (neo4j/uuid))))
(defn merge-tags [tags instance-uuid user-uuid] (defn merge-tags! [tags instance-uuid user-uuid]
(apply neo4j/exec-queries! (apply neo4j/exec-queries!
(merge-tag-tuples tags instance-uuid user-uuid))) (merge-tag-tuples tags instance-uuid user-uuid)))
(neo4j/defquery remove-tag
"MATCH (i:instance {uuid:{instance_uuid}})
-[c:tagged_with]->
(t:tag {uuid:{uuid}})
DELETE c")
(defn remove-tag! [uuid instance-uuid]
(neo4j/exec-query! remove-tag
{:instance_uuid instance-uuid
:uuid uuid}))

@ -1,5 +1,5 @@
(ns wanijo.tag.routes (ns wanijo.tag.routes
(:require [compojure.core :refer [defroutes POST]] (:require [compojure.core :refer [defroutes POST DELETE]]
[ring.util.response :as resp] [ring.util.response :as resp]
[formulare.core :as form] [formulare.core :as form]
[wanijo.framework.routing :refer [register! path]] [wanijo.framework.routing :refer [register! path]]
@ -16,9 +16,9 @@
user-uuid (-> req :session :uuid)] user-uuid (-> req :session :uuid)]
(if (form/valid? forms/new-tag req) (if (form/valid? forms/new-tag req)
(do (do
(domain/merge-tags new-names (domain/merge-tags! new-names
instance-uuid instance-uuid
user-uuid) user-uuid)
(resp/redirect (path :instance-show (resp/redirect (path :instance-show
{:uuid instance-uuid}))) {:uuid instance-uuid})))
(view-instance/show! (view-instance/show!
@ -26,7 +26,14 @@
(domain-schema/accessible-schemas! user-uuid) (domain-schema/accessible-schemas! user-uuid)
req)))) req))))
(defn remove-tag! [uuid instance-uuid]
(domain/remove-tag! uuid instance-uuid)
(resp/redirect (path :instance-edit-form {:uuid instance-uuid})))
(defroutes routes (defroutes routes
(POST (register! :tag-create "/tag/:instance-uuid") (POST (register! :tag-create "/tag/:instance-uuid")
[instance-uuid :as req] [instance-uuid :as req]
(create-tag! instance-uuid req))) (create-tag! instance-uuid req))
(DELETE (register! :tag-remove "/tag/:uuid/:instance-uuid")
[uuid instance-uuid]
(remove-tag! uuid instance-uuid)))

@ -4,13 +4,20 @@
[ring.util.anti-forgery :refer [anti-forgery-field]] [ring.util.anti-forgery :refer [anti-forgery-field]]
[formulare.core :as form] [formulare.core :as form]
[wanijo.tag.forms :as forms] [wanijo.tag.forms :as forms]
[wanijo.framework.routing :refer [path]])) [wanijo.framework
[routing :refer [path]]
[view :as view]
[time :refer [prettify-dt]]]))
(defn tag->html [tag]
[:span.single-tag
[:code ":" (h (:name tag))]])
(defn tag-list [tags] (defn tag-list [tags]
[:ul.tag-list [:ul.tag-list
(for [tag tags] (for [tag tags]
[:li [:li
[:code ":" (h (:name tag))]])]) (tag->html tag)])])
(defn new-tag-form [{uuid :uuid}] (defn new-tag-form [{uuid :uuid}]
(list (list
@ -19,3 +26,22 @@
(hform/submit-button "Tag!")) (hform/submit-button "Tag!"))
[:small (str "Comma separate each tag. " [:small (str "Comma separate each tag. "
"Tag names must not contain whitespace.")])) "Tag names must not contain whitespace.")]))
(defn tag-table [{tags :tags
instance-uuid :uuid}]
[:table
[:thead
[:tr
[:th "Name"]
[:th "Created"]
[:th]]]
[:tbody
(for [tag tags]
[:tr
[:td (tag->html tag)]
[:td (prettify-dt (:created_at tag))]
[:td (hform/form-to [:delete (path :tag-remove
{:uuid (:uuid tag)
:instance-uuid instance-uuid})]
(anti-forgery-field)
(view/delete-btn))]])]])

Loading…
Cancel
Save