Skip to content

Commit

Permalink
bug fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
anatskiy committed Oct 9, 2016
1 parent f3b1232 commit 578bdf6
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 47 deletions.
23 changes: 1 addition & 22 deletions client/galaxy/scripts/mvc/history/options-menu.js
Expand Up @@ -141,30 +141,9 @@ var menu = [
}
];


// Webhooks
Webhooks.addToHistoryMenu(_l, menu);

var webhooks = new Webhooks.Webhooks();
webhooks.url = Galaxy.root + 'api/webhooks/history-menu/all';
webhooks.fetch({
async: false, // slows down History Panel loading
success: function() {
if (webhooks.length > 0) {
menu.push({
html : _l( 'Webhooks' ),
header : true
});

$.each(webhooks.models, function(index, model) {
var webhook = model.toJSON();
menu.push({
html : _l( webhook.config.title ),
anon : true
});
});
}
}
});

function buildMenu( isAnon, purgeAllowed, urlRoot ){
return _.clone( menu ).filter( function( menuOption ){
Expand Down
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/tool/tool-form.js
Expand Up @@ -85,7 +85,7 @@ define([ 'utils/utils', 'mvc/ui/ui-misc', 'mvc/ui/ui-modal', 'mvc/tool/tool-form
if ( response.jobs && response.jobs.length > 0 ) {
self.$el.append( $( '<div/>', { id: 'webhook-view' } ) );
var WebhookApp = new Webhooks.WebhookView({
urlRoot: Galaxy.root + 'api/webhooks/tools'
urlRoot: Galaxy.root + 'api/webhooks/tool'
});
}

Expand Down
76 changes: 60 additions & 16 deletions client/galaxy/scripts/mvc/webhooks.js
Expand Up @@ -5,7 +5,7 @@ define([], function() {

var WebhookModel = Backbone.Model.extend({
defaults: {
activate: true
activate: false
}
});

Expand All @@ -30,29 +30,73 @@ define([], function() {

render: function() {
var webhook = this.model.toJSON();
if (webhook.activate) {
this.$el.html('<div id="' + webhook.name + '"></div>');
if (webhook.styles) $('<style/>', {type: 'text/css'}).text(webhook.styles).appendTo('head');
if (webhook.script) $('<script/>', {type: 'text/javascript'}).text(webhook.script).appendTo('head');
}
return this;
}
});

if (webhook.type == 'masthead' && webhook.activate) {
// There must be a better way to make sure Galaxy is fully loaded
var addToMastheadMenu = function() {
var webhooks = new Webhooks();
webhooks.url = Galaxy.root + 'api/webhooks/masthead/all';
webhooks.fetch({
success: function() {
$(document).ready(function() {
Galaxy.page.masthead.collection.add({
id : webhook.name,
icon : (typeof webhook.config.icon != 'undefined') ? webhook.config.icon : '',
url : (typeof webhook.config.url != 'undefined') ? webhook.config.url : '',
tooltip : (typeof webhook.config.tooltip != 'undefined') ? webhook.config.tooltip : '',
// visible : webhook.activate
$.each(webhooks.models, function(index, model) {
var webhook = model.toJSON();
if (webhook.activate) {
Galaxy.page.masthead.collection.add({
id : webhook.name,
icon : (typeof webhook.config.icon != 'undefined') ? webhook.config.icon : '',
url : (typeof webhook.config.url != 'undefined') ? webhook.config.url : '',
tooltip : (typeof webhook.config.tooltip != 'undefined') ? webhook.config.tooltip : '',
// onclick : function() {},
// visible : webhook.activate
});
}
});
});
}
});
};

this.$el.html('<div id="' + webhook.name + '"></div>');
if (webhook.styles) $('<style/>', {type: 'text/css'}).text(webhook.styles).appendTo('head');
if (webhook.script) $('<script/>', {type: 'text/javascript'}).text(webhook.script).appendTo('head');
return this;
}
});
var addToHistoryMenu = function(_l, menu) {
var webhooks = new Webhooks();
webhooks.url = Galaxy.root + 'api/webhooks/history-menu/all';
webhooks.fetch({
async: false, // slows down History Panel loading
success: function() {
var webhooks_menu = [];

$.each(webhooks.models, function(index, model) {
var webhook = model.toJSON();
if (webhook.activate) {
webhooks_menu.push({
html : _l( webhook.config.title ),
// func: function() {},
anon : true
});
}
});

if (webhooks_menu.length > 0) {
webhooks_menu.unshift({
html : _l( 'Webhooks' ),
header : true
});
$.merge(menu, webhooks_menu);
}
}
});
};

return {
Webhooks: Webhooks,
WebhookView: WebhookView
WebhookView: WebhookView,
addToMastheadMenu: addToMastheadMenu,
addToHistoryMenu: addToHistoryMenu
};
});
Expand Up @@ -2,3 +2,4 @@ name: history_test1
title: History Menu Webhook Item 1
type:
- history-menu
activate: false
Expand Up @@ -2,3 +2,4 @@ name: history_test2
title: History Menu Webhook Item 2
type:
- history-menu
activate: false
@@ -1,6 +1,8 @@
name: masthead_test
icon: fa-repeat
type:
- masthead
activate: false

icon: fa-repeat
tooltip: Masthead Plugin Test
activate: true

3 changes: 2 additions & 1 deletion config/plugins/webhooks/phdcomics/config/phdcomics.yaml
@@ -1,4 +1,5 @@
name: phdcomics
type:
- tools
- tool
- workflow
activate: false
3 changes: 2 additions & 1 deletion config/plugins/webhooks/xkcd/config/xkcd.yml
@@ -1,4 +1,5 @@
name: xkcd
type:
- tools
- tool
- workflow
activate: true
11 changes: 9 additions & 2 deletions lib/galaxy/webhooks/__init__.py
Expand Up @@ -13,9 +13,10 @@

<<<<<<< HEAD
class Webhook(object):
def __init__(self, w_name, w_type, w_path):
def __init__(self, w_name, w_type, w_activate, w_path):
self.name = w_name
self.type = w_type
self.activate = w_activate
self.path = w_path
self.styles = ''
self.script = ''
Expand All @@ -26,6 +27,7 @@ def to_dict(self):
return {
'name': self.name,
'type': self.type,
'activate': self.activate,
'styles': self.styles,
'script': self.script,
'config': self.config
Expand Down Expand Up @@ -67,7 +69,12 @@ def load_webhook_from_config(self, config_dir, config_file):
with open(os.path.join(config_dir, config_file)) as f:
config = yaml.load(f)
path = os.path.normpath(os.path.join(config_dir, '..'))
webhook = Webhook(config['name'], config['type'], path)
webhook = Webhook(
config['name'],
config['type'],
config['activate'],
path,
)

# Read styles into a string, assuming all styles are in a
# single file
Expand Down
2 changes: 1 addition & 1 deletion static/maps/mvc/webhooks.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion static/scripts/mvc/webhooks.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 578bdf6

Please sign in to comment.