From 54ad57349c71a637d706a4aaa8a53a0362358a8a Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Mon, 3 Sep 2018 12:45:48 +0100 Subject: [PATCH 1/3] Considerable progress on the issue experts workflow, not perfect yet. --- resources/sql/queries.sql | 7 +++ .../sql/youyesyet.postgres.overrides.sql | 25 ++++++++ resources/templates/issue-expert/request.html | 23 +++++++- src/clj/youyesyet/routes/issue_experts.clj | 59 +++++++++++++++---- 4 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 resources/sql/youyesyet.postgres.overrides.sql diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 779e572..0705af8 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -67,6 +67,13 @@ WHERE canvasser_id = :id ORDER BY date desc LIMIT 1 +--:name get-locality-for-visit :? :1 +--:doc returns the locality of the address of this visit +SELECT addresses.locality +FROM addresses, visits +WHERE visits.address_id = addresses.id +AND visits.id = :id + -- I don't know why this next one isn't autogenerating, but it isn't and it's critical. -- :name list-roles-by-canvasser :? :* diff --git a/resources/sql/youyesyet.postgres.overrides.sql b/resources/sql/youyesyet.postgres.overrides.sql new file mode 100644 index 0000000..dad6bce --- /dev/null +++ b/resources/sql/youyesyet.postgres.overrides.sql @@ -0,0 +1,25 @@ +------------------------------------------------------------------------ +-- convenience view lv_followupactions of entity followupactions for +-- lists, et cetera +-- ADL is not yet correctly chaining tables when generating convenience +-- views, so the auto-generated convenience view is a horrible +-- cross-product join +------------------------------------------------------------------------ +DROP VIEW lv_followupactions; +CREATE VIEW lv_followupactions AS +SELECT electors.name ||', '|| addresses.address ||', '|| addresses.postcode ||', '|| visits.date ||', '|| issues.id AS request_id_expanded, + followupactions.request_id, + canvassers.username ||', '|| canvassers.fullname ||', '|| addresses.address ||', '|| addresses.postcode ||', '|| canvassers.phone ||', '|| canvassers.email AS actor_expanded, + followupactions.actor, + followupactions.date, + followupactions.notes, + followupactions.closed, + followupactions.id +FROM followuprequests, visits, canvassers, addresses, followupactions, issues, electors +WHERE followupactions.request_id = followuprequests.id + AND followuprequests.elector_id = electors.id + AND followuprequests.visit_id = visits.id + AND followuprequests.issue_id = issues.id + AND visits.address_id = addresses.id + AND followupactions.actor = canvassers.id +; diff --git a/resources/templates/issue-expert/request.html b/resources/templates/issue-expert/request.html index 64d8d79..295ba19 100644 --- a/resources/templates/issue-expert/request.html +++ b/resources/templates/issue-expert/request.html @@ -13,16 +13,19 @@
{% csrf-field %} + + +

{% ifmemberof canvassers teamorganisers issueexperts analysts issueeditors admin %} - + {{elector.name}} ({{elector.gender}}) {% else %} - + You are not permitted to view elector of followuprequests {% endifmemberof %} @@ -121,7 +124,21 @@ {% endifmemberof %}

- +

+ + {% ifmemberof admin issueexperts %} + + {% endifmemberof %} +

{% ifmemberof admin issueexperts %}

{% ifmemberof issueexperts analysts issueeditors admin %} - by {{visit.canvasser_id_expanded}} at {{visit.date}} + by {{visit.canvasser_id_expanded}} on {{visit.date}} {% else %} @@ -46,8 +46,17 @@

+ {% ifmemberof issueexperts analysts issueeditors admin %} + + {{issue.id}} + + {% else %} + + You are not permitted to view visit of followuprequests + + {% endifmemberof %} {% ifmemberof issueexperts admin %}

