Fix webhook filtering, make it a bit more defensive. Minor other tweaks.

This commit is contained in:
Dannon Baker
2018-02-01 12:18:02 -05:00
parent 22b0b2f2e9
commit fa0ba22f97
4 changed files with 18 additions and 5 deletions
+4 -2
View File
@@ -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;
+1
View File
@@ -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",
+11 -3
View File
@@ -19,8 +19,9 @@ const WebhookView = Backbone.View.extend({
const webhooks = new Webhooks();
webhooks.fetch({
success: data => {
data.reset(filterType(data, options.type));
if (options.type) {
data.reset(filterType(data, options.type));
}
if (data.length > 0) {
this.render(weightedRandomPick(data));
}
@@ -50,7 +51,14 @@ const load = options => {
};
function filterType(data, type) {
return data.models.filter(item => item.get("type").indexOf(type) !== -1);
return data.models.filter(item => {
let itype = item.get("type");
if (itype) {
return itype.indexOf(type) !== -1;
} else {
return false;
}
});
}
function weightedRandomPick(data) {
+2
View File
@@ -1,4 +1,6 @@
/** Creates a generic/global Galaxy environment, loads shared libraries and a fake server */
/* global define */
define(
[
"jquery",