Skip to content

Commit

Permalink
task/WP-90 List registrations UTH feedback (#155)
Browse files Browse the repository at this point in the history
* Pre-sort table entries from newest to oldest received + add context for filtering by business name

* Added business name filter + needed CSS, and js functions for new filter + clear selections button

* Modified status filter url param + added url patterns for new org filter
  • Loading branch information
edmondsgarrett committed May 16, 2023
1 parent 977a522 commit fbc6bdd
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
background-position: right 6px top 50%; /* 5px design * 1.2 design-to-app ratio */
background-size: auto 10px; /* ~8px design * 1.2 design-to-app ratio (rounded) */
}
.status-filter.org-filter {
width: max-content;
}

/* SEE: https://css-tricks.com/responsive-data-tables/ */
@media (max-width: 767px) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ <h1>List Registrations</h1>
<div class="filter-content">
<span><b>Filter by Status: </b></span>
<select id="statusFilter" class="status-filter" onchange="filterTableByStatus()">
{% for option in filter_options %}
<option class="dropdown-text" {% if option == selected_filter %}selected{% endif %}>{{ option }}</option>
{% for option in status_options %}
<option class="dropdown-text" {% if option == selected_status %}selected{% endif %}>{{ option }}</option>
{% endfor %}
</select>
<span><b>Filter by Organization: </b></span>
<select id="organizationFilter" class="status-filter org-filter" onchange="filterTableByOrganization()">
{% for option in org_options %}
<option class="dropdown-text" {% if option == selected_org %}selected{% endif %}>{{ option }}</option>
{% endfor %}
</select>
{% if selected_status or selected_org %}
<button onclick="clearSelections()">Clear Options</button>
{% endif %}
</div>
</div>
<table id="registrationTable" class="registration-table">
Expand Down Expand Up @@ -58,15 +67,44 @@ <h1>List Registrations</h1>
</div>
<script>
function filterTableByStatus() {
var dropdown, filter, xhr;
var dropdown, statusFilter, xhr, url_params, url;
dropdown = document.getElementById("statusFilter");
filter = dropdown.value;
statusFilter = dropdown.value;
url_params = `?status=${statusFilter}`;
{% if selected_org %}
url_params += `&org={{selected_org}}`;
{% endif %}
url = `/administration/list-registration-requests/${url_params}`;
xhr = new XMLHttpRequest();
xhr.open('GET', `/administration/list-registration-requests/?filter=${filter}`);
xhr.open('GET', url);
xhr.send();
window.location.href = `/administration/list-registration-requests/?filter=${filter}`;
window.location.href = url;
window.location.load();
}
function filterTableByOrganization() {
var input, orgFilter, xhr, url_params, url;
input = document.getElementById("organizationFilter");
orgFilter = input.value.replace("&", encodeURIComponent('&'));
url_params = `?org=${orgFilter}`;
{% if selected_status %}
url_params = `?status={{selected_status}}&org=${orgFilter}`;
{% endif %}
url = `/administration/list-registration-requests/${url_params}`;
xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.send();
window.location.href = url;
window.location.load();
}
function clearSelections() {
var xhr;
xhr = new XMLHttpRequest();
xhr.open('GET', '/administration/list-registration-requests/')
xhr.send()
window.location.href = '/administration/list-registration-requests/';
window.location.load();
}

function openAction(reg_id) {
var actionsDropdown, selectedOption, modal_id;
actionsDropdown = document.getElementById(`actionsDropdown_${reg_id}`);
Expand Down
4 changes: 3 additions & 1 deletion apcd-cms/src/apps/admin_regis_table/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
app_name = 'administration'
urlpatterns = [
path('list-registration-requests/', RegistrationsTable.as_view(), name='admin_regis_table'),
path(r'list-registration-requests/?filter=(?P<filter>)/', RegistrationsTable.as_view(), name='admin_regis_table'),
path(r'list-registration-requests/?status=(?P<status>)/', RegistrationsTable.as_view(), name='admin_regis_table'),
path(r'list-registration-requests/?org=(?P<org>)/', RegistrationsTable.as_view(), name='admin_regis_table'),
path(r'list-registration-requests/?status=(?P<status>)&org=(?P<org>)/', RegistrationsTable.as_view(), name='admin_regis_table')
]
40 changes: 34 additions & 6 deletions apcd-cms/src/apps/admin_regis_table/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from apps.utils.utils import table_filter
from apps.components.paginator.paginator import paginator
import logging
from dateutil import parser

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -215,19 +216,46 @@ def _set_modal_content(reg, reg_ent, reg_cont, org_types):
}

context['header'] = ['Business Name', 'Type', 'Location', 'Registration Status', 'Actions']
context['filter_options'] = ['All', 'Received', 'Processing', 'Complete']
context['status_options'] = ['All', 'Received', 'Processing', 'Complete']
context['org_options'] = ['All']

try:
page_num = int(self.request.GET.get('page'))
except:
page_num = 1

def getDate(row):
date = row[1]
return parser.parse(date) if date is not None else parser.parse('1-1-0001') # put 'None' date entries all together at end of listing

registrations_content = sorted(registrations_content, key=lambda row:getDate(row), reverse=True) # sort registrations by newest to oldest

registration_table_entries = []
for registration in registrations_content:
associated_entities = [ent for ent in registrations_entities if ent[1] == registration[0]]
associated_contacts = [cont for cont in registrations_contacts if cont[1] == registration[0]]
registration_table_entries.append(_set_registration(registration, associated_entities, associated_contacts))
org_name = registration[7]
if org_name not in context['org_options']:
context['org_options'].append(org_name)

status_filter = self.request.GET.get('status')
org_filter = self.request.GET.get('org')

context['selected_status'] = None
if status_filter is not None and status_filter != 'All':
context['selected_status'] = status_filter
registration_table_entries = table_filter(status_filter, registration_table_entries, 'reg_status')

filter = self.request.GET.get('filter')
context['selected_org'] = None
if org_filter is not None and org_filter != 'All':
context['selected_org'] = org_filter
registration_table_entries = table_filter(org_filter.replace("(", "").replace(")",""), registration_table_entries, 'biz_name')

context['selected_filter'] = None
if filter is not None and filter != 'All':
context['selected_filter'] = filter
registration_table_entries = table_filter(filter, registration_table_entries, 'reg_status')
queryStr = '?'
if len(self.request.META['QUERY_STRING']) > 0:
queryStr = queryStr + self.request.META['QUERY_STRING'].replace(f'page={page_num}', '') + ('&' if self.request.GET.get('page') is None else '')
context['query_str'] = queryStr
context.update(paginator(self.request, registration_table_entries))
context['pagination_url_namespaces'] = 'administration:admin_regis_table'
return context

0 comments on commit fbc6bdd

Please sign in to comment.