From 97382b415d390ef9459988cc4bbcdfaf736849d4 Mon Sep 17 00:00:00 2001 From: Pat Phongsvirajati Date: Wed, 17 Aug 2022 11:04:02 -0400 Subject: [PATCH] As a proof of concept, added 2 different methods for regulatory and statutory citations. One with python and one with typehead JS. --- fec/fec/static/js/modules/typeahead.js | 81 +++++++++++++++++++ .../templates/legal-search-results-murs.jinja | 13 +++ fec/legal/views.py | 8 +- 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/fec/fec/static/js/modules/typeahead.js b/fec/fec/static/js/modules/typeahead.js index 22151fce8c..017f31fa20 100644 --- a/fec/fec/static/js/modules/typeahead.js +++ b/fec/fec/static/js/modules/typeahead.js @@ -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('/')) @@ -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, @@ -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', @@ -187,6 +233,39 @@ var auditCandidateDataset = { } }; +var caseRegulatoryCitationDataset = { + name: 'caseRegulatoryCitation', + display: 'regulatory', + limit: 10, + source: caseRegulatoryEngine, + templates: { + header: 'Select a citation:', + pending: + 'Loading citations…', + notFound: Handlebars.compile(''), // This has to be empty to not show anything + suggestion: Handlebars.compile( + '{{ citation }}' + ) + } +}; + +var caseStatutoryCitationDataset = { + name: 'caseStatutoryCitation', + display: 'statutory', + limit: 10, + source: caseStatutoryEngine, + templates: { + header: 'Select a citation:', + pending: + 'Loading citations…', + notFound: Handlebars.compile(''), // This has to be empty to not show anything + suggestion: Handlebars.compile( + '{{ citation }}' + ) + } +}; + + /* 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 @@ -239,6 +318,8 @@ var datasets = { committees: committeeDataset, auditCandidates: auditCandidateDataset, auditCommittees: auditCommitteeDataset, + caseRegulatoryCitation: caseRegulatoryCitationDataset, + caseStatutoryCitation: caseStatutoryCitationDataset, allData: [candidateDataset, committeeDataset], all: [candidateDataset, committeeDataset, individualDataset, siteDataset] }; diff --git a/fec/legal/templates/legal-search-results-murs.jinja b/fec/legal/templates/legal-search-results-murs.jinja index 899ee5a3d6..fd8edaa647 100644 --- a/fec/legal/templates/legal-search-results-murs.jinja +++ b/fec/legal/templates/legal-search-results-murs.jinja @@ -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 %} @@ -15,6 +16,18 @@ + {# Python API call without suggestions #} +
+ + +
+
+ + +
+ {# 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') }}
diff --git a/fec/legal/views.py b/fec/legal/views.py index ab7e6299d2..885fbca454 100644 --- a/fec/legal/views.py +++ b/fec/legal/views.py @@ -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', @@ -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', { @@ -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', })