{{issue.brief|safe}} From cb9e38cdc8376ef69deda6475f5fc0c2e863f3a4 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Fri, 14 Sep 2018 16:30:35 +0100 Subject: [PATCH 3/3] Some improvement to the followuprequest form Allowing handling of 'other', to capture electors concerns other than the ones we've selected. --- .../sql/youyesyet.postgres.overrides.sql | 1 + src/cljs/youyesyet/canvasser_app/core.cljs | 1 + .../youyesyet/canvasser_app/handlers.cljs | 42 +++++++++++++++++++ .../canvasser_app/subscriptions.cljs | 10 +++++ .../canvasser_app/views/followup.cljs | 18 ++++++-- .../youyesyet/canvasser_app/views/gdpr.cljs | 2 +- youyesyet.adl.xml | 5 ++- 7 files changed, 74 insertions(+), 5 deletions(-) diff --git a/resources/sql/youyesyet.postgres.overrides.sql b/resources/sql/youyesyet.postgres.overrides.sql index 146a2db..d0c7a9b 100644 --- a/resources/sql/youyesyet.postgres.overrides.sql +++ b/resources/sql/youyesyet.postgres.overrides.sql @@ -42,3 +42,4 @@ WHERE followupactions.request_id = followuprequests.id AND visits.address_id = addresses.id AND followupactions.actor = canvassers.id ; +GRANT SELECT ON lv_followupactions TO canvassers, issueexperts; diff --git a/src/cljs/youyesyet/canvasser_app/core.cljs b/src/cljs/youyesyet/canvasser_app/core.cljs index 2dbbe2e..f6daa12 100644 --- a/src/cljs/youyesyet/canvasser_app/core.cljs +++ b/src/cljs/youyesyet/canvasser_app/core.cljs @@ -193,6 +193,7 @@ (rf/dispatch [:fetch-locality]) (rf/dispatch [:fetch-options]) (rf/dispatch [:fetch-issues]) + (rf/dispatch [:fetch-followupmethods]) (rf/dispatch [:dispatch-later [{:ms 60000 :dispatch [:process-queue]}]]) (load-interceptors!) (hook-browser-navigation!) diff --git a/src/cljs/youyesyet/canvasser_app/handlers.cljs b/src/cljs/youyesyet/canvasser_app/handlers.cljs index 8c853d5..18c0662 100644 --- a/src/cljs/youyesyet/canvasser_app/handlers.cljs +++ b/src/cljs/youyesyet/canvasser_app/handlers.cljs @@ -236,6 +236,41 @@ :error (:response response)))) +(reg-event-fx + :fetch-followupmethods + (fn [{db :db} _] + (js/console.log "Fetching options") + ;; we return a map of (side) effects + {:http-xhrio {:method :get + :uri (str source-host "json/auto/list-followupmethods") + :format (json-request-format) + :response-format (json-response-format {:keywords? true}) + :on-success [:process-followupmethods] + :on-failure [:bad-followupmethods]} + :db (add-to-feedback db :fetch-followupmethods)})) + + +(reg-event-db + :process-followupmethods + (fn + [db [_ response]] + (let [followupmethods (js->clj response)] + (js/console.log (str "Updating followupmethods: " followupmethods)) + (assoc + (remove-from-feedback db :fetch-followupmethods) + :followupmethods followupmethods)))) + + +(reg-event-db + :bad-followupmethods + (fn [db [_ response]] + (js/console.log "Failed to fetch followupmethods") + (dispatch [:dispatch-later [{:ms 60000 :dispatch [:fetch-followupmethods]}]]) + (assoc + db + :error (:response response)))) + + (reg-event-fx :fetch-issues (fn [{db :db} _] @@ -419,6 +454,13 @@ (assoc (clear-messages db) :elector elector)))) +(reg-event-db + :set-followupmethod + (fn [db [_ method-id]] + (js/console.log (str "Setting followupmethod to " method-id)) + (assoc db :followupmethod method-id))) + + (reg-event-db :set-issue (fn [db [_ issue]] diff --git a/src/cljs/youyesyet/canvasser_app/subscriptions.cljs b/src/cljs/youyesyet/canvasser_app/subscriptions.cljs index 8fd4218..64a0cb1 100644 --- a/src/cljs/youyesyet/canvasser_app/subscriptions.cljs +++ b/src/cljs/youyesyet/canvasser_app/subscriptions.cljs @@ -66,6 +66,16 @@ (fn [db _] (:feedback db))) +(reg-sub + :followupmethod + (fn [db _] + (:followupmethod db))) + +(reg-sub + :followupmethods + (fn [db _] + (:followupmethods db))) + (reg-sub :issue (fn [db _] diff --git a/src/cljs/youyesyet/canvasser_app/views/followup.cljs b/src/cljs/youyesyet/canvasser_app/views/followup.cljs index 115fd15..2013901 100644 --- a/src/cljs/youyesyet/canvasser_app/views/followup.cljs +++ b/src/cljs/youyesyet/canvasser_app/views/followup.cljs @@ -41,8 +41,9 @@ (let [issue @(subscribe [:issue]) issues @(subscribe [:issues]) elector @(subscribe [:elector]) - dwelling @(subscribe [:dwelling])] - (js/console.log (str "Issue is " issue "; elector is " elector)) + dwelling @(subscribe [:dwelling]) + method @(subscribe [:followupmethod])] + (js/console.log (str "followup/panel; Issue is " issue "; elector is " elector "; method is " method)) (cond (nil? dwelling) (ui/error-panel "No dwelling selected") @@ -68,8 +69,19 @@ (map #(let [] [:option {:key % :value %} %]) (keys issues))]] + (if (= issue :Other) + [:p.widget + [:label {:for "issue_detail"} "Issue detail"] + [:input {:type "text" :id "issue_detail" :name "issue_detail"}]]) [:p.widget - [:label {:for "method_detail"} "Telephone number"] + [:label {:for "method"} "Method"] + [:select {:id "method" :name "method" :defaultValue "Phone" + :on-change #(dispatch [:set-followupmethod (.-value (.-target %))])} + (map + #(let [] + [:option {:value (:id %) :key (:id %)} (:id %)]) @(subscribe [:followupmethods]))]] + [:p.widget + [:label {:for "method_detail"} (if (= @(subscribe [:followupmethod]) "Phone") "Telephone number" "EMail Address")] [:input {:type "text" :id "method_detail" :name "method_detail" :on-change #(dispatch [:set-method-detail (.-value (.-target %))])}]] [:p.widget diff --git a/src/cljs/youyesyet/canvasser_app/views/gdpr.cljs b/src/cljs/youyesyet/canvasser_app/views/gdpr.cljs index 4100a33..4372039 100644 --- a/src/cljs/youyesyet/canvasser_app/views/gdpr.cljs +++ b/src/cljs/youyesyet/canvasser_app/views/gdpr.cljs @@ -69,7 +69,7 @@ only against your electoral district, and not link it to you"]]]] [:tr [:td - [:canvas {:id "signature-pad" :on-mouse-out #(send-consent elector)}]]]]]] + [:canvas {:id "signature-pad"}]]]]]] (ui/back-link "#dwelling") (ui/big-link "I consent" :target (str "#elector") diff --git a/youyesyet.adl.xml b/youyesyet.adl.xml index 1ac1fe3..60a5adb 100644 --- a/youyesyet.adl.xml +++ b/youyesyet.adl.xml @@ -44,7 +44,7 @@ version="0.1.1"> People expert on particular issues. Able to read followup requests, and the electors to which they relate; able - to access (read/write) the issues wiki; able to write followuop + to access (read/write) the issues wiki; able to write followup action records. @@ -694,6 +694,9 @@ version="0.1.1"> column="issue_id" entity="issues" farkey="id" distinct="user"> + + +