diff --git a/client/galaxy/scripts/layout/masthead.js b/client/galaxy/scripts/layout/masthead.js index 527ce3f8b46..d6b9aaad59e 100644 --- a/client/galaxy/scripts/layout/masthead.js +++ b/client/galaxy/scripts/layout/masthead.js @@ -1,7 +1,7 @@ -import Utils from "utils/utils"; import Menu from "layout/menu"; import Scratchbook from "layout/scratchbook"; import QuotaMeter from "mvc/user/user-quotameter"; + /** Masthead **/ var View = Backbone.View.extend({ initialize: function(options) { @@ -62,7 +62,9 @@ var View = Backbone.View.extend({ var text = ""; self.collection.each(model => { var q = model.get("onbeforeunload") && model.get("onbeforeunload")(); - q && (text += `${q} `); + if (q) { + text += `${q} `; + } }); if (text !== "") { return text; diff --git a/client/galaxy/scripts/layout/menu.js b/client/galaxy/scripts/layout/menu.js index d848465994e..49edea8089f 100644 --- a/client/galaxy/scripts/layout/menu.js +++ b/client/galaxy/scripts/layout/menu.js @@ -105,15 +105,15 @@ var Collection = Backbone.Collection.extend({ // // Webhooks // - Webhooks.add({ - url: "api/webhooks/masthead/all", + Webhooks.load({ + type: "masthead", callback: function(webhooks) { $(document).ready(() => { - $.each(webhooks.models, (index, model) => { + webhooks.each(model => { var webhook = model.toJSON(); if (webhook.activate) { var obj = { - id: webhook.name, + id: webhook.id, icon: webhook.config.icon, url: webhook.config.url, tooltip: webhook.config.tooltip, diff --git a/client/galaxy/scripts/layout/page.js b/client/galaxy/scripts/layout/page.js index 8cef58f32d2..a2ce69c1655 100644 --- a/client/galaxy/scripts/layout/page.js +++ b/client/galaxy/scripts/layout/page.js @@ -2,6 +2,7 @@ import Masthead from "layout/masthead"; import Panel from "layout/panel"; import Modal from "mvc/ui/ui-modal"; import Utils from "utils/utils"; + var View = Backbone.View.extend({ el: "body", className: "full-content", @@ -61,11 +62,12 @@ var View = Backbone.View.extend({ this.render(); // start the router - this.router && + if (this.router) { Backbone.history.start({ root: Galaxy.root, pushState: true }); + } }, render: function() { diff --git a/client/galaxy/scripts/mvc/history/options-menu.js b/client/galaxy/scripts/mvc/history/options-menu.js index e8f280ebf40..a330160c045 100644 --- a/client/galaxy/scripts/mvc/history/options-menu.js +++ b/client/galaxy/scripts/mvc/history/options-menu.js @@ -175,13 +175,13 @@ var menu = [ ]; // Webhooks -Webhooks.add({ - url: "api/webhooks/history-menu/all", +Webhooks.load({ + type: "history-menu", async: false, // (hypothetically) slows down the performance callback: function(webhooks) { var webhooks_menu = []; - $.each(webhooks.models, (index, model) => { + webhooks.each(model => { var webhook = model.toJSON(); if (webhook.activate) { webhooks_menu.push({ diff --git a/client/galaxy/scripts/mvc/tool/tool-form-base.js b/client/galaxy/scripts/mvc/tool/tool-form-base.js index 65f8c197c37..87404c7da92 100644 --- a/client/galaxy/scripts/mvc/tool/tool-form-base.js +++ b/client/galaxy/scripts/mvc/tool/tool-form-base.js @@ -6,6 +6,7 @@ import Utils from "utils/utils"; import Deferred from "utils/deferred"; import Ui from "mvc/ui/ui-misc"; import FormBase from "mvc/form/form-view"; +import Webhooks from "mvc/webhooks"; import Citations from "components/Citations.vue"; import Vue from "vue"; export default FormBase.extend({ @@ -200,19 +201,23 @@ export default FormBase.extend({ } // add tool menu webhooks - $.getJSON("/api/webhooks/tool-menu/all", webhooks => { - _.each(webhooks, webhook => { - if (webhook.activate && webhook.config.function) { - menu_button.addMenu({ - icon: webhook.config.icon, - title: webhook.config.title, - onclick: function() { - var func = new Function("options", webhook.config.function); - func(options); - } - }); - } - }); + Webhooks.load({ + type: "tool-menu", + callback: function(webhooks) { + webhooks.each(model => { + var webhook = model.toJSON(); + if (webhook.activate && webhook.config.function) { + menu_button.addMenu({ + icon: webhook.config.icon, + title: webhook.config.title, + onclick: function() { + var func = new Function("options", webhook.config.function); + func(options); + } + }); + } + }); + } }); return { diff --git a/client/galaxy/scripts/mvc/tool/tool-form-composite.js b/client/galaxy/scripts/mvc/tool/tool-form-composite.js index 1beea452ce9..00a5e78f845 100644 --- a/client/galaxy/scripts/mvc/tool/tool-form-composite.js +++ b/client/galaxy/scripts/mvc/tool/tool-form-composite.js @@ -598,7 +598,7 @@ var View = Backbone.View.extend({ if ($.isArray(response) && response.length > 0) { self.$el.append($("
", { id: "webhook-view" })); var WebhookApp = new Webhooks.WebhookView({ - urlRoot: `${Galaxy.root}api/webhooks/workflow`, + type: "workflow", toolId: job_def.tool_id, toolVersion: job_def.tool_version }); diff --git a/client/galaxy/scripts/mvc/tool/tool-form.js b/client/galaxy/scripts/mvc/tool/tool-form.js index f946fdd325a..5dec9427bff 100644 --- a/client/galaxy/scripts/mvc/tool/tool-form.js +++ b/client/galaxy/scripts/mvc/tool/tool-form.js @@ -227,7 +227,7 @@ var View = Backbone.View.extend({ if (response.jobs && response.jobs.length > 0) { self.$el.append($("
", { id: "webhook-view" })); var WebhookApp = new Webhooks.WebhookView({ - urlRoot: `${Galaxy.root}api/webhooks/tool`, + type: "tool", toolId: job_def.tool_id }); } diff --git a/client/galaxy/scripts/mvc/webhooks.js b/client/galaxy/scripts/mvc/webhooks.js index 44c460fde3b..c1f2400fcf5 100644 --- a/client/galaxy/scripts/mvc/webhooks.js +++ b/client/galaxy/scripts/mvc/webhooks.js @@ -1,66 +1,86 @@ -/** - Webhooks -**/ +import Utils from "utils/utils"; -var WebhookModel = Backbone.Model.extend({ - defaults: { - activate: false +const Webhooks = Backbone.Collection.extend({ + url: function() { + return `${Galaxy.root}api/webhooks`; } }); -var Webhooks = Backbone.Collection.extend({ - model: WebhookModel -}); - -var WebhookView = Backbone.View.extend({ +const WebhookView = Backbone.View.extend({ el: "#webhook-view", initialize: function(options) { - var me = this; - var toolId = options.toolId || ""; - var toolVersion = options.toolVersion || ""; + const toolId = options.toolId || ""; + const toolVersion = options.toolVersion || ""; this.$el.attr("tool_id", toolId); this.$el.attr("tool_version", toolVersion); - this.model = new WebhookModel(); - this.model.urlRoot = options.urlRoot; - this.model.fetch({ - success: function() { - me.render(); + const webhooks = new Webhooks(); + webhooks.fetch({ + success: data => { + if (options.type) { + data.reset(filterType(data, options.type)); + } + if (data.length > 0) { + this.render(weightedRandomPick(data)); + } } }); }, - render: function() { - var webhook = this.model.toJSON(); - - this.$el.html(`
`); - if (webhook.styles) - $("