Fixed major regression, still some problems but progress.
This commit is contained in:
parent
18a267fd8c
commit
981a4d0d34
|
@ -1,6 +1,7 @@
|
||||||
(ns ^{:doc "Manually maintained routes which handle data transfer to/from the canvasser app."
|
(ns ^{:doc "Manually maintained routes which handle data transfer to/from the canvasser app."
|
||||||
:author "Simon Brooke"} youyesyet.routes.rest
|
:author "Simon Brooke"} youyesyet.routes.rest
|
||||||
(:require [clojure.core.memoize :as memo]
|
(:require [adl-support.core :refer [massage-params]]
|
||||||
|
[clojure.core.memoize :as memo]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.tools.logging :as log]
|
[clojure.tools.logging :as log]
|
||||||
[clojure.walk :refer [keywordize-keys]]
|
[clojure.walk :refer [keywordize-keys]]
|
||||||
|
@ -96,10 +97,11 @@
|
||||||
(defn current-visit-id
|
(defn current-visit-id
|
||||||
"Return the id of the current visit by the current user, creating it if necessary."
|
"Return the id of the current visit by the current user, creating it if necessary."
|
||||||
[request]
|
[request]
|
||||||
(let [last-visit (last-visit-by-current-user request)]
|
(let [last-visit (last-visit-by-current-user request)
|
||||||
|
params (massage-params request)]
|
||||||
(if
|
(if
|
||||||
(=
|
(=
|
||||||
(:address_id (massage-params request))
|
(:address_id params)
|
||||||
(:address_id last-visit))
|
(:address_id last-visit))
|
||||||
(:id last-visit)
|
(:id last-visit)
|
||||||
(db/create-visit! db/*db* params))))
|
(db/create-visit! db/*db* params))))
|
||||||
|
@ -128,6 +130,7 @@
|
||||||
include an `issue`, an `elector_id` and an `address_id` (and also a
|
include an `issue`, an `elector_id` and an `address_id` (and also a
|
||||||
`method_id` and `method_detail`). Ye cannae reasonably create a request
|
`method_id` and `method_detail`). Ye cannae reasonably create a request
|
||||||
without having recorded the visit, so let's not muck about."
|
without having recorded the visit, so let's not muck about."
|
||||||
|
[request]
|
||||||
(let [params (massage-params request)]
|
(let [params (massage-params request)]
|
||||||
(db/create-followuprequest!
|
(db/create-followuprequest!
|
||||||
db/*db*
|
db/*db*
|
||||||
|
|
|
@ -49,9 +49,9 @@
|
||||||
(.-latitude (.-coords position)) ", "
|
(.-latitude (.-coords position)) ", "
|
||||||
(.-longitude (.-coords position))))
|
(.-longitude (.-coords position))))
|
||||||
(dispatch-sync [:set-latitude (.-latitude (.-coords position))])
|
(dispatch-sync [:set-latitude (.-latitude (.-coords position))])
|
||||||
(dispatch-sync [:set-longitude (.-longitude (.-coords position))])))
|
(dispatch-sync [:set-longitude (.-longitude (.-coords position))])
|
||||||
|
(locality (.-latitude (.-coords position)) (.-longitude (.-coords position))))))
|
||||||
(js/console.log "Geolocation not available")
|
(js/console.log "Geolocation not available")
|
||||||
(locality (.-latitude (.-coords position)) (.-longitude (.-coords position)))
|
|
||||||
(catch js/Object any
|
(catch js/Object any
|
||||||
(js/console.log "Exception while trying to access location: " + any)
|
(js/console.log "Exception while trying to access location: " + any)
|
||||||
0)))
|
0)))
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
|
|
||||||
(defn add-to-feedback
|
(defn add-to-feedback
|
||||||
"Add `x` to the feedback in this `db`."
|
"Add `x` to the feedback in this `db`."
|
||||||
[db k]
|
[db x]
|
||||||
(add-to-key db :feedback x))
|
(add-to-key db :feedback x))
|
||||||
|
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@
|
||||||
(let [locality (get-current-location)]
|
(let [locality (get-current-location)]
|
||||||
(js/console.log "Updating current location")
|
(js/console.log "Updating current location")
|
||||||
(if
|
(if
|
||||||
(and (locality > 0) (not (= locality (:locality db))))
|
(and (> locality 0) (not (= locality (:locality db))))
|
||||||
(do
|
(do
|
||||||
(dispatch :fetch-locality) ;; if the locality has changed, fetch it immediately
|
(dispatch :fetch-locality) ;; if the locality has changed, fetch it immediately
|
||||||
(assoc db :locality locality))
|
(assoc db :locality locality))
|
||||||
|
@ -212,11 +212,11 @@
|
||||||
:error (cons :fetch-locality (:error db)))))
|
:error (cons :fetch-locality (:error db)))))
|
||||||
|
|
||||||
|
|
||||||
(reg-event-fx
|
;; (reg-event-fx
|
||||||
:process-outqueue
|
;; :process-outqueue
|
||||||
(fn [{db :db} _]
|
;; (fn [{db :db} _]
|
||||||
(if
|
;; (if
|
||||||
(empty? (:outqueue db))
|
;; (empty? (:outqueue db))
|
||||||
|
|
||||||
|
|
||||||
(reg-event-fx
|
(reg-event-fx
|
||||||
|
@ -296,23 +296,22 @@
|
||||||
(reg-event-db
|
(reg-event-db
|
||||||
:send-intention
|
:send-intention
|
||||||
(fn [db [_ args]]
|
(fn [db [_ args]]
|
||||||
(let [intention (:intention args)
|
(let [intention (:intention args)]
|
||||||
elector-id (:elector-id args)]
|
|
||||||
(if
|
(if
|
||||||
(nil? (-> db :elector))
|
(nil? (-> db :elector))
|
||||||
(assoc db :error (cons "No elector found; not setting intention" (:error db)))
|
(assoc db :error (cons "No elector found; not setting intention" (:error db)))
|
||||||
(do
|
(do
|
||||||
(js/console.log (str "Setting intention of elector " old-elector " to " intention))
|
(js/console.log (str "Setting intention of elector " (-> db :elector :id) " to " intention))
|
||||||
(->
|
(assoc
|
||||||
db
|
(add-to-outqueue
|
||||||
clear-messages
|
(clear-messages db)
|
||||||
#(add-to-outqueue % (assoc
|
(assoc
|
||||||
args
|
args
|
||||||
:address_id (-> db :address :id)
|
:address_id (-> db :address :id)
|
||||||
:locality (-> db :address :locality)
|
:locality (-> db :address :locality)
|
||||||
:elector_id (-> db :elector :id)
|
:elector_id (-> db :elector :id)
|
||||||
:action :set-intention))
|
:action :set-intention))
|
||||||
#(assoc % :elector (assoc (:elector db) :intention intention))))))))
|
:elector (assoc (:elector db) :intention intention)))))))
|
||||||
|
|
||||||
|
|
||||||
(reg-event-db
|
(reg-event-db
|
||||||
|
@ -321,14 +320,16 @@
|
||||||
(if (and (:elector db) (:issue db) (:telephone db))
|
(if (and (:elector db) (:issue db) (:telephone db))
|
||||||
(do
|
(do
|
||||||
(js/console.log "Sending request")
|
(js/console.log "Sending request")
|
||||||
(-> db
|
(add-to-feedback
|
||||||
#(add-to-outqueue % {:elector_id (-> db :elector :id)
|
(add-to-outqueue
|
||||||
|
db
|
||||||
|
{:elector_id (-> db :elector :id)
|
||||||
:issue_id (-> db :issue :id)
|
:issue_id (-> db :issue :id)
|
||||||
:address_id (-> db :address :id)
|
:address_id (-> db :address :id)
|
||||||
:method_id "Phone"
|
:method_id "Phone"
|
||||||
:method_detail (-> db :method_detail)
|
:method_detail (-> db :method_detail)
|
||||||
:action :add-request})
|
:action :add-request})
|
||||||
#(add-to-feedback % :send-request)))
|
:send-request))
|
||||||
(assoc db :error "Please supply a telephone number to call"))))
|
(assoc db :error "Please supply a telephone number to call"))))
|
||||||
|
|
||||||
|
|
||||||
|
@ -341,24 +342,22 @@
|
||||||
|
|
||||||
|
|
||||||
(reg-event-db
|
(reg-event-db
|
||||||
:set-address
|
:set-address
|
||||||
(fn [db [_ address-id]]
|
(fn [db [_ address-id]]
|
||||||
(let [id (coerce-to-number address-id)
|
(let [id (coerce-to-number address-id)
|
||||||
address (first (remove nil? (map #(if (= id (:id %)) %) (:addresses db))))]
|
address (first (remove nil? (map #(if (= id (:id %)) %) (:addresses db))))]
|
||||||
(-> db
|
(clear-messages
|
||||||
clear-messages
|
(if
|
||||||
#(if
|
(assoc db (= (count (:dwellings address)) 1)
|
||||||
(= (count (:dwellings address)) 1)
|
:address address
|
||||||
(assoc %
|
:dwelling (first (:dwellings address))
|
||||||
:address address
|
:electors (:electors (first (:dwellings address)))
|
||||||
:dwelling (first (:dwellings address))
|
:page :dwelling)
|
||||||
:electors (:electors (first (:dwellings address)))
|
(assoc db
|
||||||
:page :dwelling)
|
:address address
|
||||||
(assoc %
|
:dwelling nil
|
||||||
:address address
|
:electors nil
|
||||||
:dwelling nil
|
:page :building))))))
|
||||||
:electors nil
|
|
||||||
:page :building))))))
|
|
||||||
|
|
||||||
|
|
||||||
(reg-event-db
|
(reg-event-db
|
||||||
|
|
Loading…
Reference in a new issue