Skip to content

Commit

Permalink
Add early polling locations
Browse files Browse the repository at this point in the history
- Display early polling locations in sidebar, via ejs template
- Create new early voting module to separate early voting out
- introduce ejs for templating and moment for date formatting
  • Loading branch information
carpeliam committed Oct 22, 2016
1 parent 582bbe2 commit c3e4653
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ root = true

# Change these settings to your own preference
indent_style = space
indent_size = 4
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
Expand Down
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h2>Election Day</h2>
<div class="voting-search col-sm-4">
<section class="container-fluid" id="early-voting">
<h3>Early Voting Information</h3>
<p class="lead">More to come</p>
<div id="early-voting-sidebar"></div>
</section>
<section class="container-fluid" id="election-day">
<h3>Find your polling location</h3>
Expand Down
43 changes: 17 additions & 26 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ require.config({
bootstrapTransition: '../bower_components/bootstrap-sass/assets/javascripts/bootstrap/transition',
text: '../bower_components/requirejs-text/text',
geojson: '../bower_components/geojson-google-maps/GeoJSON',
ejs: '../bower_components/ejs/ejs',
moment: '../bower_components/moment/moment',
moment_range: '../bower_components/moment-range/dist/moment-range',
json: 'vendor/json'
},
shim: {
Expand Down Expand Up @@ -59,13 +62,19 @@ require.config({
},
underscore: {
exports: '_'
},
ejs: {
exports: 'ejs'
}
}
});


