From eb029399e0c3f6029ac34b2bd4f898e3fd71ee93 Mon Sep 17 00:00:00 2001 From: Joshua Carp Date: Wed, 9 Sep 2015 12:06:38 -0400 Subject: [PATCH 1/5] Show election summary. --- static/js/modules/election-summary.js | 43 +++++++++++++++++++++++++++ static/js/pages/landing.js | 2 ++ templates/search.html | 12 ++++---- 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 static/js/modules/election-summary.js diff --git a/static/js/modules/election-summary.js b/static/js/modules/election-summary.js new file mode 100644 index 000000000..8cef3ddd4 --- /dev/null +++ b/static/js/modules/election-summary.js @@ -0,0 +1,43 @@ +'use strict'; + +/* global require, module */ + +var $ = require('jquery'); +var URI = require('URIjs'); + +var helpers = require('./helpers'); + +function ElectionSummary(selector, opts) { + this.$elm = $(selector); + this.opts = opts; + + this.$count = this.$elm.find('.count'); + this.$receipts = this.$elm.find('.receipts'); + this.$disbursements = this.$elm.find('.disbursements'); + + this.fetch(); + this.$elm.find('a.button--election').attr('href', this.buildUrl()); +} + +ElectionSummary.prototype.buildUrl = function() { + var parts = [this.opts.office, this.opts.state, this.opts.district, this.opts.cycle] + .filter(function(part) { + return !!part; + }) + .concat('') + .join('/'); + return URI(parts).toString(); +}; + +ElectionSummary.prototype.fetch = function() { + var url = helpers.buildUrl(['elections', 'summary'], this.opts); + $.getJSON(url).done(this.draw.bind(this)); +}; + +ElectionSummary.prototype.draw = function(response) { + this.$count.text(response.count); + this.$receipts.text(helpers.currency(response.receipts)); + this.$disbursements.text(helpers.currency(response.disbursements)); +}; + +module.exports = {ElectionSummary: ElectionSummary}; diff --git a/static/js/pages/landing.js b/static/js/pages/landing.js index 3b7d9371b..b4c97eded 100644 --- a/static/js/pages/landing.js +++ b/static/js/pages/landing.js @@ -7,6 +7,7 @@ var $ = require('jquery'); var tables = require('../modules/tables'); var columns = require('../modules/columns'); var lookup = require('../modules/election-lookup'); +var summary = require('../modules/election-summary'); var filingsColumns = columns.getColumns( columns.filings, @@ -23,4 +24,5 @@ $(document).ready(function() { }); new lookup.ElectionLookupPreview('#election-preview'); + new summary.ElectionSummary('#election-summary', {cycle: 2016, office: 'president'}); }); diff --git a/templates/search.html b/templates/search.html index 690bc9005..ba19e2d41 100644 --- a/templates/search.html +++ b/templates/search.html @@ -110,22 +110,22 @@

Find electio -
+

Right now in the 2016 presidential election:

Candidates Running
- [number] + [number]
Funds raised
- $[number] -
+ $[number] +
Funds spent
- $[number] + $[number]
- Compare candidates in this election + Compare candidates in this election
From 13bfe494386906b82a9538f87ade0e67fdd84508 Mon Sep 17 00:00:00 2001 From: Joshua Carp Date: Wed, 9 Sep 2015 14:32:40 -0400 Subject: [PATCH 2/5] Delete placeholder text. --- templates/search.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/search.html b/templates/search.html index ba19e2d41..4e1646fec 100644 --- a/templates/search.html +++ b/templates/search.html @@ -115,15 +115,15 @@

