mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-28 02:58:18 +08:00
Client formatting of webhooks changes.
This commit is contained in:
@@ -107,7 +107,7 @@ var Collection = Backbone.Collection.extend({
|
||||
//
|
||||
Webhooks.load({
|
||||
type: "masthead",
|
||||
callback: function (webhooks) {
|
||||
callback: function(webhooks) {
|
||||
$(document).ready(() => {
|
||||
webhooks.each(model => {
|
||||
var webhook = model.toJSON();
|
||||
|
||||
@@ -177,11 +177,11 @@ var menu = [
|
||||
// Webhooks
|
||||
Webhooks.load({
|
||||
type: "history-menu",
|
||||
async: false, // (hypothetically) slows down the performance
|
||||
async: false, // (hypothetically) slows down the performance
|
||||
callback: function(webhooks) {
|
||||
var webhooks_menu = [];
|
||||
|
||||
webhooks.each((model) => {
|
||||
webhooks.each(model => {
|
||||
var webhook = model.toJSON();
|
||||
if (webhook.activate) {
|
||||
webhooks_menu.push({
|
||||
|
||||
@@ -204,7 +204,7 @@ export default FormBase.extend({
|
||||
Webhooks.load({
|
||||
type: "tool-menu",
|
||||
callback: function(webhooks) {
|
||||
webhooks.each((model) => {
|
||||
webhooks.each(model => {
|
||||
var webhook = model.toJSON();
|
||||
if (webhook.activate && webhook.config.function) {
|
||||
menu_button.addMenu({
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
import Utils from 'utils/utils';
|
||||
import Utils from "utils/utils";
|
||||
|
||||
const Webhooks = Backbone.Collection.extend({
|
||||
url: `${Galaxy.root}api/webhooks`
|
||||
url: `${Galaxy.root}api/webhooks`
|
||||
});
|
||||
|
||||
const WebhookView = Backbone.View.extend({
|
||||
el: '#webhook-view',
|
||||
el: "#webhook-view",
|
||||
|
||||
initialize: function (options) {
|
||||
const toolId = options.toolId || '';
|
||||
const toolVersion = options.toolVersion || '';
|
||||
initialize: function(options) {
|
||||
const toolId = options.toolId || "";
|
||||
const 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);
|
||||
|
||||
const webhooks = new Webhooks();
|
||||
webhooks.fetch({
|
||||
success: data => {
|
||||
data.reset(filterType(data, options.type));
|
||||
const webhooks = new Webhooks();
|
||||
webhooks.fetch({
|
||||
success: data => {
|
||||
data.reset(filterType(data, options.type));
|
||||
|
||||
if (data.length > 0) {
|
||||
this.render(weightedRandomPick(data));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
if (data.length > 0) {
|
||||
this.render(weightedRandomPick(data));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
render: function (model) {
|
||||
const webhook = model.toJSON();
|
||||
this.$el.html(`<div id="${webhook.id}"></div>`);
|
||||
Utils.appendScriptStyle(webhook);
|
||||
return this;
|
||||
}
|
||||
render: function(model) {
|
||||
const webhook = model.toJSON();
|
||||
this.$el.html(`<div id="${webhook.id}"></div>`);
|
||||
Utils.appendScriptStyle(webhook);
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
const load = options => {
|
||||
const webhooks = new Webhooks();
|
||||
webhooks.fetch({
|
||||
async: options.async !== undefined ? options.async : true,
|
||||
success: data => {
|
||||
if (options.type) {
|
||||
data.reset(filterType(data, options.type));
|
||||
}
|
||||
options.callback(data);
|
||||
}
|
||||
});
|
||||
const webhooks = new Webhooks();
|
||||
webhooks.fetch({
|
||||
async: options.async !== undefined ? options.async : true,
|
||||
success: data => {
|
||||
if (options.type) {
|
||||
data.reset(filterType(data, options.type));
|
||||
}
|
||||
options.callback(data);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function filterType (data, type) {
|
||||
return data.models.filter(item => item.get('type').indexOf(type) !== -1);
|
||||
function filterType(data, type) {
|
||||
return data.models.filter(item => item.get("type").indexOf(type) !== -1);
|
||||
}
|
||||
|
||||
function weightedRandomPick (data) {
|
||||
const weights = data.pluck('weight');
|
||||
const sum = weights.reduce((a, b) => a + b);
|
||||
function weightedRandomPick(data) {
|
||||
const weights = data.pluck("weight");
|
||||
const sum = weights.reduce((a, b) => a + b);
|
||||
|
||||
const normalizedWeightsMap = new Map();
|
||||
weights.forEach((weight, index) => {
|
||||
normalizedWeightsMap.set(index, parseFloat((weight / sum).toFixed(2)));
|
||||
});
|
||||
const normalizedWeightsMap = new Map();
|
||||
weights.forEach((weight, index) => {
|
||||
normalizedWeightsMap.set(index, parseFloat((weight / sum).toFixed(2)));
|
||||
});
|
||||
|
||||
const table = [];
|
||||
for (const [index, weight] of normalizedWeightsMap) {
|
||||
for (let i = 0; i < weight * 100; i++) {
|
||||
table.push(index);
|
||||
const table = [];
|
||||
for (const [index, weight] of normalizedWeightsMap) {
|
||||
for (let i = 0; i < weight * 100; i++) {
|
||||
table.push(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data.at(table[Math.floor(Math.random() * table.length)]);
|
||||
return data.at(table[Math.floor(Math.random() * table.length)]);
|
||||
}
|
||||
|
||||
export default {
|
||||
WebhookView: WebhookView,
|
||||
load: load
|
||||
WebhookView: WebhookView,
|
||||
load: load
|
||||
};
|
||||
|
||||
@@ -182,7 +182,7 @@ $(document).ready(() => {
|
||||
// Load all webhooks with the type 'onload'
|
||||
Webhooks.load({
|
||||
type: "onload",
|
||||
callback: function (webhooks) {
|
||||
callback: function(webhooks) {
|
||||
webhooks.each(model => {
|
||||
var webhook = model.toJSON();
|
||||
if (webhook.activate && webhook.script) {
|
||||
|
||||
Reference in New Issue
Block a user