Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
abbc66b
2202 add deselect to next_sort helper text
leckronz Sep 23, 2020
24c9c79
2202 Allow the sorting column to be deselected when it is currently D…
leckronz Sep 24, 2020
76a4536
2202 Enable AdvancedColumn header to pass sort value as a list, and e…
leckronz Oct 7, 2020
a4197ed
2202 reorganized AdvancedColumn header to remove repeated & commented…
leckronz Oct 7, 2020
cca0164
2202 loop through search_object['sort'] when it is a list to create s…
leckronz Mar 23, 2021
f7a3a83
resolve merge conflict
leckronz Mar 23, 2021
1edd4d0
2202 remove unnecessary changes
leckronz Mar 23, 2021
43f4bc7
2202 Add numbers to column headers to show their precedence in the so…
leckronz Mar 24, 2021
0675fed
2202 indicate default sorted column, simplify changes and allow norma…
leckronz Mar 29, 2021
9c142f1
#2202 - resolve merge conflict (accept incoming changes of using form…
leckronz Jan 14, 2022
0c4ede7
2202 Revert changes to apply_sort_descriptor, split one-line if/else/…
leckronz Jan 18, 2022
f9f8b6c
2202 Correct sort order toggling for default sort field, remove indic…
leckronz Jan 21, 2022
639c26c
WIP: 2202 blank sort field indicator in searchObject['sort']
leckronz Feb 3, 2022
61ee487
#2202 - use sort object flag isInitialSort/is_initial_sort to determi…
leckronz Feb 3, 2022
885103b
#2202 - prevent situation where initial load would store an empty str…
leckronz Feb 3, 2022
4e01f24
2202 Use presence of isInitialSort in the search object to correctly …
leckronz Feb 9, 2022
58c3159
WIP: 2202 - Revert sort_descriptor to its original return type (dicti…
leckronz Feb 10, 2022
c1adfbe
2202 Add multisort as the default functionality to SeekerView Column.…
leckronz Feb 11, 2022
529f858
2202 consolidate code related to sort_rank class
leckronz Feb 11, 2022
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
4 changes: 2 additions & 2 deletions seeker/templates/advanced_seeker/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
{% endif %}
{% for col in display_columns %}
{% if use_wordwrap_header %}
{% seeker_column_header col results %}
{% seeker_column_header col results default_sort %}
{% else %}
{{ col.header }}
{% column_header col default_sort %}
{% endif %}
{% endfor %}
{% endblock table-headers %}
Expand Down
1 change: 1 addition & 0 deletions seeker/templates/advanced_seeker/seeker.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
th.sort.asc, th.sort.desc { background-color: #ffe; }
th.sort.asc:before { padding-right: 5px; content: '\25B3'; }
th.sort.desc:before { padding-right: 5px; content: '\25BD'; }
.sort_rank { color: #6a6a6a; font-size: 12px; padding-right: 5px; }
.table-seeker em { background-color: #ffd; padding: 1px 3px; border-radius: 4px; border: 1px solid #eee; }
#criteria { padding-top: 10px; }
</style>
Expand Down
1 change: 1 addition & 0 deletions seeker/templates/seeker/seeker.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
th.sort.asc, th.sort.desc { background-color: #ffe; }
th.sort.asc:before { padding-right: 5px; content: '\25B3'; }
th.sort.desc:before { padding-right: 5px; content: '\25BD'; }
.sort_rank { color: #6a6a6a; font-size: 12px; padding-right: 5px; }
.table-seeker em { background-color: #ffd; padding: 1px 3px; border-radius: 4px; border: 1px solid #eee; }
#criteria { padding-top: 10px; }
</style>
Expand Down
8 changes: 6 additions & 2 deletions seeker/templatetags/seeker.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ def seeker_column(column, result, **kwargs):


@register.simple_tag
def seeker_column_header(column, results=None):
return column.header(results)
def seeker_column_header(column, results=None, default_sort=None):
return column.header(results, default_sort)

@register.simple_tag
def column_header(column, default_sort=None):
return column.header(default_sort=default_sort)


@register.simple_tag
Expand Down
72 changes: 46 additions & 26 deletions seeker/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ def header(self):
q['s'] = '%s%s' % (d, self.field)
else:
q['s'] = self.field
next_sort = 'descending' if sort == 'Ascending' else 'ascending'
next_sort = 'sort descending' if sort == 'Ascending' else 'remove from sort' if sort == 'Descending' else 'sort ascending'
Comment thread
leckronz marked this conversation as resolved.
Outdated
sr_label = (' <span class="sr-only">(%s)</span>' % sort) if sort else ''
if self.field_definition:
span = '<span title="{}" class ="fa fa-question-circle"></span>'.format(self.field_definition)
else:
span = ''
html = '<th class="%s"><a href="?%s" title="Click to sort %s" data-sort="%s">%s%s %s</a></th>' % (cls, q.urlencode(), next_sort, q['s'], self.header_html, sr_label, span)
html = '<th class="%s"><a href="?%s" title="Click to %s" data-sort="%s">%s%s %s</a></th>' % (cls, q.urlencode(), next_sort, q['s'], self.header_html, sr_label, span)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you change this to an f-string so it's a little more readable?

html = f'<th class="{ cls }"><a href="?{ q.urlencode() }" title="Click to { next_sort }" data-sort="{ q["s"] }">{ self.header_html }{ sr_label } { span }</a></th>'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The most current version of the code uses format_html() for this line and removes mark_safe() when passing back the html at the end of the function as per #136. If I were to use an f string like in your comment, I would also need to go back to using mark_safe(), correct?
Would this be undermining your change in the linked PR 136?

return mark_safe(html)

def context(self, result, **kwargs):
Expand Down Expand Up @@ -748,19 +748,17 @@ def apply_sort_descriptor(self, sort):
desc = sort.startswith('-')
field = sort.lstrip('-')
missing = self.missing_sort
sort_querydict = {'order': 'desc' if desc else 'asc'}
if missing == '_low':
missing = '_last' if desc else '_first'
sort_querydict.update({'missing':'_last' if desc else '_first'})
elif missing == '_high':
missing = '_first' if desc else '_last'
sort_querydict.update({'missing':'_first' if desc else '_last'})
return {
field: {
'order': 'desc' if desc else 'asc',
'missing': missing,
}
sort: sort_querydict

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As discussed, I think we can revert the changes to this function

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You're correct, I've reverted them in the most recent commit

}

def sort_descriptor(self, sort):
if self.missing_sort is None or isinstance(sort, dict):
if isinstance(sort, dict):
return sort
if not isinstance(sort, list):
return self.apply_sort_descriptor(sort)
Expand Down Expand Up @@ -1054,7 +1052,8 @@ def dispatch(self, request, *args, **kwargs):

class AdvancedColumn(Column):

def header(self, results=None):
def header(self, results=None, default_sort=None):

cls = '{}_{}'.format(self.view.document._doc_type.name, self.field.replace('.', '_'))
cls += ' {}_{}'.format(self.view.document.__name__.lower(), self.field.replace('.', '_'))
if self.model_lower:
Expand All @@ -1063,18 +1062,29 @@ def header(self, results=None):
return mark_safe('<th class="%s">%s</th>' % (cls, self.header_html))
current_sort = self.view.search_object['sort']
sort = None
sort_order = 0
cls += ' sort'
if current_sort.lstrip('-') == self.field:
# If the current sort field is this field, give it a class a change direction.
sort = 'Descending' if current_sort.startswith('-') else 'Ascending'
cls += ' desc' if current_sort.startswith('-') else ' asc'
d = '' if current_sort.startswith('-') else '-'
data_sort = '{}{}'.format(d, self.field)
if not isinstance(current_sort, list):
current_sort = [current_sort]
sr_label = ''
data_sort = self.field
if not current_sort or current_sort == ['']:
if default_sort.lstrip('-') == self.field:
cls += ' desc' if default_sort.startswith('-') else ' asc'
sort_default = sort = 'Descending' if default_sort.startswith('-') else 'Ascending'
sr_label = '<span class="sr-only">({})</span>'.format(sort_default)
else:
data_sort = self.field

next_sort = 'descending' if sort == 'Ascending' else 'ascending'
sr_label = (' <span class="sr-only">(%s)</span>' % sort) if sort else ''
for sort_field in current_sort:
if sort_field.lstrip('-') == self.field:
# If the current sort field is this field, give it a class a change direction.
sort = 'Descending' if sort_field.startswith('-') else 'Ascending'
cls += ' desc' if sort_field.startswith('-') else ' asc'
d = '' if sort_field.startswith('-') else '-'
data_sort = '{}{}'.format(d, self.field)
sort_order = current_sort.index(sort_field) + 1
sr_label = ('<span class="sr-only">Number {} in sort order ({})</span>'.format(sort_order, sort))

next_sort = 'sort descending' if sort == 'Ascending' else 'remove from sort' if sort == 'Descending' else 'sort ascending'

# If results provided, we check to see if header has space to allow for wordwrapping. If it already wordwrapped
# (i.e. has <br> in header) we skip it.
Expand All @@ -1085,7 +1095,11 @@ def header(self, results=None):
span = '<span title="{}" class ="fa fa-question-circle"></span>'.format(self.field_definition)
else:
span = ''
html = '<th class="{}"><a href="#" title="Click to sort {}" data-sort="{}">{}{} {}</a></th>'.format(cls, next_sort, data_sort, self.header_html, sr_label, span)
if sort_order:
sort_rank = '<span class="sort_rank">{}</span>'.format(sort_order)
else:
sort_rank = ''
html = '<th class="{}">{}<a href="#" title="Click to {}" data-sort={}>{}{} {}</a></th>'.format(cls, sort_rank, next_sort, data_sort, self.header_html, sr_label, span)
return mark_safe(html)

def get_data_max_length(self, results):
Expand Down Expand Up @@ -1394,7 +1408,7 @@ def post(self, request, *args, **kwargs):
except ValueError:
return HttpResponseBadRequest("Improperly formatted 'search_object', json.loads failed.")

# Sanity check that the search object has all of it's required components
# Sanity check that the search object has all of its required components
if not all(k in self.search_object for k in ('query', 'keywords', 'page', 'sort', 'display')):
return HttpResponseBadRequest("The 'search_object' is not in the proper format.")

Expand Down Expand Up @@ -1525,11 +1539,16 @@ def render_results(self, export):

# Finally, grab the results.
sort = self.get_sort_field(columns, self.search_object['sort'], display)

default_sort_field = ''

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As discussed, let me know if you figure out what this was used for so we can determine if it's still needed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

default_sort_field holds the value of the field upon which to sort when no other columns have been selected, or all other columns that were previously sorted upon are deselected.
So when we first navigate to a page we are sorting by default_sort_field, say field A. If we were to sort by field B and field C, and then remove field B and field C from the sort, the results would revert to being sorted by field A.

sort_descrip_dict = self.sort_descriptor(sort)
if sort_descrip_dict:
default_sort_field = list(sort_descrip_dict.keys())[0].replace('.raw', '')
if list(sort_descrip_dict.values())[0]['order'] == 'desc':
default_sort_field = '{}{}'.format('-', default_sort_field)

if sort:
if (self.missing_sort is None or isinstance(sort, dict)) and isinstance(sort, list):
results = search.sort(*self.sort_descriptor(sort))[offset:offset + page_size].params(request_timeout=self.search_timeout).execute()
else:
results = search.sort(self.sort_descriptor(sort))[offset:offset + page_size].params(request_timeout=self.search_timeout).execute()
results = search.sort(*self.sort_descriptor(sort))[offset:offset + page_size].params(request_timeout=self.search_timeout).execute()
else:
results = search[offset:offset + page_size].params(request_timeout=self.search_timeout).execute()

Expand Down Expand Up @@ -1558,6 +1577,7 @@ def render_results(self, export):
'results': results,
'show_rank': self.show_rank,
'sort': sort,
'default_sort': default_sort_field,
'export_name': self.export_name,
'use_wordwrap_header': self.use_wordwrap_header,
'search': search
Expand Down