All Downloads are FREE. Search and download functionalities are using the official Maven repository.

webapp.scripts.modules.alerts-navigation.js Maven / Gradle / Ivy

The newest version!
Box.Application.addModule('alerts-navigation', function(context) {
  'use strict';
  var socket, seen  = [], d3, timeFormatter;
  var pollAlerts = function() {
    var pollConf = {};
    pollConf.stop = new Date().getTime();
    pollConf.start = pollConf.stop - (1000 * 60 * 60 * 12);
    pollConf.step = 10000;
    pollConf.minSteps = 30;
    pollConf.metricKey = "/event";
    var conf = JSON.stringify(pollConf);
    socket.send(conf);
  };
  var onEvents = function(event) {
    var willowEvents = JSON.parse(event.data);
    var i;
    for (i=0; i" + timeFormatter(new Date(willowEvents.data[i].timestamp)) + "" +
          willowEvents.data[i].eventType.substring(willowEvents.data[i].eventType.lastIndexOf(".") + 1) +
          "" + willowEvents.data[i].description + "");
      }
    }
  };
  var seenEvent = function(id) {
    if (seen.indexOf(id) > -1) {
      return true;
    } else {
      seen.push(id);
      return false;
    }
  };
  return {
    init: function() {
      d3 = context.getGlobal("d3");
      timeFormatter = d3.time.format("%Y-%m-%d %X");
      var loc = window.location, ws_uri;
      if (loc.protocol === "https:") {
        ws_uri = "wss:";
      } else {
        ws_uri = "ws:";
      }
      var ctx = "/";
      var ctxEnd = loc.pathname.lastIndexOf("/");
      if (ctxEnd > 0) {
        if (loc.pathname.indexOf("/") === 0) {
          ctx = "";
        }
        ctx += loc.pathname.substring(0, contextEnd) + "/";
      }
      ws_uri += "//" + loc.host + ctx + "poll/";
      socket = new WebSocket(ws_uri);
      socket.onopen = pollAlerts;
      socket.onmessage = onEvents;
    }
  };
});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy