Skip to content

Commit

Permalink
Client formatting of webhooks changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Feb 1, 2018
1 parent 90d59ac commit 57c1fc7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion client/galaxy/scripts/layout/menu.js
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions client/galaxy/scripts/mvc/history/options-menu.js
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/tool/tool-form-base.js
Expand Up @@ -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({
Expand Down
102 changes: 51 additions & 51 deletions client/galaxy/scripts/mvc/webhooks.js
@@ -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
};
2 changes: 1 addition & 1 deletion client/galaxy/scripts/onload.js
Expand Up @@ -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) {
Expand Down

0 comments on commit 57c1fc7

Please sign in to comment.