#30: Still not quite complete

This commit is contained in:
simon 2017-03-26 15:58:43 +01:00
parent 7621040c8f
commit 560938e6ae
17 changed files with 47 additions and 22 deletions

View file

@ -85,20 +85,14 @@
:profiles :profiles
{:uberjar {:omit-source true {:uberjar {:omit-source true
:prep-tasks ["compile" "bower" ["cljsbuild" "once" "min"]] :prep-tasks ["compile" ["bower" "install"] ["cljsbuild" "once" "min"]]
:cljsbuild :cljsbuild
{:builds {:builds
{:min {:min
{:source-paths ["src/cljc" "src/cljs" "env/prod/cljs"] {:source-paths ["src/cljc" "src/cljs" "env/prod/cljs"]
:compiler :compiler
{:output-to "target/cljsbuild/public/js/app.js" {:optimizations :advanced
:externs ["react/externs/react.js" "externs.js"] :pretty-print false}}}}
:optimizations :advanced
:pretty-print false
:closure-warnings
{:externs-validation :off :non-standard-jsdoc :off}}}}}
:aot :all :aot :all
:uberjar-name "youyesyet.jar" :uberjar-name "youyesyet.jar"
:source-paths ["env/prod/clj"] :source-paths ["env/prod/clj"]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 942 B

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 511 B

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 983 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

View file

@ -16,7 +16,7 @@
<input type="text" id="username" name="username"/> <input type="text" id="username" name="username"/>
</p> </p>
<p class="widget"> <p class="widget">
<label for="password">Your post-code</label> <label for="password">Your password</label>
<input type="password" id="password" name="password"/> <input type="password" id="password" name="password"/>
</p> </p>
<p class="widget"> <p class="widget">

View file

@ -105,6 +105,9 @@
(secretary/defroute "/map" [] (secretary/defroute "/map" []
(rf/dispatch [:set-active-page :map])) (rf/dispatch [:set-active-page :map]))
(secretary/defroute "/set-intention/:elector/:intention" {elector-id :elector intention :intention}
(rf/dispatch [:set-intention {:elector-id elector-id :intention intention}]))
;; ------------------------- ;; -------------------------
;; History ;; History
;; must be called after routes have been defined ;; must be called after routes have been defined

View file

@ -32,10 +32,10 @@
(def default-db (def default-db
{;;; the currently selected address, if any. {;;; the currently selected address, if any.
:address {:id 1 :address "13 Imaginary Terrace, IM1 3TE" :latitude 55.8253043 :longitude -4.2590944 :address {:id 1 :address "13 Imaginary Terrace, IM1 3TE" :latitude 55.8253043 :longitude -4.2590944
:electors [{:id 1 :name "Alan Anderson" :gender :male :intention :no} :electors [{:id 1 :name "Alan Anderson" :gender :male :intention :no}
{:id 2 :name "Ann Anderson" :gender :female} {:id 2 :name "Ann Anderson" :gender :female}
{:id 3 :name "Alex Anderson" :gender :fluid :intention :yes} {:id 3 :name "Alex Anderson" :gender :fluid :intention :yes}
{:id 4 :name "Andy Anderson" :intention :yes}]} {:id 4 :name "Andy Anderson" :intention :yes}]}
;;; a list of the addresses in the current location at which there ;;; a list of the addresses in the current location at which there
;;; are electors registered. ;;; are electors registered.
:addresses [{:id 1 :address "13 Imaginary Terrace, IM1 3TE" :latitude 55.8253043 :longitude -4.2590944 :addresses [{:id 1 :address "13 Imaginary Terrace, IM1 3TE" :latitude 55.8253043 :longitude -4.2590944
@ -44,7 +44,10 @@
{:id 3 :name "Alex Anderson" :gender :fluid :intention :yes} {:id 3 :name "Alex Anderson" :gender :fluid :intention :yes}
{:id 4 :name "Andy Anderson" :intention :yes}]}] {:id 4 :name "Andy Anderson" :intention :yes}]}]
;;; electors at the currently selected address ;;; electors at the currently selected address
:elector {:id 1 :name "Alan Anderson" :gender :male :intention :no} :electors [{:id 1 :name "Alan Anderson" :gender :male :intention :no}
{:id 2 :name "Ann Anderson" :gender :female}
{:id 3 :name "Alex Anderson" :gender :fluid :intention :yes}
{:id 4 :name "Andy Anderson" :intention :yes}]
;;; the issue from among the issues which is currently selected. ;;; the issue from among the issues which is currently selected.
:issue "Currency" :issue "Currency"
;;; the issues selected for the issues page on this day. ;;; the issues selected for the issues page on this day.

View file

@ -62,10 +62,30 @@
(assoc (assoc db :elector elector) :page page)))) (assoc (assoc db :elector elector) :page page))))
(reg-event-db
:set-intention
(fn [db [_ args]]
(let [intention (:intention args)
elector-id (read-string (:elector-id args))
elector
(first
(remove nil?
(map
#(if (= elector-id (:id %)) %)
(:electors (:address db)))))
old-address (:address db)
new-address (assoc old-address :electors (cons (assoc elector :intention intention) (remove #(= % elector) (:electors old-address))))]
(cond
(nil? elector)(do (js/console.log "No elector found; not setting intention") db)
(= intention (:intention elector)) (do (js/console.log "Elector's intention hasn't changed; not setting intention") db)
true
(do
(js/console.log (str "Setting intention of elector " elector " to " intention))
(assoc db :addresses (cons new-address (remove old-address (:addresses db)))))))))
(reg-event-db (reg-event-db
:set-issue :set-issue
(fn [db [_ issue]] (fn [db [_ issue]]
(js/console.log (str "Setting page to :issue, issue to " issue)) (js/console.log (str "Setting page to :issue, issue to " issue))
(assoc (assoc db :issue issue) :page :issue))) (assoc (assoc db :issue issue) :page :issue)))

View file

@ -61,4 +61,5 @@
[:img {:src "img/gnu.small.png" :alt "Free Software Foundation" :height "24" :width "24"}] [:img {:src "img/gnu.small.png" :alt "Free Software Foundation" :height "24" :width "24"}]
" Licensed under the " " Licensed under the "
[:a {:href "http://www.gnu.org/licenses/gpl-2.0.html"} [:a {:href "http://www.gnu.org/licenses/gpl-2.0.html"}
"GNU General Public License v2.0"]]]])) "GNU General Public License v2.0"]]
(ui/back-link)]]))

View file

@ -45,7 +45,7 @@
[elector] [elector]
(let [gender (:gender elector) (let [gender (:gender elector)
image (if gender (name gender) "unknown")] image (if gender (name gender) "unknown")]
[:td {:key (:id elector)} (if gender [:img {:src (str "img/gender/" image ".png") :alt image}])])) [:td {:key (:id elector)} [:img {:src (str "img/gender/" image ".png") :alt image}]]))
(defn genders-row (defn genders-row
[electors] [electors]
@ -84,6 +84,7 @@
[:a {:href (str "#/issues/" (:id elector))} [:a {:href (str "#/issues/" (:id elector))}
[:img {:src "/img/issues.png" :alt "Issues"}]]]) [:img {:src "/img/issues.png" :alt "Issues"}]]])
(defn issues-row (defn issues-row
[electors] [electors]
[:tr [:tr
@ -95,6 +96,7 @@
"Generate the electors panel." "Generate the electors panel."
[] []
(let [address @(subscribe [:address]) (let [address @(subscribe [:address])
addresses @(subscribe [:addresses])
electors (:electors address) electors (:electors address)
options @(subscribe [:options])] options @(subscribe [:options])]
(if address (if address

View file

@ -71,3 +71,4 @@
[:input {:id "submit" :name "submit" :type "submit" :value "Send this!"}]] [:input {:id "submit" :name "submit" :type "submit" :value "Send this!"}]]
] ]
(ui/back-link)]]))) (ui/back-link)]])))

View file

@ -64,6 +64,7 @@
(defn click-handler (defn click-handler
[id] [id]
(js/console.log (str "Click handler for address #" id))
(dispatch [:set-address id])) (dispatch [:set-address id]))
@ -71,7 +72,7 @@
"Add a map-pin at this address in this map view" "Add a map-pin at this address in this map view"
[address view] [address view]
(let [lat (:latitude address) (let [lat (:latitude address)
lon (:longitude address) lng (:longitude address)
pin (.icon js/L pin (.icon js/L
(clj->js (clj->js
{:iconUrl (str "img/map-pins/" (pin-image address) ".png") {:iconUrl (str "img/map-pins/" (pin-image address) ".png")
@ -81,7 +82,7 @@
:iconAnchor [16 41] :iconAnchor [16 41]
:shadowAnchor [16 23]})) :shadowAnchor [16 23]}))
marker (.marker js/L marker (.marker js/L
(.latLng js/L 55.82 -4.25) (.latLng js/L lat lng)
(clj->js {:icon pin :title (:address address)})) (clj->js {:icon pin :title (:address address)}))
] ]
(.on marker "click" #(fn [] (click-handler (:id address)))) (.on marker "click" #(fn [] (click-handler (:id address))))
@ -92,7 +93,7 @@
(defn map-did-mount-mapbox (defn map-did-mount-mapbox
"Did-mount function loading map tile data from MapBox (proprietary)." "Did-mount function loading map tile data from MapBox (proprietary)."
[] []
(let [view (.setView (.map js/L "map" (clj->js {:zoomControl "false"})) #js [55.82 -4.25] 13)] (let [view (.setView (.map js/L "map" (clj->js {:zoomControl "false"})) #js [55.82 -4.25] 40)]
;; NEED TO REPLACE FIXME with your mapID! ;; NEED TO REPLACE FIXME with your mapID!
(.addTo (.tileLayer js/L "http://{s}.tiles.mapbox.com/v3/FIXME/{z}/{x}/{y}.png" (.addTo (.tileLayer js/L "http://{s}.tiles.mapbox.com/v3/FIXME/{z}/{x}/{y}.png"
(clj->js {:attribution "Map data &copy; [...]" (clj->js {:attribution "Map data &copy; [...]"