From 06c4ab7e0554e2e3d1352546f8975b3a8571e320 Mon Sep 17 00:00:00 2001 From: Jeremy Goecks Date: Mon, 9 Nov 2009 14:07:16 -0500 Subject: [PATCH] Refactoring and bug fixes for grid templates. --- lib/galaxy/web/controllers/dataset.py | 2 +- lib/galaxy/web/framework/helpers/grids.py | 6 +- templates/dataset/grid.mako | 299 +----------------- templates/grid_base.mako | 358 ++++++++++++++++++++++ templates/grid_common.mako | 95 +++--- templates/history/grid.mako | 312 +------------------ 6 files changed, 409 insertions(+), 663 deletions(-) create mode 100644 templates/grid_base.mako diff --git a/lib/galaxy/web/controllers/dataset.py b/lib/galaxy/web/controllers/dataset.py index 49276fc4fdd..590d4633468 100644 --- a/lib/galaxy/web/controllers/dataset.py +++ b/lib/galaxy/web/controllers/dataset.py @@ -83,7 +83,7 @@ class HistoryDatasetAssociationListGrid( grids.Grid ): grids.MulticolFilterColumn( "Search", cols_to_filter=[ columns[0], columns[2] ], - key="free-text-search", visible=False, filterable="default" ) + key="free-text-search", visible=False, filterable="standard" ) ) operations = [] standard_filters = [] diff --git a/lib/galaxy/web/framework/helpers/grids.py b/lib/galaxy/web/framework/helpers/grids.py index d8503ce7945..01f65fe0f92 100644 --- a/lib/galaxy/web/framework/helpers/grids.py +++ b/lib/galaxy/web/framework/helpers/grids.py @@ -16,7 +16,7 @@ class Grid( object ): title = "" exposed = True model_class = None - template = "grid.mako" + template = "grid_base.mako" global_actions = [] columns = [] operations = [] @@ -99,9 +99,9 @@ class Grid( object ): if isinstance( decoded_item, list): decoded_list = from_json_string_recurse( decoded_item ) else: - decoded_list = [ str( decoded_item ) ] + decoded_list = [ unicode( decoded_item ) ] except ValueError: - decoded_list = [ str( item ) ] + decoded_list = [ unicode ( item ) ] elif isinstance( item, list): return_val = [] for element in item: diff --git a/templates/dataset/grid.mako b/templates/dataset/grid.mako index 70ca26178d3..8fc475526ee 100644 --- a/templates/dataset/grid.mako +++ b/templates/dataset/grid.mako @@ -1,298 +1 @@ -<%! from galaxy.web.framework.helpers.grids import GridColumnFilter %> - -<%inherit file="/base.mako"/> -<%def name="title()">${grid.title} - -%if message: -

-

${message}
-
-

