starring and unstarring instances

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

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

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

@ -210,3 +210,40 @@
:uuid uuid}) :uuid uuid})
first first
:starred)) :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) (domain/delete-link! link-uuid)
(resp/redirect (path :instance-edit-form {:uuid 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 (defroutes routes
(wrap-routes (wrap-routes
(GET (register! :instance-list "/instance/list/:schema-uuid") (GET (register! :instance-list "/instance/list/:schema-uuid")
[schema-uuid :as req] [schema-uuid :as req]
(list! schema-uuid req)) (list! schema-uuid req))
(let [schema-fn #(get-in % [:params :schema-uuid])] (middleware-schema/wrap-allowed-to-read
(middleware-schema/wrap-allowed-to-read schema-fn))) #(get-in % [:params :schema-uuid])))
(POST (register! :instance-new "/instance/new") [] (POST (register! :instance-new "/instance/new") []
new!) new!)
(GET (register! :instance-show "/instance/:uuid") (GET (register! :instance-show "/instance/:uuid")
@ -135,4 +150,15 @@
(DELETE (register! :instance-link-delete (DELETE (register! :instance-link-delete
"/instance/:uuid/link/:link-uuid") "/instance/:uuid/link/:link-uuid")
[uuid link-uuid :as req] [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 (:updated_at instance))]
[:td (prettify-dt (:created_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] (defn show! [instance req]
(view/layout! (view/layout!
:request req :request req
:content :content
[[:h1 [[:h1
(if (:starred instance) (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;" "&nbsp;"
(h (-> instance :schema :name)) (h (-> instance :schema :name))
"&nbsp;" "&nbsp;"

Loading…
Cancel
Save