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

New filters, sorting, and more updates for browse view #835

Open
wants to merge 42 commits into
base: develop
Choose a base branch
from

Conversation

dismantl
Copy link
Member

Status

Ready for review

Description of Changes

Fixes #798, #752, #834.

Changes proposed in this pull request:

  • Adds first name filter to sidebar
  • Adds total pay min/max filters
  • Adds photo availability filter
  • Adds sort dropdown menu to sort results by last name (default), rank, total pay, salary, and overtime
  • Adds First and Last buttons to the pager widget, in addition to existing Previous and Next
  • Removed latitude, longitude fields from FindOfficerForm since they weren't being used
  • The filter_by_form() function now takes an optional order parameter that will sort the results

Notes for Deployment

This requires a minor database migration.

Screenshots (if appropriate)

First name filter

image

Photo availability and total pay filters

image

First/Last paging buttons and sorting dropdown

image

Sorting dropdown expanded

image

Tests and linting

  • I have rebased my changes on current develop

  • pytests pass in the development environment on my local machine

  • flake8 checks pass

…ame.html partial; Allow filtering by both first name and last name
…ic from list_officers.html -> view; remove officer_name.html partial template
Copy link
Collaborator

@abandoned-prototype abandoned-prototype left a comment

Choose a reason for hiding this comment

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

Thanks @dismantl, this looks awesome! Really appreciate all the tests you added to make sure the new features stay functional. Sorry it took a little while for me to get back to you with a review. I pointed out a few things that stood out to me, let me know if you disagree with anything.
Looking forward to having these nice features in production soon!

unique_internal_identifier=form_data['unique_internal_identifier'], unit=form_data['unit'])
def gen_pagination_url(page):
return url_for('main.list_officer', department_id=department.id,
page=officers.next_num, order=order, race=form_data['race'], gender=form_data['gender'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

pretty sure this should be page=page instead of page=officers.next_num

@@ -176,12 +176,12 @@ class Salary(BaseModel):
officer_id = db.Column(db.Integer, db.ForeignKey('officers.id', ondelete='CASCADE'))
officer = db.relationship('Officer', back_populates='salaries')
salary = db.Column(db.Numeric, index=True, unique=False, nullable=False)
overtime_pay = db.Column(db.Numeric, index=True, unique=False, nullable=True)
overtime_pay = db.Column(db.Numeric, index=True, unique=False, nullable=False, server_default='0')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally NULL represents missing data so I don't think we should disallow it, because there is definitely a chance that we have salary data without overtime payment information for some departments. Was this needed to make any lookups easier/better defined?

Comment on lines +363 to +372
if order == 0: # Last name alphabetical
officer_query = officer_query.order_by(Officer.last_name, Officer.first_name, Officer.id)
elif order == 1: # Rank
officer_query = officer_query.order_by(nullslast(Job.order.desc()))
elif order == 2: # Total pay
officer_query = officer_query.order_by(nullslast(desc(salary_subq.c.salaries_salary + salary_subq.c.salaries_overtime_pay)))
elif order == 3: # Salary
officer_query = officer_query.order_by(nullslast(salary_subq.c.salaries_salary.desc()))
elif order == 4: # Overtime pay
officer_query = officer_query.order_by(nullslast(salary_subq.c.salaries_overtime_pay.desc()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Two comments here: Firstly, we need to make sure that whatever order we choose there cannot be a tie. So for example rank alone is bad. The reason is that the sorting is not guaranteed to be stable and ties will lead to issues with the pagination. Adding Officer.id as the last field to sort on in all cases would fix it. See #827 for more details on that issue

The second thing is the "magic" numbers, I would prefer to see an Enum here maybe, or strings like last_name, rank, total_pay instead of integers. This one is definitely not a requirement for me to approve this PR though

Comment on lines +13 to +17
RUN wget https://www.sqlite.org/2020/sqlite-autoconf-${SQLITE3_VERSION}.tar.gz && \
tar -xzf sqlite-autoconf-${SQLITE3_VERSION}.tar.gz && \
cd sqlite-autoconf-${SQLITE3_VERSION} && \
./configure && make && make install && ldconfig && \
cd .. && rm -r sqlite-autoconf-${SQLITE3_VERSION}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, great addition! This enables us to always have the most recent version of sqlite (by incrementing the SQLITE3_VERSION variable).

Comment on lines +206 to +214
if (window.location.href.includes('order=')) {
window.location.href = window.location.href.replace(/order=[^&]+/, 'order=' + this.value)
} else {
if (window.location.href.includes('?')) {
window.location.href = window.location.href + '&order=' + this.value;
} else {
window.location.href = window.location.href + '?order=' + this.value;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This works! If we want to simplify the code we could update it to use URLSearchParams as pointed out here: https://stackoverflow.com/a/41542008 Seems to be supported by everything except IE now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Salary filter on browse page 'Sort by' dropdown on browse page Filter by photo availability
2 participants