Client formatting of webhooks changes.

This commit is contained in:
Dannon Baker
2018-02-01 12:18:02 -05:00
parent 90d59ac923
commit 57c1fc7804
5 changed files with 56 additions and 56 deletions
+1 -1
View File
@@ -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({
+51 -51
View File
@@ -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
};
+1 -1
View File
@@ -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) {