Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dependencies and Make Generic for Any City #183

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify configurations
samc1213 committed Sep 2, 2023
commit 18c18e2fc464218fc8c6f778500aa34b0ba21d45
13 changes: 0 additions & 13 deletions config/config.json

This file was deleted.

File renamed without changes.
7 changes: 0 additions & 7 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
'use strict';

module.exports = function (grunt) {
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
require('time-grunt')(grunt);
require('load-grunt-tasks')(grunt);

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
migrations: {
path: __dirname + '/migrations',
template: grunt.file.read( __dirname + "/migrations/_template.js"),
mongo: process.env.MONGOLAB_URI || 'mongodb://localhost/recycling_' + process.env.NODE_ENV,
ext: 'js'
},
jshint: {
files: ['public/js/*.js'],
options: {
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@
"version": "0.0.1",
"private": "true",
"scripts": {
"postinstall": "script/postinstall.sh",
"test": "mocha test/unit/*.js"
},
"dependencies": {
10 changes: 5 additions & 5 deletions public/js/app.js
Original file line number Diff line number Diff line change
@@ -53,30 +53,30 @@
};

$(document).ready(function(){
WIMR.clientConfig = null
WIMR.config = null
if ($('#map').length) {
$(window).one('locationsLoaded', function(){
$("#mapSpinner").hide();
WIMR.dialog.hashChange();
});
$("#mapSpinner .show").spin("show");

$.getJSON("/clientconfig.json")
$.getJSON("/config.json")
.done(cc => {
WIMR.clientConfig = cc;
WIMR.config = cc;

// WIMR is simply an application namespace,
// defined in /views/_footer.ejs
WIMR.map = WIMR.createMap('map');
})
.always(() => {
WIMR.dialog.showTemplate('search_form', {clientConfig: WIMR.clientConfig});
WIMR.dialog.showTemplate('search_form', {config: WIMR.config});
});

$('body').on('click', '.start-over', function(e){
e.preventDefault();
WIMR.map.wimrReset();
WIMR.dialog.showTemplate('search_form', {clientConfig: WIMR.clientConfig});
WIMR.dialog.showTemplate('search_form', {config: WIMR.config});
window.location.hash = "";
});

4 changes: 2 additions & 2 deletions public/js/map.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
WIMR.createMap = function(id) {
var map = L.map(id, {
maxZoom: 20
}).setView(WIMR.clientConfig.citycentercoordinates, 11);
}).setView(WIMR.config.citycentercoordinates, 11);
var self = this;
self.locations = {};
self.pending = [];
@@ -118,7 +118,7 @@

map.wimrReset = function(done) {

map.setView(WIMR.clientConfig.citycentercoordinates, 11);
map.setView(WIMR.config.citycentercoordinates, 11);
map.wimrRefreshLocations(function(){
for (var loc in self.locations) {
var mkr = self.locations[loc];
6 changes: 3 additions & 3 deletions public/js/view_handlers/search_form.js
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@

})
.fail(function (response){
var status = "Sorry, either the address was incorrect or doesn't exist in " + WIMR.clientConfig.cityname + ".";
var status = "Sorry, either the address was incorrect or doesn't exist in " + WIMR.config.cityname + ".";
$('#addressField').addClass('has-error');
$('#status').wimrStatus(status, 'warning');
});
@@ -78,8 +78,8 @@
});

function formatAddressRequest(inputAddress) {
var city = WIMR.clientConfig.cityname;
var state = WIMR.clientConfig.stateabbrev;
var city = WIMR.config.cityname;
var state = WIMR.config.stateabbrev;
return encodeURIComponent([inputAddress,city,state].join(','));
}

2 changes: 1 addition & 1 deletion public/js/view_handlers/submit_report.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
}

var viewVars = {};
viewVars.clientConfig = WIMR.clientConfig;
viewVars.config = WIMR.config;
WIMR.dialog.loading();
$.post('/reports.json', data)
.done(function(response){
6 changes: 3 additions & 3 deletions public/templates/finished.ejs
Original file line number Diff line number Diff line change
@@ -24,19 +24,19 @@

<li class="next-steps">
<div class="inner">
Check out our <a href="/get-involved">Get Involved</a> page and learn about <strong>futher actions</strong> to take to <strong>promote multi-unit recycling</strong> in <%= clientConfig.cityname %>!
Check out our <a href="/get-involved">Get Involved</a> page and learn about <strong>futher actions</strong> to take to <strong>promote multi-unit recycling</strong> in <%= config.cityname %>!
</div>
</li>

<!-- Hiding until functional -->
<li class='next-steps'>
<div class="inner">
<strong>Share with friends</strong> and help spread the word that <%= clientConfig.cityresidentname %>s demand better recycling services!
<strong>Share with friends</strong> and help spread the word that <%= config.cityresidentname %>s demand better recycling services!

<div class="social-links">
<div class="fb-share-button share-button" data-href="http://mybuildingdoesntrecycle.com" data-layout="button_count"></div>
<div class="twitter-share-wrapper share-button">
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://mybuildingdoesntrecycle.com" data-text="Hey <%= clientConfig.cityname %>! Does your building provide adequate recycling?">Tweet</a>
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://mybuildingdoesntrecycle.com" data-text="Hey <%= config.cityname %>! Does your building provide adequate recycling?">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>
<div class="clear"></div>
4 changes: 2 additions & 2 deletions public/templates/search_form.ejs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<form role="form" id="searchForm">
<h3 class='blue-highlight'>Hey <%= clientConfig.cityresidentname %>!</h3>
<h3 class='blue-highlight'>Hey <%= config.cityresidentname %>!</h3>
<h2 id="searchFormLabel">No recycling in your building?</h2>
<h3>Tell us about it!</h3>
<!-- This is parsed as a markdown static file and rendered here in the templateCallback -->
<p id="welcomemessage"></p>
<div class="form-group" id="addressField">
<label for="address">Enter your <%= clientConfig.cityname %> street address:</label>
<label for="address">Enter your <%= config.cityname %> street address:</label>
<input name="address" type="text" class="form-control" id="inputAddress" placeholder="Address" />
<p class="text-right" style="margin: 0;"><small>&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors</small></p>
</div>
3 changes: 1 addition & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var express = require('express')
, fs = require('fs')
, router = express.Router()
, env = process.env.NODE_ENV || 'development'
, config = require('../config/config.json')[env];
, config = require('../config/public/config.json');

router.use(function(req, res, next){
var tplFiles = fs.readdirSync('./public/js/view_handlers');
5 changes: 1 addition & 4 deletions script/export_db_to_csv
Original file line number Diff line number Diff line change
@@ -4,10 +4,7 @@ var json2csv = require('json2csv');
var mongoose = require('mongoose');
var _ = require('lodash');

var env = process.env.NODE_ENV || 'development';
var config = require('../config/config')[env];

var dbCnx = process.env.MONGOLAB_URI || config.db;
var dbCnx = process.env.MONGO_URI;
var db = mongoose.connect(dbCnx);

var Location = require('../models/Location');
14 changes: 0 additions & 14 deletions script/flushcache.js

This file was deleted.

1 change: 0 additions & 1 deletion script/postinstall.sh

This file was deleted.

48 changes: 10 additions & 38 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
const express = require('express')
, cluster = require('cluster')
, numCpus = require('os').cpus().length
, bodyParser = require('body-parser')
, fs = require('fs')
, http = require('http')
, mongoose = require('mongoose')
, morgan = require('morgan')
, compress = require('compression')
, logger = require('logfmt')
, routes = require('./routes')
, reports = require('./routes/reports')
, locations = require('./routes/locations')
, fauxAuth = require('./middleware/staging-auth')
, concurrency = process.env.WEB_CONCURRENCY
;

const app = express()
, env = app.get('env')
, config = require('./config/config')[env]
, config = require('./config/public/config.json');

, dbCnx = process.env.MONGOLAB_URI || config.db
if (!process.env.MONGO_URI) {
console.error('MONGO_URI environment variable must be set')
process.exitCode = 1
}
const dbCnx = process.env.MONGO_URI
, db = mongoose.connect(dbCnx)
, port = process.env.PORT || config.port || 3000
;
, port = process.env.PORT || 3000

// memjs reads appropriate env variables by default.
// zero configuration necessary
@@ -38,18 +33,6 @@ app.use(bodyParser.urlencoded({
extended: true
}));

switch (app.get('env')) {
case 'development':
app.use(morgan('dev'));
break;
case 'staging':
app.use(fauxAuth);
break;
default:
app.use(morgan('combined'));
break;
}

app.use(require('./routes/index.js'));
app.get('/reports/count.json', reports.count);
app.get('/reports/:id.json', reports.show);
@@ -59,17 +42,6 @@ app.get('/locations.json', locations.index);
app.get('/locations/count.json', locations.count);


if (env != 'development' && cluster.isMaster) {
for (var i = 0; i < concurrency; i++) {
cluster.fork();
}

cluster.on('exit', function(worker, code, signal) {
logger.log({worker: worker.process.pid, msg: 'died', code: code, signal: signal});
});

} else {
http.createServer(app).listen(port, function() {
logger.log({status: 'info', msg: 'server listening', port: port});
});
}
http.createServer(app).listen(port, function() {
logger.log({status: 'info', msg: 'server listening', port: port});
});