1 | <%! |
---|
2 | from galaxy.web.framework.helpers.grids import TextColumn, StateColumn, GridColumnFilter |
---|
3 | from galaxy.web.framework.helpers import iff |
---|
4 | %> |
---|
5 | |
---|
6 | ## Render a filter UI for a grid column. Filter is rendered as a table row. |
---|
7 | <%def name="render_grid_column_filter( grid, column )"> |
---|
8 | <tr> |
---|
9 | <% |
---|
10 | column_label = column.label |
---|
11 | if column.filterable == "advanced": |
---|
12 | column_label = column_label.lower() |
---|
13 | %> |
---|
14 | %if column.filterable == "advanced": |
---|
15 | <td align="left" style="padding-left: 10px">${column_label}:</td> |
---|
16 | %endif |
---|
17 | <td style="padding: 0;"> |
---|
18 | %if isinstance(column, TextColumn): |
---|
19 | <form class="text-filter-form" column_key="${column.key}" action="${url( dict() )}" method="get" > |
---|
20 | ## Carry forward filtering criteria with hidden inputs. |
---|
21 | %for temp_column in grid.columns: |
---|
22 | %if temp_column.key in cur_filter_dict: |
---|
23 | <% value = cur_filter_dict[ temp_column.key ] %> |
---|
24 | %if value != "All": |
---|
25 | <% |
---|
26 | if isinstance( temp_column, TextColumn ): |
---|
27 | value = h.to_json_string( value ) |
---|
28 | %> |
---|
29 | <input type="hidden" id="${temp_column.key}" name="f-${temp_column.key}" value='${value}'/> |
---|
30 | %endif |
---|
31 | %endif |
---|
32 | %endfor |
---|
33 | |
---|
34 | ## Print current filtering criteria and links to delete. |
---|
35 | <span id="${column.key}-filtering-criteria"> |
---|
36 | %if column.key in cur_filter_dict: |
---|
37 | <% column_filter = cur_filter_dict[column.key] %> |
---|
38 | %if isinstance( column_filter, basestring ): |
---|
39 | %if column_filter != "All": |
---|
40 | <span class='text-filter-val'> |
---|
41 | ${cur_filter_dict[column.key]} |
---|
42 | <% filter_all = GridColumnFilter( "", { column.key : "All" } ) %> |
---|
43 | <a href="${url( filter_all.get_url_args() )}"><span class="delete-search-icon" /></a> |
---|
44 | </span> |
---|
45 | %endif |
---|
46 | %elif isinstance( column_filter, list ): |
---|
47 | %for i, filter in enumerate( column_filter ): |
---|
48 | %if i > 0: |
---|
49 | , |
---|
50 | %endif |
---|
51 | <span class='text-filter-val'>${filter} |
---|
52 | <% |
---|
53 | new_filter = list( column_filter ) |
---|
54 | del new_filter[ i ] |
---|
55 | new_column_filter = GridColumnFilter( "", { column.key : h.to_json_string( new_filter ) } ) |
---|
56 | %> |
---|
57 | <a href="${url( new_column_filter.get_url_args() )}"><span class="delete-search-icon" /></a> |
---|
58 | </span> |
---|
59 | %endfor |
---|
60 | %endif |
---|
61 | %endif |
---|
62 | </span> |
---|
63 | ## Print input field for column. |
---|
64 | <span class="search-box"> |
---|
65 | <% value = iff( column.filterable == "standard", column.label.lower(), "") %> |
---|
66 | <input class="search-box-input" id="input-${column.key}-filter" name="f-${column.key}" type="text" value="${value}" size="15"/> |
---|
67 | <button class="submit-image" type="submit" title='Search'/> |
---|
68 | </span> |
---|
69 | </form> |
---|
70 | %else: |
---|
71 | <span id="${column.key}-filtering-criteria"> |
---|
72 | %for i, filter in enumerate( column.get_accepted_filters() ): |
---|
73 | <% |
---|
74 | # HACK: we know that each filter will have only a single argument, so get that single argument. |
---|
75 | for key, arg in filter.args.items(): |
---|
76 | filter_key = key |
---|
77 | filter_arg = arg |
---|
78 | %> |
---|
79 | %if i > 0: |
---|
80 | | |
---|
81 | %endif |
---|
82 | %if column.key in cur_filter_dict and column.key in filter.args and cur_filter_dict[column.key] == filter.args[column.key]: |
---|
83 | <span class="categorical-filter ${column.key}-filter current-filter">${filter.label}</span> |
---|
84 | %else: |
---|
85 | <span class="categorical-filter ${column.key}-filter"> |
---|
86 | <a href="${url( filter.get_url_args() )}" filter_key="${filter_key}" filter_val="${filter_arg}">${filter.label}</a> |
---|
87 | </span> |
---|
88 | %endif |
---|
89 | %endfor |
---|
90 | </span> |
---|
91 | %endif |
---|
92 | </td> |
---|
93 | </tr> |
---|
94 | </%def> |
---|
95 | |
---|
96 | ## Print grid search/filtering UI. |
---|
97 | <%def name="render_grid_filters( grid )"> |
---|
98 | ## Standard search. |
---|
99 | <div> |
---|
100 | <table><tr> |
---|
101 | <td style="padding: 0;"> |
---|
102 | <table> |
---|
103 | %for column in grid.columns: |
---|
104 | %if column.filterable == "standard": |
---|
105 | ${render_grid_column_filter( grid, column )} |
---|
106 | %endif |
---|
107 | %endfor |
---|
108 | </table> |
---|
109 | </td> |
---|
110 | <td> |
---|
111 | ## Clear the standard search. |
---|
112 | ##| |
---|
113 | ##<% filter_all = GridColumnFilter( "", { column.key : "All" } ) %> |
---|
114 | ##<a href="${url( filter_all.get_url_args() )}">Clear All</a> |
---|
115 | |
---|
116 | ## Only show advanced search if there are filterable columns. |
---|
117 | <% |
---|
118 | show_advanced_search_link = False |
---|
119 | for column in grid.columns: |
---|
120 | if column.filterable == "advanced": |
---|
121 | show_advanced_search_link = True |
---|
122 | break |
---|
123 | endif |
---|
124 | %> |
---|
125 | %if show_advanced_search_link: |
---|
126 | <% args = { "advanced-search" : True } %> |
---|
127 | <a style="margin-left: 10px;" href="${url( args )}" class="advanced-search-toggle">Advanced Search</a> |
---|
128 | %endif |
---|
129 | </td> |
---|
130 | </tr></table> |
---|
131 | </div> |
---|
132 | |
---|
133 | ## Advanced search. |
---|
134 | <% |
---|
135 | # Show advanced search if flag set or if there are filters for advanced search fields. |
---|
136 | advanced_search_display = "none" |
---|
137 | if 'advanced-search' in kwargs and kwargs['advanced-search'] in ['True', 'true']: |
---|
138 | advanced_search_display = "block" |
---|
139 | |
---|
140 | for column in grid.columns: |
---|
141 | if column.filterable == "advanced": |
---|
142 | ## Show div if current filter has value that is different from the default filter. |
---|
143 | if column.key in cur_filter_dict and column.key in default_filter_dict and \ |
---|
144 | cur_filter_dict[column.key] != default_filter_dict[column.key]: |
---|
145 | advanced_search_display = "block" |
---|
146 | %> |
---|
147 | <div id="more-search-options" style="display: ${advanced_search_display}; margin-top: 5px; border: 1px solid #ccc;"> |
---|
148 | <table> |
---|
149 | <tr><td style="text-align: left" colspan="100"> |
---|
150 | <% args = { "advanced-search" : False } %> |
---|
151 | <a href="${url( args )}" class="advanced-search-toggle">Close Advanced Search</a> |
---|
152 | ## Link to clear all filters. |
---|
153 | ##| |
---|
154 | ##<% |
---|
155 | ## no_filter = GridColumnFilter("Clear All", default_filter_dict) |
---|
156 | ##%> |
---|
157 | ##<a href="${url( no_filter.get_url_args() )}">${no_filter.label}</a> |
---|
158 | </td></tr> |
---|
159 | %for column in grid.columns: |
---|
160 | %if column.filterable == "advanced": |
---|
161 | ## Show div if current filter has value that is different from the default filter. |
---|
162 | %if column.key in cur_filter_dict and column.key in default_filter_dict and \ |
---|
163 | cur_filter_dict[column.key] != default_filter_dict[column.key]: |
---|
164 | <script type="text/javascript"> |
---|
165 | $('#more-search-options').css("display", "block"); |
---|
166 | </script> |
---|
167 | %endif |
---|
168 | |
---|
169 | ${render_grid_column_filter( grid, column )} |
---|
170 | %endif |
---|
171 | %endfor |
---|
172 | </table> |
---|
173 | </div> |
---|
174 | </%def> |
---|