From 3668d757f1b513c8518f4fb2ce1ba629dfeb94d4 Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Mon, 6 Feb 2012 15:22:56 -0500 Subject: [PATCH] Add a new grid to view the tool version lineage by tool id (parent/child ordered) for any tool that was ever used in the local Galaxy instance. Tool ids in this grid that are associated with tools currently loaded in the tool panel are highlighted in green and are click-able, displaying the tool. Eliminate the mappers for determining lineage, and use methods instead as the mappers were problematic. --- lib/galaxy/model/__init__.py | 54 +++++++++++++++-------- lib/galaxy/model/mapping.py | 8 +--- lib/galaxy/web/base/controller.py | 7 +++ lib/galaxy/web/controllers/admin.py | 52 ++++++++++++++++++++++ templates/admin/tool_version/grid.mako | 1 + templates/webapps/galaxy/admin/index.mako | 1 + 6 files changed, 98 insertions(+), 25 deletions(-) create mode 100644 templates/admin/tool_version/grid.mako diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index aee5166c0de..0b16d1cc96c 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -2693,31 +2693,49 @@ class ToolVersion( object ): self.create_time = create_time self.tool_id = tool_id self.tool_shed_repository = tool_shed_repository + def get_previous_version( self, app ): + sa_session = app.model.context.current + tva = sa_session.query( app.model.ToolVersionAssociation ) \ + .filter( app.model.ToolVersionAssociation.table.c.tool_id == self.id ) \ + .first() + if tva: + return sa_session.query( app.model.ToolVersion ) \ + .filter( app.model.ToolVersion.table.c.id == tva.parent_id ) \ + .first() + return None + def get_next_version( self, app ): + sa_session = app.model.context.current + tva = sa_session.query( app.model.ToolVersionAssociation ) \ + .filter( app.model.ToolVersionAssociation.table.c.parent_id == self.id ) \ + .first() + if tva: + return sa_session.query( app.model.ToolVersion ) \ + .filter( app.model.ToolVersion.table.c.id == tva.tool_id ) \ + .first() + return None def get_versions( self, app ): sa_session = app.model.context.current tool_versions = [] # Prepend ancestors. - def __ancestors( tool_version ): + def __ancestors( app, tool_version ): # Should we handle multiple parents at each level? - previous_tva = tool_version.previous_version - if previous_tva: - parent_version = previous_tva[0].parent_version - if parent_version not in tool_versions: - tool_versions.insert( 0, parent_version ) - __ancestors( parent_version ) + previous_version = tool_version.get_previous_version( app ) + if previous_version: + if previous_version not in tool_versions: + tool_versions.insert( 0, previous_version ) + __ancestors( app, previous_version ) # Append descendants. - def __descendants( tool_version ): + def __descendants( app, tool_version ): # Should we handle multiple child siblings at each level? - next_tva = sa_session.query( app.model.ToolVersionAssociation ) \ - .filter( app.model.ToolVersionAssociation.table.c.parent_id == tool_version.id ) \ - .first() - if next_tva: - current_version = next_tva.tool_version - if current_version not in tool_versions: - tool_versions.append( current_version ) - __descendants( current_version ) - __ancestors( self ) - __descendants( self ) + next_version = tool_version.get_next_version( app ) + if next_version: + if next_version not in tool_versions: + tool_versions.append( next_version ) + __descendants( app, next_version ) + __ancestors( app, self ) + if self not in tool_versions: + tool_versions.append( self ) + __descendants( app, self ) return tool_versions def get_version_ids( self, app ): return [ tool_version.tool_id for tool_version in self.get_versions( app ) ] diff --git a/lib/galaxy/model/mapping.py b/lib/galaxy/model/mapping.py index cb4ead228bb..6d41ab4044d 100644 --- a/lib/galaxy/model/mapping.py +++ b/lib/galaxy/model/mapping.py @@ -1627,13 +1627,7 @@ assign_mapper( context, ToolShedRepository, ToolShedRepository.table, assign_mapper( context, ToolVersion, ToolVersion.table ) -assign_mapper( context, ToolVersionAssociation, ToolVersionAssociation.table, - properties=dict( tool_version=relation( ToolVersion, - primaryjoin=( ToolVersionAssociation.table.c.tool_id == ToolVersion.table.c.id ), - backref='current_version' ), - parent_version=relation( ToolVersion, - primaryjoin=( ToolVersionAssociation.table.c.parent_id == ToolVersion.table.c.id ), - backref='previous_version' ) ) ) +assign_mapper( context, ToolVersionAssociation, ToolVersionAssociation.table ) # Set up proxy so that # Page.users_shared_with diff --git a/lib/galaxy/web/base/controller.py b/lib/galaxy/web/base/controller.py index f436c42d631..2fe0d04196a 100644 --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -1311,6 +1311,7 @@ class Admin( object ): group_list_grid = None quota_list_grid = None repository_list_grid = None + tool_version_list_grid = None delete_operation = None undelete_operation = None purge_operation = None @@ -1362,6 +1363,12 @@ class Admin( object ): toolbox=toolbox, message=message, status=status ) + @web.expose + @web.require_admin + def tool_versions( self, trans, **kwd ): + if 'message' not in kwd or not kwd[ 'message' ]: + kwd[ 'message' ] = 'Tool ids for tools that are currently loaded into the tool panel are highlighted in green (click to display).' + return self.tool_version_list_grid( trans, **kwd ) # Galaxy Role Stuff @web.expose @web.require_admin diff --git a/lib/galaxy/web/controllers/admin.py b/lib/galaxy/web/controllers/admin.py index 6dabc40335f..0f52ce2feaa 100644 --- a/lib/galaxy/web/controllers/admin.py +++ b/lib/galaxy/web/controllers/admin.py @@ -383,12 +383,64 @@ class QuotaListGrid( grids.Grid ): preserve_state = False use_paging = True +class ToolVersionListGrid( grids.Grid ): + class ToolIdColumn( grids.TextColumn ): + def get_value( self, trans, grid, tool_version ): + if tool_version.tool_id in trans.app.toolbox.tools_by_id: + link = url_for( controller='tool_runner', tool_id=tool_version.tool_id ) + link_str = '' % link + return '
%s%s
' % ( link_str, tool_version.tool_id ) + return tool_version.tool_id + class ToolVersionsColumn( grids.TextColumn ): + def get_value( self, trans, grid, tool_version ): + tool_ids_str = '' + for tool_id in tool_version.get_version_ids( trans.app ): + if tool_id in trans.app.toolbox.tools_by_id: + link = url_for( controller='tool_runner', tool_id=tool_version.tool_id ) + link_str = '' % link + tool_ids_str += '
%s%s

