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

Case subjects filter MURs #6530

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
144 changes: 76 additions & 68 deletions fec/data/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -1036,3 +988,59 @@
('7', 'Conciliation: Pre Probable Cause'),
('6', 'Conciliation: Probable Cause'),
])


primary_subject_ids = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name primary_subject_* and secondary_subject_* so they're more clearly tied to audits, audit categories, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rfultz I am not sure I follow, can you give example?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because these subjects are for audits specifically and we're in the constants file for data, could we rename primary_subject_ids to something like audit_primary_subject_id so we know later where and how they're being used and that they aren't simply generic subjects? (primary_subject_ids, secondary_subject_placeholder, secondary_subject_ids)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constants specific to audits are still named audit_category_options and audit_sub_category_options . The primary/secondary subject constants are specific to MUR/ADR.

"": "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",
}
}
21 changes: 14 additions & 7 deletions fec/data/templates/macros/filters/dropdown-json.jinja
Original file line number Diff line number Diff line change
@@ -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='') %}
<div class="filter js-filter js-filter-control" data-filter="select"
data-validate="false" data-modifies-filter="{{ name }}" data-required-default="{{ default }}">
<label for="{{ name }}" class="label">{{ label }}</label>
<label for="{{ name }}" class="label t-inline-block">{{ label }}</label>
{% if show_tooltip_text != '' %}
<div class="tooltip__container u-margin--bottom">
<button class="tooltip__trigger"><span class="u-visually-hidden">Learn more</span></button>
<div class="tooltip tooltip--left tooltip--above">
<p class="tooltip__content tooltip__content">{{ show_tooltip_text }}</p>
</div>
</div>
{% endif %}
<select id="{{ name }}" name="{{ name }}">
{% for option in options %}
<option value={{option[keys[0]]}}>{{ option[keys[1]] }}</option>
{% for key,value in options.items() %}
<option value="{{ key }}">{{ value }}</option>
{% endfor %}
</select>
</div>
{% endmacro %}


{% macro select_json_indentation(name, label, keys, options={}, default=none) %}
<div class="filter js-filter js-filter-control sub--filter--indent" data-filter="select"
data-validate="false" data-modifies-filter="{{ name }}" data-required-default="{{ default }}">
<label for="{{ name }}" class="label">{{ label }}</label>
<select id="{{ name }}" name="{{ name }}">
{% for option in options %}
<option value={{option[keys[0]]}}>{{ option[keys[1]] }}</option>
{% for key,value in options.items() %}
<option value="{{ key }}">{{ value }}</option>
{% endfor %}
</select>
</div>
Expand Down
69 changes: 67 additions & 2 deletions fec/legal/templates/layouts/legal-doc-search-results.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,80 @@
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');

// 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');
};
});

// 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));
};
};

} else {
secondary_select_div.style.display = 'none';
};
};
});
</script>
{% endblock %}
44 changes: 41 additions & 3 deletions fec/legal/templates/legal-search-results-adrs.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/dropdown-json.jinja' as dropdown %}
{% set document_type_display_name = 'Alternative Dispute Resolution' %}

{% block header %}
Expand Down Expand Up @@ -57,11 +58,31 @@
</div>
</div>
</div>

<div class="filter">
<button type="submit" class="button button--cta">Apply filters</button>
</div>
<div class="js-accordion accordion--neutral" data-content-prefix="filter" data-open-first="true">
<button type="button" class="js-accordion-trigger accordion__button">Case details</button>
<div class="accordion__content">
{{
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=""
)
}}
</div>
</div>
<div class="filters__inner">
<button type="submit" class="button button--cta">Apply filters</button>
</div>
{% endblock %}

{% block message %}
Expand Down Expand Up @@ -115,6 +136,16 @@
{% endfor %}
</li>
{% endif %}
{% if primary_subject_id or secondary_subject_id_name %}
<li data-tag-category="primary_subject_id" class="tag__category tag__category__range--date">
{% if primary_subject_id_name and primary_subject_id %}
<div data-removable="true" class="tag__item">{{ primary_subject_id_name }}<button class="button js-close tag__remove" data-tag="primary_subject_id"><span class="u-visually-hidden">Remove</span></button></div>
{% endif %}
{% if secondary_subject_id_name %}
<div data-removable="true" class="tag__item">{{ secondary_subject_id_name }}<button class="button js-close tag__remove" data-tag="secondary_subject_id"><span class="u-visually-hidden">Remove</span></button></div>
{% endif %}
</li>
{% endif %}
</ul>
</div>
</div>
Expand All @@ -130,3 +161,10 @@
{% include 'partials/legal-pagination.jinja' %}
{% endwith %}
{% endblock %}
{% block scripts %}
{# super loads scripts from parent #}
{{ super() }}
<script>
window.context = {{ context_vars|to_json|safe }};
</script>
{% endblock %}
Loading