%!
from galaxy.web.framework.helpers.grids import TextColumn, StateColumn, GridColumnFilter
from galaxy.web.framework.helpers import iff
%>
## Render a filter UI for a grid column. Filter is rendered as a table row.
<%def name="render_grid_column_filter( grid, column )">
<%
column_label = column.label
if column.filterable == "advanced":
column_label = column_label.lower()
%>
%if column.filterable == "advanced":
${column_label}: |
%endif
%if isinstance(column, TextColumn):
%else:
%for i, filter in enumerate( column.get_accepted_filters() ):
<%
# HACK: we know that each filter will have only a single argument, so get that single argument.
for key, arg in filter.args.items():
filter_key = key
filter_arg = arg
%>
%if i > 0:
|
%endif
%if column.key in cur_filter_dict and column.key in filter.args and cur_filter_dict[column.key] == filter.args[column.key]:
${filter.label}
%else:
${filter.label}
%endif
%endfor
%endif
|
%def>
## Print grid search/filtering UI.
<%def name="render_grid_filters( grid )">
## Standard search.
%for column in grid.columns:
%if column.filterable == "standard":
${render_grid_column_filter( grid, column )}
%endif
%endfor
|
## Clear the standard search.
##|
##<% filter_all = GridColumnFilter( "", { column.key : "All" } ) %>
##Clear All
## Only show advanced search if there are filterable columns.
<%
show_advanced_search_link = False
for column in grid.columns:
if column.filterable == "advanced":
show_advanced_search_link = True
break
endif
%>
%if show_advanced_search_link:
<% args = { "advanced-search" : True } %>
Advanced Search
%endif
|
## Advanced search.
<%
# Show advanced search if flag set or if there are filters for advanced search fields.
advanced_search_display = "none"
if 'advanced-search' in kwargs and kwargs['advanced-search'] in ['True', 'true']:
advanced_search_display = "block"
for column in grid.columns:
if column.filterable == "advanced":
## Show div if current filter has value that is different from the default filter.
if column.key in cur_filter_dict and column.key in default_filter_dict and \
cur_filter_dict[column.key] != default_filter_dict[column.key]:
advanced_search_display = "block"
%>
<% args = { "advanced-search" : False } %>
Close Advanced Search
## Link to clear all filters.
##|
##<%
## no_filter = GridColumnFilter("Clear All", default_filter_dict)
##%>
##${no_filter.label}
|
%for column in grid.columns:
%if column.filterable == "advanced":
## Show div if current filter has value that is different from the default filter.
%if column.key in cur_filter_dict and column.key in default_filter_dict and \
cur_filter_dict[column.key] != default_filter_dict[column.key]:
%endif
${render_grid_column_filter( grid, column )}
%endif
%endfor
%def>