starring and unstarring instances

integration-tests
Josha von Gizycki 6 years ago
parent 5f33a2c9a4
commit 983460cd68

@ -188,6 +188,10 @@ form {
input, select {
grid-column: 2;
h1 & {
padding: 0;
}
}
.flash--error {

@ -76,6 +76,11 @@
[:li [:a {:href (path :instance-list
{:schema-uuid (:uuid schema)})}
(h (:name schema))]])]]
[:secion
[:h2 "Prefiltered"]
[:ul
[:li [:a {:href (path :instance-list-starred)}
"Starred"]]]]
[:section
[:h2 "Visualisation"]
[:ul

@ -210,3 +210,40 @@
:uuid uuid})
first
:starred))
(neo4j/defquery mark-starred
"MATCH (i:instance {uuid:{uuid}}),
(u:user {uuid:{user_uuid}})
MERGE (i)-[s:starred_by]->(u)
ON CREATE
SET s.created_at = {now}")
(defn mark-starred! [uuid user-uuid]
(neo4j/exec-query! mark-starred
{:uuid uuid
:user_uuid user-uuid
:now (neo4j/now-str)}))
(neo4j/defquery remove-starred
"MATCH (:instance {uuid:{uuid}})
-[s:starred_by]->
(:user {uuid:{user_uuid}})
DELETE s")
(defn remove-starred! [uuid user-uuid]
(neo4j/exec-query! remove-starred
{:uuid uuid
:user_uuid user-uuid}))
(neo4j/defquery starred-by-user
"MATCH (u:user {uuid:{user_uuid}})
<-[s:starred_by]-
(i:instance)
RETURN i, s
ORDER BY s.created_at DESC")
(defn starred-by-user! [user-uuid]
(map #(assoc (:i %)
:starred_at (-> % :s :created_at))
(neo4j/exec-query! starred-by-user
{:user_uuid user-uuid})))

@ -103,13 +103,28 @@
(domain/delete-link! link-uuid)
(resp/redirect (path :instance-edit-form {:uuid uuid})))
(defn mark-starred! [uuid req]
(domain/mark-starred! uuid
(-> req :session :uuid))
(resp/redirect (path :instance-show {:uuid uuid})))
(defn remove-starred! [uuid req]
(domain/remove-starred! uuid
(-> req :session :uuid))
(resp/redirect (path :instance-show {:uuid uuid})))
(defn list-starred! [req]
(view/list-starred
(domain/starred-by-user! (-> req :session :uuid))
req))
(defroutes routes
(wrap-routes
(GET (register! :instance-list "/instance/list/:schema-uuid")
[schema-uuid :as req]
(list! schema-uuid req))
(let [schema-fn #(get-in % [:params :schema-uuid])]
(middleware-schema/wrap-allowed-to-read schema-fn)))
(middleware-schema/wrap-allowed-to-read
#(get-in % [:params :schema-uuid])))
(POST (register! :instance-new "/instance/new") []
new!)
(GET (register! :instance-show "/instance/:uuid")
@ -135,4 +150,15 @@
(DELETE (register! :instance-link-delete
"/instance/:uuid/link/:link-uuid")
[uuid link-uuid :as req]
(delete-link! uuid link-uuid req)))
(delete-link! uuid link-uuid req))
(POST (register! :instance-mark-starred
"/instance/:uuid/starred")
[uuid :as req]
(mark-starred! uuid req))
(DELETE (register! :instance-remove-starred
"/instance/:uuid/starred")
[uuid :as req]
(remove-starred! uuid req))
(GET (register! :instance-list-starred "/instance/starred/list")
[:as req]
(list-starred! req)))

@ -39,13 +39,42 @@
[:td (prettify-dt (:updated_at instance))]
[:td (prettify-dt (:created_at instance))]])]]]))
(defn list-starred [instances req]
(view/layout!
:request req
:content
[[:h1 "Starred instances"]
[:table
[:thead
[:tr
[:th "Name"]
[:th "Starred"]
[:th "Updated"]
[:th "Created"]]]
[:tbody
(for [instance instances]
[:tr
[:td
[:a {:href (path :instance-show instance)}
(h (:name instance))]]
[:td (prettify-dt (:starred_at instance))]
[:td (prettify-dt (:updated_at instance))]
[:td (prettify-dt (:created_at instance))]])]]]))
(defn show! [instance req]
(view/layout!
:request req
:content
[[:h1
(if (:starred instance)
"★" "☆")
(hform/form-to {:class "inline"}
[:delete (path :instance-mark-starred instance)]
(anti-forgery-field)
(hform/submit-button "★"))
(hform/form-to {:class "inline"}
[:post (path :instance-mark-starred instance)]
(anti-forgery-field)
(hform/submit-button "☆")))
"&nbsp;"
(h (-> instance :schema :name))
"&nbsp;"

Loading…
Cancel
Save