' % ( link_str, tool_id ) + else: + tool_ids_str += '%s
' % tool_id + return tool_ids_str + class ToolShedRepositoryColumn( grids.TextColumn ): + def get_value( self, trans, grid, tool_version ): + if tool_version.tool_shed_repository: + return tool_version.tool_shed_repository.name + return '' + # Grid definition + title = "Tool versions" + model_class = model.ToolVersion + template='/admin/tool_version/grid.mako' + default_sort_key = "tool_id" + columns = [ + ToolIdColumn( "Tool id", + key='tool_id', + attach_popup=False ), + ToolVersionsColumn( "Version lineage by tool id (parent/child ordered)" ), + ToolShedRepositoryColumn( "Tool shed repository" ), + ] + columns.append( grids.MulticolFilterColumn( "Search repository name", + cols_to_filter=[ columns[0] ], + key="free-text-search", + visible=False, + filterable="standard" ) ) + global_actions = [] + operations = [] + standard_filters = [] + default_filter = {} + num_rows_per_page = 50 + preserve_state = False + use_paging = True + def build_initial_query( self, trans, **kwd ): + return trans.sa_session.query( self.model_class ) + class AdminGalaxy( BaseUIController, Admin, AdminActions, UsesQuota, QuotaParamParser ): user_list_grid = UserListGrid() role_list_grid = RoleListGrid() group_list_grid = GroupListGrid() quota_list_grid = QuotaListGrid() + tool_version_list_grid = ToolVersionListGrid() delete_operation = grids.GridOperation( "Delete", condition=( lambda item: not item.deleted ), allow_multiple=True ) undelete_operation = grids.GridOperation( "Undelete", condition=( lambda item: item.deleted and not item.purged ), allow_multiple=True ) purge_operation = grids.GridOperation( "Purge", condition=( lambda item: item.deleted and not item.purged ), allow_multiple=True ) diff --git a/templates/admin/tool_version/grid.mako b/templates/admin/tool_version/grid.mako new file mode 100644 index 00000000000..6a41b688c5e --- /dev/null +++ b/templates/admin/tool_version/grid.mako @@ -0,0 +1 @@ +<%inherit file="/grid_base.mako"/> diff --git a/templates/webapps/galaxy/admin/index.mako b/templates/webapps/galaxy/admin/index.mako index 6f174bf1abb..a3f1887d494 100644 --- a/templates/webapps/galaxy/admin/index.mako +++ b/templates/webapps/galaxy/admin/index.mako @@ -63,6 +63,7 @@
Server