Getting map pins working; working around (not solving) resource bug/
This commit is contained in:
parent
b25a71c4b4
commit
a01cca0a65
12 changed files with 101 additions and 690 deletions
|
|
@ -26,7 +26,9 @@
|
|||
(-> #'rest-routes
|
||||
(wrap-routes middleware/wrap-csrf)
|
||||
(wrap-routes middleware/wrap-formats))
|
||||
(route/resources "/")
|
||||
(ring/create-resource-handler
|
||||
{:path "/"})
|
||||
;; (route/resources "/")
|
||||
(route/not-found
|
||||
(:body
|
||||
(error-page {:status 404
|
||||
|
|
|
|||
14
src/clj/geocsv/routes/resources.clj
Normal file
14
src/clj/geocsv/routes/resources.clj
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(ns geocsv.routes.resources
|
||||
"Serve resources for geocsv."
|
||||
(:require [adl-support.core :as ac]
|
||||
[adl-support.rest-support :as ar]
|
||||
[clojure.core.memoize :as memo]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as s]
|
||||
[clojure.tools.logging :as log]
|
||||
[compojure.core :refer [defroutes GET POST]]
|
||||
[csv2edn.csv2edn :refer :all]
|
||||
[noir.response :as nresponse]
|
||||
[noir.util.route :as route]
|
||||
[ring.util.http-response :as response]
|
||||
))
|
||||
|
|
@ -90,6 +90,7 @@
|
|||
|
||||
(defn init! []
|
||||
(rf/dispatch-sync [:initialise-db])
|
||||
(rf/dispatch [:fetch-pin-image-names])
|
||||
(start-router!)
|
||||
(ajax/load-interceptors!)
|
||||
(mount-components))
|
||||
|
|
|
|||
|
|
@ -73,6 +73,24 @@
|
|||
:on-failure [:bad-data]}
|
||||
:db db})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:fetch-pin-image-names
|
||||
(fn [{db :db} _]
|
||||
(let [uri (assoc source-host
|
||||
:path "/get-pin-image-names")]
|
||||
(js/console.log
|
||||
(str
|
||||
"Fetching data: " uri))
|
||||
;; we return a map of (side) effects
|
||||
{:http-xhrio {:method :get
|
||||
:uri uri
|
||||
:format (json-request-format)
|
||||
:response-format (json-response-format {:keywords? true})
|
||||
:on-success [:process-pin-image-names]
|
||||
;; ignore :on-failure for now
|
||||
}
|
||||
:db db})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:fetch-docs
|
||||
(fn [_ _]
|
||||
|
|
@ -127,6 +145,17 @@
|
|||
(refresh-map-pins (assoc db :data data))
|
||||
db)})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:process-pin-image-names
|
||||
(fn
|
||||
[{db :db} [_ response]]
|
||||
(let [db' (assoc db :available-pin-images (set response))]
|
||||
(js/console.log (str "processing pin images"))
|
||||
{:db (if
|
||||
(:view db')
|
||||
(refresh-map-pins db')
|
||||
db')})))
|
||||
|
||||
(rf/reg-event-db
|
||||
:set-docs
|
||||
(fn [db [_ docs]]
|
||||
|
|
|
|||
|
|
@ -71,48 +71,56 @@
|
|||
|
||||
(defn pin-image
|
||||
"Return the name of a suitable pin image for this `record`."
|
||||
[record]
|
||||
(let [available @(subscribe [:available-pin-images])]
|
||||
(js/console.log (str "pin-image: available is of type `" (type available) "`; `(fn? available)` returns " (set? available)))
|
||||
[db record]
|
||||
(let [available (:available-pin-images db)
|
||||
category (s/capitalize
|
||||
(s/replace
|
||||
(s/lower-case
|
||||
(str (:category record)))
|
||||
#"[^a-z0-9]" "-"))]
|
||||
(if
|
||||
(contains? available (:category record))
|
||||
(str
|
||||
(s/capitalize
|
||||
(s/replace (s/lower-case (str (:category record))) #"[^a-z0-9]" "-")) "-pin")
|
||||
(available category)
|
||||
(str category "-pin")
|
||||
"unknown-pin")))
|
||||
|
||||
(defn popup-content
|
||||
"Appropriate content for the popup of a map pin for this `record`."
|
||||
[record]
|
||||
(str
|
||||
"<h5>"
|
||||
(:name record)
|
||||
"</h5><dl>"
|
||||
(apply
|
||||
str
|
||||
(map #(str "<dt>" (name %) "</dt><dd>" (record %) "</dd>") (keys record)))
|
||||
"</dl>"))
|
||||
(if
|
||||
(map? record) ;; which it should be!
|
||||
(str
|
||||
"<h5>"
|
||||
(:name record)
|
||||
"</h5><dl>"
|
||||
(apply
|
||||
str
|
||||
(map
|
||||
#(str "<dt>" (name %) "</dt><dd>" (record %) "</dd>")
|
||||
(filter #(record %) (keys record))))
|
||||
"</dl>")))
|
||||
|
||||
(defn popup-table-content
|
||||
"Appropriate content for the popup of a map pin for this `record`, as a
|
||||
table. Obviously this is semantically wrong, but for styling reasons it's
|
||||
worth trying."
|
||||
[record]
|
||||
(str
|
||||
"<h5>"
|
||||
(:name record)
|
||||
"</h5><table>"
|
||||
(apply
|
||||
str
|
||||
(map
|
||||
#(str "<tr><th>" (name %) "</th><td>" (record %) "</td></tr>")
|
||||
(sort (keys record))))
|
||||
"</table>"))
|
||||
(if
|
||||
(map? record) ;; which it should be!
|
||||
(str
|
||||
"<h5>"
|
||||
(:name record)
|
||||
"</h5><table>"
|
||||
(apply
|
||||
str
|
||||
(map
|
||||
#(str "<tr><th>" (name %) "</th><td>" (record %) "</td></tr>")
|
||||
(sort (filter #(record %) (keys record)))))
|
||||
"</table>")))
|
||||
|
||||
(defn add-map-pin
|
||||
"Add an appropriate map-pin for this `record` in this map `view`, if it
|
||||
has a valid `:latitude` and `:longitude`."
|
||||
[record index view]
|
||||
[db record index view]
|
||||
(let [lat (:latitude record)
|
||||
lng (:longitude record)]
|
||||
(if
|
||||
|
|
@ -125,7 +133,7 @@
|
|||
(clj->js
|
||||
{:iconAnchor [16 41]
|
||||
:iconSize [32 42]
|
||||
:iconUrl (str "img/map-pins/" (pin-image record) ".png")
|
||||
:iconUrl (str "img/map-pins/" (pin-image db record) ".png")
|
||||
:riseOnHover true
|
||||
:shadowAnchor [16 23]
|
||||
:shadowSize [57 24]
|
||||
|
|
@ -159,8 +167,8 @@
|
|||
data (:data db)]
|
||||
(if
|
||||
view
|
||||
(let [added (remove nil? (map #(add-map-pin %1 %2 view) data (range)))]
|
||||
(js/console.log (str "Adding " (count added) " pins")))
|
||||
(js/console.log "View is not yet ready"))
|
||||
db))
|
||||
(let [added (remove nil? (map #(add-map-pin db %1 %2 view) data (range)))]
|
||||
(js/console.log (str "Adding " (count added) " pins"))
|
||||
db)
|
||||
(do (js/console.log "View is not yet ready") db))))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue