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

Filter UI on table page #86

Closed
simonw opened this issue Nov 14, 2017 · 10 comments
Closed

Filter UI on table page #86

simonw opened this issue Nov 14, 2017 · 10 comments

Comments

@simonw
Copy link
Owner

simonw commented Nov 14, 2017

A UI for building up simple table queries by adding additional filter rules that get executed as query parameters in the URL.

@simonw simonw added this to the v2: visualization edition milestone Nov 14, 2017
@simonw simonw added the large label Nov 14, 2017
@simonw simonw changed the title Filter UI Filter UI on table page Nov 17, 2017
@simonw simonw modified the milestones: v2: visualization edition, Foreign key edition Nov 19, 2017
@simonw
Copy link
Owner Author

simonw commented Nov 19, 2017

Now that we have foreign key support (#85) this is even more important, since foreign key support actively encourages linking to filtered table views.

@simonw
Copy link
Owner Author

simonw commented Nov 19, 2017

If the selected relationship is a foreign key reference, we should resolve that foreign key and display it on the page.

@simonw
Copy link
Owner Author

simonw commented Nov 19, 2017

OK,I've figured out how to do an initial version of this without JavaScript. I'll provide three form fields labell d "add filter":

  • a select box of all of the columns
  • a select box of the available operations
  • a value box

Submit those and the site will redirect you to a correctly populated querystring for that filter.

If you have filters applied, those will display as prepopulated form field triples.

For foreign key reference filters, I will display the resolved value next to the text box containing the numeric ID. In the future this can get a select2 style treatment.

@simonw
Copy link
Owner Author

simonw commented Nov 19, 2017

I'm going to be a bit classier about this and auto generate a title for the page that describes the currently applied filters.

@simonw
Copy link
Owner Author

simonw commented Nov 19, 2017

"Tablename: 3,567 rows where status = 3 (published) and n > 55"

@simonw
Copy link
Owner Author

simonw commented Nov 19, 2017

I'll have to refactor the foreign key annotating code to be usable in other contexts - at the moment it only works for annotating displays of rows, but I need to use it to resolve selected filters as well.

simonw added a commit that referenced this issue Nov 19, 2017
Part of implementing the filters UI (refs #86) - the following:

    /trees/Trees?_filter_column=SiteOrder&_filter_op=gt&_filter_value=2

Now redirects to this;

    /trees/Trees?SiteOrder__gt=2
simonw added a commit that referenced this issue Nov 19, 2017
if filter_op contains a __ the value is set to the right hand side.

e.g.

    ?_filter_column=col&_filter_op=isnull__1&_filter_value=x

Redirects to:

    ?col__isnull=1

Refs #86
@simonw
Copy link
Owner Author

simonw commented Nov 19, 2017

I need a nicer abstraction around the concept of filters. It needs to be able to:

  • convert querystring parameters into filters
  • convert filters into a querystring
  • iterate through currently applied filters
  • convert selected filters into a human description (e.g. for a title)
  • expand filters that involve a foreign key
  • add filters
  • remove filters
  • define different types of filters

It should replace my current build_where_clauses implementation, in particular this bit:

template = {
'exact': '"{}" = :{}',
'contains': '"{}" like :{}',
'endswith': '"{}" like :{}',
'startswith': '"{}" like :{}',
'gt': '"{}" > :{}',
'gte': '"{}" >= :{}',
'lt': '"{}" < :{}',
'lte': '"{}" <= :{}',
'glob': '"{}" glob :{}',
'like': '"{}" like :{}',
'isnull': '"{}" is null',
}[lookup]
numeric_operators = {'gt', 'gte', 'lt', 'lte'}
value_convert = {
'contains': lambda s: '%{}%'.format(s),
'endswith': lambda s: '%{}'.format(s),
'startswith': lambda s: '{}%'.format(s),
}.get(lookup, lambda s: s)

simonw added a commit that referenced this issue Nov 23, 2017
This:

    ?_filter_column_1=name&_filter_op_1=contains&_filter_value_1=hello
    &_filter_column_2=age&_filter_op_2=gte&_filter_value_2=12

Now redirects to this:

    ?name__contains=hello&age__gte=12

This is needed for the filter editing interface, refs #86
simonw added a commit that referenced this issue Nov 23, 2017
@simonw
Copy link
Owner Author

simonw commented Nov 23, 2017

Here's where I am now. Needs a bit of UI tidy up and it will be good to release:

conventional_power_plants_eu__conventional_power_plants_eu

simonw added a commit that referenced this issue Nov 23, 2017
simonw added a commit that referenced this issue Nov 23, 2017
@simonw
Copy link
Owner Author

simonw commented Nov 23, 2017

fivethirtyeight__bob-ross_elements-by-episode_csv

@simonw
Copy link
Owner Author

simonw commented Nov 23, 2017

And with ef3eacf I'm ready to call this one done.

@simonw simonw closed this as completed Nov 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant