Skip to content

Commit

Permalink
Preliminary commit before fixing the search autocomplete.
Browse files Browse the repository at this point in the history
  • Loading branch information
davebx committed Jan 6, 2017
1 parent 9463d94 commit 6954c08
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 13 deletions.
13 changes: 9 additions & 4 deletions client/galaxy/scripts/mvc/toolshed/categories-view.js
@@ -1,4 +1,4 @@
define(['mvc/toolshed/toolshed-model',], function(toolshed_model) {
define(['mvc/toolshed/toolshed-model', 'mvc/toolshed/util'], function(toolshed_model, toolshed_util) {

var ToolShedCategories = Backbone.View.extend({

Expand All @@ -23,24 +23,29 @@ define(['mvc/toolshed/toolshed-model',], function(toolshed_model) {
var category_list_template = this.templateCategoryList;
this.$el.html(category_list_template(this.options));
$("#center").css('overflow', 'auto');
this.bindEvents();
},

bindEvents: function() {
// toolshed_util.initSearch('search_box');
},

reDraw: function(options) {
this.$el.empty();
this.model.url = this.model.url + '?tool_shed_url=' + this.options.tool_shed;
this.initialize(options);
this.model.fetch();
// this.model.fetch();
// this.render(options);
},

templateCategoryList: _.template([
'<div class="unified-panel-header" unselectable="on">',
'<div class="unified-panel-header-inner">Categories in <%= tool_shed.replace(/%2f/g, "/") %></div>',
'<div class="unified-panel-header-inner" style="layout: inline;">Categories in <%= tool_shed.replace(/%2f/g, "/") %></div>',
'</div>',
'<div class="unified-panel-body" id="list_categories">',
'<div id="standard-search" style="height: 2em; margin: 1em;">',
'<span class="ui-widget" >',
'<input class="search-box-input" id="repository_search" name="search" placeholder="Search repositories by name or id" size="60" type="text" />',
'<input class="search-box-input" id="search_box" data-shedurl="<%= tool_shed.replace(/%2f/g, "/") %>" name="search" placeholder="Search repositories by name or id" size="60" type="text" />',
'</span>',
'</div>',
'<div style="clear: both; margin-top: 1em;">',
Expand Down
23 changes: 21 additions & 2 deletions client/galaxy/scripts/mvc/toolshed/repositories-view.js
@@ -1,4 +1,4 @@
define(['mvc/toolshed/toolshed-model'], function(toolshed_model) {
define(['mvc/toolshed/toolshed-model', 'mvc/toolshed/util'], function(toolshed_model, toolshed_util) {

var ToolShedCategoryContentsView = Backbone.View.extend({

Expand All @@ -20,6 +20,25 @@ define(['mvc/toolshed/toolshed-model'], function(toolshed_model) {
var category_contents_template = this.templateCategoryContents;
this.$el.html(category_contents_template({category: this.model.models[0], tool_shed: this.model.tool_shed}));
$("#center").css('overflow', 'auto');
this.bindEvents();
},

bindEvents: function() {
var that = this;
// toolshed_util.searchShed();
console.log('that.selector');
require(['libs/jquery/jquery-ui'], function() {
$("search_box").autocomplete({
source: function(req, res) {console.log('blop' + req);},
minLength: 3,
select: function(event, ui) {
var tsr_id = ui.item.value;
var api_url = Galaxy.root + 'api/tool_shed/repository';
var params = {"tool_shed_url": this.model.tool_shed, "tsr_id": tsr_id};
toolshed_util.loadRepo(tsr_id, this.model.tool_shed, api_url, params);
},
});
});
},

reDraw: function(options){
Expand All @@ -34,7 +53,7 @@ define(['mvc/toolshed/toolshed-model'], function(toolshed_model) {
'<div class="unified-panel-body" id="list_repositories">',
'<div id="standard-search" style="height: 2em; margin: 1em;">',
'<span class="ui-widget" >',
'<input class="search-box-input" id="category_search" name="search" placeholder="Search repositories by name or id" size="60" type="text" />',
'<input class="search-box-input" id="search_box" name="search" data-shedurl="<%= tool_shed.replace(/%2f/g, "/") %>" placeholder="Search repositories by name or id" size="60" type="text" />',
'</span>',
'</div>',
'<div style="clear: both; margin-top: 1em;">',
Expand Down
79 changes: 79 additions & 0 deletions client/galaxy/scripts/mvc/toolshed/repository-queue-view.js
@@ -0,0 +1,79 @@
define(['mvc/toolshed/toolshed-model', 'mvc/toolshed/util'], function(toolshed_model, toolshed_util) {

var ToolShedRepoQueueView = Backbone.View.extend({

el: '#center',

defaults: {
tool_shed: "https://toolshed.g2.bx.psu.edu/"
},

initialize: function(options) {
var self = this;
this.options = _.defaults(this.options || options, this.defaults);
this.model = new toolshed_model.RepoQueue();
this.listenTo(this.model, 'sync', this.render);
this.model.url = this.model.url + '?tool_shed_url=' + this.options.tool_shed;
this.model.fetch();
},

render: function(options) {
this.options = _.extend(this.options, options);
this.options.categories = this.model.models;
var category_list_template = this.templateCategoryList;
this.$el.html(category_list_template(this.options));
$("#center").css('overflow', 'auto');
this.bindEvents();
},

bindEvents: function() {
// toolshed_util.initSearch('search_box');
},

reDraw: function(options) {
this.$el.empty();
this.model.url = this.model.url + '?tool_shed_url=' + this.options.tool_shed;
this.initialize(options);
// this.model.fetch();
// this.render(options);
},
templateRepoQueue: _.template([
'<div class="tab-pane" id="repository_queue">',
'<table id="queued_repositories" class="grid" border="0" cellpadding="2" cellspacing="2" width="100%">',
'<thead id="grid-table-header">',
'<tr>',
'<th class="datasetRow"><input class="btn btn-primary" type="submit" id="install_all" name="install_all" value="Install all" /></th>',
'<th class="datasetRow"><input class="btn btn-primary" type="submit" id="clear_queue" name="clear_queue" value="Clear queue" /></th>',
'<th class="datasetRow">ToolShed</th>',
'<th class="datasetRow">Name</th>',
'<th class="datasetRow">Owner</th>',
'<th class="datasetRow">Revision</th>',
'</tr>',
'</thead>',
'<tbody>',
'<% _.each(repositories, function(repository) { %>',
'<tr id="queued_repository_<%= repository.id %>">',
'<td class="datasetRow">',
'<input class="btn btn-primary install_one" data-repokey="<%= repository.queue_key %>" type="submit" id="install_repository_<%= repository.id %>" name="install_repository" value="Install now" />',
'</td>',
'<td class="datasetRow">',
'<input class="btn btn-primary remove_one" data-repokey="<%= repository.queue_key %>" type="submit" id="unqueue_repository_<%= repository.id %>" name="unqueue_repository" value="Remove from queue" />',
'</td>',
'<td class="datasetRow"><%= repository.tool_shed_url %></td>',
'<td class="datasetRow"><%= repository.name %></td>',
'<td class="datasetRow"><%= repository.owner %></td>',
'<td class="datasetRow"><%= repository.changeset %></td>',
'</tr>',
'<% }); %>',
'</tbody>',
'</table>',
'<input type="button" class="btn btn-primary" id="from_workflow" value="Add from workflow" />',
'</div>',
].join(''));
});

return {
RepoQueue: ToolShedRepoQueueView,
};

});
34 changes: 34 additions & 0 deletions client/galaxy/scripts/mvc/toolshed/util.js
@@ -0,0 +1,34 @@
define([], function() {
var loadRepo = function(a,b,c,d) {
console.log(a);
console.log(b);
console.log(c);
console.log(d);
};

var searchShed = function(request) {
var that = this;
console.log('shed_url');
var shed_url = this.shed_url;
var base_url = Galaxy.root + 'api/tool_shed/search';
$.get(base_url, {term: request.term, tool_shed_url: shed_url}, function(data) {
result_list = that.shedParser(data);
response(result_list);
});

};

var shedParser = function(jsondata) {
var results = [];
var hits = jsondata.hits;
$.each(hits, function(hit) {
var record = hits[hit];
var label = record.repository.name + ' by ' + record.repository.repo_owner_username + ': ' + record.repository.description;
result = {value: record.repository.id, label: label};
results.push(result);
});
return results;
};

return {loadRepo: loadRepo, searchShed: searchShed, shedParser: shedParser};
});
17 changes: 17 additions & 0 deletions lib/galaxy/webapps/galaxy/api/toolshed.py
Expand Up @@ -207,3 +207,20 @@ def repository( self, trans, **kwd ):
repository_data[ 'tool_dependencies' ] = tool_dependencies
return repository_data

@expose_api
@web.require_admin
def search( self, trans, **kwd ):
"""
GET /api/tool_shed/search
Search for a specific repository in the toolshed.
:param q: the query string to search for
:param q: str
:param tool_shed_url: the URL of the toolshed to search
:param tool_shed_url: str
"""
tool_shed_url = kwd.get( 'tool_shed_url', None )
q = kwd.get( 'term', None )
if None in [ q, tool_shed_url ]:
return {}
response = json.loads( util.url_get( tool_shed_url, params=dict( q=q ), pathspec=[ 'api', 'repositories' ] ) )
return response
10 changes: 6 additions & 4 deletions static/scripts/mvc/toolshed/categories-view.js
@@ -1,4 +1,4 @@
define([ "mvc/toolshed/toolshed-model" ], function(toolshed_model) {
define([ "mvc/toolshed/toolshed-model", "mvc/toolshed/util" ], function(toolshed_model) {
var ToolShedCategories = Backbone.View.extend({
el: "#center",
defaults: {
Expand All @@ -12,13 +12,15 @@ define([ "mvc/toolshed/toolshed-model" ], function(toolshed_model) {
render: function(options) {
this.options = _.extend(this.options, options), this.options.categories = this.model.models;
var category_list_template = this.templateCategoryList;
this.$el.html(category_list_template(this.options)), $("#center").css("overflow", "auto");
this.$el.html(category_list_template(this.options)), $("#center").css("overflow", "auto"),
this.bindEvents();
},
bindEvents: function() {},
reDraw: function(options) {
this.$el.empty(), this.model.url = this.model.url + "?tool_shed_url=" + this.options.tool_shed,
this.initialize(options), this.model.fetch();
this.initialize(options);
},
templateCategoryList: _.template([ '<div class="unified-panel-header" unselectable="on">', '<div class="unified-panel-header-inner">Categories in <%= tool_shed.replace(/%2f/g, "/") %></div>', "</div>", '<div class="unified-panel-body" id="list_categories">', '<div id="standard-search" style="height: 2em; margin: 1em;">', '<span class="ui-widget" >', '<input class="search-box-input" id="repository_search" name="search" placeholder="Search repositories by name or id" size="60" type="text" />', "</span>", "</div>", '<div style="clear: both; margin-top: 1em;">', '<table class="grid">', '<thead id="grid-table-header">', "<tr>", "<th>Name</th>", "<th>Description</th>", "<th>Repositories</th>", "</tr>", "</thead>", "<% _.each(categories, function(category) { %>", "<tr>", "<td>", '<a href="#/category/s/<%= tool_shed %>/c/<%= category.get("id") %>"><%= category.get("name") %></a>', "</td>", '<td><%= category.get("description") %></td>', '<td><%= category.get("repositories") %></td>', "</tr>", "<% }); %>", "</table>", "</div>", "</div>" ].join(""))
templateCategoryList: _.template([ '<div class="unified-panel-header" unselectable="on">', '<div class="unified-panel-header-inner" style="layout: inline;">Categories in <%= tool_shed.replace(/%2f/g, "/") %></div>', "</div>", '<div class="unified-panel-body" id="list_categories">', '<div id="standard-search" style="height: 2em; margin: 1em;">', '<span class="ui-widget" >', '<input class="search-box-input" id="search_box" data-shedurl="<%= tool_shed.replace(/%2f/g, "/") %>" name="search" placeholder="Search repositories by name or id" size="60" type="text" />', "</span>", "</div>", '<div style="clear: both; margin-top: 1em;">', '<table class="grid">', '<thead id="grid-table-header">', "<tr>", "<th>Name</th>", "<th>Description</th>", "<th>Repositories</th>", "</tr>", "</thead>", "<% _.each(categories, function(category) { %>", "<tr>", "<td>", '<a href="#/category/s/<%= tool_shed %>/c/<%= category.get("id") %>"><%= category.get("name") %></a>', "</td>", '<td><%= category.get("description") %></td>', '<td><%= category.get("repositories") %></td>', "</tr>", "<% }); %>", "</table>", "</div>", "</div>" ].join(""))
});
return {
CategoryView: ToolShedCategories
Expand Down
23 changes: 20 additions & 3 deletions static/scripts/mvc/toolshed/repositories-view.js
@@ -1,4 +1,4 @@
define([ "mvc/toolshed/toolshed-model" ], function(toolshed_model) {
define([ "mvc/toolshed/toolshed-model", "mvc/toolshed/util" ], function(toolshed_model, toolshed_util) {
var ToolShedCategoryContentsView = Backbone.View.extend({
el: "#center",
initialize: function(params) {
Expand All @@ -13,12 +13,29 @@ define([ "mvc/toolshed/toolshed-model" ], function(toolshed_model) {
this.$el.html(category_contents_template({
category: this.model.models[0],
tool_shed: this.model.tool_shed
})), $("#center").css("overflow", "auto");
})), $("#center").css("overflow", "auto"), this.bindEvents();
},
bindEvents: function() {
console.log("that.selector"), require([ "libs/jquery/jquery-ui" ], function() {
$("search_box").autocomplete({
source: function(req) {
console.log("blop" + req);
},
minLength: 3,
select: function(event, ui) {
var tsr_id = ui.item.value, api_url = Galaxy.root + "api/tool_shed/repository", params = {
tool_shed_url: this.model.tool_shed,
tsr_id: tsr_id
};
toolshed_util.loadRepo(tsr_id, this.model.tool_shed, api_url, params);
}
});
});
},
reDraw: function(options) {
this.$el.empty(), this.initialize(options);
},
templateCategoryContents: _.template([ '<div class="unified-panel-header" unselectable="on">', '<div class="unified-panel-header-inner">Repositories in <%= category.get("name") %></div>', "</div>", '<div class="unified-panel-body" id="list_repositories">', '<div id="standard-search" style="height: 2em; margin: 1em;">', '<span class="ui-widget" >', '<input class="search-box-input" id="category_search" name="search" placeholder="Search repositories by name or id" size="60" type="text" />', "</span>", "</div>", '<div style="clear: both; margin-top: 1em;">', '<table class="grid">', '<thead id="grid-table-header">', "<tr>", '<th style="width: 10%;">Owner</th>', '<th style="width: 15%;">Name</th>', "<th>Synopsis</th>", '<th style="width: 10%;">Type</th>', "</tr>", "</thead>", '<% _.each(category.get("repositories"), function(repository) { %>', "<tr>", "<td><%= repository.owner %></td>", "<td>", '<div style="float: left; margin-left: 1px;" class="menubutton split">', '<a href="#/repository/s/<%= tool_shed %>/r/<%= repository.id %>"><%= repository.name %></a>', "</div>", "</td>", "<td><%= repository.description %></td>", "<td><%= repository.type %></td>", "</tr>", "<% }); %>", "</table>", "</div>", "</div>" ].join(""))
templateCategoryContents: _.template([ '<div class="unified-panel-header" unselectable="on">', '<div class="unified-panel-header-inner">Repositories in <%= category.get("name") %></div>', "</div>", '<div class="unified-panel-body" id="list_repositories">', '<div id="standard-search" style="height: 2em; margin: 1em;">', '<span class="ui-widget" >', '<input class="search-box-input" id="search_box" name="search" data-shedurl="<%= tool_shed.replace(/%2f/g, "/") %>" placeholder="Search repositories by name or id" size="60" type="text" />', "</span>", "</div>", '<div style="clear: both; margin-top: 1em;">', '<table class="grid">', '<thead id="grid-table-header">', "<tr>", '<th style="width: 10%;">Owner</th>', '<th style="width: 15%;">Name</th>', "<th>Synopsis</th>", '<th style="width: 10%;">Type</th>', "</tr>", "</thead>", '<% _.each(category.get("repositories"), function(repository) { %>', "<tr>", "<td><%= repository.owner %></td>", "<td>", '<div style="float: left; margin-left: 1px;" class="menubutton split">', '<a href="#/repository/s/<%= tool_shed %>/r/<%= repository.id %>"><%= repository.name %></a>', "</div>", "</td>", "<td><%= repository.description %></td>", "<td><%= repository.type %></td>", "</tr>", "<% }); %>", "</table>", "</div>", "</div>" ].join(""))
});
return {
Category: ToolShedCategoryContentsView
Expand Down

0 comments on commit 6954c08

Please sign in to comment.