require(['jquery', 'polling_location_finder', 'bootstrapCollapse'], function($, findPollingLocationFor) {
//'use strict';
require(['jquery',
'early_voting_mgr', 'polling_location_finder',
'json!vendor/EARLY_VOTING_AddressPoints.geojson'],
function($, earlyVotingManager, findPollingLocationFor, earlyPollingJSON) {
'use strict';

// Tab functionality that uses window.location.hash to create "tabs"
// that are linkable/shareable/work with the "back" button etc.
Expand All @@ -89,34 +98,21 @@ require(['jquery', 'polling_location_finder', 'bootstrapCollapse'], function($,

$(window).trigger('hashchange'); // if the user navigated directly to a tab, set that active styling this way

var $address = $('#address');
//
// //starting place for google maps typeahead search
// var defaultBounds = new google.maps.LatLngBounds(
// //harvard square
// new google.maps.LatLng(42.3735695,-71.1233489)
// );

earlyVotingManager.init();

var defaultBounds = new google.maps.LatLngBounds(

var $address = $('#address');

var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(42.360129, -71.148834),
new google.maps.LatLng(42.389868, -71.075535)
);

//
var options = {
var autocomplete = new google.maps.places.Autocomplete($address.get(0), {
bounds: defaultBounds
};


var autocomplete = new google.maps.places.Autocomplete($address.get(0), options);

autocomplete.addListener('place_changed', function() {
// var place = autocomplete.getPlace();
searchForAddress();
});

autocomplete.addListener('place_changed', searchForAddress);


$('#view_directions').on('click', function () {
Expand Down Expand Up @@ -166,11 +162,9 @@ require(['jquery', 'polling_location_finder', 'bootstrapCollapse'], function($,
var address = $address.val();
var geocoder = new google.maps.Geocoder();


// clear details pane
$('#directions').empty();


// go right to the first result if there's only one, or display a list if there are multiples
function displaySearchResults(results) {
var addressClickHandler = function() {
Expand All @@ -193,7 +187,6 @@ require(['jquery', 'polling_location_finder', 'bootstrapCollapse'], function($,

// only valid Cambridge street addresses, please
function addressIsCambridgeStreetAddress(address) {

var zip_index = -1;

var addr_components = address.address_components;
Expand All @@ -210,7 +203,6 @@ require(['jquery', 'polling_location_finder', 'bootstrapCollapse'], function($,
isStreetAddress = ($.inArray('street_address', address.types)) > -1;

return isInCambridge && isStreetAddress;

}

geocoder.geocode({
Expand Down Expand Up @@ -240,7 +232,6 @@ require(['jquery', 'polling_location_finder', 'bootstrapCollapse'], function($,
} else {
displaySearchResults(results);
google.maps.event.trigger(map, 'resize');

}
});
}
Expand Down
34 changes: 34 additions & 0 deletions app/scripts/early_voting_mgr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
define(
[
'jquery', 'moment', 'ejs', 'geojson',
'json!vendor/EARLY_VOTING_AddressPoints.geojson',
'text!templates/early_voting_sidebar.ejs', 'moment_range'
],
function($, moment, ejs, GeoJSON, earlyVotingJSON, earlyVotingSidebarTmpl) {
'use strict';

var earlyVotingLocations = new GeoJSON(earlyVotingJSON);

var $el = $('#early-voting-sidebar');

function getDirections(destination) {
var url;
if (navigator.userAgent.match(/iPhone|iPad|iPod/)) {
url = "http://maps.apple.com/?saddr=Current+Location&daddr=";
} else {
url = "https://maps.google.com/maps?daddr=";
}
return encodeURI(url + destination);
}

return {
init: function() {
$el.html(ejs.render(earlyVotingSidebarTmpl, {
moment: moment,
locations: earlyVotingLocations,
getDirections: getDirections
}));
}
}
}
);
18 changes: 18 additions & 0 deletions app/scripts/templates/early_voting_sidebar.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<% locations.forEach(function(location, i) { %>
<div class="early-voting-location" id="location<%= i %>">
<h4><%= location.geojsonProperties.LOCATION %></h4>
<div>
<a href="<%= getDirections(location.geojsonProperties.Full_Addr + ', Cambridge, MA') %>" target="_blank">Directions</a>
</div>
<ul>
<% location.geojsonProperties.hours.forEach(function(interval) { %>
<%
var dates = moment.range(interval).toDate();
var startDate = moment(dates[0]);
var endDate = moment(dates[1]);
%>
<li><%= startDate.format('MMM Do, h:mma') %> - <%= endDate.format('h:mma') %></li>
<% }) %>
</ul>
</div>
<% }) %>
5 changes: 5 additions & 0 deletions app/scripts/vendor/EARLY_VOTING_AddressPoints.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"Full_Addr": "125 Sixth St",
"Entry": "Primary",
"TYPE": "BUILDING",
"LOCATION":"Robert W. Healy Public Safety Facility",
"hours": [ "2016-10-24T18:00:00.000Z/2016-10-25T00:00:00.000Z",
"2016-10-25T13:00:00.000Z/2016-10-25T21:00:00.000Z",
"2016-10-26T18:00:00.000Z/2016-10-27T00:00:00.000Z",
Expand Down Expand Up @@ -52,6 +53,7 @@
"Full_Addr": "250 Fresh Pond Pkwy",
"Entry": "Primary",
"TYPE": "BUILDING",
"LOCATION": "Cambridge Water Department",
"hours": [ "2016-10-24T18:00:00.000Z/2016-10-25T00:00:00.000Z",
"2016-10-25T13:00:00.000Z/2016-10-25T21:00:00.000Z",
"2016-10-26T18:00:00.000Z/2016-10-27T00:00:00.000Z",
Expand Down Expand Up @@ -84,6 +86,7 @@
"Full_Addr": "51 Inman St",
"Entry": "Primary",
"TYPE": "BUILDING",
"LOCATION": "Department of Human Service Programs",
"hours": [ "2016-10-24T12:30:00.000Z/2016-10-25T00:00:00.000Z",
"2016-10-25T12:30:00.000Z/2016-10-25T21:00:00.000Z",
"2016-10-26T12:30:00.000Z/2016-10-27T00:00:00.000Z",
Expand Down Expand Up @@ -117,6 +120,7 @@
"Full_Addr": "449 Broadway",
"Entry": "Primary",
"TYPE": "BUILDING",
"LOCATION": "Cambridge Public Library",
"hours": [ "2016-10-24T18:00:00.000Z/2016-10-25T00:00:00.000Z",
"2016-10-25T13:00:00.000Z/2016-10-25T21:00:00.000Z",
"2016-10-26T18:00:00.000Z/2016-10-27T00:00:00.000Z",
Expand Down Expand Up @@ -150,6 +154,7 @@
"Entry": "Primary",
"last_edited_date": "2015-10-08",
"TYPE": "BUILDING",
"LOCATION": "O'Neill Branch Library",
"last_edited_user": "JAMERO",
"hours": [ "2016-10-24T18:00:00.000Z/2016-10-25T00:00:00.000Z",
"2016-10-25T13:00:00.000Z/2016-10-25T21:00:00.000Z",
Expand Down
5 changes: 4 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"requirejs-text": "~2.0.10",
"geojson-google-maps": "*",
"font-awesome": "~4.0.2",
"bootstrap-sass": "~3.3.7"
"bootstrap-sass": "~3.3.7",
"moment": "^2.15.1",
"moment-range": "^2.1.0",
"ejs": "^1.0.0"
},
"devDependencies": {}
}
Loading

0 comments on commit c3e4653

Please sign in to comment.