Skip to content

Commit

Permalink
make location generic
Browse files Browse the repository at this point in the history
  • Loading branch information
dylang committed Oct 28, 2011
1 parent d4b80c6 commit 1e21553
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 86 deletions.
1 change: 0 additions & 1 deletion .idea/jsLibraryMappings.xml

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

3 changes: 1 addition & 2 deletions nodemon-ignore → .nodemonignore
Expand Up @@ -5,5 +5,4 @@
/data/*
/views/*
*.css
*.js
*.svn
*.svn
31 changes: 1 addition & 30 deletions lib/jobHandler.js
Expand Up @@ -5,16 +5,12 @@
*/

var log = require('logging').from(__filename),
Jobvite = require('jobvite'),
jobDAO = require('./jobs/dao'),
Constants = require('./jobs/constants'),
Util = require('./jobs/util'),
team_pages = require('./jobs/team_pages'),
ReferralHandler = require('./referralHandler'),
Server;

//<%= locals.job ? '- ' + locals.job.title + ' (' + Constants.short(locals.job.location) + ')' : '' %><%= locals.location ? Constants.long(locals.location) : '' %><%= locals.team && locals.all_teams[locals.team] ? '- ' + locals.all_teams[locals.team] : '' %>

//app.get('/search/:query'
function render_search(req, res, next) {
var query = Util.unurl(req.params.query);
Expand Down Expand Up @@ -52,25 +48,6 @@ function search_json(req, res) {
}


function render_sf(req, res, next) {
var collection = jobDAO.location(Constants.LOCATIONS.sf.id);
res.render('locations/sf.ejs', {
collection: collection,
title: Constants.LOCATIONS.sf.name,
currentPageID: 'jobs'
});
}

function render_dc(req, res, next) {
var collection = jobDAO.location(Constants.LOCATIONS.va.id);
res.render('locations/dc.ejs',{
collection: collection,
title: Constants.LOCATIONS.va.name,
currentPageID: 'jobs'
});

}

function render_team(req, res, next) {
var team_id = req.params.team_id,
location_id = req.params.location_id;
Expand Down Expand Up @@ -218,8 +195,6 @@ function addHandlers(options) {
Server.get('/search/:query', render_search);

Server.get('/teams', render_teams);
Server.get('/san-francisco', render_sf);
Server.get('/dc-northern-virginia', render_dc);

Server.get('/:team_id', render_team);

Expand All @@ -231,11 +206,7 @@ function addHandlers(options) {

Server.get('/:location/:team', render_team);

Server.get('/all-reqs', all_reqs)

Server.locals({
Constants: Constants
});
Server.get('/all-reqs', all_reqs);

jobDAO.init({ auto_update: Server.set('env') == 'production'}, function() {
log('jobs ready');
Expand Down
18 changes: 0 additions & 18 deletions lib/jobs/constants.js
Expand Up @@ -6,27 +6,9 @@

var log = require('logging').from(__filename);

module.exports.LOCATIONS = {
va: { id: 'va', short_name: 'DC/VA', name: 'DC/Northern Virginia', url: 'dc-northern-virginia'},
sf: { id: 'sf', short_name: 'SF', name: 'San Francisco', url: 'san-francisco'}
};

module.exports.MILLISECONDS_PER_MINUTE = 1000*60;
module.exports.MILLISECONDS_PER_HOUR = 1000*60*60;
module.exports.MILLISECONDS_PER_DAY = 1000*60*60*24;
module.exports.UPDATE_INTERVAL_MINUTES = 20;

var _id = {
'arlington, va, united states': 'va',
'dc-northern-virginia': 'va',

'san-francisco': 'sf',
'san francisco, ca, united states': 'sf'
};

function id(id_) {
return _id[id_.toLowerCase()];
}


module.exports.id = id;
5 changes: 1 addition & 4 deletions lib/jobs/dao.js
Expand Up @@ -90,13 +90,10 @@ function location(location_id) {

function team_jobs(team_id) {
//render just one team
var jobs_sf = query({team_id: team_id, location_id: Constants.LOCATIONS.sf.id }).toArray();
var jobs_dc = query({team_id: team_id, location_id: Constants.LOCATIONS.va.id }).toArray();

return {
name: team(team_id).name,
jobs_sf: jobs_sf,
jobs_dc: jobs_dc
jobs: query({team_id: team_id }).toArray()
};
}

Expand Down
21 changes: 3 additions & 18 deletions lib/jobs/update.js
Expand Up @@ -7,7 +7,6 @@
var log = require('logging').from(__filename),
Jobs = require('jobvite').Jobs,
Lean = require('lean'),
Constants = require('./constants'),
Sort = require('./sort'),
Util = require('./util');

Expand Down Expand Up @@ -49,16 +48,13 @@ function format_description(desc) {
}

function create_urls(job) {
if (!Constants.LOCATIONS[job.location_id]) {
log ('UNKNOWN LOCATION', job);
}


var team = job.team,
team_url = Util.url(team),

title_url = Util.url(job.title),

full_url = ['', Constants.LOCATIONS[job.location_id].url, team_url, title_url ].join('/'),
full_url = ['', Util.url(job.location), team_url, title_url ].join('/'),
apply_url = '/apply' + full_url;

return {
Expand Down Expand Up @@ -88,25 +84,14 @@ function process(err, jobs_array, callback) {
jobs_array.forEach(function(job) {

// location
job.location_id = Constants.id(job.location);
job.location_id = Util.url(job.location);
job.team_id = Util.url(job.team);

job.description = format_description(job.description);
if (!DB_Teams.get(job.team_id)) {
DB_Teams.set(job.team_id, { id: job.team_id, name: job.team});
}

if (!Constants.LOCATIONS[job.location_id]) {

//super lazy clone
var clone = JSON.parse(JSON.stringify(job));

job.location_id = 'va';
clone.date = job.date;
clone.location_id = 'sf';
clone.id = job.id + '-sf';
jobs_array.push(clone);
}
});

jobs_array.forEach(function(job) {
Expand Down
8 changes: 7 additions & 1 deletion lib/jobs/util.js
@@ -1,6 +1,11 @@
function url(s) {
s = s || '';
s = s.replace(/[^a-zA-Z0-9\s]/g, '').trim().replace(/\s+/g, '-').toLowerCase();
s = s
.toLowerCase()
.replace(/[^a-z0-9\s]/g, '')
.replace(/united states/, '')
.trim()
.replace(/\s+/g, '-');
return s;
}

Expand Down Expand Up @@ -31,6 +36,7 @@ function search_string(job) {
}



module.exports.url = url;
module.exports.unurl = unurl;
module.exports.toArray = toArray;
Expand Down
2 changes: 1 addition & 1 deletion server.js
Expand Up @@ -112,7 +112,7 @@ Server.error(function(err, req, res, next){
err.arguments && log(err.arguments);
err.stack && log(err.stack);
log('*************************************');
next();
//next();
}
if (Server.get('env') == 'production') {
res.redirect('/');
Expand Down
2 changes: 1 addition & 1 deletion views/job-pages/atom.ejs
Expand Up @@ -14,7 +14,7 @@
<id>tag:opower.com,2010:jobs</id>
<% jobs.forEach(function(job) { %>
<entry>
<title><%= job.title %><%- job.location_id == Constants.LOCATIONS.sf.id ? ' (SF)' : '' %></title>
<title><%= job.title + ' ' + job.location %></title>
<link href="<%= url %><%= job.urls.full_url %>"/>
<id>tag:opowerjobs.com,2010:job_<%= job.id %></id>
<updated><%= job.date.toISOString() %></updated>
Expand Down
4 changes: 2 additions & 2 deletions views/job-pages/job.ejs
Expand Up @@ -14,7 +14,7 @@
<div class="span-17 first last flag clearfix">
<div class="span-11 first">
<h5>Find other jobs in:</h5>
<a href="<%- href(Constants.LOCATIONS[job.location_id].url) %>" class="button blue-button button-small button-left"><%- Constants.LOCATIONS[job.location_id].short_name %></a><a href="<%- href(job.urls.team) %>" class="button blue-button button-small button-right"><%= job.team_id %></a>
<a href="<%- href(job.urls.team) %>" class="button blue-button button-small"><%= job.team_id %></a>
</div>
<div class="span-6 last">
<h5>Share this job:</h5>
Expand All @@ -25,7 +25,7 @@
<div class="company">
<strong>About the Company</strong>
<p>Opower is an energy efficiency and smart-grid software company. Our products encourage energy efficiency by empowering people to make better decisions about the ways they use energy every day. With industry-leading data analytics and a unique approach to customer engagement, we're changing the way the world understands personal energy consumption, and helping more than 40 utilities---including 8 of the US’s 10 largest—achieve unprecedented, sustainable energy savings in tens of millions of households.</p>
<p>In April 2010, President Obama gave his national policy speech on green-job creation from our office in the Washington, DC area. In September of 2010, we were named a Technology Pioneer by the World Economic Forum in Davos, Switzerland, for creating "innovations that will have a critical impact on the future of business and society.” In January, the Washington Post called us one of "5 Companies that will Lead in 2011," and in March, the Wall Street Journal named us a Top 10 Cleantech company. By the end of this year, the energy we save will equal a third of the power produced by the entire US solar industry, and have the impact of effectively removing 50,000 homes from the grid.</p>
<p>In March 2010, President Obama gave his national policy speech on green-job creation from our office in the Washington, DC area. In September of 2010, we were named a Technology Pioneer by the World Economic Forum in Davos, Switzerland, for creating "innovations that will have a critical impact on the future of business and society.” In January, the Washington Post called us one of "5 Companies that will Lead in 2011," and in March, the Wall Street Journal named us a Top 10 Cleantech company. By the end of this year, the energy we save will equal a third of the power produced by the entire US solar industry, and have the impact of effectively removing 50,000 homes from the grid.</p>
<p>Founded in 2007, Opower has offices in Arlington, Virginia, and San Francisco, California. Our rapidly expanding team includes software engineers, product specialists, behavioral scientists, statisticians, marketing experts, infographic designers, and efficiency advocates.</p>
</div>
</div>
Expand Down
9 changes: 4 additions & 5 deletions views/jobs/job.ejs
Expand Up @@ -3,12 +3,11 @@
*/ %>
<li>
<a href="<%= job.urls ? href(job.urls.full_url) : '' %>">
<%= job.title + (job.urls ? '' : "!!!!!!!!!") %>

<%= job.title %>
<% if (locals.show_location) { %>
<% if (job.location_id == Constants.LOCATIONS.sf.id) { %>
(SF)
<% } else {} %>
<span class="location">
<%= job.location %>
</span>
<% } %>
</a>
</li>
5 changes: 3 additions & 2 deletions views/jobs/req.ejs
Expand Up @@ -2,9 +2,10 @@
<div class="banner">
<h2 class="title strong span-17 last">
<%= job.title %>

<%- '(' + Constants.LOCATIONS[job.location_id].short_name + ')' %>
</h2>
<h3>
<%- job.location %>
</h3>
<div class="location">
<a href="<%- href(job.urls.team) %>">&laquo; Back to <%- job.team %> jobs</a>
</div>
Expand Down
6 changes: 5 additions & 1 deletion views/teams/team.ejs
Expand Up @@ -11,7 +11,11 @@

<div class="clear" style="padding-top:40px;"></div>
<% if (collection) { %>
<%- partial('../jobs/jobs-grouped-by-location.ejs', { collection: [collection] }) %>
<ul>
<%- partial('../jobs/job', { collection: collection.jobs, as: 'job', show_location: true } ) %>
</ul>
<% } else { %>
New opportunities for this team will be posted here. Check back soon.
<% } %>
Expand Down

0 comments on commit 1e21553

Please sign in to comment.