From d729459e924d676d7117f13060fd3962be5621e6 Mon Sep 17 00:00:00 2001 From: Simon Brooke <simon@journeyman.cc> Date: Wed, 29 Jan 2020 12:56:06 +0000 Subject: [PATCH] Resources now working. --- README.md | 18 +++++- project.clj | 6 +- resources/docs/docs.md | 18 +++++- resources/html/error.html | 2 +- resources/html/home.html | 53 +++++++++--------- resources/public/css/screen.css | 8 +-- .../{unknown-pin.png => Unknown-pin.png} | Bin .../{unknown-pin.svg => Unknown-pin.svg} | 0 resources/public/img/map-pins/unknown-pin.xcf | Bin 3759 -> 0 bytes src/clj/geocsv/handler serves resources.clj | 40 +++++++++++++ src/clj/geocsv/handler.clj | 9 +-- src/clj/geocsv/routes/resources.clj | 14 ----- src/cljs/geocsv/core.cljs | 29 +++++++++- src/cljs/geocsv/gis.cljs | 2 +- 14 files changed, 137 insertions(+), 62 deletions(-) rename resources/public/img/map-pins/{unknown-pin.png => Unknown-pin.png} (100%) rename resources/public/img/map-pins/{unknown-pin.svg => Unknown-pin.svg} (100%) delete mode 100644 resources/public/img/map-pins/unknown-pin.xcf create mode 100644 src/clj/geocsv/handler serves resources.clj delete mode 100644 src/clj/geocsv/routes/resources.clj diff --git a/README.md b/README.md index 34f9e16..9a1ef18 100644 --- a/README.md +++ b/README.md @@ -20,18 +20,32 @@ If you run the server running **geocsv**, the simplest way to add CSV files is s https://geocsv.example.com/ -and the file you want to view is `myfile.csv`, then you would specify this as +and the file you want to view is `myfile.csv`, then you would specify this as the value of `file` in the query part of the URL. https://geocsv.example.com/?file=myfile.csv +### Loading CSV file onto another public server + +If you're not running the **geocsv** server yourself, you can upload the CSV to another server which is accessible by the **geocsv** server. You can then map data from the CSV file by specifying the URL of the file as the value of `uri` in the query part of the URL: + + https://geocsv.example.com/?uri=http://my.other.server/path/to/myfile.csv + ### Using a Google spreadsheet -If you use [Google Sheets](https://www.google.co.uk/sheets/about/), then every sheet has a 'document id', a long string of characters which uniquely identifies that sheet. Suppose your Google spreadsheet has a document id of `abcdefghijklmnopqrstuvwxyz-12345`, then you could pull data from this spreadsheet by specifying: +If you use [Google Sheets](https://www.google.co.uk/sheets/about/), then every sheet has a 'document id', a long string of characters which uniquely identifies that sheet. Suppose your Google spreadsheet has a document id of `abcdefghijklmnopqrstuvwxyz-12345`, then you could pull data from this spreadsheet by specifying this as the value of `docid` in the query part of the URL: https://geocsv.example.com/?docid=abcdefghijklmnopqrstuvwxyz-12345 The spreadsheet **must** be publicly readable. +### Precedence + +Nothing, of course, stops you from specifying multiple arguments in the query part of the URL, but only one will be used. The precedence is in this order: + +1. `docid` is considered first, and overrides anything else; +2. `uri` is considered next, and overrides `file`; +3. the value of `file` is considered only if neither of the other two are present. + ## Not yet working GeoCSV is at an early stage of development, and some features are not yet working. diff --git a/project.clj b/project.clj index fa8b919..b4d1cc9 100644 --- a/project.clj +++ b/project.clj @@ -32,6 +32,7 @@ [org.clojure/tools.cli "0.4.2"] [org.clojure/tools.logging "0.5.0"] [org.webjars.npm/bulma "0.8.0"] + [org.webjars.npm/leaflet "1.6.0"] [org.webjars.npm/material-icons "0.3.1"] [org.webjars/webjars-locator "0.38"] [re-frame "0.10.9"] @@ -43,10 +44,6 @@ [selmer "1.12.18"]] :min-lein-version "2.0.0" - :npm {:dependencies [[bulma "0.8.0"] - [leaflet "1.3.1"] - [material-design-icons "3.0.1"]] - :root "resources/public/js/lib/node_modules"} :source-paths ["src/clj" "src/cljs" "src/cljc"] :test-paths ["test/clj"] @@ -56,7 +53,6 @@ :plugins [[lein-cljsbuild "1.1.7"] [lein-codox "0.10.7"] - [lein-npm "0.6.2"] [lein-release "1.0.5"]] :clean-targets ^{:protect false} diff --git a/resources/docs/docs.md b/resources/docs/docs.md index 34f9e16..9a1ef18 100644 --- a/resources/docs/docs.md +++ b/resources/docs/docs.md @@ -20,18 +20,32 @@ If you run the server running **geocsv**, the simplest way to add CSV files is s https://geocsv.example.com/ -and the file you want to view is `myfile.csv`, then you would specify this as +and the file you want to view is `myfile.csv`, then you would specify this as the value of `file` in the query part of the URL. https://geocsv.example.com/?file=myfile.csv +### Loading CSV file onto another public server + +If you're not running the **geocsv** server yourself, you can upload the CSV to another server which is accessible by the **geocsv** server. You can then map data from the CSV file by specifying the URL of the file as the value of `uri` in the query part of the URL: + + https://geocsv.example.com/?uri=http://my.other.server/path/to/myfile.csv + ### Using a Google spreadsheet -If you use [Google Sheets](https://www.google.co.uk/sheets/about/), then every sheet has a 'document id', a long string of characters which uniquely identifies that sheet. Suppose your Google spreadsheet has a document id of `abcdefghijklmnopqrstuvwxyz-12345`, then you could pull data from this spreadsheet by specifying: +If you use [Google Sheets](https://www.google.co.uk/sheets/about/), then every sheet has a 'document id', a long string of characters which uniquely identifies that sheet. Suppose your Google spreadsheet has a document id of `abcdefghijklmnopqrstuvwxyz-12345`, then you could pull data from this spreadsheet by specifying this as the value of `docid` in the query part of the URL: https://geocsv.example.com/?docid=abcdefghijklmnopqrstuvwxyz-12345 The spreadsheet **must** be publicly readable. +### Precedence + +Nothing, of course, stops you from specifying multiple arguments in the query part of the URL, but only one will be used. The precedence is in this order: + +1. `docid` is considered first, and overrides anything else; +2. `uri` is considered next, and overrides `file`; +3. the value of `file` is considered only if neither of the other two are present. + ## Not yet working GeoCSV is at an early stage of development, and some features are not yet working. diff --git a/resources/html/error.html b/resources/html/error.html index 88103f7..fd31cc5 100644 --- a/resources/html/error.html +++ b/resources/html/error.html @@ -4,7 +4,7 @@ <title>Something Bad Happened</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - {% style "/js/lib/node_modules/bulma/css/bulma.min.css" %} + {% style "/assets/bulma/css/bulma.min.css" %} <style type="text/css"> html { height: 100%; diff --git a/resources/html/home.html b/resources/html/home.html index 5f65079..74314ba 100644 --- a/resources/html/home.html +++ b/resources/html/home.html @@ -1,32 +1,31 @@ <!DOCTYPE html> <html> <head> - <meta charset="UTF-8"/> - <meta name="viewport" content="width=device-width, initial-scale=1"> - <title>Welcome to geocsv</title> + <meta charset="UTF-8"/> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>Welcome to geocsv</title> </head> <body> + <div id="app"> - <div class="splash-screen"> - <div class="sk-fading-circle"> - <div class="sk-circle1 sk-circle"></div> - <div class="sk-circle2 sk-circle"></div> - <div class="sk-circle3 sk-circle"></div> - <div class="sk-circle4 sk-circle"></div> - <div class="sk-circle5 sk-circle"></div> - <div class="sk-circle6 sk-circle"></div> - <div class="sk-circle7 sk-circle"></div> - <div class="sk-circle8 sk-circle"></div> - <div class="sk-circle9 sk-circle"></div> - <div class="sk-circle10 sk-circle"></div> - <div class="sk-circle11 sk-circle"></div> - <div class="sk-circle12 sk-circle"></div> + <section class="section"> + <div class="container is-fluid"> + <div class="content"> + <h4 class="title">Welcome to geocsv</h4> + <p>If you're seeing this message, that means you haven't yet compiled your ClojureScript!</p> + <p>Please run <code>lein figwheel</code> to start the ClojureScript compiler and reload the page.</p> + <h4>For better ClojureScript development experience in Chrome follow these steps:</h4> + <ul> + <li>Open DevTools + <li>Go to Settings ("three dots" icon in the upper right corner of DevTools > Menu > Settings F1 > General > Console) + <li>Check-in "Enable custom formatters" + <li>Close DevTools + <li>Open DevTools + </ul> + <p>See <a href="http://www.luminusweb.net/docs/clojurescript.md">ClojureScript</a> documentation for further details.</p> + </div> </div> - </div> - <p class="footer"> - <b>geocsv</b> is loading. - You must enable JavaScript to use <b>geocsv</b>. - </p> + </section> </div> {% block foot %} @@ -44,20 +43,20 @@ {% endblock %} <!-- scripts and styles --> - {% style "/js/lib/node_modules/bulma/css/bulma.min.css" %} - {% style "/js/lib/node_modules/material-icons/iconfont/material-icons.css" %} + {% style "/assets/bulma/css/bulma.min.css" %} + {% style "/assets/material-icons/css/material-icons.min.css" %} {% style "/css/screen.css" %} {% style "/css/geocsv.css" %} <script type="text/javascript"> - var csrfToken = "{{csrf-token}}"; + var csrfToken = "{{csrf-token}}"; </script> <!-- scripts and styles --> <!-- ATTENTION \/ --> <!-- ATTENTION /\ --> <!-- Leaflet --> - {% style "js/lib/node_modules/leaflet/dist/leaflet.css" %} - {% script "/js/lib/node_modules/leaflet/dist/leaflet.js" %} + {% style "/assets/leaflet/dist/leaflet.css" %} + {% script "/assets/leaflet/dist/leaflet.js" %} {% script "/js/app.js" %} </body> </html> diff --git a/resources/public/css/screen.css b/resources/public/css/screen.css index 16aa762..e90ddb8 100644 --- a/resources/public/css/screen.css +++ b/resources/public/css/screen.css @@ -6,12 +6,12 @@ body { font-family: 'Material Icons'; font-style: normal; font-weight: 400; - src: url(/js/lib/node_modules/material-icons/iconfont/MaterialIcons-Regular.eot); /* For IE6-8 */ + src: url(/assets/material-icons/iconfont/MaterialIcons-Regular.eot); /* For IE6-8 */ src: local('Material Icons'), local('MaterialIcons-Regular'), - url(/js/lib/node_modules/material-icons/iconfont/MaterialIcons-Regular.woff2) format('woff2'), - url(/js/lib/node_modules/material-icons/iconfont/MaterialIcons-Regular.woff) format('woff'), - url(/js/lib/node_modules/material-icons/iconfont/MaterialIcons-Regular.ttf) format('truetype'); + url(/assets/material-icons/iconfont/MaterialIcons-Regular.woff2) format('woff2'), + url(/assets/material-icons/iconfont/MaterialIcons-Regular.woff) format('woff'), + url(/assets/material-icons/iconfont/MaterialIcons-Regular.ttf) format('truetype'); } .material-icons { font-family: 'Material Icons'; diff --git a/resources/public/img/map-pins/unknown-pin.png b/resources/public/img/map-pins/Unknown-pin.png similarity index 100% rename from resources/public/img/map-pins/unknown-pin.png rename to resources/public/img/map-pins/Unknown-pin.png diff --git a/resources/public/img/map-pins/unknown-pin.svg b/resources/public/img/map-pins/Unknown-pin.svg similarity index 100% rename from resources/public/img/map-pins/unknown-pin.svg rename to resources/public/img/map-pins/Unknown-pin.svg diff --git a/resources/public/img/map-pins/unknown-pin.xcf b/resources/public/img/map-pins/unknown-pin.xcf deleted file mode 100644 index b55b9f8500df60592bec0955d09938cc0df70bf0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3759 zcmds4YitzP6`q;h^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9wUfc#4+5dp*?^;|bbk023~8u3RS z%|{vj4>L7_9H>GBpMc@FXKTbSpf0F~j`o8G_1{MhftGpsz9NC)rD&%gP$X_56tolx z0d?hz#BF}INQBHH(L8ytNc`n1iv&Zdb?382siCIMtcClZOm`X4q1&ammEpMYXDCie zmwv^=m2uggtH%3OopFUL=Cq#AxH+73#rWQZs0VcQoX`V+qI{OU%aw5Ios@^D*f4Gp zbu#%WQ3r`y%qczbWWPn1FQ!vt-C#FsAPbqa)N2LO*{pcY1a5OhoY<R{MA7HrY#ifZ zIFWe1c=4k?x{o=d^<I`~*)PR=FaG1|mv@GJsE6ZnQ(uk6lc_Y+16iS!0a+5WnN%_! ziw<~91FmlZc=)g@a1DWrhL}kw6VvB7##|cBO?j?lz=5LbI#>{c%ni<N(l$;y8&C*I z>sgJkkqe$YYv<zKUu40xt|_vVz1__fnBxk#)EO17Y-GmlS+4LNd`XgJFc!s3AP+k@ zwP#e67)chh*-XNMCq5Q4Sy8-`%)q`b<=s2D#C5W*PdU$6Dw&An2|FisPbE{Sk6?px zKSZLBbC`46Ir)=RVzd_mEO{=cqBrmD!^X*;p~OHBadU1e-aE6w1Oii~JMu*jydKT- z33!r6jP7JN_}0$<otwu=>ZujR4G%Y;OMCi_N2#}r>%AVX6ukA`G>(!)`@L=i;E-u| z`@pC6aqiO-G>q3N8>M}%$0#uL&%v911tjf*Vycj`Ga1`S<1EK@>o*uXQ%Z>n_HdsY zW#nq~rqSm?L2_@>{@EQrM+6k@GWHQ+n{mx>l3Np`5!{+o&NxfD0%H^WtI?0a-RVCQ Cjpg|O diff --git a/src/clj/geocsv/handler serves resources.clj b/src/clj/geocsv/handler serves resources.clj new file mode 100644 index 0000000..e86d51b --- /dev/null +++ b/src/clj/geocsv/handler serves resources.clj @@ -0,0 +1,40 @@ +(ns geocsv.handler + (:require [compojure.core :refer [routes wrap-routes]] + [geocsv.env :refer [defaults]] + [geocsv.middleware :as middleware] + [geocsv.layout :refer [error-page]] + [geocsv.routes.home :refer [home-routes]] + [geocsv.routes.json :refer [json-routes]] + [reitit.ring :as ring] + [ring.middleware.content-type :refer [wrap-content-type]] + [ring.middleware.webjars :refer [wrap-webjars]] + [mount.core :as mount])) + +(mount/defstate init-app + :start ((or (:init defaults) (fn []))) + :stop ((or (:stop defaults) (fn [])))) + +(mount/defstate app-routes + :start + (ring/ring-handler + (ring/router + [(home-routes) +;; (-> #'json-routes +;; (wrap-routes middleware/wrap-csrf) +;; (wrap-routes middleware/wrap-formats)) + ]) + (ring/routes + (ring/create-resource-handler + {:path "/"}) + (wrap-content-type + (wrap-webjars (constantly nil))) + (ring/create-default-handler + {:not-found + (constantly (error-page {:status 404, :title "404 - Page not found"})) + :method-not-allowed + (constantly (error-page {:status 405, :title "405 - Not allowed"})) + :not-acceptable + (constantly (error-page {:status 406, :title "406 - Not acceptable"}))})))) + +(defn app [] + (middleware/wrap-base #'app-routes)) diff --git a/src/clj/geocsv/handler.clj b/src/clj/geocsv/handler.clj index b1929ec..8c0e65a 100644 --- a/src/clj/geocsv/handler.clj +++ b/src/clj/geocsv/handler.clj @@ -22,13 +22,14 @@ (routes (-> #'home-routes (wrap-routes middleware/wrap-csrf) - (wrap-routes middleware/wrap-formats)) + (wrap-routes middleware/wrap-formats) + wrap-webjars) (-> #'rest-routes (wrap-routes middleware/wrap-csrf) (wrap-routes middleware/wrap-formats)) - (ring/create-resource-handler - {:path "/"}) -;; (route/resources "/") +;; (ring/create-resource-handler +;; {:path "/"}) + (route/resources "/") (route/not-found (:body (error-page {:status 404 diff --git a/src/clj/geocsv/routes/resources.clj b/src/clj/geocsv/routes/resources.clj deleted file mode 100644 index 3511ae7..0000000 --- a/src/clj/geocsv/routes/resources.clj +++ /dev/null @@ -1,14 +0,0 @@ -(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] - )) diff --git a/src/cljs/geocsv/core.cljs b/src/cljs/geocsv/core.cljs index a85d2f3..92bf1c7 100644 --- a/src/cljs/geocsv/core.cljs +++ b/src/cljs/geocsv/core.cljs @@ -3,6 +3,7 @@ [day8.re-frame.http-fx] [reagent.core :as r] [re-frame.core :as rf] + [geocsv.gis :as gis] [geocsv.views.map :as mv] [goog.events :as events] [goog.history.EventType :as HistoryEventType] @@ -11,7 +12,7 @@ [geocsv.events] [reitit.core :as reitit] [reitit.frontend.easy :as rfe] - [clojure.string :as string]) + [clojure.string :as s]) (:import goog.History)) (defn nav-link [uri title page] @@ -39,7 +40,31 @@ (defn about-page [] [:section.section>div.container>div.content - [:img {:src "/img/warning_clojure.png"}]]) + [:img {:src "/img/warning_clojure.png"}] + (when-let [images @(rf/subscribe [:available-pin-images])] + [:div + [:h2 "The following pin images are available on this server"] + (apply + vector + (cons + :ol + (map + #(vector + :ol + [:img + {:src + (str + "img/map-pins/" + (s/capitalize + (s/replace + (s/lower-case + (str %)) + #"[^a-z0-9]" "-")) + "-pin.png") + :alt %}] + " " + %) + (sort images))))])]) (defn home-page [] [:section.section>div.container>div.content diff --git a/src/cljs/geocsv/gis.cljs b/src/cljs/geocsv/gis.cljs index 3aefc87..59d8323 100644 --- a/src/cljs/geocsv/gis.cljs +++ b/src/cljs/geocsv/gis.cljs @@ -81,7 +81,7 @@ (if (available category) (str category "-pin") - "unknown-pin"))) + "Unknown-pin"))) (defn popup-content "Appropriate content for the popup of a map pin for this `record`."