From f5afa67eedec8ec38a240de911294426f2652287 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Mon, 2 Jul 2018 10:51:42 +0100 Subject: [PATCH] More work on UI, but this commit has a regression The user is no longer correctly stored in the session, and I'm not sure why not. --- env/dev/clj/youyesyet/core.clj | 11 +- project.clj | 4 +- resources/sql/queries.auto.sql | 2 +- resources/sql/youyesyet.postgres.sql | 4 +- .../templates/auto/application-index.html | 66 +- .../auto/form-addresses-Address.html | 66 +- .../auto/form-authorities-Authority.html | 66 +- .../auto/form-canvassers-Canvasser.html | 66 +- .../auto/form-districts-District.html | 66 +- .../auto/form-dwellings-Dwelling.html | 66 +- .../templates/auto/form-electors-Elector.html | 66 +- .../form-followupactions-Followupaction.html | 66 +- .../form-followupmethods-Followupmethod.html | 66 +- ...form-followuprequests-Followuprequest.html | 66 +- .../templates/auto/form-genders-Gender.html | 66 +- .../auto/form-intentions-Intention.html | 66 +- .../templates/auto/form-issues-Issue.html | 66 +- .../templates/auto/form-options-Option.html | 66 +- resources/templates/auto/form-roles-Role.html | 66 +- resources/templates/auto/form-teams-Team.html | 66 +- .../templates/auto/form-visits-Visit.html | 66 +- .../auto/list-addresses-Addresses.html | 133 +- .../auto/list-authorities-Authorities.html | 126 +- .../auto/list-canvassers-Canvassers.html | 126 +- .../auto/list-districts-Districts.html | 126 +- .../auto/list-dwellings-Dwellings.html | 126 +- .../auto/list-electors-Electors.html | 126 +- .../list-followupactions-Followupactions.html | 126 +- .../list-followupmethods-Followupmethods.html | 126 +- ...ist-followuprequests-Followuprequests.html | 126 +- .../templates/auto/list-genders-Genders.html | 126 +- .../auto/list-intentions-Intentions.html | 126 +- .../templates/auto/list-issues-Issues.html | 126 +- .../templates/auto/list-options-Options.html | 126 +- .../templates/auto/list-roles-Roles.html | 126 +- .../templates/auto/list-teams-Teams.html | 126 +- .../templates/auto/list-visits-Visits.html | 126 +- resources/templates/base.html | 6 +- src/clj/youyesyet/db/core.clj | 3 +- src/clj/youyesyet/layout.clj | 35 +- src/clj/youyesyet/middleware.clj | 17 +- src/clj/youyesyet/routes/auto.clj | 1088 +++++++++---- src/clj/youyesyet/routes/auto_json.clj | 1407 +++++++++++++++-- src/clj/youyesyet/routes/home.clj | 84 +- youyesyet.adl.xml | 31 - youyesyet.canonical.adl.xml | 38 +- 46 files changed, 3054 insertions(+), 2821 deletions(-) diff --git a/env/dev/clj/youyesyet/core.clj b/env/dev/clj/youyesyet/core.clj index 1b703a4..c64c2e7 100644 --- a/env/dev/clj/youyesyet/core.clj +++ b/env/dev/clj/youyesyet/core.clj @@ -46,7 +46,9 @@ mount/start-with-args :started)] (log/info component "started")) - (.addShutdownHook (Runtime/getRuntime) (Thread. handler/destroy))) + (.addShutdownHook (Runtime/getRuntime) + (Thread. handler/destroy))) + (defn -main [& args] (cond @@ -57,4 +59,9 @@ (System/exit 0)) :else (start-app args))) - + +(mount/stop) + +(mount/start) + + diff --git a/project.clj b/project.clj index 61956c8..303e26e 100644 --- a/project.clj +++ b/project.clj @@ -62,7 +62,9 @@ [lein-codox "0.10.3"]] :bower-dependencies [[leaflet "0.7.3"] - [jquery "3.3.1"]] + [jquery "3.3.1"] + [datatables.net "1.10.19"] + [datatables.net-dt "1.10.19"]] :bower {:directory "resources/public/js/lib"} :cucumber-feature-paths ["test/clj/features"] diff --git a/resources/sql/queries.auto.sql b/resources/sql/queries.auto.sql index e08aa23..27bdde1 100644 --- a/resources/sql/queries.auto.sql +++ b/resources/sql/queries.auto.sql @@ -1,7 +1,7 @@ ------------------------------------------------------------------------ -- File queries.sql -- --- autogenerated by adl.to-hugsql-queries at 2018-06-30T11:35:59.388Z +-- autogenerated by adl.to-hugsql-queries at 2018-07-01T22:15:28.111Z -- -- See [Application Description -- Language](https://github.com/simon-brooke/adl). diff --git a/resources/sql/youyesyet.postgres.sql b/resources/sql/youyesyet.postgres.sql index e787f6f..a8aab30 100644 --- a/resources/sql/youyesyet.postgres.sql +++ b/resources/sql/youyesyet.postgres.sql @@ -5,7 +5,7 @@ -- -- auto-generated by [Application Description Language framework] -- --- (https://github.com/simon-brooke/adl) at 20180630T113600.308Z +-- (https://github.com/simon-brooke/adl) at 20180701T221532.672Z -- -- -- A web-app intended to be used by canvassers campaigning for a @@ -75,7 +75,7 @@ CREATE TABLE addresses ( id SERIAL NOT NULL PRIMARY KEY, address VARCHAR(256) NOT NULL, - postcode VARCHAR(16) CONSTRAINT pattern_1 CHECK (postcode ~* '^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([AZa-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))[0-9][A-Za-z]{2})$'), + postcode VARCHAR(16) CONSTRAINT pattern_14 CHECK (postcode ~* '^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([AZa-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))[0-9][A-Za-z]{2})$'), phone VARCHAR(16), district_id INTEGER, latitude DOUBLE PRECISION, diff --git a/resources/templates/auto/application-index.html b/resources/templates/auto/application-index.html index c379eea..27f6615 100644 --- a/resources/templates/auto/application-index.html +++ b/resources/templates/auto/application-index.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -184,50 +167,3 @@ All visits made by canvassers to dwellings in which opinions were recorded.
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-addresses-Address.html b/resources/templates/auto/form-addresses-Address.html index ee7c8ba..6fbbbc4 100644 --- a/resources/templates/auto/form-addresses-Address.html +++ b/resources/templates/auto/form-addresses-Address.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -171,50 +154,3 @@ To delete this addresses record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-authorities-Authority.html b/resources/templates/auto/form-authorities-Authority.html index fa47abe..02749f0 100644 --- a/resources/templates/auto/form-authorities-Authority.html +++ b/resources/templates/auto/form-authorities-Authority.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -148,50 +131,3 @@ To delete this authorities record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-canvassers-Canvasser.html b/resources/templates/auto/form-canvassers-Canvasser.html index ba56e4a..7e94c21 100644 --- a/resources/templates/auto/form-canvassers-Canvasser.html +++ b/resources/templates/auto/form-canvassers-Canvasser.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -239,50 +222,3 @@ To delete this canvassers record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-districts-District.html b/resources/templates/auto/form-districts-District.html index 851e38f..733f6f2 100644 --- a/resources/templates/auto/form-districts-District.html +++ b/resources/templates/auto/form-districts-District.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -76,50 +59,3 @@ To delete this districts record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-dwellings-Dwelling.html b/resources/templates/auto/form-dwellings-Dwelling.html index 4a164ab..692539f 100644 --- a/resources/templates/auto/form-dwellings-Dwelling.html +++ b/resources/templates/auto/form-dwellings-Dwelling.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -99,50 +82,3 @@ To delete this dwellings record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-electors-Elector.html b/resources/templates/auto/form-electors-Elector.html index d2ceff2..6ad712a 100644 --- a/resources/templates/auto/form-electors-Elector.html +++ b/resources/templates/auto/form-electors-Elector.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -157,50 +140,3 @@ To delete this electors record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-followupactions-Followupaction.html b/resources/templates/auto/form-followupactions-Followupaction.html index 9486e73..ac42a80 100644 --- a/resources/templates/auto/form-followupactions-Followupaction.html +++ b/resources/templates/auto/form-followupactions-Followupaction.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -158,50 +141,3 @@ To delete this followupactions record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-followupmethods-Followupmethod.html b/resources/templates/auto/form-followupmethods-Followupmethod.html index 0ebe89e..b1810ab 100644 --- a/resources/templates/auto/form-followupmethods-Followupmethod.html +++ b/resources/templates/auto/form-followupmethods-Followupmethod.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -58,50 +41,3 @@ To delete this followupmethods record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-followuprequests-Followuprequest.html b/resources/templates/auto/form-followuprequests-Followuprequest.html index 810e20a..fc30435 100644 --- a/resources/templates/auto/form-followuprequests-Followuprequest.html +++ b/resources/templates/auto/form-followuprequests-Followuprequest.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -148,50 +131,3 @@ To delete this followuprequests record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-genders-Gender.html b/resources/templates/auto/form-genders-Gender.html index 33c1930..9beaae3 100644 --- a/resources/templates/auto/form-genders-Gender.html +++ b/resources/templates/auto/form-genders-Gender.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -58,50 +41,3 @@ To delete this genders record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-intentions-Intention.html b/resources/templates/auto/form-intentions-Intention.html index b2287ec..d04e85a 100644 --- a/resources/templates/auto/form-intentions-Intention.html +++ b/resources/templates/auto/form-intentions-Intention.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -126,50 +109,3 @@ To delete this intentions record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-issues-Issue.html b/resources/templates/auto/form-issues-Issue.html index cd89da2..e2e6ebc 100644 --- a/resources/templates/auto/form-issues-Issue.html +++ b/resources/templates/auto/form-issues-Issue.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -94,50 +77,3 @@ To delete this issues record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-options-Option.html b/resources/templates/auto/form-options-Option.html index 5e4524b..01647cf 100644 --- a/resources/templates/auto/form-options-Option.html +++ b/resources/templates/auto/form-options-Option.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -58,50 +41,3 @@ To delete this options record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-roles-Role.html b/resources/templates/auto/form-roles-Role.html index ed2f57a..6a6986a 100644 --- a/resources/templates/auto/form-roles-Role.html +++ b/resources/templates/auto/form-roles-Role.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -99,50 +82,3 @@ To delete this roles record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-teams-Team.html b/resources/templates/auto/form-teams-Team.html index 6f4bc0d..da15535 100644 --- a/resources/templates/auto/form-teams-Team.html +++ b/resources/templates/auto/form-teams-Team.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -181,50 +164,3 @@ To delete this teams record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/form-visits-Visit.html b/resources/templates/auto/form-visits-Visit.html index 9482227..0607158 100644 --- a/resources/templates/auto/form-visits-Visit.html +++ b/resources/templates/auto/form-visits-Visit.html @@ -1,24 +1,7 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - - -{{site-title}}: {{title}} - - -{% endblock %} {% block content %}
@@ -122,50 +105,3 @@ To delete this visits record
{% endblock %} -{% block foot %} - - -{% endblock %} \ No newline at end of file diff --git a/resources/templates/auto/list-addresses-Addresses.html b/resources/templates/auto/list-addresses-Addresses.html index 7ad3988..532526f 100644 --- a/resources/templates/auto/list-addresses-Addresses.html +++ b/resources/templates/auto/list-addresses-Addresses.html @@ -1,48 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} {% block big-links %} +
- + +
+ {% endblock %} {% block content %} -
+ {% csrf-field %} - - - - + + @@ -91,7 +87,7 @@ longitude @@ -129,63 +125,30 @@ View {% endfor %} - -
- +
-{% endblock %} -{% block foot %} - - {% endblock %} {% block extra-script %} -var form = document.getElementById("content"); -document.getElementById("next-selector").addEventListener("click", function () { - form.submit(); -}); + var form = document.getElementById('list-addresses-Addresses'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); + + {% ifunequal offset \"0\" %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); {% endblock %} diff --git a/resources/templates/auto/list-authorities-Authorities.html b/resources/templates/auto/list-authorities-Authorities.html index d479410..6692a65 100644 --- a/resources/templates/auto/list-authorities-Authorities.html +++ b/resources/templates/auto/list-authorities-Authorities.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -57,7 +69,7 @@ authorize-uri @@ -84,62 +96,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-authorities-Authorities'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-canvassers-Canvassers.html b/resources/templates/auto/list-canvassers-Canvassers.html index 2e2daf8..b1a546f 100644 --- a/resources/templates/auto/list-canvassers-Canvassers.html +++ b/resources/templates/auto/list-canvassers-Canvassers.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -87,7 +99,7 @@ authorised @@ -135,62 +147,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-canvassers-Canvassers'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-districts-Districts.html b/resources/templates/auto/list-districts-Districts.html index 5aa04b4..75c7410 100644 --- a/resources/templates/auto/list-districts-Districts.html +++ b/resources/templates/auto/list-districts-Districts.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -45,7 +57,7 @@ name @@ -66,62 +78,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-districts-Districts'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-dwellings-Dwellings.html b/resources/templates/auto/list-dwellings-Dwellings.html index d4a5468..e71d566 100644 --- a/resources/templates/auto/list-dwellings-Dwellings.html +++ b/resources/templates/auto/list-dwellings-Dwellings.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -51,7 +63,7 @@ sub-address @@ -77,62 +89,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-dwellings-Dwellings'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-electors-Electors.html b/resources/templates/auto/list-electors-Electors.html index 78da6fe..7250f3c 100644 --- a/resources/templates/auto/list-electors-Electors.html +++ b/resources/templates/auto/list-electors-Electors.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -69,7 +81,7 @@ gender @@ -106,62 +118,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-electors-Electors'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-followupactions-Followupactions.html b/resources/templates/auto/list-followupactions-Followupactions.html index c0c7c29..43967c2 100644 --- a/resources/templates/auto/list-followupactions-Followupactions.html +++ b/resources/templates/auto/list-followupactions-Followupactions.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -69,7 +81,7 @@ closed @@ -106,62 +118,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-followupactions-Followupactions'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-followupmethods-Followupmethods.html b/resources/templates/auto/list-followupmethods-Followupmethods.html index fba6c0f..7a2f684 100644 --- a/resources/templates/auto/list-followupmethods-Followupmethods.html +++ b/resources/templates/auto/list-followupmethods-Followupmethods.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -39,7 +51,7 @@ id @@ -57,62 +69,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-followupmethods-Followupmethods'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-followuprequests-Followuprequests.html b/resources/templates/auto/list-followuprequests-Followuprequests.html index 1a92655..20146d0 100644 --- a/resources/templates/auto/list-followuprequests-Followuprequests.html +++ b/resources/templates/auto/list-followuprequests-Followuprequests.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -63,7 +75,7 @@ method_id @@ -101,62 +113,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-followuprequests-Followuprequests'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-genders-Genders.html b/resources/templates/auto/list-genders-Genders.html index d421968..cd81ff6 100644 --- a/resources/templates/auto/list-genders-Genders.html +++ b/resources/templates/auto/list-genders-Genders.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -39,7 +51,7 @@ id @@ -57,62 +69,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-genders-Genders'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-intentions-Intentions.html b/resources/templates/auto/list-intentions-Intentions.html index de75da8..5d2e535 100644 --- a/resources/templates/auto/list-intentions-Intentions.html +++ b/resources/templates/auto/list-intentions-Intentions.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -57,7 +69,7 @@ locality @@ -90,62 +102,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-intentions-Intentions'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-issues-Issues.html b/resources/templates/auto/list-issues-Issues.html index af0eb2c..1cbe0bb 100644 --- a/resources/templates/auto/list-issues-Issues.html +++ b/resources/templates/auto/list-issues-Issues.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -51,7 +63,7 @@ current @@ -75,62 +87,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-issues-Issues'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-options-Options.html b/resources/templates/auto/list-options-Options.html index 3479834..65821ec 100644 --- a/resources/templates/auto/list-options-Options.html +++ b/resources/templates/auto/list-options-Options.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -39,7 +51,7 @@ id @@ -57,62 +69,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-options-Options'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-roles-Roles.html b/resources/templates/auto/list-roles-Roles.html index 8a2a73f..276d38a 100644 --- a/resources/templates/auto/list-roles-Roles.html +++ b/resources/templates/auto/list-roles-Roles.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -45,7 +57,7 @@ name @@ -66,62 +78,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-roles-Roles'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-teams-Teams.html b/resources/templates/auto/list-teams-Teams.html index bbc027c..a353d40 100644 --- a/resources/templates/auto/list-teams-Teams.html +++ b/resources/templates/auto/list-teams-Teams.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -63,7 +75,7 @@ longitude @@ -95,62 +107,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-teams-Teams'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/auto/list-visits-Visits.html b/resources/templates/auto/list-visits-Visits.html index bdcfddb..70a4964 100644 --- a/resources/templates/auto/list-visits-Visits.html +++ b/resources/templates/auto/list-visits-Visits.html @@ -1,32 +1,44 @@ {% extends "base.html" %} - -{% block head %} - - - - - - - - - - - -{{site-title}}: {{title}} - +{% block back-links %} +
+ +
{% endblock %} - -{% block content %} -
+{% block big-links %} +
+ +
+ +{% endblock %} +{% block content %} + +{% csrf-field %} + + @@ -57,7 +69,7 @@ date @@ -88,62 +100,30 @@ View {% endfor %} - - - -
- +
{% endblock %} -{% block foot %} - + var form = document.getElementById('list-visits-Visits'); + var ow = document.getElementById('offset'); + var lw = document.getElementById('limit'); + form.addEventListener('submit', function() { + ow.value='0'; + }); -{% endblock %} \ No newline at end of file + {% ifunequal offset 0 %} + document.getElementById('prev-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)-parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); + {% endifunequal %} + + document.getElementById('next-selector').addEventListener('click', function () { + ow.value=(parseInt(ow.value)+parseInt(lw.value)); + console.log('Updated offset to ' + ow.value); + form.submit(); + }); +{% endblock %} diff --git a/resources/templates/base.html b/resources/templates/base.html index a219f55..93c779c 100644 --- a/resources/templates/base.html +++ b/resources/templates/base.html @@ -11,11 +11,11 @@ {{site-title}}: {{title}} {% script "js/lib/jquery/dist/jquery.min.js" %} + {% endblock %} {% block extra-head %} {% endblock %} - {% endblock %} {% block whole-page %} @@ -48,7 +48,7 @@ {% block big-links %} {% endblock %} - +
{% block content %} @@ -81,13 +81,11 @@ {% endblock %} diff --git a/src/clj/youyesyet/db/core.clj b/src/clj/youyesyet/db/core.clj index 2158558..ccbb495 100644 --- a/src/clj/youyesyet/db/core.clj +++ b/src/clj/youyesyet/db/core.clj @@ -1,5 +1,4 @@ -(ns ^{:doc "Database access functions." - :author "Simon Brooke"} +(ns ^{:doc "Database access functions, mostly from Luminus template."} youyesyet.db.core (:require [cheshire.core :refer [generate-string parse-string]] diff --git a/src/clj/youyesyet/layout.clj b/src/clj/youyesyet/layout.clj index 060082a..2033ecf 100644 --- a/src/clj/youyesyet/layout.clj +++ b/src/clj/youyesyet/layout.clj @@ -50,7 +50,10 @@ user (do (log/debug (str "seeking roles for user " user)) - (set (map #(lower-case (:name %)) (db/list-roles-by-canvasser db/*db* user)))))) + (let [roles + (set (map #(lower-case (:name %)) (db/list-roles-by-canvasser db/*db* user)))] + (log/debug (str "found roles " roles " for user " user)) + roles)))) ;; role assignments change only rarely. @@ -58,22 +61,26 @@ (defn render - "renders the HTML template located relative to resources/templates" + "renders the HTML `template` located relative to resources/templates in + the context of this session and with these parameters." [template session & [params]] (let [user (:user session)] - (content-type - (ok + (log/debug (str "layout/render: template: '" template "'; user: '" user "'.")) + (assoc + (content-type + (ok (parser/render-file - template - (assoc params - :page template - :csrf-token *anti-forgery-token* - :user user - :user-roles (get-user-roles user) - :site-title (:site-title env) - :site-logo (:site-logo env) - :version (System/getProperty "youyesyet.version")))) - "text/html; charset=utf-8"))) + template + (assoc params + :page template + :csrf-token *anti-forgery-token* + :version (System/getProperty "youyesyet.version")))) + "text/html; charset=utf-8") + :user user + :user-roles (get-user-roles user) + :site-title (:site-title env) + :site-logo (:site-logo env) + :session session))) (defn error-page diff --git a/src/clj/youyesyet/middleware.clj b/src/clj/youyesyet/middleware.clj index 96414ac..fe581a2 100644 --- a/src/clj/youyesyet/middleware.clj +++ b/src/clj/youyesyet/middleware.clj @@ -1,16 +1,17 @@ (ns ^{:doc "Plumbing, mainly boilerplate from Luminus."} youyesyet.middleware - (:require [youyesyet.env :refer [defaults]] - [clojure.tools.logging :as log] - [youyesyet.layout :refer [*app-context* error-page]] + (:require [clojure.tools.logging :as log] [ring.middleware.anti-forgery :refer [wrap-anti-forgery]] - [ring.middleware.webjars :refer [wrap-webjars]] + [ring.middleware.defaults :refer [site-defaults wrap-defaults]] [ring.middleware.format :refer [wrap-restful-format]] - [youyesyet.config :refer [env]] + [ring.middleware.webjars :refer [wrap-webjars]] [ring-ttl-session.core :refer [ttl-memory-store]] - [ring.middleware.defaults :refer [site-defaults wrap-defaults]]) + [youyesyet.env :refer [defaults]] + [youyesyet.config :refer [env]] + [youyesyet.layout :refer [*app-context* error-page]]) (:import [javax.servlet ServletContext])) + (defn wrap-context [handler] (fn [request] (binding [*app-context* @@ -26,6 +27,7 @@ (:app-context env))] (handler request)))) + (defn wrap-internal-error [handler] (fn [req] (try @@ -36,6 +38,7 @@ :title "Something very bad has happened!" :message "We've dispatched a team of highly trained gnomes to take care of the problem."}))))) + (defn wrap-csrf [handler] (wrap-anti-forgery handler @@ -44,6 +47,7 @@ {:status 403 :title "Invalid anti-forgery token"})})) + (defn wrap-formats [handler] (let [wrapped (wrap-restful-format handler @@ -53,6 +57,7 @@ ;; since they're not compatible with this middleware ((if (:websocket? request) handler wrapped) request)))) + (defn wrap-base [handler] (-> ((:middleware defaults) handler) wrap-webjars diff --git a/src/clj/youyesyet/routes/auto.clj b/src/clj/youyesyet/routes/auto.clj index 4e02a3a..63860d0 100644 --- a/src/clj/youyesyet/routes/auto.clj +++ b/src/clj/youyesyet/routes/auto.clj @@ -1,9 +1,11 @@ (ns youyesyet.routes.auto - "User interface routes for Youyesyet auto-generated by [Application Description Language framework](https://github.com/simon-brooke/adl) at 20180630T113600.562Z" + "User interface routes for Youyesyet auto-generated by [Application Description Language framework](https://github.com/simon-brooke/adl) at 20180701T221533.599Z" (:require [adl-support.core :as support] [clojure.java.io :as io] + [clojure.set :refer [subset?]] + [clojure.tools.logging :as log] [compojure.core :refer [defroutes GET POST]] [hugsql.core :as hugsql] [noir.response :as nresponse] @@ -25,523 +27,1023 @@ list-addresses-Addresses [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some + #{"district_id" "postcode" "longitude" "id" "latitude" "address" + "locality" "phone"} + (keys p)) + (support/do-or-log-error + (db/search-strings-address db/*db* p) + :message + "Error while searching address records" + :error-return + {:warnings ["Error while searching address records"]}) + (support/do-or-log-error + (db/list-addresses db/*db* {}) + :message + "Error while fetching address records" + :error-return + {:warnings ["Error while fetching address records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-addresses-Addresses.html") - (:session r) - {:title "Addresses", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-address db/*db* p) - (db/list-addresses db/*db* {}))}))) + (:session 'r) + (merge {:title "Addresses", :params p} c)))) (defn form-addresses-Address [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"id"} #{p keys}) (db/get-address db/*db* p)) + :message + "Error while fetching address record" + :error-return + {:warnings ["Error while fetching address record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil), + :districts + (support/do-or-log-error + (db/list-districts db/*db*) + :message + "Error while fetching district record")})] (l/render (support/resolve-template "form-addresses-Address.html") - (:session r) - {:title "Address", - :params p, - :record - (if (empty? (remove nil? (vals p))) [] (db/get-address db/*db* p)), - :districts (db/list-districts db/*db*)}))) + (:session 'r) + (merge {:title "Address", :params p} c)))) (defn list-authorities-Authorities [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some + #{"authorize-uri" "request-token-uri" "access-token-uri" + "consumer-key" "id" "consumer-secret"} + (keys p)) + (support/do-or-log-error + (db/search-strings-authority db/*db* p) + :message + "Error while searching authority records" + :error-return + {:warnings ["Error while searching authority records"]}) + (support/do-or-log-error + (db/list-authorities db/*db* {}) + :message + "Error while fetching authority records" + :error-return + {:warnings ["Error while fetching authority records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-authorities-Authorities.html") - (:session r) - {:title "Authorities", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-authority db/*db* p) - (db/list-authorities db/*db* {}))}))) + (:session 'r) + (merge {:title "Authorities", :params p} c)))) (defn form-authorities-Authority [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"id"} #{p keys}) (db/get-authority db/*db* p)) + :message + "Error while fetching authority record" + :error-return + {:warnings ["Error while fetching authority record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil)})] (l/render (support/resolve-template "form-authorities-Authority.html") - (:session r) - {:title "Authority", - :params p, - :record - (if - (empty? (remove nil? (vals p))) - [] - (db/get-authority db/*db* p))}))) + (:session 'r) + (merge {:title "Authority", :params p} c)))) (defn list-canvassers-Canvassers [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some + #{"username" "address_id" "elector_id" "id" "email" + "authority_id" "authorised" "phone" "fullname" "roles"} + (keys p)) + (support/do-or-log-error + (db/search-strings-canvasser db/*db* p) + :message + "Error while searching canvasser records" + :error-return + {:warnings ["Error while searching canvasser records"]}) + (support/do-or-log-error + (db/list-canvassers db/*db* {}) + :message + "Error while fetching canvasser records" + :error-return + {:warnings ["Error while fetching canvasser records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-canvassers-Canvassers.html") - (:session r) - {:title "Canvassers", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-canvasser db/*db* p) - (db/list-canvassers db/*db* {}))}))) + (:session 'r) + (merge {:title "Canvassers", :params p} c)))) (defn form-canvassers-Canvasser [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"id"} #{p keys}) (db/get-canvasser db/*db* p)) + :message + "Error while fetching canvasser record" + :error-return + {:warnings ["Error while fetching canvasser record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil), + :electors + (support/do-or-log-error + (db/list-electors db/*db*) + :message + "Error while fetching elector record"), + :addresses + (support/do-or-log-error + (db/list-addresses db/*db*) + :message + "Error while fetching address record"), + :authorities + (support/do-or-log-error + (db/list-authorities db/*db*) + :message + "Error while fetching authority record"), + :roles + (support/do-or-log-error + (db/list-roles db/*db*) + :message + "Error while fetching role record")})] (l/render (support/resolve-template "form-canvassers-Canvasser.html") - (:session r) - {:title "Canvasser", - :params p, - :record - (if - (empty? (remove nil? (vals p))) - [] - (db/get-canvasser db/*db* p)), - :electors (db/list-electors db/*db*), - :addresses (db/list-addresses db/*db*), - :authorities (db/list-authorities db/*db*), - :roles (db/list-roles db/*db*)}))) + (:session 'r) + (merge {:title "Canvasser", :params p} c)))) (defn list-districts-Districts [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some #{"id" "name"} (keys p)) + (support/do-or-log-error + (db/search-strings-district db/*db* p) + :message + "Error while searching district records" + :error-return + {:warnings ["Error while searching district records"]}) + (support/do-or-log-error + (db/list-districts db/*db* {}) + :message + "Error while fetching district records" + :error-return + {:warnings ["Error while fetching district records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-districts-Districts.html") - (:session r) - {:title "Districts", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-district db/*db* p) - (db/list-districts db/*db* {}))}))) + (:session 'r) + (merge {:title "Districts", :params p} c)))) (defn form-districts-District [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"id"} #{p keys}) (db/get-district db/*db* p)) + :message + "Error while fetching district record" + :error-return + {:warnings ["Error while fetching district record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil)})] (l/render (support/resolve-template "form-districts-District.html") - (:session r) - {:title "District", - :params p, - :record - (if - (empty? (remove nil? (vals p))) - [] - (db/get-district db/*db* p))}))) + (:session 'r) + (merge {:title "District", :params p} c)))) (defn list-dwellings-Dwellings [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some #{"sub-address" "address_id" "id"} (keys p)) + (support/do-or-log-error + (db/search-strings-dwelling db/*db* p) + :message + "Error while searching dwelling records" + :error-return + {:warnings ["Error while searching dwelling records"]}) + (support/do-or-log-error + (db/list-dwellings db/*db* {}) + :message + "Error while fetching dwelling records" + :error-return + {:warnings ["Error while fetching dwelling records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-dwellings-Dwellings.html") - (:session r) - {:title "Dwellings", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-dwelling db/*db* p) - (db/list-dwellings db/*db* {}))}))) + (:session 'r) + (merge {:title "Dwellings", :params p} c)))) (defn form-dwellings-Dwelling [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"id"} #{p keys}) (db/get-dwelling db/*db* p)) + :message + "Error while fetching dwelling record" + :error-return + {:warnings ["Error while fetching dwelling record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil), + :addresses + (support/do-or-log-error + (db/list-addresses db/*db*) + :message + "Error while fetching address record")})] (l/render (support/resolve-template "form-dwellings-Dwelling.html") - (:session r) - {:title "Dwelling", - :params p, - :record - (if - (empty? (remove nil? (vals p))) - [] - (db/get-dwelling db/*db* p)), - :addresses (db/list-addresses db/*db*)}))) + (:session 'r) + (merge {:title "Dwelling", :params p} c)))) (defn list-electors-Electors [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some + #{"id" "gender" "email" "name" "dwelling_id" "phone"} + (keys p)) + (support/do-or-log-error + (db/search-strings-elector db/*db* p) + :message + "Error while searching elector records" + :error-return + {:warnings ["Error while searching elector records"]}) + (support/do-or-log-error + (db/list-electors db/*db* {}) + :message + "Error while fetching elector records" + :error-return + {:warnings ["Error while fetching elector records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-electors-Electors.html") - (:session r) - {:title "Electors", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-elector db/*db* p) - (db/list-electors db/*db* {}))}))) + (:session 'r) + (merge {:title "Electors", :params p} c)))) (defn form-electors-Elector [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"id"} #{p keys}) (db/get-elector db/*db* p)) + :message + "Error while fetching elector record" + :error-return + {:warnings ["Error while fetching elector record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil), + :dwellings + (support/do-or-log-error + (db/list-dwellings db/*db*) + :message + "Error while fetching dwelling record"), + :genders + (support/do-or-log-error + (db/list-genders db/*db*) + :message + "Error while fetching gender record")})] (l/render (support/resolve-template "form-electors-Elector.html") - (:session r) - {:title "Elector", - :params p, - :record - (if (empty? (remove nil? (vals p))) [] (db/get-elector db/*db* p)), - :dwellings (db/list-dwellings db/*db*), - :genders (db/list-genders db/*db*)}))) + (:session 'r) + (merge {:title "Elector", :params p} c)))) (defn list-followupactions-Followupactions [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some + #{"request_id" "id" "closed" "date" "notes" "actor"} + (keys p)) + (support/do-or-log-error + (db/search-strings-followupaction db/*db* p) + :message + "Error while searching followupaction records" + :error-return + {:warnings ["Error while searching followupaction records"]}) + (support/do-or-log-error + (db/list-followupactions db/*db* {}) + :message + "Error while fetching followupaction records" + :error-return + {:warnings ["Error while fetching followupaction records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-followupactions-Followupactions.html") - (:session r) - {:title "Followupactions", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-followupaction db/*db* p) - (db/list-followupactions db/*db* {}))}))) + (:session 'r) + (merge {:title "Followupactions", :params p} c)))) (defn form-followupactions-Followupaction [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if + (subset? #{"id"} #{p keys}) + (db/get-followupaction db/*db* p)) + :message + "Error while fetching followupaction record" + :error-return + {:warnings ["Error while fetching followupaction record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil), + :followuprequests + (support/do-or-log-error + (db/list-followuprequests db/*db*) + :message + "Error while fetching followuprequest record"), + :canvassers + (support/do-or-log-error + (db/list-canvassers db/*db*) + :message + "Error while fetching canvasser record")})] (l/render (support/resolve-template "form-followupactions-Followupaction.html") - (:session r) - {:title "Followupaction", - :params p, - :record - (if - (empty? (remove nil? (vals p))) - [] - (db/get-followupaction db/*db* p)), - :followuprequests (db/list-followuprequests db/*db*), - :canvassers (db/list-canvassers db/*db*)}))) + (:session 'r) + (merge {:title "Followupaction", :params p} c)))) (defn list-followupmethods-Followupmethods [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some #{"id"} (keys p)) + (support/do-or-log-error + (db/search-strings-followupmethod db/*db* p) + :message + "Error while searching followupmethod records" + :error-return + {:warnings ["Error while searching followupmethod records"]}) + (support/do-or-log-error + (db/list-followupmethods db/*db* {}) + :message + "Error while fetching followupmethod records" + :error-return + {:warnings ["Error while fetching followupmethod records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-followupmethods-Followupmethods.html") - (:session r) - {:title "Followupmethods", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-followupmethod db/*db* p) - (db/list-followupmethods db/*db* {}))}))) + (:session 'r) + (merge {:title "Followupmethods", :params p} c)))) (defn form-followupmethods-Followupmethod [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if + (subset? #{"id"} #{p keys}) + (db/get-followupmethod db/*db* p)) + :message + "Error while fetching followupmethod record" + :error-return + {:warnings ["Error while fetching followupmethod record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil)})] (l/render (support/resolve-template "form-followupmethods-Followupmethod.html") - (:session r) - {:title "Followupmethod", - :params p, - :record - (if - (empty? (remove nil? (vals p))) - [] - (db/get-followupmethod db/*db* p))}))) + (:session 'r) + (merge {:title "Followupmethod", :params p} c)))) (defn list-followuprequests-Followuprequests [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some + #{"elector_id" "id" "issue_id" "visit_id" "method_id"} + (keys p)) + (support/do-or-log-error + (db/search-strings-followuprequest db/*db* p) + :message + "Error while searching followuprequest records" + :error-return + {:warnings ["Error while searching followuprequest records"]}) + (support/do-or-log-error + (db/list-followuprequests db/*db* {}) + :message + "Error while fetching followuprequest records" + :error-return + {:warnings ["Error while fetching followuprequest records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-followuprequests-Followuprequests.html") - (:session r) - {:title "Followuprequests", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-followuprequest db/*db* p) - (db/list-followuprequests db/*db* {}))}))) + (:session 'r) + (merge {:title "Followuprequests", :params p} c)))) (defn form-followuprequests-Followuprequest [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if + (subset? #{"id"} #{p keys}) + (db/get-followuprequest db/*db* p)) + :message + "Error while fetching followuprequest record" + :error-return + {:warnings ["Error while fetching followuprequest record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil), + :electors + (support/do-or-log-error + (db/list-electors db/*db*) + :message + "Error while fetching elector record"), + :visits + (support/do-or-log-error + (db/list-visits db/*db*) + :message + "Error while fetching visit record"), + :issues + (support/do-or-log-error + (db/list-issues db/*db*) + :message + "Error while fetching issue record"), + :followupmethods + (support/do-or-log-error + (db/list-followupmethods db/*db*) + :message + "Error while fetching followupmethod record")})] (l/render (support/resolve-template "form-followuprequests-Followuprequest.html") - (:session r) - {:title "Followuprequest", - :params p, - :record - (if - (empty? (remove nil? (vals p))) - [] - (db/get-followuprequest db/*db* p)), - :electors (db/list-electors db/*db*), - :visits (db/list-visits db/*db*), - :issues (db/list-issues db/*db*), - :followupmethods (db/list-followupmethods db/*db*)}))) + (:session 'r) + (merge {:title "Followuprequest", :params p} c)))) (defn list-genders-Genders [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some #{"id"} (keys p)) + (support/do-or-log-error + (db/search-strings-gender db/*db* p) + :message + "Error while searching gender records" + :error-return + {:warnings ["Error while searching gender records"]}) + (support/do-or-log-error + (db/list-genders db/*db* {}) + :message + "Error while fetching gender records" + :error-return + {:warnings ["Error while fetching gender records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-genders-Genders.html") - (:session r) - {:title "Genders", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-gender db/*db* p) - (db/list-genders db/*db* {}))}))) + (:session 'r) + (merge {:title "Genders", :params p} c)))) (defn form-genders-Gender [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"id"} #{p keys}) (db/get-gender db/*db* p)) + :message + "Error while fetching gender record" + :error-return + {:warnings ["Error while fetching gender record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil)})] (l/render (support/resolve-template "form-genders-Gender.html") - (:session r) - {:title "Gender", - :params p, - :record - (if - (empty? (remove nil? (vals p))) - [] - (db/get-gender db/*db* p))}))) + (:session 'r) + (merge {:title "Gender", :params p} c)))) (defn list-intentions-Intentions [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"Id"})) + c + (let + [records + (if + (some + #{"elector_id" "option_id" "locality" "visit_id" "Id"} + (keys p)) + (support/do-or-log-error + (db/search-strings-intention db/*db* p) + :message + "Error while searching intention records" + :error-return + {:warnings ["Error while searching intention records"]}) + (support/do-or-log-error + (db/list-intentions db/*db* {}) + :message + "Error while fetching intention records" + :error-return + {:warnings ["Error while fetching intention records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-intentions-Intentions.html") - (:session r) - {:title "Intentions", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-intention db/*db* p) - (db/list-intentions db/*db* {}))}))) + (:session 'r) + (merge {:title "Intentions", :params p} c)))) (defn form-intentions-Intention [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"Id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"Id"} #{p keys}) (db/get-intention db/*db* p)) + :message + "Error while fetching intention record" + :error-return + {:warnings ["Error while fetching intention record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil), + :visits + (support/do-or-log-error + (db/list-visits db/*db*) + :message + "Error while fetching visit record"), + :electors + (support/do-or-log-error + (db/list-electors db/*db*) + :message + "Error while fetching elector record"), + :options + (support/do-or-log-error + (db/list-options db/*db*) + :message + "Error while fetching option record")})] (l/render (support/resolve-template "form-intentions-Intention.html") - (:session r) - {:title "Intention", - :params p, - :record - (if - (empty? (remove nil? (vals p))) - [] - (db/get-intention db/*db* p)), - :visits (db/list-visits db/*db*), - :electors (db/list-electors db/*db*), - :options (db/list-options db/*db*)}))) + (:session 'r) + (merge {:title "Intention", :params p} c)))) (defn list-issues-Issues [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some #{"url" "id" "current"} (keys p)) + (support/do-or-log-error + (db/search-strings-issue db/*db* p) + :message + "Error while searching issue records" + :error-return + {:warnings ["Error while searching issue records"]}) + (support/do-or-log-error + (db/list-issues db/*db* {}) + :message + "Error while fetching issue records" + :error-return + {:warnings ["Error while fetching issue records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-issues-Issues.html") - (:session r) - {:title "Issues", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-issue db/*db* p) - (db/list-issues db/*db* {}))}))) + (:session 'r) + (merge {:title "Issues", :params p} c)))) (defn form-issues-Issue [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"id"} #{p keys}) (db/get-issue db/*db* p)) + :message + "Error while fetching issue record" + :error-return + {:warnings ["Error while fetching issue record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil)})] (l/render (support/resolve-template "form-issues-Issue.html") - (:session r) - {:title "Issue", - :params p, - :record - (if (empty? (remove nil? (vals p))) [] (db/get-issue db/*db* p))}))) + (:session 'r) + (merge {:title "Issue", :params p} c)))) (defn list-options-Options [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some #{"id"} (keys p)) + (support/do-or-log-error + (db/search-strings-option db/*db* p) + :message + "Error while searching option records" + :error-return + {:warnings ["Error while searching option records"]}) + (support/do-or-log-error + (db/list-options db/*db* {}) + :message + "Error while fetching option records" + :error-return + {:warnings ["Error while fetching option records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-options-Options.html") - (:session r) - {:title "Options", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-option db/*db* p) - (db/list-options db/*db* {}))}))) + (:session 'r) + (merge {:title "Options", :params p} c)))) (defn form-options-Option [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"id"} #{p keys}) (db/get-option db/*db* p)) + :message + "Error while fetching option record" + :error-return + {:warnings ["Error while fetching option record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil)})] (l/render (support/resolve-template "form-options-Option.html") - (:session r) - {:title "Option", - :params p, - :record - (if - (empty? (remove nil? (vals p))) - [] - (db/get-option db/*db* p))}))) + (:session 'r) + (merge {:title "Option", :params p} c)))) (defn list-roles-Roles [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some #{"members" "id" "name"} (keys p)) + (support/do-or-log-error + (db/search-strings-role db/*db* p) + :message + "Error while searching role records" + :error-return + {:warnings ["Error while searching role records"]}) + (support/do-or-log-error + (db/list-roles db/*db* {}) + :message + "Error while fetching role records" + :error-return + {:warnings ["Error while fetching role records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-roles-Roles.html") - (:session r) - {:title "Roles", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-role db/*db* p) - (db/list-roles db/*db* {}))}))) + (:session 'r) + (merge {:title "Roles", :params p} c)))) (defn form-roles-Role [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"id"} #{p keys}) (db/get-role db/*db* p)) + :message + "Error while fetching role record" + :error-return + {:warnings ["Error while fetching role record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil), + :canvassers + (support/do-or-log-error + (db/list-canvassers db/*db*) + :message + "Error while fetching canvasser record")})] (l/render (support/resolve-template "form-roles-Role.html") - (:session r) - {:title "Role", - :params p, - :record - (if (empty? (remove nil? (vals p))) [] (db/get-role db/*db* p)), - :canvassers (db/list-canvassers db/*db*)}))) + (:session 'r) + (merge {:title "Role", :params p} c)))) (defn list-teams-Teams [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some + #{"organisers" "district_id" "members" "longitude" "id" + "latitude" "name"} + (keys p)) + (support/do-or-log-error + (db/search-strings-team db/*db* p) + :message + "Error while searching team records" + :error-return + {:warnings ["Error while searching team records"]}) + (support/do-or-log-error + (db/list-teams db/*db* {}) + :message + "Error while fetching team records" + :error-return + {:warnings ["Error while fetching team records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-teams-Teams.html") - (:session r) - {:title "Teams", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-team db/*db* p) - (db/list-teams db/*db* {}))}))) + (:session 'r) + (merge {:title "Teams", :params p} c)))) (defn form-teams-Team [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"id"} #{p keys}) (db/get-team db/*db* p)) + :message + "Error while fetching team record" + :error-return + {:warnings ["Error while fetching team record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil), + :districts + (support/do-or-log-error + (db/list-districts db/*db*) + :message + "Error while fetching district record"), + :canvassers + (support/do-or-log-error + (db/list-canvassers db/*db*) + :message + "Error while fetching canvasser record")})] (l/render (support/resolve-template "form-teams-Team.html") - (:session r) - {:title "Team", - :params p, - :record - (if (empty? (remove nil? (vals p))) [] (db/get-team db/*db* p)), - :districts (db/list-districts db/*db*), - :canvassers (db/list-canvassers db/*db*)}))) + (:session 'r) + (merge {:title "Team", :params p} c)))) (defn list-visits-Visits [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [records + (if + (some #{"address_id" "id" "canvasser_id" "date"} (keys p)) + (support/do-or-log-error + (db/search-strings-visit db/*db* p) + :message + "Error while searching visit records" + :error-return + {:warnings ["Error while searching visit records"]}) + (support/do-or-log-error + (db/list-visits db/*db* {}) + :message + "Error while fetching visit records" + :error-return + {:warnings ["Error while fetching visit records"]}))] + (if (:warnings records) records {:records records}))] (l/render (support/resolve-template "list-visits-Visits.html") - (:session r) - {:title "Visits", - :params p, - :records - (if - (not (empty? (remove nil? (vals p)))) - (db/search-strings-visit db/*db* p) - (db/list-visits db/*db* {}))}))) + (:session 'r) + (merge {:title "Visits", :params p} c)))) (defn form-visits-Visit [r] (let - [p (support/massage-params (:params r))] + [p + (merge + {:offset 0, :limit 25} + (support/massage-params (:params r) (:form-params r) #{"id"})) + c + (let + [record + (support/do-or-log-error + (if (subset? #{"id"} #{p keys}) (db/get-visit db/*db* p)) + :message + "Error while fetching visit record" + :error-return + {:warnings ["Error while fetching visit record"]})] + {:warnings (:warnings record), + :record (assoc record :warnings nil), + :addresses + (support/do-or-log-error + (db/list-addresses db/*db*) + :message + "Error while fetching address record"), + :canvassers + (support/do-or-log-error + (db/list-canvassers db/*db*) + :message + "Error while fetching canvasser record")})] (l/render (support/resolve-template "form-visits-Visit.html") - (:session r) - {:title "Visit", - :params p, - :record - (if (empty? (remove nil? (vals p))) [] (db/get-visit db/*db* p)), - :addresses (db/list-addresses db/*db*), - :canvassers (db/list-canvassers db/*db*)}))) + (:session 'r) + (merge {:title "Visit", :params p} c)))) (defn raw-resolve-handler diff --git a/src/clj/youyesyet/routes/auto_json.clj b/src/clj/youyesyet/routes/auto_json.clj index cccc570..9c7234b 100644 --- a/src/clj/youyesyet/routes/auto_json.clj +++ b/src/clj/youyesyet/routes/auto_json.clj @@ -1,10 +1,11 @@ (ns youyesyet.routes.auto-json - "JSON routes for youyesyet auto-generated by [Application Description Language framework](https://github.com/simon-brooke/adl) at 20180630T113559.533Z" + "JSON routes for youyesyet auto-generated by [Application Description Language framework](https://github.com/simon-brooke/adl) at 20180701T221528.540Z" (:require [adl-support.core :as support] - [clojure.java.io :as io] [clojure.core.memoize :as memo] + [clojure.java.io :as io] + [clojure.tools.logging :as log] [compojure.core :refer [defroutes GET POST]] [hugsql.core :as hugsql] [noir.response :as nresponse] @@ -16,228 +17,629 @@ create-address! "Auto-generated method to insert one record to the `addresses` table. Expects the following key(s) to be present in `params`: `(:address :postcode :phone :district_id :latitude :longitude :locality)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-address! params))) + (do + (log/debug + (str + "Calling query '" + "create-address!" + "' with params " + (map + (fn + [p] + (if + (#{"postcode" "address"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/create-address! params))) (defn create-authority! "Auto-generated method to insert one record to the `authorities` table. Expects the following key(s) to be present in `params`: `(:request-token-uri :access-token-uri :authorize-uri :consumer-key :consumer-secret :id)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-authority! params))) + (do + (log/debug + (str + "Calling query '" + "create-authority!" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/create-authority! params))) (defn create-canvasser! "Auto-generated method to insert one record to the `canvassers` table. Expects the following key(s) to be present in `params`: `(:username :fullname :elector_id :address_id :phone :email :authority_id :authorised)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-canvasser! params))) + (do + (log/debug + (str + "Calling query '" + "create-canvasser!" + "' with params " + (map + (fn + [p] + (if + (#{"username" "address_id" "email" "phone" "fullname"} + (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/create-canvasser! params))) (defn create-district! "Auto-generated method to insert one record to the `districts` table. Expects the following key(s) to be present in `params`: `(:name)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-district! params))) + (do + (log/debug + (str + "Calling query '" + "create-district!" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/create-district! params))) (defn create-dwelling! "Auto-generated method to insert one record to the `dwellings` table. Expects the following key(s) to be present in `params`: `(:address_id :sub-address)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-dwelling! params))) + (do + (log/debug + (str + "Calling query '" + "create-dwelling!" + "' with params " + (map + (fn + [p] + (if + (#{"sub-address" "address_id"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/create-dwelling! params))) (defn create-elector! "Auto-generated method to insert one record to the `electors` table. Expects the following key(s) to be present in `params`: `(:name :dwelling_id :phone :email :gender)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-elector! params))) + (do + (log/debug + (str + "Calling query '" + "create-elector!" + "' with params " + (map + (fn + [p] + (if + (#{"gender" "email" "name" "phone"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/create-elector! params))) (defn create-followupaction! "Auto-generated method to insert one record to the `followupactions` table. Expects the following key(s) to be present in `params`: `(:request_id :actor :date :notes :closed)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-followupaction! params))) + (do + (log/debug + (str + "Calling query '" + "create-followupaction!" + "' with params " + (map + (fn + [p] + (if (#{"date" "notes"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/create-followupaction! params))) (defn create-followupmethod! "Auto-generated method to insert one record to the `followupmethods` table. Expects the following key(s) to be present in `params`: `(:id)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-followupmethod! params))) + (do + (log/debug + (str + "Calling query '" + "create-followupmethod!" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/create-followupmethod! params))) (defn create-followuprequest! "Auto-generated method to insert one record to the `followuprequests` table. Expects the following key(s) to be present in `params`: `(:elector_id :visit_id :issue_id :method_id)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-followuprequest! params))) + (do + (log/debug + (str + "Calling query '" + "create-followuprequest!" + "' with params " + (map + (fn + [p] + (if + (#{"elector_id" "issue_id" "visit_id"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/create-followuprequest! params))) (defn create-gender! "Auto-generated method to insert one record to the `genders` table. Expects the following key(s) to be present in `params`: `(:id)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-gender! params))) + (do + (log/debug + (str + "Calling query '" + "create-gender!" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/create-gender! params))) (defn create-intention! "Auto-generated method to insert one record to the `intentions` table. Expects the following key(s) to be present in `params`: `(:visit_id :elector_id :option_id :locality)`. Returns a map containing the keys `#{\"Id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-intention! params))) + (do + (log/debug + (str + "Calling query '" + "create-intention!" + "' with params " + (map + (fn [p] (if (#{} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/create-intention! params))) (defn create-issue! "Auto-generated method to insert one record to the `issues` table. Expects the following key(s) to be present in `params`: `(:url :current :id)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-issue! params))) + (do + (log/debug + (str + "Calling query '" + "create-issue!" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/create-issue! params))) (defn create-option! "Auto-generated method to insert one record to the `options` table. Expects the following key(s) to be present in `params`: `(:id)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-option! params))) + (do + (log/debug + (str + "Calling query '" + "create-option!" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/create-option! params))) (defn create-role! "Auto-generated method to insert one record to the `roles` table. Expects the following key(s) to be present in `params`: `(:name)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-role! params))) + (do + (log/debug + (str + "Calling query '" + "create-role!" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/create-role! params))) (defn create-team! "Auto-generated method to insert one record to the `teams` table. Expects the following key(s) to be present in `params`: `(:name :district_id :latitude :longitude)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-team! params))) + (do + (log/debug + (str + "Calling query '" + "create-team!" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/create-team! params))) (defn create-visit! "Auto-generated method to insert one record to the `visits` table. Expects the following key(s) to be present in `params`: `(:address_id :canvasser_id :date)`. Returns a map containing the keys `#{\"id\"}` identifying the record created." [{:keys [params]}] - (do (db/create-visit! params))) + (do + (log/debug + (str + "Calling query '" + "create-visit!" + "' with params " + (map + (fn + [p] + (if + (#{"address_id" "date"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/create-visit! params))) (defn delete-address! "Auto-generated method to delete one record from the `addresses` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-address! params)) + (do + (log/debug + (str + "Calling query '" + "delete-address!" + "' with params " + (map + (fn + [p] + (if + (#{"postcode" "address"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/delete-address! params)) (response/found "/")) (defn delete-authority! "Auto-generated method to delete one record from the `authorities` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-authority! params)) + (do + (log/debug + (str + "Calling query '" + "delete-authority!" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/delete-authority! params)) (response/found "/")) (defn delete-canvasser! "Auto-generated method to delete one record from the `canvassers` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-canvasser! params)) + (do + (log/debug + (str + "Calling query '" + "delete-canvasser!" + "' with params " + (map + (fn + [p] + (if + (#{"username" "address_id" "email" "phone" "fullname"} + (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/delete-canvasser! params)) (response/found "/")) (defn delete-district! "Auto-generated method to delete one record from the `districts` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-district! params)) + (do + (log/debug + (str + "Calling query '" + "delete-district!" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/delete-district! params)) (response/found "/")) (defn delete-dwelling! "Auto-generated method to delete one record from the `dwellings` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-dwelling! params)) + (do + (log/debug + (str + "Calling query '" + "delete-dwelling!" + "' with params " + (map + (fn + [p] + (if + (#{"sub-address" "address_id"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/delete-dwelling! params)) (response/found "/")) (defn delete-elector! "Auto-generated method to delete one record from the `electors` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-elector! params)) + (do + (log/debug + (str + "Calling query '" + "delete-elector!" + "' with params " + (map + (fn + [p] + (if + (#{"gender" "email" "name" "phone"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/delete-elector! params)) (response/found "/")) (defn delete-followupaction! "Auto-generated method to delete one record from the `followupactions` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-followupaction! params)) + (do + (log/debug + (str + "Calling query '" + "delete-followupaction!" + "' with params " + (map + (fn + [p] + (if (#{"date" "notes"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/delete-followupaction! params)) (response/found "/")) (defn delete-followupmethod! "Auto-generated method to delete one record from the `followupmethods` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-followupmethod! params)) + (do + (log/debug + (str + "Calling query '" + "delete-followupmethod!" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/delete-followupmethod! params)) (response/found "/")) (defn delete-followuprequest! "Auto-generated method to delete one record from the `followuprequests` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-followuprequest! params)) + (do + (log/debug + (str + "Calling query '" + "delete-followuprequest!" + "' with params " + (map + (fn + [p] + (if + (#{"elector_id" "issue_id" "visit_id"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/delete-followuprequest! params)) (response/found "/")) (defn delete-gender! "Auto-generated method to delete one record from the `genders` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-gender! params)) + (do + (log/debug + (str + "Calling query '" + "delete-gender!" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/delete-gender! params)) (response/found "/")) (defn delete-intention! "Auto-generated method to delete one record from the `intentions` table. Expects the following key(s) to be present in `params`: `#{\"Id\"}`." [{:keys [params]}] - (do (db/delete-intention! params)) + (do + (log/debug + (str + "Calling query '" + "delete-intention!" + "' with params " + (map + (fn [p] (if (#{} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/delete-intention! params)) (response/found "/")) (defn delete-issue! "Auto-generated method to delete one record from the `issues` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-issue! params)) + (do + (log/debug + (str + "Calling query '" + "delete-issue!" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/delete-issue! params)) (response/found "/")) (defn delete-option! "Auto-generated method to delete one record from the `options` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-option! params)) + (do + (log/debug + (str + "Calling query '" + "delete-option!" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/delete-option! params)) (response/found "/")) (defn delete-role! "Auto-generated method to delete one record from the `roles` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-role! params)) + (do + (log/debug + (str + "Calling query '" + "delete-role!" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/delete-role! params)) (response/found "/")) (defn delete-team! "Auto-generated method to delete one record from the `teams` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-team! params)) + (do + (log/debug + (str + "Calling query '" + "delete-team!" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/delete-team! params)) (response/found "/")) (defn delete-visit! "Auto-generated method to delete one record from the `visits` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`." [{:keys [params]}] - (do (db/delete-visit! params)) + (do + (log/debug + (str + "Calling query '" + "delete-visit!" + "' with params " + (map + (fn + [p] + (if + (#{"address_id" "date"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/delete-visit! params)) (response/found "/")) (def get-address (memo/ttl - (fn [{:keys [params]}] (do (db/get-address params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-address" + "' with params " + (map + (fn + [p] + (if + (#{"postcode" "address"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/get-address params)) + nil) :ttl/threshold 1000000000)) (def get-authority (memo/ttl - (fn [{:keys [params]}] (do (db/get-authority params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-authority" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/get-authority params)) + nil) :ttl/threshold 10000000000)) (def get-canvasser (memo/ttl - (fn [{:keys [params]}] (do (db/get-canvasser params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-canvasser" + "' with params " + (map + (fn + [p] + (if + (#{"username" "address_id" "email" "phone" "fullname"} + (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/get-canvasser params)) + nil) :ttl/threshold 10000000)) @@ -246,7 +648,22 @@ (memo/ttl (fn [{:keys [params]}] - (do (db/get-canvasser-by-username params)) + (do + (log/debug + (str + "Calling query '" + "get-canvasser-by-username" + "' with params " + (map + (fn + [p] + (if + (#{"username" "address_id" "email" "phone" "fullname"} + (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/get-canvasser-by-username params)) nil) :ttl/threshold 10000000)) @@ -254,21 +671,67 @@ (def get-district (memo/ttl - (fn [{:keys [params]}] (do (db/get-district params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-district" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/get-district params)) + nil) :ttl/threshold 10000000000)) (def get-dwelling (memo/ttl - (fn [{:keys [params]}] (do (db/get-dwelling params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-dwelling" + "' with params " + (map + (fn + [p] + (if + (#{"sub-address" "address_id"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/get-dwelling params)) + nil) :ttl/threshold 1000000000)) (def get-elector (memo/ttl - (fn [{:keys [params]}] (do (db/get-elector params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-elector" + "' with params " + (map + (fn + [p] + (if + (#{"gender" "email" "name" "phone"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/get-elector params)) + nil) :ttl/threshold 100000000)) @@ -276,81 +739,240 @@ get-followupaction "Auto-generated method to select one record from the `followupactions` table. Expects the following key(s) to be present in `params`: `#{\"id\"}`. Returns a map containing the following keys: `clojure.lang.LazySeq@6b32af0e`." [{:keys [params]}] - (do (db/get-followupaction params))) + (do + (log/debug + (str + "Calling query '" + "get-followupaction" + "' with params " + (map + (fn + [p] + (if (#{"date" "notes"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/get-followupaction params))) (def get-followupmethod (memo/ttl - (fn [{:keys [params]}] (do (db/get-followupmethod params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-followupmethod" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/get-followupmethod params)) + nil) :ttl/threshold 10000000000)) (def get-followuprequest (memo/ttl - (fn [{:keys [params]}] (do (db/get-followuprequest params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-followuprequest" + "' with params " + (map + (fn + [p] + (if + (#{"elector_id" "issue_id" "visit_id"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/get-followuprequest params)) + nil) :ttl/threshold 100000)) (def get-gender (memo/ttl - (fn [{:keys [params]}] (do (db/get-gender params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-gender" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/get-gender params)) + nil) :ttl/threshold 1000000000)) -(defn +(def get-intention - "Auto-generated method to select one record from the `intentions` table. Expects the following key(s) to be present in `params`: `#{\"Id\"}`. Returns a map containing the following keys: `clojure.lang.LazySeq@27b20cd9`." - [{:keys [params]}] - (do (db/get-intention params))) + (memo/ttl + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-intention" + "' with params " + (map + (fn [p] (if (#{} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/get-intention params)) + nil) + :ttl/threshold + 100000)) (def get-issue (memo/ttl - (fn [{:keys [params]}] (do (db/get-issue params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-issue" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/get-issue params)) + nil) :ttl/threshold 1000000)) (def get-option (memo/ttl - (fn [{:keys [params]}] (do (db/get-option params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-option" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/get-option params)) + nil) :ttl/threshold 10000000000)) (def get-role (memo/ttl - (fn [{:keys [params]}] (do (db/get-role params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-role" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/get-role params)) + nil) :ttl/threshold 10000000000)) (def get-role-by-name (memo/ttl - (fn [{:keys [params]}] (do (db/get-role-by-name params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-role-by-name" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/get-role-by-name params)) + nil) :ttl/threshold 10000000000)) (def get-team (memo/ttl - (fn [{:keys [params]}] (do (db/get-team params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-team" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/get-team params)) + nil) :ttl/threshold 10000000)) (def get-visit (memo/ttl - (fn [{:keys [params]}] (do (db/get-visit params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "get-visit" + "' with params " + (map + (fn + [p] + (if + (#{"address_id" "date"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/get-visit params)) + nil) :ttl/threshold 100000)) (def list-addresses (memo/ttl - (fn [{:keys [params]}] (do (db/list-addresses params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-addresses" + "' with params " + (map + (fn + [p] + (if + (#{"postcode" "address"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/list-addresses params)) + nil) :ttl/threshold 1000000000)) @@ -362,14 +984,44 @@ (def list-authorities (memo/ttl - (fn [{:keys [params]}] (do (db/list-authorities params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-authorities" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/list-authorities params)) + nil) :ttl/threshold 10000000000)) (def list-canvassers (memo/ttl - (fn [{:keys [params]}] (do (db/list-canvassers params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-canvassers" + "' with params " + (map + (fn + [p] + (if + (#{"username" "address_id" "email" "phone" "fullname"} + (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/list-canvassers params)) + nil) :ttl/threshold 10000000)) @@ -396,14 +1048,43 @@ (def list-districts (memo/ttl - (fn [{:keys [params]}] (do (db/list-districts params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-districts" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/list-districts params)) + nil) :ttl/threshold 10000000000)) (def list-dwellings (memo/ttl - (fn [{:keys [params]}] (do (db/list-dwellings params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-dwellings" + "' with params " + (map + (fn + [p] + (if + (#{"sub-address" "address_id"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/list-dwellings params)) + nil) :ttl/threshold 1000000000)) @@ -415,7 +1096,24 @@ (def list-electors (memo/ttl - (fn [{:keys [params]}] (do (db/list-electors params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-electors" + "' with params " + (map + (fn + [p] + (if + (#{"gender" "email" "name" "phone"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/list-electors params)) + nil) :ttl/threshold 100000000)) @@ -433,7 +1131,18 @@ list-followupactions "Auto-generated method to select all records from the `followupactions` table. If the keys `(:limit :offset)` are present in the request then they will be used to page through the data. Returns a sequence of maps each containing the following keys: `(:request_id :actor :date :notes :closed :id)`." [{:keys [params]}] - (do (db/list-followupactions params))) + (do + (log/debug + (str + "Calling query '" + "list-followupactions" + "' with params " + (map + (fn + [p] + (if (#{"date" "notes"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/list-followupactions params))) (defn list-followupactions-by-canvasser @@ -448,14 +1157,43 @@ (def list-followupmethods (memo/ttl - (fn [{:keys [params]}] (do (db/list-followupmethods params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-followupmethods" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/list-followupmethods params)) + nil) :ttl/threshold 10000000000)) (def list-followuprequests (memo/ttl - (fn [{:keys [params]}] (do (db/list-followuprequests params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-followuprequests" + "' with params " + (map + (fn + [p] + (if + (#{"elector_id" "issue_id" "visit_id"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/list-followuprequests params)) + nil) :ttl/threshold 100000)) @@ -482,15 +1220,40 @@ (def list-genders (memo/ttl - (fn [{:keys [params]}] (do (db/list-genders params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-genders" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/list-genders params)) + nil) :ttl/threshold 1000000000)) -(defn +(def list-intentions - "Auto-generated method to select all records from the `intentions` table. If the keys `(:limit :offset)` are present in the request then they will be used to page through the data. Returns a sequence of maps each containing the following keys: `(:visit_id :elector_id :option_id :locality :Id)`." - [{:keys [params]}] - (do (db/list-intentions params))) + (memo/ttl + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-intentions" + "' with params " + (map + (fn [p] (if (#{} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/list-intentions params)) + nil) + :ttl/threshold + 100000)) (defn list-intentions-by-elector @@ -510,21 +1273,57 @@ (def list-issues (memo/ttl - (fn [{:keys [params]}] (do (db/list-issues params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-issues" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/list-issues params)) + nil) :ttl/threshold 1000000)) (def list-options (memo/ttl - (fn [{:keys [params]}] (do (db/list-options params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-options" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/list-options params)) + nil) :ttl/threshold 10000000000)) (def list-roles (memo/ttl - (fn [{:keys [params]}] (do (db/list-roles params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-roles" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/list-roles params)) + nil) :ttl/threshold 10000000000)) @@ -536,7 +1335,19 @@ (def list-teams (memo/ttl - (fn [{:keys [params]}] (do (db/list-teams params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-teams" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/list-teams params)) + nil) :ttl/threshold 10000000)) @@ -553,7 +1364,24 @@ (def list-visits (memo/ttl - (fn [{:keys [params]}] (do (db/list-visits params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "list-visits" + "' with params " + (map + (fn + [p] + (if + (#{"address_id" "date"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/list-visits params)) + nil) :ttl/threshold 100000)) @@ -570,42 +1398,135 @@ (def search-strings-address (memo/ttl - (fn [{:keys [params]}] (do (db/search-strings-address params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-address" + "' with params " + (map + (fn + [p] + (if + (#{"postcode" "address"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/search-strings-address params)) + nil) :ttl/threshold 1000000000)) (def search-strings-authority (memo/ttl - (fn [{:keys [params]}] (do (db/search-strings-authority params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-authority" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/search-strings-authority params)) + nil) :ttl/threshold 10000000000)) (def search-strings-canvasser (memo/ttl - (fn [{:keys [params]}] (do (db/search-strings-canvasser params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-canvasser" + "' with params " + (map + (fn + [p] + (if + (#{"username" "address_id" "email" "phone" "fullname"} + (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/search-strings-canvasser params)) + nil) :ttl/threshold 10000000)) (def search-strings-district (memo/ttl - (fn [{:keys [params]}] (do (db/search-strings-district params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-district" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/search-strings-district params)) + nil) :ttl/threshold 10000000000)) (def search-strings-dwelling (memo/ttl - (fn [{:keys [params]}] (do (db/search-strings-dwelling params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-dwelling" + "' with params " + (map + (fn + [p] + (if + (#{"sub-address" "address_id"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/search-strings-dwelling params)) + nil) :ttl/threshold 1000000000)) (def search-strings-elector (memo/ttl - (fn [{:keys [params]}] (do (db/search-strings-elector params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-elector" + "' with params " + (map + (fn + [p] + (if + (#{"gender" "email" "name" "phone"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/search-strings-elector params)) + nil) :ttl/threshold 100000000)) @@ -613,14 +1534,34 @@ search-strings-followupaction "Auto-generated method to select all records from the `followupactions` table with any text field matching the value of the key `:pattern` which should be in the request. If the keys `(:limit :offset)` are present in the request then they will be used to page through the data. Returns a sequence of maps each containing the following keys: `(:request_id :actor :date :notes :closed :id)`." [{:keys [params]}] - (do (db/search-strings-followupaction params))) + (do + (log/debug + (str + "Calling query '" + "search-strings-followupaction" + "' with params " + (map + (fn + [p] + (if (#{"date" "notes"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/search-strings-followupaction params))) (def search-strings-followupmethod (memo/ttl (fn [{:keys [params]}] - (do (db/search-strings-followupmethod params)) + (do + (log/debug + (str + "Calling query '" + "search-strings-followupmethod" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/search-strings-followupmethod params)) nil) :ttl/threshold 10000000000)) @@ -630,7 +1571,21 @@ (memo/ttl (fn [{:keys [params]}] - (do (db/search-strings-followuprequest params)) + (do + (log/debug + (str + "Calling query '" + "search-strings-followuprequest" + "' with params " + (map + (fn + [p] + (if + (#{"elector_id" "issue_id" "visit_id"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/search-strings-followuprequest params)) nil) :ttl/threshold 100000)) @@ -638,48 +1593,138 @@ (def search-strings-gender (memo/ttl - (fn [{:keys [params]}] (do (db/search-strings-gender params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-gender" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/search-strings-gender params)) + nil) :ttl/threshold 1000000000)) -(defn +(def search-strings-intention - "Auto-generated method to select all records from the `intentions` table with any text field matching the value of the key `:pattern` which should be in the request. If the keys `(:limit :offset)` are present in the request then they will be used to page through the data. Returns a sequence of maps each containing the following keys: `(:visit_id :elector_id :option_id :locality :Id)`." - [{:keys [params]}] - (do (db/search-strings-intention params))) + (memo/ttl + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-intention" + "' with params " + (map + (fn [p] (if (#{} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/search-strings-intention params)) + nil) + :ttl/threshold + 100000)) (def search-strings-issue (memo/ttl - (fn [{:keys [params]}] (do (db/search-strings-issue params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-issue" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/search-strings-issue params)) + nil) :ttl/threshold 1000000)) (def search-strings-option (memo/ttl - (fn [{:keys [params]}] (do (db/search-strings-option params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-option" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/search-strings-option params)) + nil) :ttl/threshold 10000000000)) (def search-strings-role (memo/ttl - (fn [{:keys [params]}] (do (db/search-strings-role params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-role" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/search-strings-role params)) + nil) :ttl/threshold 10000000000)) (def search-strings-team (memo/ttl - (fn [{:keys [params]}] (do (db/search-strings-team params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-team" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/search-strings-team params)) + nil) :ttl/threshold 10000000)) (def search-strings-visit (memo/ttl - (fn [{:keys [params]}] (do (db/search-strings-visit params)) nil) + (fn + [{:keys [params]}] + (do + (log/debug + (str + "Calling query '" + "search-strings-visit" + "' with params " + (map + (fn + [p] + (if + (#{"address_id" "date"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/search-strings-visit params)) + nil) :ttl/threshold 100000)) @@ -687,91 +1732,241 @@ update-address! "Auto-generated method to update one record in the `addresses` table. Expects the following key(s) to be present in `params`: `(:address :district_id :id :latitude :locality :longitude :phone :postcode)`." [{:keys [params]}] - (do (db/update-address! params)) + (do + (log/debug + (str + "Calling query '" + "update-address!" + "' with params " + (map + (fn + [p] + (if + (#{"postcode" "address"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/update-address! params)) (response/found "/")) (defn update-authority! "Auto-generated method to update one record in the `authorities` table. Expects the following key(s) to be present in `params`: `(:access-token-uri :authorize-uri :consumer-key :consumer-secret :id :request-token-uri)`." [{:keys [params]}] - (do (db/update-authority! params)) + (do + (log/debug + (str + "Calling query '" + "update-authority!" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/update-authority! params)) (response/found "/")) (defn update-canvasser! "Auto-generated method to update one record in the `canvassers` table. Expects the following key(s) to be present in `params`: `(:address_id :authorised :authority_id :elector_id :email :fullname :id :phone :username)`." [{:keys [params]}] - (do (db/update-canvasser! params)) + (do + (log/debug + (str + "Calling query '" + "update-canvasser!" + "' with params " + (map + (fn + [p] + (if + (#{"username" "address_id" "email" "phone" "fullname"} + (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/update-canvasser! params)) (response/found "/")) (defn update-district! "Auto-generated method to update one record in the `districts` table. Expects the following key(s) to be present in `params`: `(:id :name)`." [{:keys [params]}] - (do (db/update-district! params)) + (do + (log/debug + (str + "Calling query '" + "update-district!" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/update-district! params)) (response/found "/")) (defn update-dwelling! "Auto-generated method to update one record in the `dwellings` table. Expects the following key(s) to be present in `params`: `(:address_id :id :sub-address)`." [{:keys [params]}] - (do (db/update-dwelling! params)) + (do + (log/debug + (str + "Calling query '" + "update-dwelling!" + "' with params " + (map + (fn + [p] + (if + (#{"sub-address" "address_id"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/update-dwelling! params)) (response/found "/")) (defn update-elector! "Auto-generated method to update one record in the `electors` table. Expects the following key(s) to be present in `params`: `(:dwelling_id :email :gender :id :name :phone)`." [{:keys [params]}] - (do (db/update-elector! params)) + (do + (log/debug + (str + "Calling query '" + "update-elector!" + "' with params " + (map + (fn + [p] + (if + (#{"gender" "email" "name" "phone"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/update-elector! params)) (response/found "/")) (defn update-followupaction! "Auto-generated method to update one record in the `followupactions` table. Expects the following key(s) to be present in `params`: `(:actor :closed :date :id :notes :request_id)`." [{:keys [params]}] - (do (db/update-followupaction! params)) + (do + (log/debug + (str + "Calling query '" + "update-followupaction!" + "' with params " + (map + (fn + [p] + (if (#{"date" "notes"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/update-followupaction! params)) (response/found "/")) (defn update-followuprequest! "Auto-generated method to update one record in the `followuprequests` table. Expects the following key(s) to be present in `params`: `(:elector_id :id :issue_id :method_id :visit_id)`." [{:keys [params]}] - (do (db/update-followuprequest! params)) + (do + (log/debug + (str + "Calling query '" + "update-followuprequest!" + "' with params " + (map + (fn + [p] + (if + (#{"elector_id" "issue_id" "visit_id"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/update-followuprequest! params)) (response/found "/")) (defn update-intention! "Auto-generated method to update one record in the `intentions` table. Expects the following key(s) to be present in `params`: `(:Id :elector_id :locality :option_id :visit_id)`." [{:keys [params]}] - (do (db/update-intention! params)) + (do + (log/debug + (str + "Calling query '" + "update-intention!" + "' with params " + (map + (fn [p] (if (#{} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/update-intention! params)) (response/found "/")) (defn update-issue! "Auto-generated method to update one record in the `issues` table. Expects the following key(s) to be present in `params`: `(:current :id :url)`." [{:keys [params]}] - (do (db/update-issue! params)) + (do + (log/debug + (str + "Calling query '" + "update-issue!" + "' with params " + (map + (fn [p] (if (#{"id"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/update-issue! params)) (response/found "/")) (defn update-role! "Auto-generated method to update one record in the `roles` table. Expects the following key(s) to be present in `params`: `(:id :name)`." [{:keys [params]}] - (do (db/update-role! params)) + (do + (log/debug + (str + "Calling query '" + "update-role!" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/update-role! params)) (response/found "/")) (defn update-team! "Auto-generated method to update one record in the `teams` table. Expects the following key(s) to be present in `params`: `(:district_id :id :latitude :longitude :name)`." [{:keys [params]}] - (do (db/update-team! params)) + (do + (log/debug + (str + "Calling query '" + "update-team!" + "' with params " + (map + (fn [p] (if (#{"name"} (str (name p))) (params p) "[ELIDED]")) + (keys params)))) + (db/update-team! params)) (response/found "/")) (defn update-visit! "Auto-generated method to update one record in the `visits` table. Expects the following key(s) to be present in `params`: `(:address_id :canvasser_id :date :id)`." [{:keys [params]}] - (do (db/update-visit! params)) + (do + (log/debug + (str + "Calling query '" + "update-visit!" + "' with params " + (map + (fn + [p] + (if + (#{"address_id" "date"} (str (name p))) + (params p) + "[ELIDED]")) + (keys params)))) + (db/update-visit! params)) (response/found "/")) (defroutes diff --git a/src/clj/youyesyet/routes/home.clj b/src/clj/youyesyet/routes/home.clj index 86b2729..bcd418b 100644 --- a/src/clj/youyesyet/routes/home.clj +++ b/src/clj/youyesyet/routes/home.clj @@ -1,17 +1,16 @@ (ns ^{:doc "Routes/pages available to unauthenticated users." :author "Simon Brooke"} youyesyet.routes.home (:require [clojure.java.io :as io] + [clojure.string :as s] [clojure.tools.logging :as log] [clojure.walk :refer [keywordize-keys]] - [noir.response :as nresponse] [noir.util.route :as route] - [ring.util.http-response :refer [content-type ok]] + [ring.util.http-response :as response] [youyesyet.config :refer [env]] [youyesyet.db.core :as db-core] [youyesyet.layout :as layout] [youyesyet.oauth :as oauth] [compojure.core :refer [defroutes GET POST]] - [ring.util.http-response :as response] )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -63,13 +62,13 @@ user (:user session) roles (if user (db-core/list-roles-by-canvasser db-core/*db* {:id (:id user)}))] (cond - roles (layout/render "roles.html" - (:session request) - {:title (str "Welcome " (:fullname user) ", what do you want to do?") - :user user - :roles roles}) - (empty? roles)(response/found "/app") - true (assoc (response/found "/login") :session (dissoc session :user))))) + roles (layout/render "roles.html" + (:session request) + {:title (str "Welcome " (:fullname user) ", what do you want to do?") + :user user + :roles roles}) + (empty? roles)(response/found "/app") + true (assoc (response/found "/login") :session (dissoc session :user))))) (defn home-page [] @@ -86,42 +85,47 @@ password (:password params) redirect-to (or (:redirect-to params) "roles")] (cond - (:authority params) - (let [auth (oauth/authority! (:authority params))] - (if auth - (do - (log/info "Attempting to authorise with authority " (:authority params)) - (oauth/fetch-request-token - (assoc request :session (assoc session :authority auth)) - auth)) - (throw (Exception. (str "No such authority: " (:authority params)))))) - ;; this is obviously, ABSURDLY, insecure. I don't want to put just-about-good-enough, - ;; it-will-do-for-now security in place; instead, I want this to be test code only - ;; until we have o-auth properly working. - (and user (= username password)) - (assoc - (response/found redirect-to) - :session (assoc session :user user :roles (layout/get-user-roles user))) - username + (:authority params) + (let [auth (oauth/authority! (:authority params))] + (if auth + (do + (log/info "Attempting to authorise with authority " (:authority params)) + (oauth/fetch-request-token + (assoc request :session (assoc session :authority auth)) + auth)) + (throw (Exception. (str "No such authority: " (:authority params)))))) + ;; this is obviously, ABSURDLY, insecure. I don't want to put just-about-good-enough, + ;; it-will-do-for-now security in place; instead, I want this to be test code only + ;; until we have o-auth properly working. + (and user (= username password)) + (let + [roles (layout/get-user-roles user)] + (log/info (str "Logged in user '" username "' with roles " roles)) + (assoc + (response/found redirect-to) + :session + (assoc session :user user :roles roles))) + ;; if we've got a username but either no user object or else + ;; the password doesn't match + username (layout/render - "login.html" - session - {:title (str "User " username " is unknown") :redirect-to redirect-to}) - true + "login.html" + session + {:title (str "User " username " is unknown") + :redirect-to redirect-to + :warnings ["Your user name was not recognised or your password did not match"]}) + ;; if we've no username, just invite the user to log in + true (layout/render - "login.html" - session - {:title "Please log in" - :redirect-to redirect-to - :authorities (db-core/list-authorities db-core/*db*)})))) + "login.html" + session + {:title "Please log in" + :redirect-to redirect-to + :authorities (db-core/list-authorities db-core/*db*)})))) (defroutes home-routes (GET "/" [] (home-page)) -;; (GET "/js/:file" [file] -;; (-> (io/input-stream (str "resources/public/js/" file)) -;; ok -;; (content-type "text/javascript;charset=UTF-8"))) (GET "/home" [] (home-page)) (GET "/about" [] (about-page)) (GET "/roles" request (route/restricted (roles-page request))) diff --git a/youyesyet.adl.xml b/youyesyet.adl.xml index d542d6f..ac62804 100644 --- a/youyesyet.adl.xml +++ b/youyesyet.adl.xml @@ -12,37 +12,6 @@ There must also be an administrative interface through which privileged users can set the system up and authorise canvassers, and a 'followup' interface through which issue-expert specialist canvassers can address particular electors' queries. - - - - - - - - - {{site-title}}: {{title}} - - - - - - - See diff --git a/youyesyet.canonical.adl.xml b/youyesyet.canonical.adl.xml index 1034995..60c7984 100644 --- a/youyesyet.canonical.adl.xml +++ b/youyesyet.canonical.adl.xml @@ -21,36 +21,6 @@ There must also be an administrative interface through which privileged users can set the system up and authorise canvassers, and a 'followup' interface through which issue-expert specialist canvassers can address particular electors' queries. - - - - - - - - - {{site-title}}: {{title}} - - - - - - See https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/488478/Bulk_Data_Transfer_-_additional_validation_valid_from_12_November_2015.pdf, @@ -102,7 +72,7 @@ - + @@ -113,8 +83,8 @@ - -
+ +
@@ -332,7 +302,7 @@ - + Intentions of electors to vote for options elicited in visits.