diff --git a/project.clj b/project.clj index 9992b17..3da9450 100644 --- a/project.clj +++ b/project.clj @@ -1,19 +1,23 @@ (defproject geocsv "0.1.0-SNAPSHOT" - :description "FIXME: write description" + :description "A wee tool to show comma-separated value data on a map." :url "http://example.com/FIXME" - :dependencies [[ch.qos.logback/logback-classic "1.2.3"] + :dependencies [[adl-support "0.1.6"] + [ch.qos.logback/logback-classic "1.2.3"] [cheshire "5.9.0"] [cljs-ajax "0.8.0"] [cljsjs/leaflet "1.2.0-0"] [clojure.java-time "0.3.2"] [com.cemerick/url "0.1.1"] [com.cognitect/transit-clj "0.8.319"] + [compojure "1.6.1"] [cprop "0.1.15"] + [csv2edn "0.1.5"] [day8.re-frame/http-fx "0.1.6"] [expound "0.8.3"] [funcool/struct "1.4.0"] + [lib-noir "0.9.9" :exclusions [org.clojure/tools.reader]] [luminus-jetty "0.1.7"] [luminus-transit "0.1.2"] [luminus/ring-ttl-session "0.3.3"] diff --git a/resources/public/img/map-pins/Anchor-customer-pin.png b/resources/public/img/map-pins/Anchor-customer-pin.png new file mode 100644 index 0000000..4cbe582 Binary files /dev/null and b/resources/public/img/map-pins/Anchor-customer-pin.png differ diff --git a/resources/public/img/map-pins/Anchor-customer-pin.svg b/resources/public/img/map-pins/Anchor-customer-pin.svg new file mode 100644 index 0000000..4fc6591 --- /dev/null +++ b/resources/public/img/map-pins/Anchor-customer-pin.svg @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Basic pin for SceneHere + 20100801 + + + Simon Brooke + + + + + Copyright (c) 2010 Simon Brooke + + + basic_map_pin.svg + + Basic default map pin + $Revision: 1.2 $ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/public/img/map-pins/Broadband-supplier-pin.png b/resources/public/img/map-pins/Broadband-supplier-pin.png new file mode 100644 index 0000000..7d07d8b Binary files /dev/null and b/resources/public/img/map-pins/Broadband-supplier-pin.png differ diff --git a/resources/public/img/map-pins/Broadband-supplier-pin.svg b/resources/public/img/map-pins/Broadband-supplier-pin.svg new file mode 100644 index 0000000..905c241 --- /dev/null +++ b/resources/public/img/map-pins/Broadband-supplier-pin.svg @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Basic pin for SceneHere + 20100801 + + + Simon Brooke + + + + + Copyright (c) 2010 Simon Brooke + + + basic_map_pin.svg + + Basic default map pin + $Revision: 1.2 $ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/public/img/map-pins/Investor-pin.png b/resources/public/img/map-pins/Investor-pin.png new file mode 100644 index 0000000..cebbfbb Binary files /dev/null and b/resources/public/img/map-pins/Investor-pin.png differ diff --git a/resources/public/img/map-pins/Investor-pin.svg b/resources/public/img/map-pins/Investor-pin.svg new file mode 100644 index 0000000..da764a0 --- /dev/null +++ b/resources/public/img/map-pins/Investor-pin.svg @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Basic pin for SceneHere + 20100801 + + + Simon Brooke + + + + + Copyright (c) 2010 Simon Brooke + + + basic_map_pin.svg + + Basic default map pin + $Revision: 1.2 $ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/public/img/map-pins/Landowner-pin.png b/resources/public/img/map-pins/Landowner-pin.png new file mode 100644 index 0000000..0a8a6ec Binary files /dev/null and b/resources/public/img/map-pins/Landowner-pin.png differ diff --git a/resources/public/img/map-pins/Landowner-pin.svg b/resources/public/img/map-pins/Landowner-pin.svg new file mode 100644 index 0000000..3f3a1a7 --- /dev/null +++ b/resources/public/img/map-pins/Landowner-pin.svg @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Basic pin for SceneHere + 20100801 + + + Simon Brooke + + + + + Copyright (c) 2010 Simon Brooke + + + basic_map_pin.svg + + Basic default map pin + $Revision: 1.2 $ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/public/img/map-pins/Operator-pin.png b/resources/public/img/map-pins/Operator-pin.png new file mode 100644 index 0000000..114a5f7 Binary files /dev/null and b/resources/public/img/map-pins/Operator-pin.png differ diff --git a/resources/public/img/map-pins/Operator-pin.svg b/resources/public/img/map-pins/Operator-pin.svg new file mode 100644 index 0000000..fb2ddfc --- /dev/null +++ b/resources/public/img/map-pins/Operator-pin.svg @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Basic pin for SceneHere + 20100801 + + + Simon Brooke + + + + + Copyright (c) 2010 Simon Brooke + + + basic_map_pin.svg + + Basic default map pin + $Revision: 1.2 $ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/public/img/map-pins/Other-key-customers-pin.png b/resources/public/img/map-pins/Other-key-customers-pin.png new file mode 100644 index 0000000..3cfa7e8 Binary files /dev/null and b/resources/public/img/map-pins/Other-key-customers-pin.png differ diff --git a/resources/public/img/map-pins/Other-key-customers-pin.svg b/resources/public/img/map-pins/Other-key-customers-pin.svg new file mode 100644 index 0000000..df0a5e3 --- /dev/null +++ b/resources/public/img/map-pins/Other-key-customers-pin.svg @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Basic pin for SceneHere + 20100801 + + + Simon Brooke + + + + + Copyright (c) 2010 Simon Brooke + + + basic_map_pin.svg + + Basic default map pin + $Revision: 1.2 $ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/public/img/map-pins/Power-supplier-pin.png b/resources/public/img/map-pins/Power-supplier-pin.png new file mode 100644 index 0000000..c766d43 Binary files /dev/null and b/resources/public/img/map-pins/Power-supplier-pin.png differ diff --git a/resources/public/img/map-pins/Power-supplier-pin.svg b/resources/public/img/map-pins/Power-supplier-pin.svg new file mode 100644 index 0000000..74f9329 --- /dev/null +++ b/resources/public/img/map-pins/Power-supplier-pin.svg @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Basic pin for SceneHere + 20100801 + + + Simon Brooke + + + + + Copyright (c) 2010 Simon Brooke + + + basic_map_pin.svg + + Basic default map pin + $Revision: 1.2 $ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/clj/geocsv/handler.clj b/src/clj/geocsv/handler.clj index 15308eb..48c42d8 100644 --- a/src/clj/geocsv/handler.clj +++ b/src/clj/geocsv/handler.clj @@ -1,13 +1,14 @@ (ns geocsv.handler - (:require - [geocsv.middleware :as middleware] - [geocsv.layout :refer [error-page]] - [geocsv.routes.home :refer [home-routes]] - [reitit.ring :as ring] - [ring.middleware.content-type :refer [wrap-content-type]] - [ring.middleware.webjars :refer [wrap-webjars]] - [geocsv.env :refer [defaults]] - [mount.core :as mount])) + (: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 []))) @@ -17,7 +18,10 @@ :start (ring/ring-handler (ring/router - [(home-routes)]) + [(home-routes) + (-> #'json/json-routes + (wrap-routes middleware/wrap-csrf) + (wrap-routes middleware/wrap-formats))]) (ring/routes (ring/create-resource-handler {:path "/"}) diff --git a/src/clj/geocsv/routes/home.clj b/src/clj/geocsv/routes/home.clj index 9eec70f..fbfd090 100644 --- a/src/clj/geocsv/routes/home.clj +++ b/src/clj/geocsv/routes/home.clj @@ -1,10 +1,9 @@ (ns geocsv.routes.home - (:require - [geocsv.layout :as layout] - [clojure.java.io :as io] - [geocsv.middleware :as middleware] - [ring.util.response] - [ring.util.http-response :as response])) + (:require [clojure.java.io :as io] + [geocsv.layout :as layout] + [geocsv.middleware :as middleware] + [ring.util.response] + [ring.util.http-response :as response])) (defn home-page [request] (layout/render request "home.html")) diff --git a/src/clj/geocsv/routes/json.clj b/src/clj/geocsv/routes/json.clj new file mode 100644 index 0000000..b9e7d30 --- /dev/null +++ b/src/clj/geocsv/routes/json.clj @@ -0,0 +1,91 @@ +(ns geocsv.routes.json + "JSON routes 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] + )) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; geocsv.routes.json: data service handlers. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2016 Simon Brooke for Radical Independence Campaign +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defn get-pin-image-names + [request] + (ar/do-or-server-fail + (map + #(s/replace (.getName %) #"-pin\.png$" "") + (let [grammar-matcher (.getPathMatcher + (java.nio.file.FileSystems/getDefault) + "glob:*-pin.png")] + (->> "resources/public/img/map-pins" + clojure.java.io/file + file-seq + (filter #(.isFile %)) + (filter #(.matches grammar-matcher (.getFileName (.toPath %))))))) + 200)) + +(defn get-data-uri + "Return JSON formatted data taken from the CSV file at this URI. The file + must exist, be publicly readable, and use commas as separators." + [uri] + (csv->json uri)) + +(defn get-data-google + "Return JSON formatted data taken from the Google Sheets spreadsheet with + this `docid`. The spreadsheet must exist and must be publicly readable." + [docid] + (get-data-uri + (str + "https://docs.google.com/spreadsheets/d/" + docid + "/export?format=csv"))) + +(defn get-data-file + "Return JSON formatted data taken from the CSV file with the name `filename` + in the directory `resources/public/data`. TODO: There is a safe way to + access the content of the resource directory but I don't recall it just now." + [filename] + (csv->json (io/reader (io/file (str "resources/public/data/" filename))))) + +(defn get-data + [request] + (ar/do-or-server-fail + (let [params (ac/massage-params request)] + (cond + (:docid params) (get-data-google (:docid params)) + (:uri params) (get-data-uri (:uri params)) + (:file params) (get-data-file (:file params)) + :else (get-data-file "data.csv"))) + 200)) + +(defroutes json-routes + (GET "/get-pin-image-names" request (get-pin-image-names request)) + (POST "/get-pin-image-names" request (get-pin-image-names request)) + (GET "/get-data" request (get-data request)))