From 507f0f3e02be7496d97be060294e8dcb9f9498e9 Mon Sep 17 00:00:00 2001 From: John Carroll Date: Tue, 29 Oct 2024 13:55:46 -0400 Subject: [PATCH 1/6] subject filter for adrs and murs, refinemacros, adjust audit constants to accomodate --- fec/data/constants.py | 144 +++++++++--------- .../macros/filters/dropdown-json.jinja | 21 ++- .../layouts/legal-doc-search-results.jinja | 70 ++++++++- .../templates/legal-search-results-adrs.jinja | 37 +++++ .../templates/legal-search-results-murs.jinja | 32 +++- .../templates/partials/legal-pagination.jinja | 6 +- .../partials/legal-search-results-mur.jinja | 2 +- fec/legal/views.py | 55 ++++++- 8 files changed, 281 insertions(+), 86 deletions(-) diff --git a/fec/data/constants.py b/fec/data/constants.py index a669530b3..76d29678f 100644 --- a/fec/data/constants.py +++ b/fec/data/constants.py @@ -373,75 +373,27 @@ primary_category_keys = ['primary_category_id', 'primary_category_name'] sub_category_keys = ['sub_category_id', 'sub_category_name'] -audit_primary_categories_options = [ - { - "primary_category_id": 'all', - "primary_category_name": 'All' - }, - { - "primary_category_id": '2', - "primary_category_name": 'Allocation Issues' - }, - { - "primary_category_id": '3', - "primary_category_name": 'Disclosure' - }, - { - "primary_category_id": '5', - "primary_category_name": 'Excessive Contributions' - }, - { - "primary_category_id": '1', - "primary_category_name": 'Failure to File Reports/Schedules/Notices' - }, - { - "primary_category_id": '8', - "primary_category_name": 'Loans' - }, - { - "primary_category_id": '7', - "primary_category_name": 'Misstatement of Financial Activity' - }, - { - "primary_category_id": '14', - "primary_category_name": 'Net Outstanding Campaign/Convention ' + 'Expenditures/Obligations' - }, - { - "primary_category_id": '16', - "primary_category_name": 'No Findings or Issues/Not a Committee' - }, - { - "primary_category_id": '9', - "primary_category_name": 'Other' - }, - { - "primary_category_id": '15', - "primary_category_name": 'Payments/Disgorgements' - }, - { - "primary_category_id": '6', - "primary_category_name": 'Prohibited Contributions' - }, - { - "primary_category_id": '4', - "primary_category_name": 'Recordkeeping' - }, - { - "primary_category_id": '17', - "primary_category_name": 'Referred Findings Not Listed' - }, - { - "primary_category_id": '13', - "primary_category_name": 'Repayment to US Treasury' - } -] +audit_primary_categories_options = OrderedDict([ + ('all', 'All'), + ('2', 'Allocation Issues'), + ('3', 'Disclosure'), + ('5', 'Excessive Contributions'), + ('1', 'Failure to File Reports/Schedules/Notices'), + ('8', 'Loans'), + ('7', 'Misstatement of Financial Activity'), + ('14', 'Net Outstanding Campaign/Convention ' + 'Expenditures/Obligations'), + ('16', 'No Findings or Issues/Not a Committee'), + ('9', 'Other'), + ('15', 'Payments/Disgorgements'), + ('6', 'Prohibited Contributions'), + ('4', 'Recordkeeping'), + ('17', 'Referred Findings Not Listed'), + ('13', 'Repayment to US Treasury') +]) -audit_sub_categories_options = [ - { - "sub_category_id": 'all', - "sub_category_name": ' ' - } -] +audit_sub_categories_options = OrderedDict([ + ('all', 'All') +]) table_columns = OrderedDict([ @@ -1036,3 +988,59 @@ ('7', 'Conciliation: Pre Probable Cause'), ('6', 'Conciliation: Probable Cause'), ]) + + +primary_subject_ids = { + "": "All", + "1": "Allocation", + "2": "Committees", + "3": "Contributions", + "4": "Disclaimer", + "5": "Disbursements", + "6": "Electioneering", + "7": "Expenditures", + "8": "Express Advocacy", + "9": "Foreign Nationals", + "10": "Fraudulent misrepresentation", + "11": "Issue Advocacy", + "12": "Knowing and Willful", + "13": "Loans", + "14": "Non-federal", + "15": "Other", + "16": "Personal use", + "17": "Presidential", + "18": "Reporting", + "19": "Soft Money", +} + +secondary_subject_placeholder = { + "": "All", +} + +secondary_subject_ids = { + "2": { + "1": "Candidate", + "2": "Multi-candidate", + "3": "Non-Party", + "4": "PAC", + "5": "Party", + "6": "Political", + "7": "Presidential", + }, + "3": { + "8": "Corporations", + "9": "Excessive", + "10": "Exemptions", + "11": "In the name of another", + "12": "Labor Unions", + "13": "Limitations", + "14": "National Bank", + "15": "Prohibited", + }, + "7": { + "10": "Exemptions", + "16": "Coordinated", + "17": "Limits", + "18": "Prohibitions", + } +} diff --git a/fec/data/templates/macros/filters/dropdown-json.jinja b/fec/data/templates/macros/filters/dropdown-json.jinja index 2a8c254ca..72e26ca37 100644 --- a/fec/data/templates/macros/filters/dropdown-json.jinja +++ b/fec/data/templates/macros/filters/dropdown-json.jinja @@ -1,23 +1,30 @@ -{% macro select_json(name, label, keys, options={}, default=none) %} +{% macro select_json(name, label, keys, options={}, default=none, show_tooltip_text='') %}
- + + {% if show_tooltip_text != '' %} +
+ +
+

