Skip to content

Commit

Permalink
Enable preview of repository from workflows missing tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
davebx committed Feb 14, 2017
1 parent 259c3c5 commit b15fdf0
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 15 deletions.
18 changes: 14 additions & 4 deletions client/galaxy/scripts/admin.toolshed.js
Expand Up @@ -3,13 +3,15 @@ define(["mvc/toolshed/shed-list-view",
"mvc/toolshed/repositories-view",
"mvc/toolshed/repository-view",
"mvc/toolshed/repository-queue-view",
"mvc/toolshed/repo-status-view"],
"mvc/toolshed/repo-status-view",
"mvc/toolshed/workflows-view"],
function(mod_shed_list_view,
mod_categories_view,
mod_repositories_view,
mod_repository_view,
mod_repoqueue_view,
mod_repo_status_view) {
mod_repo_status_view,
mod_workflows_view) {

var AdminToolshedRouter = Backbone.Router.extend({

Expand All @@ -24,6 +26,7 @@ define(["mvc/toolshed/shed-list-view",
"" : "toolsheds",
"sheds" : "toolsheds",
"queue" : "queue",
"workflows" : "workflows",
"status/r/:repositories" : "status",
"status" : "status",
"categories/s/:tool_shed" : "categories",
Expand Down Expand Up @@ -56,6 +59,7 @@ define(["mvc/toolshed/shed-list-view",
initialize: function() {
Galaxy.admintoolshedapp = this;
this.admin_toolshed_router = new AdminToolshedRouter();
$("#panel_header").append('<div class="unified-panel-header-inner"><a href="#/queue">Repository Queue</a></div>');

this.admin_toolshed_router.on('route:queue', function() {
if (Galaxy.admintoolshedapp.adminRepoQueueView) {
Expand Down Expand Up @@ -105,8 +109,14 @@ define(["mvc/toolshed/shed-list-view",
Galaxy.admintoolshedapp.adminRepoStatusView = new mod_repo_status_view.RepoStatus({repositories: repositories.split('|')});
}
});

$("#panel_header").append('<span style="position: absolute; top: 0px; right: 0px;"><a href="#/queue">Repository Queue</a></span>');
this.admin_toolshed_router.on('route:workflows', function() {
if (Galaxy.admintoolshedapp.adminWorkflowsView) {
Galaxy.admintoolshedapp.adminWorkflowsView.reDraw();
}
else {
Galaxy.admintoolshedapp.adminWorkflowsView = new mod_workflows_view.Workflows();
}
});

Backbone.history.start({pushState: false});
},
Expand Down
4 changes: 2 additions & 2 deletions client/galaxy/scripts/mvc/toolshed/repository-queue-view.js
Expand Up @@ -29,6 +29,7 @@ define(['mvc/toolshed/toolshed-model', 'mvc/toolshed/util'], function(toolshed_m
var repository_metadata = that.loadFromQueue($(this).attr('data-repokey'));
that.installFromQueue(repository_metadata, $(this).attr('data-repokey'));
});
$('#from_workflow').on('click', function() { Backbone.history.navigate('workflows', {trigger: true, replace:true}); });
},

installFromQueue: function install_from_queue(repository_metadata, queue_key) {
Expand Down Expand Up @@ -118,8 +119,7 @@ define(['mvc/toolshed/toolshed-model', 'mvc/toolshed/util'], function(toolshed_m
'</table>',
'<input type="button" class="btn btn-primary" id="from_workflow" value="Add from workflow" />',
'</div>',
].join(''))
});
].join('')),

return {
RepoQueueView: View,
Expand Down
13 changes: 12 additions & 1 deletion client/galaxy/scripts/mvc/toolshed/toolshed-model.js
Expand Up @@ -73,6 +73,16 @@ define([], function() {
model: RepoStatusModel
});

var WorkflowToolsModel = Backbone.Model.extend({
defaults: [{}],
urlRoot: Galaxy.root + 'api/workflows?missing_tools=True',
});

var WorkflowToolsCollection = Backbone.Collection.extend({
url: Galaxy.root + 'api/workflows?missing_tools=True',
model: WorkflowToolsModel
});

return {
ShedModel: ToolShedModel,
ShedsCollection: ToolShedsCollection,
Expand All @@ -83,7 +93,8 @@ define([], function() {
RepositoryModel: ToolShedRepositoryModel,
RepositoryCollection: ToolShedRepositoryCollection,
RepoQueue: RepoQueueCollection,
RepoStatus: RepoStatusCollection
RepoStatus: RepoStatusCollection,
WorkflowTools: WorkflowToolsCollection
};

});
103 changes: 103 additions & 0 deletions client/galaxy/scripts/mvc/toolshed/workflows-view.js
@@ -0,0 +1,103 @@
define(['mvc/toolshed/toolshed-model', 'mvc/toolshed/util'], function(toolshed_model, toolshed_util) {

var View = Backbone.View.extend({

el: '#center',

defaults: [{}],

initialize: function(options) {
var that = this;
this.model = new toolshed_model.WorkflowTools();
this.listenTo(this.model, 'sync', this.render);
this.model.fetch();
that.render();
},

render: function(options) {
var that = this;
var workflows_missing_tools = that.templateWorkflows;
var workflows = that.model.models;
_.each(workflows.attributes, function(wo) {
console.log({wo: workflows.get(wo)});
});
console.log(workflows);
that.$el.html(workflows_missing_tools({workflows: workflows}));
$("#center").css('overflow', 'auto');
that.bindEvents();
},

bindEvents: function() {
var that = this;
$('.show_wf_repo').on('click', function() {
var tool_ids = $(this).attr('data-toolids');
var toolshed = $(this).attr('data-shed');
var api_url = Galaxy.root + 'api/tool_shed/repository'
var params = {'tool_ids': tool_ids};
$.get(api_url, params, function(data) {
repository_id = data.repository.id;
var new_route = 'repository/s/' + toolshed.replace(/:/g, '%3a').replace(/\//g, '%2f') + '/r/' + data.repository.id;
Backbone.history.navigate(new_route, {trigger: true, replace:true});
});
});
$('#from_workflow').on('click', that.loadWorkflows);
},

reDraw: function(options) {
this.$el.empty();
this.initialize(options);
this.model.fetch();
this.render(options);
},

templateWorkflows: _.template([
'<table id="workflows_missing_tools" class="grid" border="0" cellpadding="2" cellspacing="2" width="100%">',
'<thead id="grid-table-header">',
'<tr>',
'<th class="datasetRow">Workflows</th>',
'<th class="datasetRow">Tool IDs</th>',
'<th class="datasetRow">Shed</th>',
'<th class="datasetRow">Name</th>',
'<th class="datasetRow">Owner</th>',
'<th class="datasetRow">Actions</th>',
'</tr>',
'</thead>',
'<tbody>',
'<% _.each(workflows, function(workflow) { %>',
'<tr>',
'<td class="datasetRow">',
'<ul class="workflow_names">',
'<% _.each(workflow.get("workflows"), function(name) { %>',
'<li class="workflow_names"><%= name %></li>',
'<% }); %>',
'</ul>',
'</td>',
'<td class="datasetRow">',
'<ul class="workflow_tools">',
'<% _.each(workflow.get("tools"), function(tool) { %>',
'<li class="workflow_tools"><%= tool %></li>',
'<% }); %>',
'</ul>',
'</td>',
'<td class="datasetRow"><%= workflow.get("shed") %></td>',
'<td class="datasetRow"><%= workflow.get("repository") %></td>',
'<td class="datasetRow"><%= workflow.get("owner") %></td>',
'<td class="datasetRow">',
'<ul class="workflow_tools">',
'<li class="workflow_tools">',
'<input type="button" class="show_wf_repo btn btn-primary" data-shed="<%= workflow.get("shed") %>" data-owner="<%= workflow.get("owner") %>" data-repo="<%= workflow.get("repository") %>" data-toolids="<%= workflow.get("tools").join(",") %>" value="Preview" /></li>',
'<li><input type="button" class="queue_wf_repo btn btn-primary" data-shed="<%= workflow.get("shed") %>" data-owner="<%= workflow.get("owner") %>" data-repo="<%= workflow.get("repository") %>" data-toolids="<%= workflow.get("tools").join(",") %>" value="Add to queue" /></li>',
'</ul>',
'</td>',
'</tr>',
'<% }); %>',
'</ul>',
'</div>',
].join(''))
});

return {
Workflows: View,
};

});
17 changes: 15 additions & 2 deletions lib/galaxy/webapps/galaxy/api/workflows.py
Expand Up @@ -42,6 +42,12 @@ def __init__( self, app ):
self.workflow_manager = workflows.WorkflowsManager( app )
self.workflow_contents_manager = workflows.WorkflowContentsManager( app )

def __get_full_shed_url( self, url ):
for name, shed_url in self.app.tool_shed_registry.tool_sheds.items():
if url in shed_url:
return shed_url
return None

@expose_api
def index(self, trans, **kwd):
"""
Expand Down Expand Up @@ -79,6 +85,7 @@ def index(self, trans, **kwd):
rval.append(item)
if missing_tools:
workflows_missing_tools = []
workflows = []
workflows_by_toolshed = dict()
for key, value in enumerate(rval):
tool_ids = []
Expand All @@ -94,15 +101,21 @@ def index(self, trans, **kwd):
for workflow in workflows_missing_tools:
for tool_id in workflow[ 'missing_tools' ]:
toolshed, _, owner, name, tool, version = tool_id.split( '/' )
shed_url = self.__get_full_shed_url( toolshed )
repo_identifier = '/'.join( [ toolshed, owner, name ] )
if repo_identifier not in workflows_by_toolshed:
workflows_by_toolshed[ repo_identifier ] = dict( tools=[ tool_id ], workflows=[ workflow[ 'name' ] ] )
workflows_by_toolshed[ repo_identifier ] = dict( shed=shed_url.rstrip('/'), repository=name, owner=owner, tools=[ tool_id ], workflows=[ workflow[ 'name' ] ] )
else:
if tool_id not in workflows_by_toolshed[ repo_identifier ][ 'tools' ]:
workflows_by_toolshed[ repo_identifier ][ 'tools' ].append( tool_id )
if workflow[ 'name' ] not in workflows_by_toolshed[ repo_identifier ][ 'workflows' ]:
workflows_by_toolshed[ repo_identifier ][ 'workflows' ].append( workflow[ 'name' ] )
return workflows_by_toolshed
for repo_tag in workflows_by_toolshed:
workflows.append( workflows_by_toolshed[ repo_tag ] )
return workflows
# import json
# log.debug(json.dumps(workflows_by_toolshed, indent=2))
# return workflows_by_toolshed
return rval

@expose_api
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/tool_shed/api/repositories.py
Expand Up @@ -440,7 +440,7 @@ def index( self, trans, deleted=False, owner=None, name=None, **kwd ):
else:
metadata_dict[ 'repository_dependencies' ] = []
if metadata.includes_tool_dependencies:
metadata_dict[ 'tool_dependencies' ] = repository.get_tool_dependencies( changehash )
metadata_dict[ 'tool_dependencies' ] = repository.get_tool_dependencies( self.app, changehash )
else:
metadata_dict[ 'tool_dependencies' ] = {}
if metadata.includes_tools:
Expand Down
9 changes: 6 additions & 3 deletions static/scripts/admin.toolshed.js
@@ -1,4 +1,4 @@
define([ "mvc/toolshed/shed-list-view", "mvc/toolshed/categories-view", "mvc/toolshed/repositories-view", "mvc/toolshed/repository-view", "mvc/toolshed/repository-queue-view", "mvc/toolshed/repo-status-view" ], function(mod_shed_list_view, mod_categories_view, mod_repositories_view, mod_repository_view, mod_repoqueue_view, mod_repo_status_view) {
define([ "mvc/toolshed/shed-list-view", "mvc/toolshed/categories-view", "mvc/toolshed/repositories-view", "mvc/toolshed/repository-view", "mvc/toolshed/repository-queue-view", "mvc/toolshed/repo-status-view", "mvc/toolshed/workflows-view" ], function(mod_shed_list_view, mod_categories_view, mod_repositories_view, mod_repository_view, mod_repoqueue_view, mod_repo_status_view, mod_workflows_view) {
var AdminToolshedRouter = Backbone.Router.extend({
initialize: function() {
this.routesHit = 0, Backbone.history.on("route", function() {
Expand All @@ -9,6 +9,7 @@ define([ "mvc/toolshed/shed-list-view", "mvc/toolshed/categories-view", "mvc/too
"": "toolsheds",
sheds: "toolsheds",
queue: "queue",
workflows: "workflows",
"status/r/:repositories": "status",
status: "status",
"categories/s/:tool_shed": "categories",
Expand All @@ -27,6 +28,7 @@ define([ "mvc/toolshed/shed-list-view", "mvc/toolshed/categories-view", "mvc/too
},
initialize: function() {
Galaxy.admintoolshedapp = this, this.admin_toolshed_router = new AdminToolshedRouter(),
$("#panel_header").append('<div class="unified-panel-header-inner"><a href="#/queue">Repository Queue</a></div>'),
this.admin_toolshed_router.on("route:queue", function() {
Galaxy.admintoolshedapp.adminRepoQueueView ? Galaxy.admintoolshedapp.adminRepoQueueView.reDraw() : Galaxy.admintoolshedapp.adminRepoQueueView = new mod_repoqueue_view.RepoQueueView();
}), this.admin_toolshed_router.on("route:toolsheds", function() {
Expand Down Expand Up @@ -59,8 +61,9 @@ define([ "mvc/toolshed/shed-list-view", "mvc/toolshed/categories-view", "mvc/too
}) : Galaxy.admintoolshedapp.adminRepoStatusView = new mod_repo_status_view.RepoStatus({
repositories: repositories.split("|")
});
}), $("#panel_header").append('<span style="position: absolute; top: 0px; right: 0px;"><a href="#/queue">Repository Queue</a></span>'),
Backbone.history.start({
}), this.admin_toolshed_router.on("route:workflows", function() {
Galaxy.admintoolshedapp.adminWorkflowsView ? Galaxy.admintoolshedapp.adminWorkflowsView.reDraw() : Galaxy.admintoolshedapp.adminWorkflowsView = new mod_workflows_view.Workflows();
}), Backbone.history.start({
pushState: !1
});
}
Expand Down

0 comments on commit b15fdf0

Please sign in to comment.