Fixed major regression, still some problems but progress.

This commit is contained in:
Simon Brooke 2018-07-26 11:12:50 +01:00
parent 18a267fd8c
commit 981a4d0d34
3 changed files with 48 additions and 46 deletions

View file

@ -1,6 +1,7 @@
(ns ^{:doc "Manually maintained routes which handle data transfer to/from the canvasser app."
: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.tools.logging :as log]
[clojure.walk :refer [keywordize-keys]]
@ -96,10 +97,11 @@
(defn current-visit-id
"Return the id of the current visit by the current user, creating it if necessary."
[request]
(let [last-visit (last-visit-by-current-user request)]
(let [last-visit (last-visit-by-current-user request)
params (massage-params request)]
(if
(=
(:address_id (massage-params request))
(:address_id params)
(:address_id last-visit))
(:id last-visit)
(db/create-visit! db/*db* params))))
@ -128,6 +130,7 @@
include an `issue`, an `elector_id` and an `address_id` (and also a
`method_id` and `method_detail`). Ye cannae reasonably create a request
without having recorded the visit, so let's not muck about."
[request]
(let [params (massage-params request)]
(db/create-followuprequest!
db/*db*

View file

@ -49,9 +49,9 @@
(.-latitude (.-coords position)) ", "
(.-longitude (.-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")
(locality (.-latitude (.-coords position)) (.-longitude (.-coords position)))
(catch js/Object any
(js/console.log "Exception while trying to access location: " + any)
0)))

View file

@ -70,7 +70,7 @@
(defn add-to-feedback
"Add `x` to the feedback in this `db`."
[db k]
[db x]
(add-to-key db :feedback x))
@ -179,7 +179,7 @@
(let [locality (get-current-location)]
(js/console.log "Updating current location")
(if
(and (locality > 0) (not (= locality (:locality db))))
(and (> locality 0) (not (= locality (:locality db))))
(do
(dispatch :fetch-locality) ;; if the locality has changed, fetch it immediately
(assoc db :locality locality))
@ -212,11 +212,11 @@
:error (cons :fetch-locality (:error db)))))
(reg-event-fx
:process-outqueue
(fn [{db :db} _]
(if
(empty? (:outqueue db))
;; (reg-event-fx
;; :process-outqueue
;; (fn [{db :db} _]
;; (if
;; (empty? (:outqueue db))
(reg-event-fx
@ -296,23 +296,22 @@
(reg-event-db
:send-intention
(fn [db [_ args]]
(let [intention (:intention args)
elector-id (:elector-id args)]
(let [intention (:intention args)]
(if
(nil? (-> db :elector))
(assoc db :error (cons "No elector found; not setting intention" (:error db)))
(do
(js/console.log (str "Setting intention of elector " old-elector " to " intention))
(->
db
clear-messages
#(add-to-outqueue % (assoc
(js/console.log (str "Setting intention of elector " (-> db :elector :id) " to " intention))
(assoc
(add-to-outqueue
(clear-messages db)
(assoc
args
:address_id (-> db :address :id)
:locality (-> db :address :locality)
:elector_id (-> db :elector :id)
:action :set-intention))
#(assoc % :elector (assoc (:elector db) :intention intention))))))))
:elector (assoc (:elector db) :intention intention)))))))
(reg-event-db
@ -321,14 +320,16 @@
(if (and (:elector db) (:issue db) (:telephone db))
(do
(js/console.log "Sending request")
(-> db
#(add-to-outqueue % {:elector_id (-> db :elector :id)
(add-to-feedback
(add-to-outqueue
db
{:elector_id (-> db :elector :id)
:issue_id (-> db :issue :id)
:address_id (-> db :address :id)
:method_id "Phone"
:method_detail (-> db :method_detail)
:action :add-request})
#(add-to-feedback % :send-request)))
:send-request))
(assoc db :error "Please supply a telephone number to call"))))
@ -345,16 +346,14 @@
(fn [db [_ address-id]]
(let [id (coerce-to-number address-id)
address (first (remove nil? (map #(if (= id (:id %)) %) (:addresses db))))]
(-> db
clear-messages
#(if
(= (count (:dwellings address)) 1)
(assoc %
(clear-messages
(if
(assoc db (= (count (:dwellings address)) 1)
:address address
:dwelling (first (:dwellings address))
:electors (:electors (first (:dwellings address)))
:page :dwelling)
(assoc %
(assoc db
:address address
:dwelling nil
:electors nil