You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wanijo/src/wanijo/instance/view/show.clj

113 lines
4.1 KiB

(ns wanijo.instance.view.show
(:require [hiccup.form :as hform]
[hiccup.core :refer [h]]
[ring.util.anti-forgery :refer [anti-forgery-field]]
[wanijo.infra.view :as view]
[wanijo.infra.routing :refer [path]]
[wanijo.infra.time :refer [prettify-dt]]
[wanijo.instance.view.view :as view-instance]
[wanijo.tag.view :as view-tag]
[markdown.core :as md]
[wanijo.visualisation.viz :as viz]))
(defn links-table [heading direction instance]
[:section.links-in
[:h2 (h heading)]
[:table
[:thead
[:tr
[:th "Name"]
[:th "Instance"]
[:th "Schema"]
[:th "Created"]]]
[:tbody
(for [{:keys [link source schema target] :as row} (direction instance)
:let [name (:name link)
empty (empty? name)
name (if empty [:i "empty"] (h name))
other (or source target)]]
[:tr
[:td name
(view-instance/tags-for-search row)]
[:td [:a {:href (path :instance-show other)}
(h (:name other))]]
[:td [:a {:href (path :instance-list
{:schema-uuid (:uuid schema)})}
(h (:name schema))]]
[:td (prettify-dt (:created_at link))]])]]])
(defn show [instance schemas req]
(view/layout
:request req
:title (str (:name instance) " - " (-> instance :schema :name))
: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 "☆")))
" "
(h (-> instance :schema :name))
" "
[:small (h (:name instance))]]
[:p [:small
[:a {:href (path :instance-list
{:schema-uuid (-> instance :schema :uuid)})}
"Back to List"]
" | "
[:a {:href (path :instance-edit-form instance)}
"Edit Instance"]
" | "
[:a {:href (path :vis-explore {:instance-uuid (:uuid instance)})}
"Explore from here"]
" | "
[:a {:href "#quick-edits"}
"Quick edits"]]]
(when (seq (:tags instance))
[:section.tags
(view-tag/tag-list (:tags instance))])
(when (seq (:properties instance))
[:section.properties
[:h2 "Properties"]
(for [prop (:properties instance)
:let [attr (:attribute prop)
type (:type attr)
render-fn (case type
"date" #(str (prettify-dt %))
"markdown" md/md-to-html-string
#(str "<p>" % "</p>"))]]
(list [:h3 (h (:name attr))]
[:div {:class (str "instance-content "
"attr-type-" type)}
(render-fn (:value prop))]))])
(when (or (seq (:links-out instance))
(seq (:links-in instance)))
[:section.visualisation
[:h2 "Visualisation"]
[:p (viz/single-instance instance)]])
(when (seq (:links-out instance))
(links-table "Outgoing links" :links-out instance))
(when (seq (:links-in instance))
(links-table "Incoming links" :links-in instance))
[:section.quick-edits
[:h2 {:id "quick-edits"} "Quick edits"]
[:section.link-instance
[:h3 "Link Instance with Instance of Schema..."]
[:ul
(for [schema schemas]
[:li
[:a {:href (path :instance-link-selection
{:uuid (:uuid instance)
:schema-uuid (:uuid schema)})}
(h (:name schema))]])]
[:a {:href (path :instance-bulk-link-selection instance)}
"Bulk create links"]]
[:section.tag-instance
[:h3 "Add or create Tags"]
(view-tag/new-tag-form instance)]]]))