From 6070bf07e18b0d3ebc210f3c4c44a1ed14b1dd27 Mon Sep 17 00:00:00 2001 From: Evgeny Anatskiy Date: Thu, 7 Dec 2017 18:25:58 +0100 Subject: [PATCH] simplify Webhooks' structure --- client/galaxy/scripts/layout/menu.js | 8 +- .../scripts/mvc/history/options-menu.js | 8 +- .../galaxy/scripts/mvc/tool/tool-form-base.js | 31 +++-- .../scripts/mvc/tool/tool-form-composite.js | 2 +- client/galaxy/scripts/mvc/tool/tool-form.js | 2 +- client/galaxy/scripts/mvc/webhooks.js | 100 ++++++++-------- client/galaxy/scripts/onload.js | 26 ++-- .../{config/searchover.yaml => config.yml} | 2 +- .../demo/search/{static => }/script.js | 2 +- .../demo/search/{static => }/styles.css | 0 .../demo/tool_list/{helper => }/__init__.py | 0 .../{config/tool_list.yml => config.yml} | 4 +- .../tour_generator/{helper => }/__init__.py | 0 .../{config/tour_generator.yml => config.yml} | 2 +- .../tour_generator/{static => }/script.js | 2 +- .../tour_generator/{static => }/styles.css | 0 lib/galaxy/webapps/galaxy/api/webhooks.py | 47 ++------ lib/galaxy/webapps/galaxy/buildapp.py | 26 ++-- lib/galaxy/webhooks/__init__.py | 111 +++++++++--------- .../{config/history_test1.yml => config.yml} | 4 +- .../{config/history_test2.yml => config.yml} | 4 +- .../{config/masthead_test.yml => config.yml} | 4 +- .../phdcomics/{helper => }/__init__.py | 0 .../{config/phdcomics.yaml => config.yaml} | 2 +- .../webhooks/phdcomics/{static => }/script.js | 2 +- .../phdcomics/{static => }/styles.css | 0 .../trans_object/{helper => }/__init__.py | 0 .../{config/trans_object.yaml => config.yaml} | 4 +- .../xkcd/{config/xkcd.yml => config.yml} | 2 +- .../webhooks/xkcd/{static => }/script.js | 0 .../webhooks/xkcd/{static => }/styles.css | 0 31 files changed, 175 insertions(+), 220 deletions(-) rename config/plugins/webhooks/demo/search/{config/searchover.yaml => config.yml} (82%) rename config/plugins/webhooks/demo/search/{static => }/script.js (99%) rename config/plugins/webhooks/demo/search/{static => }/styles.css (100%) rename config/plugins/webhooks/demo/tool_list/{helper => }/__init__.py (100%) rename config/plugins/webhooks/demo/tool_list/{config/tool_list.yml => config.yml} (94%) rename config/plugins/webhooks/demo/tour_generator/{helper => }/__init__.py (100%) rename config/plugins/webhooks/demo/tour_generator/{config/tour_generator.yml => config.yml} (95%) rename config/plugins/webhooks/demo/tour_generator/{static => }/script.js (97%) rename config/plugins/webhooks/demo/tour_generator/{static => }/styles.css (100%) rename test/functional/webhooks/history_test1/{config/history_test1.yml => config.yml} (71%) rename test/functional/webhooks/history_test2/{config/history_test2.yml => config.yml} (71%) rename test/functional/webhooks/masthead_test/{config/masthead_test.yml => config.yml} (84%) rename test/functional/webhooks/phdcomics/{helper => }/__init__.py (100%) rename test/functional/webhooks/phdcomics/{config/phdcomics.yaml => config.yaml} (72%) rename test/functional/webhooks/phdcomics/{static => }/script.js (95%) rename test/functional/webhooks/phdcomics/{static => }/styles.css (100%) rename test/functional/webhooks/trans_object/{helper => }/__init__.py (100%) rename test/functional/webhooks/trans_object/{config/trans_object.yaml => config.yaml} (56%) rename test/functional/webhooks/xkcd/{config/xkcd.yml => config.yml} (79%) rename test/functional/webhooks/xkcd/{static => }/script.js (100%) rename test/functional/webhooks/xkcd/{static => }/styles.css (100%) diff --git a/client/galaxy/scripts/layout/menu.js b/client/galaxy/scripts/layout/menu.js index d848465994e..149b7ff040f 100644 --- a/client/galaxy/scripts/layout/menu.js +++ b/client/galaxy/scripts/layout/menu.js @@ -105,11 +105,11 @@ var Collection = Backbone.Collection.extend({ // // Webhooks // - Webhooks.add({ - url: "api/webhooks/masthead/all", - callback: function(webhooks) { + 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 = { diff --git a/client/galaxy/scripts/mvc/history/options-menu.js b/client/galaxy/scripts/mvc/history/options-menu.js index e8f280ebf40..d5377e9773c 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", - async: false, // (hypothetically) slows down the performance +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..ab473cf36a4 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..5d7141c6e25 100644 --- a/client/galaxy/scripts/mvc/webhooks.js +++ b/client/galaxy/scripts/mvc/webhooks.js @@ -1,66 +1,58 @@ -/** - Webhooks -**/ +import Utils from 'utils/utils'; -var WebhookModel = Backbone.Model.extend({ - defaults: { - activate: false - } +const Webhooks = Backbone.Collection.extend({ + url: `${Galaxy.root}api/webhooks` }); -var Webhooks = Backbone.Collection.extend({ - model: WebhookModel -}); +const WebhookView = Backbone.View.extend({ + el: '#webhook-view', -var WebhookView = Backbone.View.extend({ - el: "#webhook-view", + initialize: function (options) { + const toolId = options.toolId || ''; + const toolVersion = options.toolVersion || ''; - initialize: function(options) { - var me = this; - var toolId = options.toolId || ""; - var toolVersion = options.toolVersion || ""; + this.$el.attr('tool_id', toolId); + this.$el.attr('tool_version', 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(); - } - }); - }, - - render: function() { - var webhook = this.model.toJSON(); - - this.$el.html(`
`); - if (webhook.styles) - $("