Skip to content

Commit

Permalink
add .env and routes to start #44, remove unused links, make notice fu…
Browse files Browse the repository at this point in the history
…ll screen
  • Loading branch information
kmcurry committed Sep 24, 2018
1 parent eb54de0 commit 4ee6f46
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GEOCODER_KEY=AIzaSyARkBbFV0fE_q9WkLN2PaM-7Ip2JltKy8s
GOOGLE_APIS_KEY=AIzaSyDnUIMupv7DsRZDPB0zkeSJrtn8hSE6uWk

30 changes: 5 additions & 25 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ var path = require('path'),
fs = require('fs'),
locations = require('./locations/locations');

require('dotenv').config();

var app = express();

app.locations = locations;

// allow custom bower install location with default
var bowerComponents = path.join(__dirname + '/bower_components');
if (process.env.BOWER_PATH) {
Expand All @@ -22,36 +26,12 @@ app.use(bodyParser.urlencoded({
app.set('view engine', 'pug');
app.set('views', path.resolve('public/views'));

app.get('/', function(req, res) {
res.render('index', {
locations: JSON.stringify(locations)
});
});

app.get('/about', function(req, res) {
res.render('about');
});

app.get('/eastereggs', function(req, res) {
res.render('easteregg');
});

app.get('/search/:loc', function(req, res) {
var position = null;
if (req.params.loc) {
// verify min format, i.e., comma separated values
position = req.params.loc.split(',');
}

res.render('simple', {
locations: JSON.stringify(locations),
position: position
});
});

// default to port 3000, but allow custom env PORT to override
var port = process.env.PORT || 3000;

app.listen(port, function() {
require('./routes')(app);
console.log('App listening on port ' + port);
});
17 changes: 11 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"body-parser": "^1.18.3",
"bower": "^1.8.4",
"chai": "^4.1.2",
"dotenv": "^6.0.0",
"express": "4.16.2",
"lodash": "^4.17.10",
"nodemon": "^1.18.4",
Expand Down
66 changes: 66 additions & 0 deletions public/css/notice.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
.modal {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
}

.modal-dialog {
position: fixed;
margin: 0;
width: 100%;
height: 100%;
padding: 0;
}

.modal-content {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
border: 2px solid #3c7dcf;
border-radius: 0;
box-shadow: none;
}

.modal-header {
position: absolute;
top: 0;
right: 0;
left: 0;
height: 50px;
padding: 10px;
background: #6598d9;
border: 0;
}

.modal-title {
font-weight: 300;
font-size: 2em;
color: #fff;
line-height: 30px;
}

.modal-body {
font-size:300px;
text-align:center;
position: absolute;
top: 50px;
bottom: 60px;
width: 100%;
font-weight: 300;
overflow: auto;
}

.modal-footer {
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 60px;
padding: 10px;
background: #f1f3f5;
}
44 changes: 22 additions & 22 deletions public/js/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var locations = {};
var searchPosition = [];
//setting a value here can be used to handle errors with unmatched cities
var cityStr = "Not Found";
var objPath;
var DataDirectory;
//Used to filter address by city
var supportedCities = [
"Charlottesville",
Expand Down Expand Up @@ -42,7 +42,7 @@ function getAddress(searchPosition) {
});
}
//Needs work for error handling unmatched cities or states
function setObjPath(address) {
function loadDataDirectory(address) {
//console.log(address);
formattedAddress = address.formatted_address;
console.log("The address is: " + formattedAddress);
Expand All @@ -55,7 +55,7 @@ function setObjPath(address) {
cityPath = cityStr.replace(/\s+/g, '');
console.log("The city to search is: " + cityStr);
//create object path to dynamically insert city into function parameters
objPath = cityPath.split('.').reduce((o, i) => o[i], locations.Virginia);
DataDirectory = cityPath.split('.').reduce((o, i) => o[i], locations.Virginia);
}

function getFeaturesForLocation(address, position) {
Expand All @@ -73,28 +73,28 @@ function getFeaturesForLocation(address, position) {
var LL = L.latLng(ll[1], ll[0]);
// use location to find out which census block they are inside.

getRepresentation(objPath.representatives, address.formatted_address);
getRepresentation(DataDirectory.representatives, address.formatted_address);

L.esri.query({
url: objPath.boundary
url: DataDirectory.boundary
}).intersects(LL).run(function (error, data) {
d3.select("#city").html(cityStr);
getAICUZ(objPath.property.AICUZ, ll);
getEvacuationZone(objPath.evacuation, ll);
getSchools(objPath.schools, ll, 3);
getParks(objPath.recreation.parks, ll, 1);
getClosestThing(objPath.recreation.parks, ll, "park");
getClosestThing(objPath.recreation.libraries, ll, "library");
// getClosestThing(objPath.fire.hydrants.public, ll, "hydrant-public", "feet");
// getClosestThing(objPath.fire.hydrants.private, ll, "hydrant-private", "feet");
getClosestThing(objPath.recreation.centers, ll, "recCenter");
getNearbyNeighborhoods(objPath.neighborhoods, ll, 1, "neighborhoods")
getAverageResponseTime(objPath.medical.emergency.calls, ll, .25, "ems");
getAverageResponseTime(objPath.police.calls, ll, .25, "police");
getPoliceIncidents(objPath.police.incidents, ll, .5, 30);
//getCountWithinDays(objPath.police.calls, ll, 1, 30, "police-calls");
getFloodZone(objPath.property.FIRM, ll);
getPropertySales(objPath.property.sales, address)
getAICUZ(DataDirectory.property.AICUZ, ll);
getEvacuationZone(DataDirectory.evacuation, ll);
getSchools(DataDirectory.schools, ll, 3);
getParks(DataDirectory.recreation.parks, ll, 1);
getClosestThing(DataDirectory.recreation.parks, ll, "park");
getClosestThing(DataDirectory.recreation.libraries, ll, "library");
// getClosestThing(DataDirectory.fire.hydrants.public, ll, "hydrant-public", "feet");
// getClosestThing(DataDirectory.fire.hydrants.private, ll, "hydrant-private", "feet");
getClosestThing(DataDirectory.recreation.centers, ll, "recCenter");
getNearbyNeighborhoods(DataDirectory.neighborhoods, ll, 1, "neighborhoods")
getAverageResponseTime(DataDirectory.medical.emergency.calls, ll, .25, "ems");
getAverageResponseTime(DataDirectory.police.calls, ll, .25, "police");
getPoliceIncidents(DataDirectory.police.incidents, ll, .5, 30);
//getCountWithinDays(DataDirectory.police.calls, ll, 1, 30, "police-calls");
getFloodZone(DataDirectory.property.FIRM, ll);
getPropertySales(DataDirectory.property.sales, address)
});
}

Expand Down Expand Up @@ -1010,7 +1010,7 @@ async function start() {
await getAddress(searchPosition)
.then(function (address) {
var addr = address;
setObjPath(address);
loadDataDirectory(address);
getFeaturesForLocation(addr, searchPosition);
})
.catch(function (err) {
Expand Down
3 changes: 2 additions & 1 deletion public/views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ script(src="/bower_components/bootstrap/dist/js/bootstrap.min.js")
script(src="/bower_components/jquery-ui/jquery-ui.min.js")
link(rel="stylesheet"
href="/bower_components/jquery-ui/themes/smoothness/jquery-ui.css")
script(src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDnUIMupv7DsRZDPB0zkeSJrtn8hSE6uWk&libraries=places&callback=initAutocomplete" async defer)
script(src="/js/index.js")
script(src="/js/google.js")
script(src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDnUIMupv7DsRZDPB0zkeSJrtn8hSE6uWk&libraries=places&callback=initAutocomplete" async defer)



3 changes: 2 additions & 1 deletion public/views/notice.pug
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
link(rel='stylesheet', href="/css/notice.css")
div(class="modal fade" tabindex="-1" role="dialog" id="notice")
div(class="modal-dialog" role="document")
div(class="modal-content")
div(class="modal-header")
h1(class="modal-title" style="text-align:center") Evacuation Zone
button(type="button" class="close" data-dismiss="modal" aria-label="Close")
span(aria-hidden="true")
div(class="modal-body" style="font-size:100px;text-align:center")
div(class="modal-body")
div(id="modal-body")
div(id="modal-detail" style="font-size:30px !important;")
p
Expand Down
42 changes: 42 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*jslint node: true*/
var routeLoader = function (app) {

app.use(function (req, res, next) {
console.debug(req.ip + " request for " + req.path);
next();
});

app.get('/', function (req, res) {
res.render('index', {
locations: JSON.stringify(app.locations)
});
});

app.get('/about', function (req, res) {
res.render('about');
});

app.get('/eastereggs', function (req, res) {
res.render('easteregg');
});

app.get('/search/:loc', function (req, res) {
var position = null;
if (req.params.loc) {
// verify min format, i.e., comma separated values
position = req.params.loc.split(',');
}

res.render('simple', {
locations: JSON.stringify(app.locations),
position: position
});
});

// app.use(function (req, res, next) {
// res.status(404).render('404');
// });

};

module.exports = routeLoader;

0 comments on commit 4ee6f46

Please sign in to comment.