-%endif - -<%def name="javascripts()"> - ${parent.javascripts()} - ${h.js("jquery.autocomplete", "autocomplete_tagging" )} - - - -<%def name="stylesheets()"> - ${h.css( "base", "autocomplete_tagging" )} - - - -<%namespace file="../grid_common.mako" import="*" /> - -## Print grid header. -${render_grid_filters()} - -## Print grid. -
- - - - %for column in grid.columns: - %if column.visible: - <% - href = "" - extra = "" - if column.sortable: - if sort_key == column.key: - if sort_order == "asc": - href = url( sort=( "-" + column.key ) ) - extra = "↓" - else: - href = url( sort=( column.key ) ) - extra = "↑" - else: - href = url( sort=column.key ) - %> - 1: - colspan="${column.ncells}" - %endif - > - %if href: - ${column.label} - %else: - ${column.label} - %endif - ${extra} - - %endif - %endfor - - - - - %for i, item in enumerate( query ): - - ## Data columns - %for column in grid.columns: - %if column.visible: - <% - # Link - link = column.get_link( trans, grid, item ) - if link: - href = url( **link ) - else: - href = None - # Value (coerced to list so we can loop) - value = column.get_value( trans, grid, item ) - if column.ncells == 1: - value = [ value ] - %> - %for cellnum, v in enumerate( value ): - <% - if isinstance(v, str): - v = unicode(v, 'utf-8') - # Attach popup menu? - if column.attach_popup and cellnum == 0: - extra = '' % i - else: - extra = "" - %> - %if href: - - %else: - - %endif - %endfor - %endif - %endfor - ## Actions column - - - %endfor - - - %if num_pages > 1: - - - - - %endif - %if grid.operations: - - - - - %endif - -
${v}${extra} -
- %for operation in grid.operations: - %if operation.allowed( item ): - ${operation.label} - %endif - %endfor -
-
- Page: - %for page_index in range(1, num_pages + 1): - %if page_index == cur_page_num: - ${page_index} - %else: - <% args = { "page" : page_index } %> - ${page_index} - %endif - %endfor -
- For selected histories: - %for operation in grid.operations: - %if operation.allow_multiple: - - %endif - %endfor -
-
+<%inherit file="/grid_base.mako"/> \ No newline at end of file diff --git a/templates/grid_base.mako b/templates/grid_base.mako new file mode 100644 index 00000000000..e30763510dc --- /dev/null +++ b/templates/grid_base.mako @@ -0,0 +1,358 @@ +<%! + from galaxy.model import History, HistoryDatasetAssociation + def inherit(context): + if context.get('use_panels'): + return '/base_panels.mako' + else: + return '/base.mako' +%> +<%inherit file="${inherit(context)}"/> + +## Render the grid's basic elements. Each of these elements can be subclassed. +%if message: +

+

${message}
+
+

+%endif + +${self.grid_header()} +${self.grid_table()} + +## Function definitions. + +<%def name="title()">${grid.title} + +<%def name="javascripts()"> + ${parent.javascripts()} + ${h.js("jquery.autocomplete", "autocomplete_tagging" )} + + + +<%def name="stylesheets()"> + ${h.css( "base", "autocomplete_tagging" )} + + + +<%namespace file="./grid_common.mako" import="*" /> + +## Print grid header. +<%def name="grid_header()"> +
+

${grid.title}

+ + %if grid.global_actions: + + %endif + + ${render_grid_filters()} +
+ + +## Print grid. +<%def name="grid_table()"> +
+ + + + + %for column in grid.columns: + %if column.visible: + <% + href = "" + extra = "" + if column.sortable: + if sort_key == column.key: + if sort_order == "asc": + href = url( sort=( "-" + column.key ) ) + extra = "↓" + else: + href = url( sort=( column.key ) ) + extra = "↑" + else: + href = url( sort=column.key ) + %> + 1: + colspan="${column.ncells}" + %endif + > + %if href: + ${column.label} + %else: + ${column.label} + %endif + ${extra} + + %endif + %endfor + + + + + %for i, item in enumerate( query ): + + ## Item selection column + + ## Data columns + %for column in grid.columns: + %if column.visible: + <% + # Link + link = column.get_link( trans, grid, item ) + if link: + href = url( **link ) + else: + href = None + # Value (coerced to list so we can loop) + value = column.get_value( trans, grid, item ) + if column.ncells == 1: + value = [ value ] + %> + %for cellnum, v in enumerate( value ): + <% + # Handle non-ascii chars. + if isinstance(v, str): + v = unicode(v, 'utf-8') + # Attach popup menu? + if column.attach_popup and cellnum == 0: + extra = '' % i + else: + extra = "" + %> + %if href: + + %else: + + %endif + %endfor + %endif + %endfor + ## Actions column + + + %endfor + + + ## Row for navigating among pages. + %if num_pages > 1: + + + + + %endif + + ## Grid operations. + + + + +
+ + ${v}${extra} +
+ %for operation in grid.operations: + %if operation.allowed( item ): + <% + target = "" + if operation.target: + target = "target='" + operation.target + "'" + %> + ${operation.label} + %endif + %endfor +
+
+ Page ${cur_page_num} of ${num_pages} +     Go to: + ## Next page link. + %if cur_page_num != num_pages: + <% args = { "page" : cur_page_num+1 } %> + Next + %endif + ## Previous page link. + %if cur_page_num != 1: + | + <% args = { "page" : cur_page_num-1 } %> + Previous + %endif + ## Go to page select box. + | Select: + + ## Show all link. + <% args = { "page" : "all" } %> + | Show all histories on one page +
+ <% + # Mapping between item class and plural term for item. + plural = "items" + if grid.model_class == History: + plural = "histories" + elif grid.model_class == HistoryDatasetAssociation: + plural = "datasets" + %> + For selected ${plural}: + %for operation in grid.operations: + %if operation.allow_multiple: + + %endif + %endfor +
+
+ \ No newline at end of file diff --git a/templates/grid_common.mako b/templates/grid_common.mako index 78a32c3600c..68f625d97e6 100644 --- a/templates/grid_common.mako +++ b/templates/grid_common.mako @@ -73,57 +73,52 @@ ## Print grid search/filtering UI. <%def name="render_grid_filters()"> -
-

