Tactical commit while I try to understand why the app doesn't rebuild
This commit is contained in:
parent
f5afa67eed
commit
16af040537
45 changed files with 282 additions and 1973 deletions
|
|
@ -1,484 +0,0 @@
|
|||
(ns ^{:doc "Korma-flavour database setup, now obsolete but retained for documentation."
|
||||
:author "Simon Brooke"} youyesyet.db.schema
|
||||
(:require [clojure.java.jdbc :as sql]
|
||||
[korma.core :as kc]
|
||||
[youyesyet.db.core :as yyydb]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;
|
||||
;;;; youyesyet.db.schema: database schema for youyesyet.
|
||||
;;;;
|
||||
;;;; This program is free software; you can redistribute it and/or
|
||||
;;;; modify it under the terms of the GNU General Public License
|
||||
;;;; as published by the Free Software Foundation; either version 2
|
||||
;;;; of the License, or (at your option) any later version.
|
||||
;;;;
|
||||
;;;; This program is distributed in the hope that it will be useful,
|
||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;;;; GNU General Public License for more details.
|
||||
;;;;
|
||||
;;;; You should have received a copy of the GNU General Public License
|
||||
;;;; along with this program; if not, write to the Free Software
|
||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
;;;; USA.
|
||||
;;;;
|
||||
;;;; Copyright (C) 2016 Simon Brooke for Radical Independence Campaign
|
||||
;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
;;; Note that this is the (old) Korma way of doing things;
|
||||
;;; it may not play well with migrations, nor with the HugSQL way of doing things recommended
|
||||
;;; in Web Development with Clojure, Second Ed. So this may be temporary 'get us started' code,
|
||||
;;; which later gets thrown away. The 'create-x-table!' functions in this file may be
|
||||
;;; redundant, and if they are the namespace probably needs to be renamed to 'entities'.
|
||||
;;; See also resources/migrations/20161014170335-basic-setup.up.sql
|
||||
|
||||
(defn create-districts-table!
|
||||
"Create a table to hold the electoral districts in which electors are registered.
|
||||
Note that, as this app is being developed for the independence referendum in which
|
||||
polling is across the whole of Scotland, this part of the design isn't fully thought
|
||||
through; if later adapted to general or local elections, some breakdown or hierarchy
|
||||
of polling districts into constituencies will be required."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:districts
|
||||
;; it may be necessary to have a serial abstract primary key but I suspect
|
||||
;; polling districts already have numbers assigned by the Electoral Commission and
|
||||
;; it would be sensible to use those. TODO: check.
|
||||
[:id "integer not null primary key"]
|
||||
[:name "varchar(64) not null"]
|
||||
;; TODO: it would make sense to hold polygon data for polling districts so we can reflect
|
||||
;; them on the map, but I haven't thought through how to do that yet.
|
||||
)))
|
||||
|
||||
|
||||
(kc/defentity district
|
||||
(kc/pk :id)
|
||||
(kc/table :districts)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id :name))
|
||||
|
||||
|
||||
(defn create-addresses-table!
|
||||
"Create a table to hold the addresses at which electors are registered."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:addresses
|
||||
[:id "serial not null primary key"]
|
||||
;; we do NOT want to hold multiple address records for the same household. When we receive
|
||||
;; the electoral roll data the addresses are likely to be text fields inlined in the elector
|
||||
;; record; in digesting the roll data we need to split these out and resolve them against existing
|
||||
;; addresses in the table, creating a new address record only if there's no match.
|
||||
[:address "varchar(256) not null unique"]
|
||||
[:postcode "varchar(16)"]
|
||||
[:phone "varchar(16)"]
|
||||
;; the electoral district within which this address exists
|
||||
[:district_id "integer references districts(id)"]
|
||||
[:latitude :real]
|
||||
[:longitude :real])))
|
||||
|
||||
|
||||
(kc/defentity address
|
||||
(kc/pk :id)
|
||||
(kc/table :addresses)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id :address :postcode :phone :latitude :longitude)
|
||||
(kc/has-one district))
|
||||
|
||||
|
||||
(defn create-authorities-table!
|
||||
"Create a table to hold the oauth authorities against which we with authenticate canvassers."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:authorities
|
||||
[:id "varchar(32) not null primary key"]
|
||||
;; more stuff here when I understand more
|
||||
)))
|
||||
|
||||
|
||||
(kc/defentity authority
|
||||
(kc/pk :id)
|
||||
(kc/table :authorities)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id))
|
||||
|
||||
|
||||
(defn create-electors-table!
|
||||
"Create a table to hold electors data."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:electors
|
||||
;; id should be the roll number on the electoral roll, I think, but only if this is unique
|
||||
;; across Scotland. Otherwise we need a separate id field. TODO: check.
|
||||
[:id "integer primary key"]
|
||||
[:name "varchar(64) not null"]
|
||||
[:address_id "integer not null references addresses(id)" ]
|
||||
[:phone "varchar(16)"]
|
||||
;; we'll probably only capture email data on electors if they request a followup
|
||||
;; on a particular issue by email.
|
||||
[:email "varchar(128)"])))
|
||||
|
||||
|
||||
(kc/defentity elector
|
||||
(kc/pk :id)
|
||||
(kc/table :electors)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id :name :phone :email)
|
||||
(kc/has-one address))
|
||||
|
||||
|
||||
;;; Lifecycle of the canvasser record goes like this, I think:
|
||||
;;; A canvasser record is created when an existing canvasser issues an invitation to a friend.
|
||||
;;; The invitation takes the form of an automatically generated email with a magic token in it.
|
||||
;;; At this point the record has only an email address, the introduced_by and the magic token,
|
||||
;;; which is itself probably a hash of the email address. Therefore, having the username as the
|
||||
;;; primary key won't work.
|
||||
;;;
|
||||
;;; The invited person clicks on the link in the email and completes the sign-up form, adding
|
||||
;;; their full name, and their phone number. If the username they have chosen is unique, they
|
||||
;;; are then sent a second email with a new magic token, possibly a hash of email address +
|
||||
;;; full name. When they click on the link in this second email, their 'authorised' flag is
|
||||
;;; set to 'true'.
|
||||
;;;
|
||||
;;; Administrators can also create canvasser records directly.aw
|
||||
;;; TODO: Do we actually need a username at all? Wouldn't the email address do?
|
||||
|
||||
(defn create-canvassers-table!
|
||||
"Create a table to hold data on canvassers (including authentication data)."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:canvassers
|
||||
;; id is the username the canvasser logs in as.
|
||||
[:id "serial primary key"]
|
||||
[:username "varchar(32) unique"]
|
||||
[:fullname "varchar(64) not null"]
|
||||
;; most canvassers will be electors, we should link them:
|
||||
[:elector_id "integer references electors(id) on delete no action"]
|
||||
;; but some canvassers may not be electors, so we need contact details separately:
|
||||
[:address_id "integer not null references addresses(id)" ]
|
||||
[:phone "varchar(16)"]
|
||||
[:email "varchar(128)"]
|
||||
;; with which authority do we authenticate this canvasser? I do not want to hold even
|
||||
;; encrypted passwords locally
|
||||
[:authority_id "varchar(32) not null references authorities(id) on delete no action"]
|
||||
[:introduced_by "integer references canvassers(id)"]
|
||||
[:is_admin :boolean]
|
||||
;; true if the canvasser is authorised to use the app; else false. This allows us to
|
||||
;; block canvassers we suspect of misbehaving.
|
||||
[:authorised :boolean])))
|
||||
|
||||
|
||||
(kc/defentity canvasser
|
||||
(kc/pk :id)
|
||||
(kc/table :canvassers)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id :fullname :phone :email :is_admin :authorised)
|
||||
(kc/has-one elector)
|
||||
(kc/has-one address)
|
||||
;; (kc/has-one canvasser {:fk :introduced_by})
|
||||
(kc/has-one authority))
|
||||
|
||||
|
||||
(defn create-visits-table!
|
||||
"Create a table to record visits by canvassers to addresses (including virtual visits by telephone)."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:visits
|
||||
[:id "serial not null primary key"]
|
||||
[:address_id "integer not null references addresses(id)"]
|
||||
[:canvasser_id "integer not null references canvassers(id)"]
|
||||
[:date "timestamp with time zone not null default now()"])))
|
||||
|
||||
|
||||
(kc/defentity visit
|
||||
(kc/pk :id)
|
||||
(kc/table :visits)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id :date)
|
||||
(kc/has-one address)
|
||||
(kc/has-one canvasser))
|
||||
|
||||
|
||||
(defn create-options-table!
|
||||
"Create a table to record options in the vote. This app is being created for the Independence
|
||||
referendum, which will have just two options, 'Yes' and 'No', but it might later be adapted
|
||||
for more general political canvassing."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:options
|
||||
;; id is also the text of the option; e.g. 'Yes', 'No'.
|
||||
[:id "varchar(32) not null primary key"]
|
||||
;; To do elections you probably need party and candidate and stuff here, but
|
||||
;; for the referendum it's unnecessary.
|
||||
)))
|
||||
|
||||
|
||||
(kc/defentity option
|
||||
(kc/pk :id)
|
||||
(kc/table :options)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id))
|
||||
|
||||
|
||||
(defn create-option-district-table!
|
||||
"Create a table to link options to the districts in which they are relevant. This is extremely
|
||||
simple for the referendum: both options are relevant to all districts. This table is essentially
|
||||
'for later expansion'."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:optionsdistricts
|
||||
[:option_id "varchar(32) not null references options(option)"]
|
||||
[:district_id "integer not null references districts(id)"])))
|
||||
|
||||
|
||||
;; I think we don't need an entity for optionsdistricts, because it's just a link table.
|
||||
|
||||
|
||||
(defn create-intention-table!
|
||||
"Create a table to record the intention of an elector as solicited by a canvasser during a visit.
|
||||
TODO: decide whether to insert a record in this table for 'don't knows'."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:intentions
|
||||
[:id "serial primary key"]
|
||||
;; the elector who gave this intention
|
||||
[:elector_id "integer not null references electors(id)"]
|
||||
;; the option the elector said they were planning to vote for
|
||||
[:option_id "varchar(32) not null references options(option)"]
|
||||
[:visit_id "integer not null references visits(id)"])))
|
||||
|
||||
|
||||
(kc/defentity intention
|
||||
(kc/pk :id)
|
||||
(kc/table :intentions)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id)
|
||||
(kc/has-one elector)
|
||||
(kc/has-one option)
|
||||
(kc/has-one visit))
|
||||
|
||||
|
||||
(defn create-issues-table!
|
||||
"A table for issues we predict electors may raise on the doorstep, for which we may be
|
||||
able to provide extra information or arrange for issue-specialists to phone and talk
|
||||
to the elector."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:issues
|
||||
;; short name of this issue, e.g. 'currency', 'defence', 'pensions'
|
||||
[:id "varchar(32) not null primary key"]
|
||||
;; URL of some brief material the canvasser can use on the doorstap
|
||||
[:url "varchar(256)"])))
|
||||
|
||||
|
||||
(kc/defentity issue
|
||||
(kc/pk :id)
|
||||
(kc/table :issues)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id :url))
|
||||
|
||||
|
||||
(defn create-followup-methods-table!
|
||||
"Create a table to hold reference data on followup methods."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:followupmethods
|
||||
[;; the method, e.g. 'telephone', 'email', 'post'
|
||||
:id "varchar(32) not null primary key"])))
|
||||
|
||||
|
||||
(kc/defentity followup-method
|
||||
(kc/pk :id)
|
||||
(kc/table :followupmethods)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id))
|
||||
|
||||
|
||||
(defn create-issue-expertise-table!
|
||||
"A table to record which canvassers have expertise in which issues, so that followup
|
||||
requests can be directed to the right canvassers."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:issueexpertise
|
||||
;; the expert canvasser
|
||||
[:canvasser_id "integer not null references canvassers(id)"]
|
||||
;; the issue they have expertise in
|
||||
[:issue_id "varchar(32) not null references issues(id)"]
|
||||
;; the method by which this expert can respond to electors on this issue
|
||||
[:method_id "varchar(32) not null references followupmethods(id)"])))
|
||||
|
||||
|
||||
(kc/defentity issue-expertise
|
||||
(kc/table :issueexpertise)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id)
|
||||
(kc/has-one canvasser)
|
||||
(kc/has-one issue)
|
||||
(kc/has-one followup-method))
|
||||
|
||||
|
||||
(defn create-followup-requests-table!
|
||||
"Create a table to record requests for followup contacts on particular issues."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:followuprequests
|
||||
[:id "serial primary key"]
|
||||
[:elector_id "integer not null references electors(id)"]
|
||||
[:visit_id "integer not null references visits(id)"]
|
||||
[:issue_id "varchar(32) not null references issues(id)"]
|
||||
;; We probably need a followupmethod (telephone, email, postal) and, for telephone,
|
||||
;; convenient times but I haven't thought through how to represent this or how
|
||||
;; the user interface will work.
|
||||
[:method_id "varchar(32) not null references followupmethods(id)"])))
|
||||
|
||||
|
||||
(kc/defentity followup-request
|
||||
(kc/table :followuprequests)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id)
|
||||
(kc/has-one elector)
|
||||
(kc/has-one visit)
|
||||
(kc/has-one issue)
|
||||
(kc/has-one followup-method))
|
||||
|
||||
|
||||
(defn create-followup-actions-table!
|
||||
"Create a table to record actions on followup requests. Record in this table are almost
|
||||
certainly created through a desktop-style interface rather than through te app, so it's
|
||||
reasonable that there should be narrative fields."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:followupactions
|
||||
[:id "serial primary key"]
|
||||
[:request_id "integer not null references followuprequests(id)"]
|
||||
[:actor "integer not null references canvassers(id)"]
|
||||
[:date "timestamp with time zone not null default now()"]
|
||||
[:notes "text"]
|
||||
;; true if this action closes the request
|
||||
[:closed :boolean])))
|
||||
|
||||
|
||||
(kc/defentity followup-action
|
||||
(kc/table :followupactions)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id :notes :date :closed)
|
||||
(kc/has-one followup-request)
|
||||
(kc/has-one canvasser {:fk :actor}))
|
||||
|
||||
|
||||
|
||||
(defn create-role-table!
|
||||
"Create a table to record roles. I'm not even yet certain that this is strictly necessary,
|
||||
but it allows us to record the fact that different users (canvassers) have different roles
|
||||
in the system."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:roles
|
||||
[:id "serial primary key"]
|
||||
[:name "varchar(64) not null"])))
|
||||
|
||||
|
||||
(defn create-role-membership-table!
|
||||
"Create a link table to record membership of roles."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:rolememberships
|
||||
[:role_id "integer not null references role(id)"]
|
||||
[:canvasser_id "integer not null references canvasser(id)"])))
|
||||
|
||||
|
||||
(kc/defentity role
|
||||
(kc/table :roles)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id :name)
|
||||
(kc/many-to-many canvasser :rolememberships))
|
||||
|
||||
|
||||
(defn create-team-table!
|
||||
"Create a table to record teams."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:teams
|
||||
[:id "serial primary key"]
|
||||
[:name "varchar(64) not null"]
|
||||
;; the electoral district within which this address exists
|
||||
[:district_id "integer references districts(id)"]
|
||||
;; nominal home location of this team
|
||||
[:latitude :real]
|
||||
[:longitude :real])))
|
||||
|
||||
|
||||
(defn create-team-membership-table!
|
||||
"Create a link table to record membership of team."
|
||||
[]
|
||||
(sql/db-do-commands
|
||||
yyydb/*db*
|
||||
(sql/create-table-ddl
|
||||
:teammemberships
|
||||
[:team_id "integer not null references team(id)"]
|
||||
[:canvasser_id "integer not null references canvasser(id)"])))
|
||||
|
||||
|
||||
(kc/defentity team
|
||||
(kc/table :teams)
|
||||
(kc/database yyydb/*db*)
|
||||
(kc/entity-fields :id :name :latitude :longitude)
|
||||
(kc/has-one district)
|
||||
(kc/many-to-many canvasser :teammemberships))
|
||||
|
||||
|
||||
(defn init-db! []
|
||||
"Initialised the whole database."
|
||||
(create-districts-table!)
|
||||
(create-addresses-table!)
|
||||
(create-authorities-table!)
|
||||
(create-electors-table!)
|
||||
(create-canvassers-table!)
|
||||
(create-visits-table!)
|
||||
(create-options-table!)
|
||||
(create-issues-table!)
|
||||
(create-followup-methods-table!)
|
||||
(create-issue-expertise-table!)
|
||||
(create-followup-requests-table!)
|
||||
(create-followup-actions-table!)
|
||||
(create-role-table!)
|
||||
(create-role-membership-table!)
|
||||
(create-team-table!)
|
||||
(create-team-membership-table!)
|
||||
)
|
||||
|
|
@ -9,7 +9,6 @@
|
|||
[youyesyet.config :refer [env]]
|
||||
[youyesyet.layout :refer [error-page]]
|
||||
[youyesyet.middleware :as middleware]
|
||||
[youyesyet.routes.authenticated :refer [authenticated-routes]]
|
||||
[youyesyet.routes.home :refer [home-routes]]
|
||||
[youyesyet.routes.oauth :refer [oauth-routes]]
|
||||
[youyesyet.routes.auto-json :refer [auto-rest-routes]]
|
||||
|
|
@ -73,7 +72,7 @@
|
|||
(wrap-routes middleware/wrap-csrf)
|
||||
(wrap-routes middleware/wrap-formats))
|
||||
'oauth-routes
|
||||
#'authenticated-routes
|
||||
(route/resources "/")
|
||||
(route/not-found
|
||||
(:body
|
||||
(error-page {:status 404
|
||||
|
|
|
|||
|
|
@ -66,21 +66,18 @@
|
|||
[template session & [params]]
|
||||
(let [user (:user session)]
|
||||
(log/debug (str "layout/render: template: '" template "'; user: '" user "'."))
|
||||
(assoc
|
||||
(content-type
|
||||
(ok
|
||||
(content-type
|
||||
(ok
|
||||
(parser/render-file
|
||||
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)))
|
||||
template
|
||||
(assoc params
|
||||
:page template
|
||||
:csrf-token *anti-forgery-token*
|
||||
:user user
|
||||
:user-roles (get-user-roles user)
|
||||
:site-title (:site-title env)
|
||||
:version (System/getProperty "youyesyet.version"))))
|
||||
"text/html; charset=utf-8")))
|
||||
|
||||
|
||||
(defn error-page
|
||||
|
|
|
|||
|
|
@ -1,76 +0,0 @@
|
|||
(ns ^{:doc "Routes/pages available to all authenticated users."
|
||||
:author "Simon Brooke"}
|
||||
youyesyet.routes.authenticated
|
||||
(:require [clojure.java.io :as io]
|
||||
[clojure.walk :refer [keywordize-keys]]
|
||||
[compojure.core :refer [defroutes GET POST]]
|
||||
[noir.response :as nresponse]
|
||||
[noir.util.route :as route]
|
||||
[ring.util.http-response :as response]
|
||||
[youyesyet.layout :as layout]
|
||||
[youyesyet.db.core :as db]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;
|
||||
;;;; youyesyet.routes.authenticated: routes and pages for authenticated users.
|
||||
;;;;
|
||||
;;;; This program is free software; you can redistribute it and/or
|
||||
;;;; modify it under the terms of the GNU General Public License
|
||||
;;;; as published by the Free Software Foundation; either version 2
|
||||
;;;; of the License, or (at your option) any later version.
|
||||
;;;;
|
||||
;;;; This program is distributed in the hope that it will be useful,
|
||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;;;; GNU General Public License for more details.
|
||||
;;;;
|
||||
;;;; You should have received a copy of the GNU General Public License
|
||||
;;;; along with this program; if not, write to the Free Software
|
||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
;;;; USA.
|
||||
;;;;
|
||||
;;;; Copyright (C) 2016 Simon Brooke for Radical Independence Campaign
|
||||
;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;; This code adapted from http://www.luminusweb.net/docs#accessing_the_database
|
||||
|
||||
(defn post?
|
||||
"Return true if the argument is a ring request which is a post request"
|
||||
[request]
|
||||
true)
|
||||
|
||||
(defn canvasser-page
|
||||
"Process this canvasser request, and render the canvasser page"
|
||||
[request]
|
||||
(let [canvasser (if
|
||||
(:params request)
|
||||
(let [params (:params request)]
|
||||
(if (:id params)
|
||||
(if (post? request)
|
||||
(db/update-canvasser! params)
|
||||
(db/create-canvasser! params))
|
||||
(db/get-canvasser (:id params)))
|
||||
))]
|
||||
(layout/render
|
||||
"canvasser.html"
|
||||
(:session request)
|
||||
{:title (if canvasser
|
||||
(str
|
||||
"Edit canvasser "
|
||||
(:fullname canvasser)
|
||||
" "
|
||||
(:email canvasser))
|
||||
"Add new canvasser")
|
||||
:canvasser canvasser
|
||||
:address (if (:address_id canvasser) (db/get-address (:address_id canvasser)))})))
|
||||
|
||||
(defn routing-page
|
||||
"Render the routing page, which offers routes according to the user's roles"
|
||||
[request]
|
||||
(layout/render "routing.html" (:session request)))
|
||||
|
||||
(defroutes authenticated-routes
|
||||
(GET "/edit-canvasser" request (canvasser-page request))
|
||||
(POST "/edit-canvasser" request (canvasser-page request))
|
||||
(GET "/routing" [request] (routing-page request)))
|
||||
|
|
@ -36,12 +36,14 @@
|
|||
;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn app-page []
|
||||
(layout/render "app.html" {}))
|
||||
(defn app-page [request]
|
||||
(layout/render "app.html" {:title "Canvasser app"
|
||||
:user (:user (:session request))}))
|
||||
|
||||
|
||||
(defn about-page []
|
||||
(layout/render "about.html" {} {:title (str "About " (:site-title env))}))
|
||||
(layout/render "about.html" {} {:title
|
||||
(str "About " (:site-title env))}))
|
||||
|
||||
|
||||
(defn call-me-page [request]
|
||||
|
|
@ -129,8 +131,7 @@
|
|||
(GET "/home" [] (home-page))
|
||||
(GET "/about" [] (about-page))
|
||||
(GET "/roles" request (route/restricted (roles-page request)))
|
||||
(GET "/canvassers" [] (route/restricted (app-page)))
|
||||
(GET "/app" [] (route/restricted (app-page)))
|
||||
(GET "/canvassers" [request] (route/restricted (app-page request)))
|
||||
(GET "/call-me" [] (call-me-page nil))
|
||||
(POST "/call-me" request (call-me-page request))
|
||||
(GET "/auth" request (login-page request))
|
||||
|
|
|
|||
|
|
@ -224,3 +224,17 @@
|
|||
(if (integer? zoom)
|
||||
(assoc db :zoom zoom)
|
||||
db)))
|
||||
|
||||
|
||||
(defn get-current-location []
|
||||
"Get the current location from the device."
|
||||
(try
|
||||
(if (.-geolocation js/navigator)
|
||||
(.getCurrentPosition
|
||||
(.-geolocation js/navigator)
|
||||
(fn [position]
|
||||
(dispatch [:set-latitude (.-latitude (.-coords position))])
|
||||
(dispatch [:set-longitude (.-longitude (.-coords position))])))
|
||||
(js/console.log "Geolocation not available"))
|
||||
(catch js/Object any
|
||||
(js/console.log "Exception while trying to access location: " + any))))
|
||||
|
|
|
|||
|
|
@ -27,9 +27,6 @@
|
|||
|
||||
;;; This is the constructor for the atom in which the state of the user interface is held.
|
||||
;;; The atom gets updated by 'events' registered in handler.cljs, q.v.
|
||||
;;;
|
||||
;;; not wonderfully happy with 'db' as a name for this namespace; will probably change to
|
||||
;;; 'client-state'.
|
||||
|
||||
(def default-db
|
||||
{;;; the currently selected address, if any.
|
||||
|
|
@ -87,3 +84,4 @@
|
|||
:latitude 55.82
|
||||
:longitude -4.25
|
||||
:zoom 12})
|
||||
|
||||
|
|
|
|||
|
|
@ -28,15 +28,22 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
(defn back-link []
|
||||
[:div.back-link-container {:id "back-link-container"}
|
||||
[:a {:href "javascript:history.back()" :id "back-link"} "Back"]])
|
||||
(defn back-link
|
||||
"Generate a back link to the preceding page, or, if `target` is specified,
|
||||
to a particular page."
|
||||
([]
|
||||
(back-link "javascript:history.back()"))
|
||||
([target]
|
||||
[:div.back-link-container {:id "back-link-container"}
|
||||
[:a {:href target :id "back-link"} "Back"]]))
|
||||
|
||||
|
||||
(defn big-link [text target]
|
||||
(defn big-link
|
||||
[text & {:keys [target intention]}]
|
||||
[:div.big-link-container {:key target}
|
||||
[:a.big-link {:href target} text]])
|
||||
|
||||
[:a.big-link (merge
|
||||
(if target {:href target}{})
|
||||
(if intention {:on-click intention}))
|
||||
text]])
|
||||
|
||||
(defn nav-link [uri title page collapsed?]
|
||||
(let [selected-page (rf/subscribe [:page])]
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
[dwelling]
|
||||
(ui/big-link
|
||||
(:sub-address dwelling)
|
||||
(str "#/electors/" (:id dwelling))) )
|
||||
:target (str "#/electors/" (:id dwelling))) )
|
||||
(sort
|
||||
#(< (:sub-address %1) (:sub-address %2))
|
||||
(:dwellings address)))]]]))
|
||||
|
|
|
|||
104
src/cljs/youyesyet/canvasser_app/views/elector.cljs
Normal file
104
src/cljs/youyesyet/canvasser_app/views/elector.cljs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
(ns ^{:doc "Canvasser app single elector panel."
|
||||
:author "Simon Brooke"}
|
||||
youyesyet.canvasser-app.views.electors
|
||||
(:require [reagent.core :refer [atom]]
|
||||
[re-frame.core :refer [reg-sub subscribe dispatch]]
|
||||
[youyesyet.canvasser-app.ui-utils :as ui]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;
|
||||
;;;; youyesyet.canvasser-app.views.elector: elector view for youyesyet.
|
||||
;;;;
|
||||
;;;; This program is free software; you can redistribute it and/or
|
||||
;;;; modify it under the terms of the GNU General Public License
|
||||
;;;; as published by the Free Software Foundation; either version 2
|
||||
;;;; of the License, or (at your option) any later version.
|
||||
;;;;
|
||||
;;;; This program is distributed in the hope that it will be useful,
|
||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;;;; GNU General Public License for more details.
|
||||
;;;;
|
||||
;;;; You should have received a copy of the GNU General Public License
|
||||
;;;; along with this program; if not, write to the Free Software
|
||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
;;;; USA.
|
||||
;;;;
|
||||
;;;; Copyright (C) 2016 Simon Brooke for Radical Independence Campaign
|
||||
;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
(defn gender-row
|
||||
"Generate a row containing a cell showing the gender of this `elector`."
|
||||
[elector]
|
||||
(let [gender (:gender elector)
|
||||
image (if gender (name gender) "unknown")]
|
||||
[:tr
|
||||
[:td {:key (:id elector)}
|
||||
[:img {:src (str "img/gender/" image ".png") :alt image}]]]))
|
||||
|
||||
|
||||
(defn name-row
|
||||
"Generate a row containing a cell showing the name of this `elector`."
|
||||
[elector]
|
||||
[:tr
|
||||
[:td {:key (:id elector)}
|
||||
(:name elector)]])
|
||||
|
||||
|
||||
(defn option-row
|
||||
"Generate a row showing this `option` for this elector."
|
||||
[elector option]
|
||||
(let [optid (:id option)
|
||||
optname (name optid)]
|
||||
[:tr {:key (str "options-" optname)}
|
||||
(let [selected (= optid (:intention elector))
|
||||
image (if selected (str "img/option/" optname "-selected.png")
|
||||
(str "img/option/" optname "-unselected.png"))]
|
||||
[:td {:key (str "option-" optid "-" (:id elector))}
|
||||
[:img
|
||||
{:src image
|
||||
:alt optname
|
||||
:on-click #(dispatch
|
||||
[:send-intention {:elector-id (:id elector)
|
||||
:intention optid}])}]])]))
|
||||
|
||||
(defn issue-row
|
||||
"Generate a row containing an issue cell for a particular elector"
|
||||
[elector]
|
||||
[:tr
|
||||
[:td {:key (:id elector)}
|
||||
[:a {:href (str "#/issues/" (:id elector))}
|
||||
[:img {:src "img/issues.png" :alt "Issues"}]]]])
|
||||
|
||||
|
||||
(defn panel
|
||||
"Generate the elector panel."
|
||||
[]
|
||||
(let [address @(subscribe [:address])
|
||||
dwelling @(subscribe [:dwelling])
|
||||
elector @(subscribe [:elector])
|
||||
electors [elector]
|
||||
options @(subscribe [:options])
|
||||
sub-address (:sub-address dwelling)]
|
||||
(if address
|
||||
[:div
|
||||
[:h1 (if sub-address
|
||||
(str sub-address ", " (:address address))
|
||||
(:address address))]
|
||||
[:div.container {:id "main-container"}
|
||||
[:table
|
||||
[:tbody
|
||||
;; genders row
|
||||
(gender-row elector)
|
||||
;; names row
|
||||
(name-row elector)
|
||||
;; options rows
|
||||
(map
|
||||
#(option-row elector %)
|
||||
options)
|
||||
;; issues row
|
||||
(issues-row elector)]]
|
||||
(ui/back-link)]]
|
||||
(ui/error-panel "No address selected"))))
|
||||
|
|
@ -40,15 +40,17 @@
|
|||
;;; Each column contains
|
||||
;;; 1. a stick figure identifying gender (for recognition);
|
||||
;;; 2. the elector's name;
|
||||
;;; 3. one icon for each option on the ballot;
|
||||
;;; 4. an 'issues' icon.
|
||||
;;; The mechanics of how this panel is laid out don't matter.
|
||||
|
||||
(defn gender-cell
|
||||
[elector]
|
||||
(let [gender (:gender elector)
|
||||
image (if gender (name gender) "unknown")]
|
||||
[:td {:key (:id elector)} [:img {:src (str "img/gender/" image ".png") :alt image}]]))
|
||||
[:td {:key (str "gender-" (:id elector))}
|
||||
[:img {:src (str "img/gender/" image ".png") :alt image
|
||||
:on-click #(dispatch
|
||||
[:set-elector-and-page {:elector-id (:id elector)
|
||||
:page "gdpr"}])}]]))
|
||||
|
||||
|
||||
(defn genders-row
|
||||
|
|
@ -60,7 +62,12 @@
|
|||
|
||||
(defn name-cell
|
||||
[elector]
|
||||
[:td {:key (str "name-" (:id elector))} (:name elector)])
|
||||
[:td {:key (str "name-" (:id elector))
|
||||
:on-click #(dispatch
|
||||
[:set-elector-and-page {:elector-id (:id elector)
|
||||
:page "gdpr"}])}
|
||||
(:name elector)])
|
||||
|
||||
|
||||
(defn names-row
|
||||
[electors]
|
||||
|
|
@ -69,41 +76,6 @@
|
|||
#(name-cell %) electors)])
|
||||
|
||||
|
||||
(defn options-row
|
||||
[electors option]
|
||||
(let [optid (:id option)
|
||||
optname (name optid)]
|
||||
[:tr {:key (str "options-" optname)}
|
||||
(map
|
||||
(fn [elector] (let [selected (= optid (:intention elector))
|
||||
image (if selected (str "img/option/" optname "-selected.png")
|
||||
(str "img/option/" optname "-unselected.png"))]
|
||||
[:td {:key (str "option-" optid "-" (:id elector))}
|
||||
[:img
|
||||
{:src image
|
||||
:alt optname
|
||||
:on-click #(dispatch
|
||||
[:send-intention {:elector-id (:id elector)
|
||||
:intention optid}])}]]))
|
||||
;; TODO: impose an ordering on electors - by name or by id
|
||||
electors)]))
|
||||
|
||||
|
||||
(defn issue-cell
|
||||
"Create an issue cell for a particular elector"
|
||||
[elector]
|
||||
[:td {:key (:id elector)}
|
||||
[:a {:href (str "#/issues/" (:id elector))}
|
||||
[:img {:src "img/issues.png" :alt "Issues"}]]])
|
||||
|
||||
|
||||
(defn issues-row
|
||||
[electors]
|
||||
[:tr
|
||||
(map
|
||||
#(issue-cell %)
|
||||
electors)])
|
||||
|
||||
(defn panel
|
||||
"Generate the electors panel."
|
||||
[]
|
||||
|
|
@ -123,13 +95,7 @@
|
|||
;; genders row
|
||||
(genders-row electors)
|
||||
;; names row
|
||||
(names-row electors)
|
||||
;; options rows
|
||||
(map
|
||||
#(options-row electors %)
|
||||
options)
|
||||
;; issues row
|
||||
(issues-row electors)]]
|
||||
(names-row electors)]]
|
||||
(ui/back-link)]]
|
||||
(ui/error-panel "No address selected"))))
|
||||
|
||||
|
|
|
|||
60
src/cljs/youyesyet/canvasser_app/views/gdpr.cljs
Normal file
60
src/cljs/youyesyet/canvasser_app/views/gdpr.cljs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
(ns ^{:doc "Canvasser app electors in household panel."
|
||||
:author "Simon Brooke"}
|
||||
youyesyet.canvasser-app.views.gdpr
|
||||
(:require [reagent.core :refer [atom]]
|
||||
[re-frame.core :refer [reg-sub subscribe dispatch]]
|
||||
[youyesyet.canvasser-app.ui-utils :as ui]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;
|
||||
;;;; youyesyet.canvasser-app.views.gdpr: consent form.
|
||||
;;;;
|
||||
;;;; This program is free software; you can redistribute it and/or
|
||||
;;;; modify it under the terms of the GNU General Public License
|
||||
;;;; as published by the Free Software Foundation; either version 2
|
||||
;;;; of the License, or (at your option) any later version.
|
||||
;;;;
|
||||
;;;; This program is distributed in the hope that it will be useful,
|
||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;;;; GNU General Public License for more details.
|
||||
;;;;
|
||||
;;;; You should have received a copy of the GNU General Public License
|
||||
;;;; along with this program; if not, write to the Free Software
|
||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
;;;; USA.
|
||||
;;;;
|
||||
;;;; Copyright (C) 2016 Simon Brooke for Radical Independence Campaign
|
||||
;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; OK, the idea here is a GDPR consent form to be signed by the elector
|
||||
|
||||
|
||||
(defn gdpr-panel-render
|
||||
[]
|
||||
(let [elector @(subscribe [:elector])]
|
||||
[:div
|
||||
[:h1 "GDPR Consent"]
|
||||
[:div.container {:id "main-container"}
|
||||
(ui/back-link "#electors")
|
||||
[:table
|
||||
[:tbody
|
||||
[:tr
|
||||
[:th "I," (:name elector)]]
|
||||
[:tr
|
||||
[:td
|
||||
[:p "Consent to have data about my voting intention stored by "
|
||||
[:b "Project Hope"]
|
||||
" for use in the current referendum campaign, after which
|
||||
it will be anonymised or deleted."]
|
||||
[:p [:i "If you do not consent, we will store your voting intention
|
||||
only against your electoral district, and not link it to you"]]]]
|
||||
[:tr
|
||||
[:td {:id "signature-pad"}
|
||||
[:canvas]]]]]]
|
||||
(ui/big-link "I consent" :target "#elector") ;; TODO: need to save the signature
|
||||
(ui/big-link "I DO NOT consent" :target "#elector")]))
|
||||
|
||||
|
||||
|
||||
|
|
@ -47,5 +47,5 @@
|
|||
[:div {:id "issue-text"
|
||||
:dangerouslySetInnerHTML
|
||||
{:__html (md->html (issues issue))}}]]
|
||||
(ui/big-link "Request call" "#/followup")
|
||||
(ui/big-link "Request call" :target "#/followup")
|
||||
(ui/back-link)]]))
|
||||
|
|
|
|||
|
|
@ -46,5 +46,5 @@
|
|||
[:div.container {:id "main-container"}
|
||||
(ui/back-link)
|
||||
[:div {:id "issue-list"}
|
||||
(map (fn [k] (ui/big-link k (str "#/issue/" k))) (keys issues))]]]
|
||||
(map (fn [k] (ui/big-link k :target (str "#/issue/" k))) (keys issues))]]]
|
||||
(ui/error-panel "No issues loaded"))))
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
:author "Simon Brooke"}
|
||||
youyesyet.canvasser-app.views.map
|
||||
(:require [re-frame.core :refer [reg-sub subscribe dispatch]]
|
||||
[reagent.core :as reagent]))
|
||||
[reagent.core :as reagent]
|
||||
[youyesyet.canvasser-app.handlers :refer [get-current-location]]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;
|
||||
|
|
@ -115,6 +116,7 @@
|
|||
(defn map-did-mount-mapbox
|
||||
"Did-mount function loading map tile data from MapBox (proprietary)."
|
||||
[]
|
||||
(get-current-location)
|
||||
(let [view (.setView (.map js/L "map" (clj->js {:zoomControl "false"})) #js [55.82 -4.25] 40)]
|
||||
;; NEED TO REPLACE FIXME with your mapID!
|
||||
(.addTo (.tileLayer js/L "http://{s}.tiles.mapbox.com/v3/FIXME/{z}/{x}/{y}.png"
|
||||
|
|
@ -126,6 +128,7 @@
|
|||
(defn map-did-mount-osm
|
||||
"Did-mount function loading map tile data from Open Street Map."
|
||||
[]
|
||||
(get-current-location)
|
||||
(let [view (.setView
|
||||
(.map js/L "map" (clj->js {:zoomControl false}))
|
||||
#js [@(subscribe [:latitude]) @(subscribe [:longitude])]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue