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

[Proof of concept - do not merge] MUR citation filters #5376

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
81 changes: 81 additions & 0 deletions fec/fec/static/js/modules/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ function formatAuditCandidate(result) {
};
}

function formatCaseRegulatoryCitation(result) {
return {
citation: result.citation_text,
type: 'caseRegulatoryCitation'
};
}

function formatCaseStatutoryCitation(result) {
return {
citation: result.citation_text,
type: 'caseStatutoryCitation'
};
}

function getUrl(resource) {
return URI(window.API_LOCATION)
.path([window.API_VERSION, 'names', resource, ''].join('/'))
Expand All @@ -68,6 +82,16 @@ function getUrl(resource) {
.readable();
}

function getCitationUrl(citationType) {
return URI(window.API_LOCATION)
.path([window.API_VERSION, 'legal', 'citation', citationType, ''].join('/'))
.query({
wildcard: '%QUERY',
api_key: window.API_KEY_PUBLIC
})
.readable();
}

var engineOpts = {
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
Expand Down Expand Up @@ -118,6 +142,28 @@ var auditCandidateEngine = createEngine({
}
});

// Uses seperate resource path: /legal/citation/regulation/[query_string]/
var caseRegulatoryEngine = createEngine({
remote: {
url: getCitationUrl('regulation'),
wildcard: '%QUERY',
transform: function(response) {
return _.map(response.results, formatCaseRegulatoryCitation);
}
}
});

// Uses seperate resource path: /legal/citation/statute/[query_string]/
var caseStatutoryEngine = createEngine({
remote: {
url: getCitationUrl('statute'),
wildcard: '%QUERY',
transform: function(response) {
return _.map(response.results, formatCaseStatutoryCitation);
}
}
});

var candidateDataset = {
name: 'candidate',
display: 'name',
Expand Down Expand Up @@ -187,6 +233,39 @@ var auditCandidateDataset = {
}
};

var caseRegulatoryCitationDataset = {
name: 'caseRegulatoryCitation',
display: 'regulatory',
limit: 10,
source: caseRegulatoryEngine,
templates: {
header: '<span class="tt-suggestion__header">Select a citation:</span>',
pending:
'<span class="tt-suggestion__loading">Loading citations&hellip;</span>',
notFound: Handlebars.compile(''), // This has to be empty to not show anything
suggestion: Handlebars.compile(
'<span class="tt-suggestion__name">{{ citation }}</span>'
)
}
};

var caseStatutoryCitationDataset = {
name: 'caseStatutoryCitation',
display: 'statutory',
limit: 10,
source: caseStatutoryEngine,
templates: {
header: '<span class="tt-suggestion__header">Select a citation:</span>',
pending:
'<span class="tt-suggestion__loading">Loading citations&hellip;</span>',
notFound: Handlebars.compile(''), // This has to be empty to not show anything
suggestion: Handlebars.compile(
'<span class="tt-suggestion__name">{{ citation }}</span>'
)
}
};


/* This is a fake dataset for showing an empty option with the query
* when clicked, this will load the receipts page,
* filtered to contributions from this person
Expand Down Expand Up @@ -239,6 +318,8 @@ var datasets = {
committees: committeeDataset,
auditCandidates: auditCandidateDataset,
auditCommittees: auditCommitteeDataset,
caseRegulatoryCitation: caseRegulatoryCitationDataset,
caseStatutoryCitation: caseStatutoryCitationDataset,
allData: [candidateDataset, committeeDataset],
all: [candidateDataset, committeeDataset, individualDataset, siteDataset]
};
Expand Down
13 changes: 13 additions & 0 deletions fec/legal/templates/legal-search-results-murs.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "layouts/legal-doc-search-results.jinja" %}
{% import 'macros/legal.jinja' as legal %}
{% import 'macros/filters/typeahead-filter.jinja' as typeahead %}
{% set document_type_display_name = 'Closed Matters Under Review' %}

{% block header %}
Expand All @@ -15,6 +16,18 @@
<label class="label" for="case_no">MUR number</label>
<input id="case_no" name="case_no" type="text" value="{{ case_no }}">
</div>
{# Python API call without suggestions #}
<div class="filter">
<label class="label" for="case_regulatory_citation">Regulatory citation</label>
<input id="case_regulatory_citation" name="case_regulatory_citation" type="text" value="{{ case_regulatory_citation }}">
</div>
<div class="filter">
<label class="label" for="case_regulatory_citation">Regulatory citation</label>
<input id="case_regulatory_citation" name="case_regulatory_citation" type="text" value="{{ case_regulatory_citation }}">
</div>
{# Regulatory and statutory citations hooked up with suggestions, not functioning and only for concept #}
{{ typeahead.field(name = 'case_regulatory_citation', title = 'Regulatory citation', dataset='caseRegulatoryCitation') }}
{{ typeahead.field(name = 'case_statutory_citation', title = 'Statutory citation', dataset='caseStatutoryCitation') }}
<div class="filter">
<label class="label" for="case_respondents">MUR respondents</label>
<input id="case_respondents" name="case_respondents" type="text" value="{{ case_respondents }}">
Expand Down
8 changes: 7 additions & 1 deletion fec/legal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def legal_doc_search_mur(request):
case_max_open_date = request.GET.get('case_max_open_date', '')
case_min_close_date = request.GET.get('case_min_close_date', '')
case_max_close_date = request.GET.get('case_max_close_date', '')
case_statutory_citation = request.GET.get('case_statutory_citation', '')
case_regulatory_citation = request.GET.get('case_regulatory_citation', '')

results = api_caller.load_legal_search_results(
query, 'murs',
Expand All @@ -153,7 +155,9 @@ def legal_doc_search_mur(request):
case_min_open_date=case_min_open_date,
case_max_open_date=case_max_open_date,
case_min_close_date=case_min_close_date,
case_max_close_date=case_max_close_date
case_max_close_date=case_max_close_date,
case_statutory_citation=case_statutory_citation,
case_regulatory_citation=case_regulatory_citation,
)

return render(request, 'legal-search-results-murs.jinja', {
Expand All @@ -166,6 +170,8 @@ def legal_doc_search_mur(request):
'case_max_open_date': case_max_open_date,
'case_min_close_date': case_min_close_date,
'case_max_close_date': case_max_close_date,
'case_statutory_citation': case_statutory_citation,
'case_regulatory_citation': case_regulatory_citation,
'query': query,
'social_image_identifier': 'legal',
})
Expand Down