{{ show_tooltip_text }}

+
+
+ {% endif %}
{% endmacro %} - {% macro select_json_indentation(name, label, keys, options={}, default=none) %}
diff --git a/fec/legal/templates/layouts/legal-doc-search-results.jinja b/fec/legal/templates/layouts/legal-doc-search-results.jinja index 63d4e4cee..596a6b4a1 100644 --- a/fec/legal/templates/layouts/legal-doc-search-results.jinja +++ b/fec/legal/templates/layouts/legal-doc-search-results.jinja @@ -134,15 +134,81 @@ url.searchParams.append('mur_disposition_category_id', cat); } }); + } else if (tag && tag == 'primary_subject_id') { // Check if tag is not null or undefined + // Get the index from the tag + // const selectedCategories = url.searchParams.getAll('primary_subject_id'); + // // Remove all instances of 'case_doc_category_id' from the URL + url.searchParams.delete('primary_subject_id'); + url.searchParams.delete('secondary_subject_id'); + } else if (tag && tag == 'secondary_subject_id') { // Check if tag is not null or undefined + // // Get the index from the tag + // const selectedCategories = url.searchParams.getAll('primary_subject_id'); + // Remove all instances of 'case_doc_category_id' from the URL + url.searchParams.delete('secondary_subject_id'); } else { // For all other tags, remove the corresponding search parameter url.searchParams.delete(tag); } - + + // Go back to first page in case there are fewer pages in new result set + url.searchParams.set('offset', 0) // Redirect to the updated URL window.location = url.toString(); }); }); - }); + + // JS for subject MUR/ADR selects + const subject_select = document.getElementById('primary_subject_id'); + const secondary_select_div = document.querySelector("[data-modifies-filter='secondary_subject_id']"); + const secondary_select = document.getElementById('secondary_subject_id'); + + window.context = {{ context_vars|to_json|safe }}; + const secondary_subject_ids = window.context.secondary_subject_ids; + const primary_subject_id = window.context.primary_subject_id; + const secondary_subject_id = window.context.secondary_subject_id; + + // Load secondary select on page load + load_secondary_select(primary_subject_id); + + // Add aria attribute to selected option in primary select + Array.from(subject_select.options).forEach(option => { + if (option.value == primary_subject_id) { + //option.selected = 'selected'; + option.setAttribute('aria-selected', 'true'); + }; + }); + + // Load secondary select, upon change of primary select + subject_select.addEventListener('change', (event) => { + const selected_id = event.target.value; + load_secondary_select(selected_id); + }); + + function load_secondary_select(id){ + // First, reset the secondary select to default + secondary_select.replaceChildren(new Option('All', "", false, true)) + // Populate secondary select options, if applicable + if (id in secondary_subject_ids) { + // Show secondary select + secondary_select_div.style.display = 'block'; + // Append secondary select options + for (const [key, value] of Object.entries(secondary_subject_ids[id])) { + //If there is a current secondary_subject_id, append it as the selected option + if (key == secondary_subject_id) { + secondary_select.append(new Option(value, key, true, true)); + // Add aria-selected to that option + secondary_select.options[secondary_select.selectedIndex].setAttribute('aria-selected', 'true'); + // Append other options, unselected + } else { + secondary_select.append(new Option(value, key)); + }; + }; + + } else { + secondary_select_div.style.display = 'none'; + }; + }; + }); + {% endblock %} diff --git a/fec/legal/templates/legal-search-results-adrs.jinja b/fec/legal/templates/legal-search-results-adrs.jinja index 3e3849542..be3ab3bb7 100644 --- a/fec/legal/templates/legal-search-results-adrs.jinja +++ b/fec/legal/templates/legal-search-results-adrs.jinja @@ -1,5 +1,6 @@ {% extends "layouts/legal-doc-search-results.jinja" %} {% import 'macros/legal.jinja' as legal %} +{% import 'macros/filters/dropdown-json.jinja' as dropdown %} {% set document_type_display_name = 'Alternative Dispute Resolution' %} {% block header %} @@ -57,11 +58,33 @@ + {{ + dropdown.select_json( + 'primary_subject_id', + 'Case subject', + options=constants.primary_subject_ids, + default="" + ) + }} + {{ + dropdown.select_json_indentation( + 'secondary_subject_id', + 'Secondary case subject', + options=constants.secondary_subject_placeholder, + default="" + ) + }}
+ {% endblock %} {% block message %} @@ -115,6 +138,16 @@ {% endfor %} {% endif %} + {% if primary_subject_id or secondary_subject_id_name %} +
  • + {% if primary_subject_id_name and primary_subject_id %} +
    {{ primary_subject_id_name }}
    + {% endif %} + {% if secondary_subject_id_name %} +
    {{ secondary_subject_id_name }}
    + {% endif %} +
  • + {% endif %} @@ -130,3 +163,7 @@ {% include 'partials/legal-pagination.jinja' %} {% endwith %} {% endblock %} +{% block scripts %} + {# super loads scripts from parent #} + {{ super() }} +{% endblock %} diff --git a/fec/legal/templates/legal-search-results-murs.jinja b/fec/legal/templates/legal-search-results-murs.jinja index cb1af56a5..b7e1348df 100644 --- a/fec/legal/templates/legal-search-results-murs.jinja +++ b/fec/legal/templates/legal-search-results-murs.jinja @@ -1,6 +1,7 @@ {% extends "layouts/legal-doc-search-results.jinja" %} {% import 'macros/legal.jinja' as legal %} {% import 'macros/filters/checkbox.jinja' as checkbox %} +{% import 'macros/filters/dropdown-json.jinja' as dropdown %} {% set document_type_display_name = 'Closed Matters Under Review' %} {% block header %} @@ -71,6 +72,25 @@ prefix='mur_disposition_category_id', show_tooltip_text='Final disposition does not search archived cases' ) }} + + {{ + dropdown.select_json( + 'primary_subject_id', + 'Case subject', + options=constants.primary_subject_ids, + default="", + show_tooltip_text='Case subject does not search archived cases' + + ) + }} + {{ + dropdown.select_json_indentation( + 'secondary_subject_id', + 'Secondary case subject', + options=constants.secondary_subject_placeholder, + default="" + ) + }}
    @@ -137,6 +157,16 @@ {% endfor %} {% endif %} + {% if primary_subject_id or secondary_subject_id_name %} +
  • + {% if primary_subject_id_name and primary_subject_id %} +
    {{ primary_subject_id_name }}
    + {% endif %} + {% if secondary_subject_id_name %} +
    {{ secondary_subject_id_name }}
    + {% endif %} +
  • + {% endif %}
    @@ -195,7 +225,7 @@ location.reload(); }; - + // JS for final disposition filter // Allow the selected-item button to uncheck box in list above $(document).on('click','.dropdown__item', function(e){ const btn = $(this).find('.dropdown__item--selected'); diff --git a/fec/legal/templates/partials/legal-pagination.jinja b/fec/legal/templates/partials/legal-pagination.jinja index 5ae590d3b..e9529f8ed 100644 --- a/fec/legal/templates/partials/legal-pagination.jinja +++ b/fec/legal/templates/partials/legal-pagination.jinja @@ -31,7 +31,7 @@ {% endif %} {% if current_page > 1 %} - + {% else %} Previous {% endif %} @@ -41,12 +41,12 @@ {% if page == current_page %} {{ page }} {% else %} - {{ page }} + {{ page }} {% endif %} {% endfor %} {% if offset + limit < total_all %} - + {% else %} Next {% endif %} diff --git a/fec/legal/templates/partials/legal-search-results-mur.jinja b/fec/legal/templates/partials/legal-search-results-mur.jinja index e41d12acb..5adbe3401 100644 --- a/fec/legal/templates/partials/legal-search-results-mur.jinja +++ b/fec/legal/templates/partials/legal-search-results-mur.jinja @@ -60,7 +60,7 @@ {{ disposition }} ({{ disposition_dict[disposition] }} respondents){% if not loop.last %}; {% endif %} {% endfor %} {% else %} - Disposition(s): Not available for archived cases + Case details preview not available for archived cases {% endif %} +
    + +
    + {{ + dropdown.select_json( + 'primary_subject_id', + 'Case subject', + options=constants.primary_subject_ids, + default="" + ) + }} + {{ + dropdown.select_json_indentation( + 'secondary_subject_id', + 'Secondary case subject', + options=constants.secondary_subject_placeholder, default="" - ) - }} - {{ - dropdown.select_json_indentation( - 'secondary_subject_id', - 'Secondary case subject', - options=constants.secondary_subject_placeholder, - default="" - ) - }} - -
    - + ) + }}
    - +
    + +
    {% endblock %} {% block message %} @@ -166,4 +164,7 @@ display: none; {% block scripts %} {# super loads scripts from parent #} {{ super() }} + {% endblock %} diff --git a/fec/legal/templates/legal-search-results-murs.jinja b/fec/legal/templates/legal-search-results-murs.jinja index b7e1348df..a4b2ae8fe 100644 --- a/fec/legal/templates/legal-search-results-murs.jinja +++ b/fec/legal/templates/legal-search-results-murs.jinja @@ -243,7 +243,7 @@ setTimeout(function() { (function() { //Create an object of the mur_disposition_category_id parameter value(s) from the request - const queryFields = {'mur_disposition_category_id':window.context.mur_disposition_category_id} + const queryFields = {'mur_disposition_category_id': window.context.mur_disposition_category_id} // Create an array to hold checkbox html elements const queryBoxes = []; // Iterate the key/vals of queryFields From 469262ad8f96a083e96a8cb222631464bcf884de Mon Sep 17 00:00:00 2001 From: John Carroll Date: Thu, 31 Oct 2024 13:38:09 -0400 Subject: [PATCH 3/6] conditional pagination params so irrelevant params dont show up on other pages(AFs Statutes) that share parent template --- fec/legal/templates/partials/legal-pagination.jinja | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fec/legal/templates/partials/legal-pagination.jinja b/fec/legal/templates/partials/legal-pagination.jinja index e9529f8ed..0421c5045 100644 --- a/fec/legal/templates/partials/legal-pagination.jinja +++ b/fec/legal/templates/partials/legal-pagination.jinja @@ -31,7 +31,7 @@ {% endif %} {% if current_page > 1 %} - + {% else %} Previous {% endif %} @@ -41,12 +41,12 @@ {% if page == current_page %} {{ page }} {% else %} - {{ page }} + {{ page }} {% endif %} {% endfor %} {% if offset + limit < total_all %} - + {% else %} Next {% endif %} From 75553d0d420f43302fced9fe5310840cc27c98a6 Mon Sep 17 00:00:00 2001 From: John Carroll Date: Fri, 1 Nov 2024 01:11:10 -0400 Subject: [PATCH 4/6] rm adr subject filter, adjust js to accommodate --- .../layouts/legal-doc-search-results.jinja | 95 ++++++++++--------- .../templates/legal-search-results-adrs.jinja | 35 ------- .../templates/legal-search-results-murs.jinja | 3 + fec/legal/views.py | 29 +----- 4 files changed, 53 insertions(+), 109 deletions(-) diff --git a/fec/legal/templates/layouts/legal-doc-search-results.jinja b/fec/legal/templates/layouts/legal-doc-search-results.jinja index 69a815196..7bce67b20 100644 --- a/fec/legal/templates/layouts/legal-doc-search-results.jinja +++ b/fec/legal/templates/layouts/legal-doc-search-results.jinja @@ -156,58 +156,59 @@ window.location = url.toString(); }); }); - + // JS for subject MUR/ADR selects - const subject_select = document.getElementById('primary_subject_id'); - const secondary_select_div = document.querySelector("[data-modifies-filter='secondary_subject_id']"); - const secondary_select = document.getElementById('secondary_subject_id'); - - // The window.context is declared in the child templates (MUR/ADR) - const secondary_subject_ids = window.context.secondary_subject_ids; - const primary_subject_id = window.context.primary_subject_id; - const secondary_subject_id = window.context.secondary_subject_id; - - // Populate secondary select on page load - load_secondary_select(primary_subject_id); - - // Add aria attribute to selected option in primary select - Array.from(subject_select.options).forEach(option => { - if (option.value == primary_subject_id) { - //option.selected = 'selected'; - option.setAttribute('aria-selected', 'true'); - }; - }); + // The window.context is declared in the child templates (MURm, ADR(maybe later)) + if (window.context && window.context.result_type == 'murs') { + const secondary_subject_ids = window.context.secondary_subject_ids; + const primary_subject_id = window.context.primary_subject_id; + const secondary_subject_id = window.context.secondary_subject_id; + + const subject_select = document.getElementById('primary_subject_id'); + const secondary_select_div = document.querySelector("[data-modifies-filter='secondary_subject_id']"); + const secondary_select = document.getElementById('secondary_subject_id'); + + // Populate secondary select on page load + load_secondary_select(primary_subject_id); + + // Add aria attribute to selected option in primary select + Array.from(subject_select.options).forEach(option => { + if (option.value == primary_subject_id) { + option.setAttribute('aria-selected', 'true'); + }; + }); - // Load secondary select, upon change of primary select - subject_select.addEventListener('change', (event) => { - const selected_id = event.target.value; - load_secondary_select(selected_id); - }); + // Load secondary select, upon change of primary select + subject_select.addEventListener('change', (event) => { + const selected_id = event.target.value; + load_secondary_select(selected_id); + }); - function load_secondary_select(id){ - // First, reset the secondary select to default - secondary_select.replaceChildren(new Option('All', "", false, true)) - // Show and populate secondary select options, if applicable - if (id in secondary_subject_ids) { - // Show secondary select - secondary_select_div.style.display = 'block'; - // Append secondary select options - for (const [key, value] of Object.entries(secondary_subject_ids[id])) { - //If there is a current secondary_subject_id, append it as the selected option - if (key == secondary_subject_id) { - secondary_select.append(new Option(value, key, true, true)); - // Add aria-selected to that option - secondary_select.options[secondary_select.selectedIndex].setAttribute('aria-selected', 'true'); - // Append other options, unselected - } else { - secondary_select.append(new Option(value, key)); + function load_secondary_select(id){ + // First, reset the secondary select to default + secondary_select.replaceChildren(new Option('All', "", false, true)) + // Show and populate secondary select options, if applicable + if (id in secondary_subject_ids) { + // Show secondary select + secondary_select_div.style.display = 'block'; + // Append secondary select options + for (const [key, value] of Object.entries(secondary_subject_ids[id])) { + //If there is a current secondary_subject_id, append it as the selected option + if (key == secondary_subject_id) { + secondary_select.append(new Option(value, key, true, true)); + // Add aria-selected to that option + secondary_select.options[secondary_select.selectedIndex].setAttribute('aria-selected', 'true'); + // Append other options, unselected + } else { + secondary_select.append(new Option(value, key)); + }; }; - }; - } else { - secondary_select_div.style.display = 'none'; + } else { + secondary_select_div.style.display = 'none'; + }; }; - }; - }); + } + }); {% endblock %} diff --git a/fec/legal/templates/legal-search-results-adrs.jinja b/fec/legal/templates/legal-search-results-adrs.jinja index 9fc05e706..6103cd308 100644 --- a/fec/legal/templates/legal-search-results-adrs.jinja +++ b/fec/legal/templates/legal-search-results-adrs.jinja @@ -59,32 +59,10 @@
    -
    - -
    - {{ - dropdown.select_json( - 'primary_subject_id', - 'Case subject', - options=constants.primary_subject_ids, - default="" - ) - }} - {{ - dropdown.select_json_indentation( - 'secondary_subject_id', - 'Secondary case subject', - options=constants.secondary_subject_placeholder, - default="" - ) - }} -
    -
    {% endblock %} - {% block message %}
    @@ -136,16 +114,6 @@ {% endfor %} {% endif %} - {% if primary_subject_id or secondary_subject_id_name %} -
  • - {% if primary_subject_id_name and primary_subject_id %} -
    {{ primary_subject_id_name }}
    - {% endif %} - {% if secondary_subject_id_name %} -
    {{ secondary_subject_id_name }}
    - {% endif %} -
  • - {% endif %}
    @@ -164,7 +132,4 @@ {% block scripts %} {# super loads scripts from parent #} {{ super() }} - {% endblock %} diff --git a/fec/legal/templates/legal-search-results-murs.jinja b/fec/legal/templates/legal-search-results-murs.jinja index a4b2ae8fe..f444aece7 100644 --- a/fec/legal/templates/legal-search-results-murs.jinja +++ b/fec/legal/templates/legal-search-results-murs.jinja @@ -185,6 +185,9 @@ {% endblock %} {% block scripts %} + {# super loads scripts from parent #} {{ super() }}