${grid.title}

- - ## Default search. -
- - - -
- - %for column in grid.columns: - %if column.filterable == "default": - ${render_grid_column_filter(column)} - %endif - %endfor -
-
- ##| - ##<% filter_all = GridColumnFilter( "", { column.key : "All" } ) %> - ##Clear All - | Advanced Search -
-
- - - ## Advanced search. - + + ## Advanced search. + \ No newline at end of file diff --git a/templates/history/grid.mako b/templates/history/grid.mako index ecb321e90a7..6a41b688c5e 100644 --- a/templates/history/grid.mako +++ b/templates/history/grid.mako @@ -1,311 +1 @@ -<%! from galaxy.web.framework.helpers.grids import TextColumn, GridColumnFilter %> - -<%inherit file="/base.mako"/> -<%def name="title()">${grid.title} - -%if message: -

-

${message}
-
-

-%endif - -<%def name="javascripts()"> - ${parent.javascripts()} - ${h.js("jquery.autocomplete", "autocomplete_tagging" )} - - - -<%def name="stylesheets()"> - ${h.css( "base", "autocomplete_tagging" )} - - - -<%namespace file="../grid_common.mako" import="*" /> - -## Print grid header. -${render_grid_filters()} - -## Print grid. -
- - - - - - %for column in grid.columns: - %if column.visible: - <% - href = "" - extra = "" - if column.sortable: - if sort_key == column.key: - if sort_order == "asc": - href = url( sort=( "-" + column.key ) ) - extra = "↓" - else: - href = url( sort=( column.key ) ) - extra = "↑" - else: - href = url( sort=column.key ) - %> - 1: - colspan="${column.ncells}" - %endif - > - %if href: - ${column.label} - %else: - ${column.label} - %endif - ${extra} - - %endif - %endfor - - - - - %for i, item in enumerate( query ): - - ## Item selection column - - ## Data columns - %for column in grid.columns: - %if column.visible: - <% - # Link - link = column.get_link( trans, grid, item ) - if link: - href = url( **link ) - else: - href = None - # Value (coerced to list so we can loop) - value = column.get_value( trans, grid, item ) - if column.ncells == 1: - value = [ value ] - %> - %for cellnum, v in enumerate( value ): - <% - # Attach popup menu? - if column.attach_popup and cellnum == 0: - extra = '' % i - else: - extra = "" - %> - %if href: - - %else: - - %endif - %endfor - %endif - %endfor - ## Actions column - - - %endfor - - - ## Row for navigating among pages. - %if num_pages > 1: - - - - - %endif - %if grid.operations: - - - - - %endif - -
- - ${v}${extra} -
- %for operation in grid.operations: - %if operation.allowed( item ): - ${operation.label} - %endif - %endfor -
-
- Page ${cur_page_num} of ${num_pages} -     Go to: - ## Next page link. - %if cur_page_num != num_pages: - <% args = { "page" : cur_page_num+1 } %> - Next - %endif - ## Previous page link. - %if cur_page_num != 1: - | - <% args = { "page" : cur_page_num-1 } %> - Previous - %endif - ## Go to page select box. - | Select: - - ## Show all link. - <% args = { "page" : "all" } %> - | Show all histories on one page - - -
- For selected histories: - %for operation in grid.operations: - %if operation.allow_multiple: - - %endif - %endfor -
-
+<%inherit file="/grid_base.mako"/>