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

Feature/consolidate search #226

Merged
merged 6 commits into from
Jun 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions openfecwebapp/api_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def load_nested_type(parent_type, c_id, nested_type, *path, **filters):
def load_cmte_financials(committee_id, **filters):
filters.update({
'per_page': MAX_FINANCIALS_COUNT,
'report_type': filters.get('report_type', []) + ['-TER']
})

reports = _call_api('committee', committee_id, 'reports', **filters)
Expand Down
2 changes: 1 addition & 1 deletion static/js/modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var defaultOpts = {
};

function onSelectChange($input, updatedText) {
$input.attr('placeholder', updatedText);
$input.attr('placeholder', updatedText).attr('aria-label', updatedText);
};

var Search = function($el, opts) {
Expand Down
84 changes: 20 additions & 64 deletions static/js/modules/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,20 @@ var officeMap = {
var filterCandidates = function(result) {
return {
name: result.name,
id: result.candidate_id,
id: result.id,
office: officeMap[result.office_sought]
};
};

var filterCommittees = function(result) {
return {
name: result.name,
id: result.committee_id
};
};

module.exports = {
getUrl: function() {
var url;
if (typeof API_LOCATION !== 'undefined') {
url = URI(API_LOCATION)
.path([API_VERSION, 'names'].join('/'))
.query({
q: '%QUERY',
api_key: API_KEY
})
.readable();
} else {
url = "/rest/names?q=%QUERY";
}
return url;
},

getCandidateUrl: function(url) {
return URI(url).addSearch('type', 'candidate').readable();
},

getCommitteeUrl: function(url) {
return URI(url).addSearch('type', 'committee').readable();
getUrl: function(resource) {
return URI(API_LOCATION)
.path([API_VERSION, 'names', resource].join('/'))
.query({
q: '%QUERY',
api_key: API_KEY
})
.readable();
},

/**
Expand Down Expand Up @@ -126,50 +105,29 @@ module.exports = {
committeeEngine,
candidateSuggestion,
committeeSuggestion,
headerTpl,
glossaryEngine,
glossarySuggestion,
options,
candidateDataSet,
committeeDataSet,
url,
self = this;

url = this.getUrl();

// Creating a candidate suggestion engine
candidateEngine = this.createEngine('Candidates', this.getCandidateUrl(url),
function(response) {
return _.chain(response.results)
.filter(function(result) {
return result.candidate_id;
})
.map(function(result) {
return filterCandidates(result);
})
.value();
});
committeeEngine = this.createEngine('Committees', this.getCommitteeUrl(url),
function(response) {
return _.chain(response.results)
.filter(function(result) {
return result.committee_id;
})
.map(function(result) {
return filterCommittees(result);
})
.value();
});
candidateEngine = this.createEngine('Candidates', this.getUrl('candidates'), function(response) {
return _.map(response.results, function(result) {
return filterCandidates(result);
});
});

committeeEngine = this.createEngine('Committees', this.getUrl('committees'), function(response) {
return response.results;
});

// Templates for results
candidateSuggestion = Handlebars.compile(
'<span><span class="tt-suggestion__name">{{ name }}</span>' +
'<span class="tt-suggestion__office">{{ office }}</span></span>');
committeeSuggestion = Handlebars.compile('<span>{{ name }}</span>');
headerTpl = function(label) {
return Handlebars.compile('<span class="tt-dropdown-title">' + label +
'</span>');
};

options = {
minLength: 3,
Expand All @@ -182,8 +140,7 @@ module.exports = {
displayKey: 'name',
source: candidateEngine.ttAdapter(),
templates: {
suggestion: candidateSuggestion,
header: headerTpl('Candidates'),
suggestion: candidateSuggestion
}
};

Expand All @@ -192,8 +149,7 @@ module.exports = {
displayKey: 'name',
source: committeeEngine.ttAdapter(),
templates: {
suggestion: committeeSuggestion,
header: headerTpl('Committees'),
suggestion: committeeSuggestion
}
};

Expand Down
2 changes: 1 addition & 1 deletion templates/committees-single.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ <h5>{{ pretty_name }}</h5>

<section class="page-section" id="section-1" role="tabpanel" aria-hidden="false" aria-labelledby="section-1-header">
<div class="container committee-summary">
{% if totals %}
{% if reports and totals %}
<h2 id="section-1-header" tabindex="0">Financial Summary</h2>
<p class="text--lead">Get the full picture of all of the money received and spent by this committee.</p>
<div class="page-subsection page-subsection--noline">
Expand Down
4 changes: 2 additions & 2 deletions templates/partials/search-bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
Committees</option>
</select>
<input class="search-bar" type="text" name="search"
aria-label="Search for candidates and committees"
placeholder="Search for candidates by name" autocomplete="off"
aria-label="Enter a candidate name"
placeholder="Enter a candidate name" autocomplete="off"
autocorrect="off" autocapitalize="off" spellcheck="false"
value="{{ query or '' }}">
<button class="search-submit primary"><img width="16" height="16" src="/static/img/icon-search--white.svg" alt="Magnifying glass icon"></button>
Expand Down