Right now in the 2016 presidenti
Candidates Running
- [number] +
Funds raised
- $[number] +
Funds spent
- $[number] +
Compare candidates in this election
From 9c985cdcfe004234164a08843db6de156d03eb5d Mon Sep 17 00:00:00 2001 From: Joshua Carp Date: Wed, 9 Sep 2015 14:42:46 -0400 Subject: [PATCH 3/5] Fix Selenium test. --- tests/selenium/error_page_test.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/selenium/error_page_test.py b/tests/selenium/error_page_test.py index 24e55e33a..92a70a35b 100644 --- a/tests/selenium/error_page_test.py +++ b/tests/selenium/error_page_test.py @@ -1,3 +1,5 @@ +from selenium.webdriver.common.keys import Keys + from .base_test_class import BaseTest @@ -15,7 +17,8 @@ def testErrorPageLoads(self): def testErrorPageSearch(self): self.driver.get(self.url) main = self.driver.find_element_by_tag_name('main') - main.find_element_by_class_name('js-search-input').send_keys('obama') - main.find_element_by_class_name('button--primary').click() + field = main.find_element_by_class_name('js-search-input') + field.send_keys('obama') + field.send_keys(Keys.ENTER) self.elementExistsByClassName('tst-search_results') From ac0e4c08c4feef5686fb8ec59e3e873ed7f287fa Mon Sep 17 00:00:00 2001 From: Joshua Carp Date: Wed, 9 Sep 2015 16:26:06 -0400 Subject: [PATCH 4/5] Prepend classes with "-js". h/t @msecret --- static/js/modules/election-summary.js | 28 +++++++++++++-------------- templates/search.html | 8 ++++---- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/static/js/modules/election-summary.js b/static/js/modules/election-summary.js index 8cef3ddd4..3ef9f9f11 100644 --- a/static/js/modules/election-summary.js +++ b/static/js/modules/election-summary.js @@ -7,28 +7,28 @@ var URI = require('URIjs'); var helpers = require('./helpers'); +function buildUrl(opts) { + var parts = [opts.office, opts.state, opts.district, opts.cycle] + .filter(function(part) { + return !!part; + }) + .concat('') + .join('/'); + return URI(parts).toString(); +} + function ElectionSummary(selector, opts) { this.$elm = $(selector); this.opts = opts; - this.$count = this.$elm.find('.count'); - this.$receipts = this.$elm.find('.receipts'); - this.$disbursements = this.$elm.find('.disbursements'); + this.$count = this.$elm.find('.js-count'); + this.$receipts = this.$elm.find('.js-receipts'); + this.$disbursements = this.$elm.find('.js-disbursements'); this.fetch(); - this.$elm.find('a.button--election').attr('href', this.buildUrl()); + this.$elm.find('.js-election-url').attr('href', buildUrl(this.opts)); } -ElectionSummary.prototype.buildUrl = function() { - var parts = [this.opts.office, this.opts.state, this.opts.district, this.opts.cycle] - .filter(function(part) { - return !!part; - }) - .concat('') - .join('/'); - return URI(parts).toString(); -}; - ElectionSummary.prototype.fetch = function() { var url = helpers.buildUrl(['elections', 'summary'], this.opts); $.getJSON(url).done(this.draw.bind(this)); diff --git a/templates/search.html b/templates/search.html index 4e1646fec..1d7331742 100644 --- a/templates/search.html +++ b/templates/search.html @@ -115,17 +115,17 @@

Right now in the 2016 presidenti
Candidates Running
- +
Funds raised
- +
Funds spent
- +
- Compare candidates in this election + Compare candidates in this election
From ee81f73ac2413b6bd1e2dd87a0f19c8b233cdde0 Mon Sep 17 00:00:00 2001 From: Joshua Carp Date: Wed, 9 Sep 2015 23:11:50 -0400 Subject: [PATCH 5/5] Fix election URLs. h/t @noahmanger --- static/js/modules/election-summary.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/js/modules/election-summary.js b/static/js/modules/election-summary.js index 3ef9f9f11..b3b0e798a 100644 --- a/static/js/modules/election-summary.js +++ b/static/js/modules/election-summary.js @@ -8,7 +8,7 @@ var URI = require('URIjs'); var helpers = require('./helpers'); function buildUrl(opts) { - var parts = [opts.office, opts.state, opts.district, opts.cycle] + var parts = ['elections', opts.office, opts.state, opts.district, opts.cycle] .filter(function(part) { return !!part; })