Skip to content
This repository has been archived by the owner on Dec 23, 2017. It is now read-only.

Commit

Permalink
Merge pull request #10 from 18F/refactor_152_integration
Browse files Browse the repository at this point in the history
Refactor 152 integration
  • Loading branch information
Noah Manger committed Dec 17, 2014
2 parents 9528bdc + 52a01ce commit bf1072a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 55 deletions.
53 changes: 37 additions & 16 deletions shared/candidate-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,50 @@ module.exports = {
i,
j,
len,
elections,
election,
year,
jlen;
jlen,
newCandidateObj;

if (typeof results !== 'undefined') {
len = results.length;
}

for (i = 0; i < len; i++) {
elections = results[i].elections;
jlen = elections.length;
// if there are multiple elections associated with this
// candidate, express them as separate rows
jlen = results[i].elections.length || 1;

for (j = 0; j < jlen; j++) {
candidates.push({
'name': results[i].name.full_name,
'id': results[i].candidate_id,
'incumbent_challenge': elections[j].incumbent_challenge,
'office': elections[j].office_sought,
'election': elections[j].election_year,
'party': elections[j].party_affiliation,
'state': elections[j].state,
'district': elections[j].district
});
newCandidateObj = {
id: '',
name: '',
office: '',
election: '',
party: '',
state: '',
district: '',
incumbent_challenge: ''
};

newCandidateObj.id = results[i].candidate_id;

if (typeof results[i].elections !== 'undefined') {
newCandidateObj.office = results[i].elections[j].office_sought_full || '';
newCandidateObj.party = results[i].elections[j].party_affiliation || '';
newCandidateObj.incumbent_challenge = results[i].elections[j].incumbent_challenge_full || '';

if (typeof results[i].elections[j].primary_committee !== 'undefined') {
newCandidateObj.election = results[i].elections[j].primary_committee.election_year || '';
}

newCandidateObj.state = results[i].elections[j].state || '';
newCandidateObj.district = results[i].elections[j].district || '';
}

if (typeof results[i].name !== 'undefined') {
newCandidateObj.name = results[i].name.full_name || '';
}

candidates.push(newCandidateObj);
}
}

Expand Down
65 changes: 32 additions & 33 deletions shared/committee-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,51 @@ module.exports = {
len,
committee,
committees = [],
type,
designation,
name,
treasurer,
state,
party,
organization;
newCommitteeObj;

if (typeof results !== 'undefined') {
len = results.length;
}

for (i = 0; i < len; i++) {
committee = results[i][0];
// don't want leftover vars from one iteration to the next
// should the corresponding if block is false
newCommitteeObj = {
id: '',
name:'',
treasurer:'',
state: '',
party: '',
type: '',
designation: '',
organization: ''
};

committee = results[i];
committee.status = results[i].status;

newCommitteeObj.id = committee.committee_id || '';

if (typeof committee.status !== 'undefined') {
type = committee.status[0].type;
designation = committee.status[0].designation;
newCommitteeObj.type = committee.status.type_full || '';
newCommitteeObj.designation = committee.status.designation_full || '';
}
else {
type = committee.type;
designation = '';
}

organization = committee.organization_type || '';

name = committee.name || '';
if (typeof committee.treasurer !== 'undefined') {
treasurer = committee.treasurer.name_full;
newCommitteeObj.treasurer = committee.treasurer.name_full || '';
}
else {
treasurer = '';

if (typeof committee.address !== 'undefined') {
newCommitteeObj.state = committee.address.state || '';
}

if (typeof committee.description !== 'undefined') {
newCommitteeObj.party = committee.description.party_full || '';
newCommitteeObj.name = committee.description.name || '';
newCommitteeObj.organization = committee.description.organization_type_full || '';
}
state = committee.address.state || '';
party = '';

committees.push({
name: name,
treasurer: treasurer,
state: state,
party: party,
type: type,
designation: designation,
organization: organization,
id: committee.committee_id
});

committees.push(newCommitteeObj);
}

return committees;
Expand Down
4 changes: 2 additions & 2 deletions static/js/modules/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var buildURL = function(e) {
}
}

return URL;
return URL + 'fields=*';
};

var filterLoadHandler = function(e) {
Expand Down Expand Up @@ -83,7 +83,7 @@ module.exports = {
});

events.on('load:browse', function(e) {
var promise = callAPI('rest/' + entityMap[e.category]);
var promise = callAPI('rest/' + entityMap[e.category] + '?fields=*');

promise.done(function(data) {
e.data = data;
Expand Down
2 changes: 1 addition & 1 deletion static/js/modules/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var buildURL = function(context) {
}
}

return URL;
return URL + 'fields=*';
};

var changeURL = function(context) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('API Module', function() {
}
};

assert.equal(api.buildURL(context), 'rest/candidate?year=2000&state=IL&');
assert.equal(api.buildURL(context), 'rest/candidate?year=2000&state=IL&fields=*');
});
});
});
4 changes: 2 additions & 2 deletions tests/unit/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('URL Module', function() {
query: 'ladybug'
};

assert.equal(urls.buildURL(context), '/insects?q=ladybug&');
assert.equal(urls.buildURL(context), '/insects?q=ladybug&fields=*');
});

it('should return a URL to match the given context when filtered', function() {
Expand All @@ -21,7 +21,7 @@ describe('URL Module', function() {
}
};

assert.equal(urls.buildURL(context), '/insects?numLegs=4&color=red&');
assert.equal(urls.buildURL(context), '/insects?numLegs=4&color=red&fields=*');
});

});
Expand Down

0 comments on commit bf1072a

Please sign in to comment.