details: http://www.bx.psu.edu/hg/galaxy/rev/cdbffdf2dbf7 changeset: 3711:cdbffdf2dbf7 user: Nate Coraor <nate@bx.psu.edu> date: Wed Apr 28 12:30:32 2010 -0400 description: A few grid hacks and community tool browser enhancements diffstat: lib/galaxy/web/framework/helpers/grids.py | 8 +- lib/galaxy/webapps/community/controllers/tool.py | 100 +++++++++++++- templates/grid_base.mako | 9 +- templates/webapps/community/category/create_category.mako | 2 +- templates/webapps/community/index.mako | 5 +- 5 files changed, 110 insertions(+), 14 deletions(-) diffs (242 lines): diff -r a5e19a623de5 -r cdbffdf2dbf7 lib/galaxy/web/framework/helpers/grids.py --- a/lib/galaxy/web/framework/helpers/grids.py Wed Apr 28 11:50:17 2010 -0400 +++ b/lib/galaxy/web/framework/helpers/grids.py Wed Apr 28 12:30:32 2010 -0400 @@ -290,7 +290,9 @@ if self.format: value = self.format( value ) return value - def get_link( self, trans, grid, item ): + def get_link( self, trans, grid, item, filter_params ): + # FIXME: filter_params is only here so we can do grid filtering from + # column links. remove once a better way is created. if self.link and self.link( item ): return self.link( item ) return None @@ -447,7 +449,7 @@ class PublicURLColumn( TextColumn ): """ Column displays item's public URL based on username and slug. """ - def get_link( self, trans, grid, item ): + def get_link( self, trans, grid, item, filter_params ): if item.user.username and item.slug: return dict( action='display_by_username_and_slug', username=item.user.username, slug=item.slug ) elif not item.user.username: @@ -483,7 +485,7 @@ if item.published: sharing_statuses.append( "Published" ) return ", ".join( sharing_statuses ) - def get_link( self, trans, grid, item ): + def get_link( self, trans, grid, item, filter_params ): if not item.deleted and ( item.users_shared_with or item.importable or item.published ): return dict( operation="share or publish", id=item.id ) return None diff -r a5e19a623de5 -r cdbffdf2dbf7 lib/galaxy/webapps/community/controllers/tool.py --- a/lib/galaxy/webapps/community/controllers/tool.py Wed Apr 28 11:50:17 2010 -0400 +++ b/lib/galaxy/webapps/community/controllers/tool.py Wed Apr 28 12:30:32 2010 -0400 @@ -20,9 +20,33 @@ if tool.categories: rval = '' for tca in tool.categories: - rval = '%s%s<br/>' % ( rval, tca.category.name ) + rval += '%s<br/>\n' % tca.category.name return rval return 'not set' + def filter( self, trans, user, query, column_filter ): + # Category.name conflicts with Tool.name, so we have to make our own filter + def get_single_filter( filter ): + return func.lower( model.Category.name ).like( "%" + filter.lower() + "%" ) + if column_filter == 'All': + pass + elif isinstance( column_filter, list ): + clause_list = [] + for filter in column_filter: + clause_list.append( get_single_filter( filter ) ) + query = query.filter( or_( *clause_list ) ) + else: + query = query.filter( get_single_filter( column_filter ) ) + return query + def get_link( self, trans, grid, tool, filter_params ): + if tool.categories: + filter_params['f-category'] = [] + for tca in tool.categories: + filter_params['f-category'].append( tca.category.name ) + if len( filter_params['f-category'] ) == 1: + filter_params['f-category'] = filter_params['f-category'][0] + filter_params['advanced-search'] = 'True' + return filter_params + return None class StateColumn( grids.GridColumn ): def get_value( self, trans, grid, tool ): state = tool.state() @@ -51,7 +75,11 @@ return accepted_filters class UserColumn( grids.TextColumn ): def get_value( self, trans, grid, tool ): - return tool.user.email + return tool.user.username + def get_link( self, trans, grid, tool, filter_params ): + filter_params['f-username'] = tool.user.username + filter_params['advanced-search'] = 'True' + return filter_params # Grid definition title = "Tools" model_class = model.Tool @@ -64,9 +92,14 @@ link=( lambda item: dict( operation="View Tool", id=item.id, cntrller='tool', webapp="community" ) ), attach_popup=True, filterable="advanced" ), - CategoryColumn( "Category", - key="category", - model_class=model.Category, + CategoryColumn( "Categories", + key="category", + model_class=model.Tool, + attach_popup=False, + filterable="advanced" ), + UserColumn( "Uploaded By", + key="username", + model_class=model.User, attach_popup=False, filterable="advanced" ), StateColumn( "State", @@ -92,6 +125,48 @@ grids.GridColumnFilter( "Deleted", args=dict( deleted=True ) ), grids.GridColumnFilter( "All", args=dict( deleted='All' ) ) ] + default_filter = dict( name="All", deleted="False", username="All" ) + num_rows_per_page = 50 + preserve_state = False + use_paging = True + def build_initial_query( self, session ): + return session.query( self.model_class ).outerjoin( model.ToolCategoryAssociation ).outerjoin( model.Category ) + def apply_default_filter( self, trans, query, **kwargs ): + return query.filter( self.model_class.deleted==False ) + +class ToolCategoryListGrid( grids.Grid ): + class NameColumn( grids.TextColumn ): + def get_value( self, trans, grid, category ): + return category.name + class DescriptionColumn( grids.TextColumn ): + def get_value( self, trans, grid, category ): + return category.description + # Grid definition + title = "Tool Categories" + model_class = model.Category + template='/webapps/community/category/grid.mako' + default_sort_key = "name" + columns = [ + NameColumn( "Name", + key="name", + model_class=model.Category, + link=( lambda item: dict( operation="Browse Category", id=item.id, webapp="community" ) ), + attach_popup=False, + filterable="advanced" ), + DescriptionColumn( "Description", + key="description", + model_class=model.Category, + attach_popup=False, + filterable="advanced" ) + ] + columns.append( grids.MulticolFilterColumn( "Search", + cols_to_filter=[ columns[0], columns[1] ], + key="free-text-search", + visible=False, + filterable="standard" ) ) + standard_filters = [ + grids.GridColumnFilter( "All", args=dict( deleted='All' ) ) + ] default_filter = dict( name="All", deleted="False" ) num_rows_per_page = 50 preserve_state = False @@ -103,6 +178,7 @@ class ToolBrowserController( BaseController ): + tool_category_list_grid = ToolCategoryListGrid() tool_list_grid = ToolListGrid() @web.expose @@ -112,6 +188,20 @@ status = params.get( 'status', 'done' ) return trans.fill_template( '/webapps/community/index.mako', message=message, status=status ) @web.expose + def browse_tool_categories( self, trans, **kwargs ): + if 'operation' in kwargs: + operation = kwargs['operation'].lower() + if operation == "browse category": + category_id = int( trans.app.security.decode_id( kwargs['id'] ) ) + category = trans.sa_session.query( model.Category ).get( category_id ) + del kwargs['id'] + del kwargs['operation'] + kwargs['f-category'] = category.name + return trans.response.send_redirect( web.url_for( controller='tool', + action='browse_tools', + **kwargs ) ) + return self.tool_category_list_grid( trans, **kwargs ) + @web.expose def browse_tools( self, trans, **kwargs ): if 'operation' in kwargs: operation = kwargs['operation'].lower() diff -r a5e19a623de5 -r cdbffdf2dbf7 templates/grid_base.mako --- a/templates/grid_base.mako Wed Apr 28 11:50:17 2010 -0400 +++ b/templates/grid_base.mako Wed Apr 28 12:30:32 2010 -0400 @@ -801,8 +801,12 @@ %for column in grid.columns: %if column.visible: <% + # Get filter params for generating filter links + filter_params = {} + for k, v in cur_filter_dict.items(): + filter_params['f-' + k] = v # Link - link = column.get_link( trans, grid, item ) + link = column.get_link( trans, grid, item, filter_params ) if link: href = url( **link ) else: @@ -827,10 +831,9 @@ cls = "menubutton" if column.attach_popup and href: cls = "menubutton split" - %> %if href: - <td><div id="${id}" class="${cls}" style="float: left;"><a class="label" href="${href}">${v}</a></td> + <td><div id="${id}" class="${cls}" style="float: left;"><a class="label" href="${href}">${v}</a></div></td> %else: <td><div id="${id}" class="${cls}"><label for="${encoded_id}">${v}</label></div></td> %endif diff -r a5e19a623de5 -r cdbffdf2dbf7 templates/webapps/community/category/create_category.mako --- a/templates/webapps/community/category/create_category.mako Wed Apr 28 11:50:17 2010 -0400 +++ b/templates/webapps/community/category/create_category.mako Wed Apr 28 12:30:32 2010 -0400 @@ -15,7 +15,7 @@ %endif <div class="toolForm"> - <div class="toolFormTitle">Create Role</div> + <div class="toolFormTitle">Create Category</div> <div class="toolFormBody"> <form name="create_category_form" id="create_category_form" action="${h.url_for( action='create_category' )}" method="post" > <div class="form-row"> diff -r a5e19a623de5 -r cdbffdf2dbf7 templates/webapps/community/index.mako --- a/templates/webapps/community/index.mako Wed Apr 28 11:50:17 2010 -0400 +++ b/templates/webapps/community/index.mako Wed Apr 28 12:30:32 2010 -0400 @@ -29,7 +29,8 @@ </div> <div class="toolSectionBody"> <div class="toolSectionBg"> - <div class="toolTitle"><a href="${h.url_for( controller='tool', action='browse_tools' )}" target="galaxy_main">Browse tools</a></div> + <div class="toolTitle"><a href="${h.url_for( controller='tool', action='browse_tool_categories' )}" target="galaxy_main">Browse tools by category</a></div> + <div class="toolTitle"><a href="${h.url_for( controller='tool', action='browse_tools' )}" target="galaxy_main">Browse all tools</a></div> </div> </div> <div class="toolSectionBody"> @@ -53,7 +54,7 @@ if trans.app.config.require_login and not trans.user: center_url = h.url_for( controller='user', action='login', message=message, status=status ) else: - center_url = h.url_for( controller='tool', action='browse_tools', message=message, status=status ) + center_url = h.url_for( controller='tool', action='browse_tool_categories', message=message, status=status ) %> <iframe name="galaxy_main" id="galaxy_main" frameborder="0" style="position: absolute; width: 100%; height: 100%;" src="${center_url}"> </iframe> </%def>