From 074f83536f77f8849e8f7db9b26ae34de7ecca62 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Sun, 14 Jul 2019 21:12:13 +0200 Subject: [PATCH] tag deleting --- resources/app/stylesheets/app.less | 5 ++++- src/wanijo/framework/neo4j.clj | 1 - src/wanijo/instance/view.clj | 4 ++++ src/wanijo/tag/domain.clj | 12 +++++++++++- src/wanijo/tag/routes.clj | 17 ++++++++++++----- src/wanijo/tag/view.clj | 30 ++++++++++++++++++++++++++++-- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/resources/app/stylesheets/app.less b/resources/app/stylesheets/app.less index 6321fb8..5bbed15 100644 --- a/resources/app/stylesheets/app.less +++ b/resources/app/stylesheets/app.less @@ -305,8 +305,11 @@ table { } .tag-list li { - display: inline-block; margin-right: .5rem; + display: inline-block; +} + +.single-tag { border: 1px solid @ci-color; border-left: .5rem solid @ci-blue; border-radius: .5rem; diff --git a/src/wanijo/framework/neo4j.clj b/src/wanijo/framework/neo4j.clj index 7f75383..cc663b4 100644 --- a/src/wanijo/framework/neo4j.clj +++ b/src/wanijo/framework/neo4j.clj @@ -54,7 +54,6 @@ {:pre [(spec/assert ::tuple-query-list tuples)]} (db/with-transaction @conn tx (doseq [tuple tuples] - (println tuple) (let [qry (first tuple) params (second tuple)] (devmode/send-to-bar diff --git a/src/wanijo/instance/view.clj b/src/wanijo/instance/view.clj index 9c5bebc..8b9fdfa 100644 --- a/src/wanijo/instance/view.clj +++ b/src/wanijo/instance/view.clj @@ -225,6 +225,10 @@ :link-uuid (:uuid link)})] (anti-forgery-field) (view/delete-btn))]])]]]) + (when (seq (:tags instance)) + [:section.tags + [:h2 "Tags"] + (view-tag/tag-table instance)]) [:section.link-instance [:h2 "Link Instance with Instance of Schema..."] [:ul diff --git a/src/wanijo/tag/domain.clj b/src/wanijo/tag/domain.clj index e46b995..c136910 100644 --- a/src/wanijo/tag/domain.clj +++ b/src/wanijo/tag/domain.clj @@ -54,6 +54,16 @@ (merge-tag-tuples (list "a" "b") (neo4j/uuid) (neo4j/uuid)))) -(defn merge-tags [tags instance-uuid user-uuid] +(defn merge-tags! [tags instance-uuid user-uuid] (apply neo4j/exec-queries! (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})) diff --git a/src/wanijo/tag/routes.clj b/src/wanijo/tag/routes.clj index c11f9f9..960b618 100644 --- a/src/wanijo/tag/routes.clj +++ b/src/wanijo/tag/routes.clj @@ -1,5 +1,5 @@ (ns wanijo.tag.routes - (:require [compojure.core :refer [defroutes POST]] + (:require [compojure.core :refer [defroutes POST DELETE]] [ring.util.response :as resp] [formulare.core :as form] [wanijo.framework.routing :refer [register! path]] @@ -16,9 +16,9 @@ user-uuid (-> req :session :uuid)] (if (form/valid? forms/new-tag req) (do - (domain/merge-tags new-names - instance-uuid - user-uuid) + (domain/merge-tags! new-names + instance-uuid + user-uuid) (resp/redirect (path :instance-show {:uuid instance-uuid}))) (view-instance/show! @@ -26,7 +26,14 @@ (domain-schema/accessible-schemas! user-uuid) req)))) +(defn remove-tag! [uuid instance-uuid] + (domain/remove-tag! uuid instance-uuid) + (resp/redirect (path :instance-edit-form {:uuid instance-uuid}))) + (defroutes routes (POST (register! :tag-create "/tag/:instance-uuid") [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))) diff --git a/src/wanijo/tag/view.clj b/src/wanijo/tag/view.clj index a60070b..a5ea0ba 100644 --- a/src/wanijo/tag/view.clj +++ b/src/wanijo/tag/view.clj @@ -4,13 +4,20 @@ [ring.util.anti-forgery :refer [anti-forgery-field]] [formulare.core :as form] [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] [:ul.tag-list (for [tag tags] [:li - [:code ":" (h (:name tag))]])]) + (tag->html tag)])]) (defn new-tag-form [{uuid :uuid}] (list @@ -19,3 +26,22 @@ (hform/submit-button "Tag!")) [:small (str "Comma separate each tag. " "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))]])]])