mitmproxy/libmproxy/web/static/js/app.js

1853 lines
56 KiB
JavaScript
Raw Normal View History

2014-09-17 13:22:42 +00:00
// http://blog.vjeux.com/2013/javascript/scroll-position-with-react.html (also contains inverse example)
var AutoScrollMixin = {
componentWillUpdate: function () {
var node = this.getDOMNode();
this._shouldScrollBottom = node.scrollTop + node.clientHeight === node.scrollHeight;
},
componentDidUpdate: function () {
if (this._shouldScrollBottom) {
var node = this.getDOMNode();
node.scrollTop = node.scrollHeight;
}
},
};
2014-09-18 19:13:50 +00:00
var StickyHeadMixin = {
2014-09-18 23:35:36 +00:00
adjustHead: function () {
2014-09-18 19:13:50 +00:00
// Abusing CSS transforms to set the element
// referenced as head into some kind of position:sticky.
var head = this.refs.head.getDOMNode();
2014-09-18 23:35:36 +00:00
head.style.transform = "translate(0," + this.getDOMNode().scrollTop + "px)";
2014-09-18 19:13:50 +00:00
}
};
var Key = {
UP: 38,
DOWN: 40,
2014-09-18 19:13:50 +00:00
PAGE_UP: 33,
PAGE_DOWN: 34,
LEFT: 37,
RIGHT: 39,
ENTER: 13,
2014-09-19 15:56:54 +00:00
ESC: 27,
TAB: 9,
SPACE: 32,
J: 74,
K: 75,
H: 72,
L: 76
2014-09-18 19:13:50 +00:00
};
2014-09-18 23:35:36 +00:00
2014-09-19 15:56:54 +00:00
var formatSize = function (bytes) {
var size = bytes;
2014-09-18 23:35:36 +00:00
var prefix = ["B", "KB", "MB", "GB", "TB"];
2014-11-27 00:40:26 +00:00
var i = 0;
while (Math.abs(size) >= 1024 && i < prefix.length - 1) {
2014-09-21 23:44:46 +00:00
i++;
2014-09-18 23:35:36 +00:00
size = size / 1024;
}
2014-09-21 23:44:46 +00:00
return (Math.floor(size * 100) / 100.0).toFixed(2) + prefix[i];
2014-09-19 15:56:54 +00:00
};
var formatTimeDelta = function (milliseconds) {
var time = milliseconds;
2014-09-21 21:43:27 +00:00
var prefix = ["ms", "s", "min", "h"];
2014-09-19 15:56:54 +00:00
var div = [1000, 60, 60];
2014-09-21 23:44:46 +00:00
var i = 0;
while (Math.abs(time) >= div[i] && i < div.length) {
time = time / div[i];
i++;
2014-09-19 15:56:54 +00:00
}
2014-09-21 23:44:46 +00:00
return Math.round(time) + prefix[i];
2014-09-18 23:35:36 +00:00
};
2014-11-29 02:25:07 +00:00
var formatTimeStamp = function (seconds) {
var ts = (new Date(seconds * 1000)).toISOString();
return ts.replace("T", " ").replace("Z", "");
};
2014-09-15 16:08:26 +00:00
const PayloadSources = {
2014-09-17 13:22:42 +00:00
VIEW: "view",
SERVER: "server"
2014-09-15 16:08:26 +00:00
};
2014-09-14 00:44:13 +00:00
2014-09-17 00:13:37 +00:00
function Dispatcher() {
2014-09-16 09:06:30 +00:00
this.callbacks = [];
}
2014-09-17 00:13:37 +00:00
Dispatcher.prototype.register = function (callback) {
2014-09-16 09:06:30 +00:00
this.callbacks.push(callback);
};
2014-09-17 00:13:37 +00:00
Dispatcher.prototype.unregister = function (callback) {
2014-09-16 09:06:30 +00:00
var index = this.callbacks.indexOf(f);
if (index >= 0) {
this.callbacks.splice(this.callbacks.indexOf(f), 1);
2014-09-14 00:44:13 +00:00
}
2014-09-16 09:06:30 +00:00
};
2014-09-17 00:13:37 +00:00
Dispatcher.prototype.dispatch = function (payload) {
2014-09-16 09:06:30 +00:00
console.debug("dispatch", payload);
2014-11-27 00:40:26 +00:00
for (var i = 0; i < this.callbacks.length; i++) {
2014-09-21 23:44:46 +00:00
this.callbacks[i](payload);
}
2014-09-16 09:06:30 +00:00
};
2014-09-14 00:44:13 +00:00
2014-09-15 16:08:26 +00:00
AppDispatcher = new Dispatcher();
2014-09-17 00:13:37 +00:00
AppDispatcher.dispatchViewAction = function (action) {
2014-09-17 13:22:42 +00:00
action.source = PayloadSources.VIEW;
2014-09-15 22:56:43 +00:00
this.dispatch(action);
2014-09-15 16:08:26 +00:00
};
2014-09-17 00:13:37 +00:00
AppDispatcher.dispatchServerAction = function (action) {
2014-09-17 13:22:42 +00:00
action.source = PayloadSources.SERVER;
2014-09-15 22:56:43 +00:00
this.dispatch(action);
2014-09-15 22:05:06 +00:00
};
2014-09-15 16:08:26 +00:00
var ActionTypes = {
2014-09-17 15:30:19 +00:00
//Settings
2014-09-17 13:22:42 +00:00
UPDATE_SETTINGS: "update_settings",
2014-09-17 15:30:19 +00:00
//EventLog
ADD_EVENT: "add_event",
//Flow
ADD_FLOW: "add_flow",
UPDATE_FLOW: "update_flow",
2014-09-15 16:08:26 +00:00
};
2014-09-14 00:44:13 +00:00
2014-09-15 16:08:26 +00:00
var SettingsActions = {
2014-09-17 00:13:37 +00:00
update: function (settings) {
2014-09-15 22:56:43 +00:00
settings = _.merge({}, SettingsStore.getAll(), settings);
//TODO: Update server.
//Facebook Flux: We do an optimistic update on the client already.
AppDispatcher.dispatchViewAction({
2014-09-17 13:22:42 +00:00
type: ActionTypes.UPDATE_SETTINGS,
2014-09-15 22:56:43 +00:00
settings: settings
});
}
2014-09-15 16:08:26 +00:00
};
2014-09-14 00:44:13 +00:00
2014-09-22 01:06:19 +00:00
var event_id = 0;
2014-09-17 15:30:19 +00:00
var EventLogActions = {
2014-11-27 00:40:26 +00:00
add_event: function (message) {
2014-09-17 15:30:19 +00:00
AppDispatcher.dispatchViewAction({
type: ActionTypes.ADD_EVENT,
data: {
message: message,
2014-09-22 01:06:19 +00:00
level: "web",
2014-11-27 00:40:26 +00:00
id: "viewAction-" + event_id++
2014-09-17 15:30:19 +00:00
}
});
}
};
2014-09-18 23:35:36 +00:00
var _MessageUtils = {
getContentType: function (message) {
2014-09-18 23:57:50 +00:00
return this.get_first_header(message, /^Content-Type$/i);
2014-09-18 23:35:36 +00:00
},
get_first_header: function (message, regex) {
//FIXME: Cache Invalidation.
if (!message._headerLookups)
Object.defineProperty(message, "_headerLookups", {
value: {},
configurable: false,
enumerable: false,
writable: false
});
if (!(regex in message._headerLookups)) {
var header;
for (var i = 0; i < message.headers.length; i++) {
if (!!message.headers[i][0].match(regex)) {
header = message.headers[i];
break;
}
}
message._headerLookups[regex] = header ? header[1] : undefined;
}
return message._headerLookups[regex];
}
};
var defaultPorts = {
"http": 80,
"https": 443
};
var RequestUtils = _.extend(_MessageUtils, {
pretty_host: function (request) {
//FIXME: Add hostheader
return request.host;
},
pretty_url: function (request) {
var port = "";
if (defaultPorts[request.scheme] !== request.port) {
port = ":" + request.port;
}
return request.scheme + "://" + this.pretty_host(request) + port + request.path;
}
});
var ResponseUtils = _.extend(_MessageUtils, {});
2014-09-16 09:06:30 +00:00
function EventEmitter() {
this.listeners = {};
}
2014-09-17 00:13:37 +00:00
EventEmitter.prototype.emit = function (event) {
2014-09-16 09:06:30 +00:00
if (!(event in this.listeners)) {
return;
2014-09-15 22:56:43 +00:00
}
2014-09-17 13:22:42 +00:00
var args = Array.prototype.slice.call(arguments, 1);
2014-09-17 00:13:37 +00:00
this.listeners[event].forEach(function (listener) {
2014-09-17 13:22:42 +00:00
listener.apply(this, args);
2014-09-16 09:06:30 +00:00
}.bind(this));
};
2014-11-28 15:03:56 +00:00
EventEmitter.prototype.addListener = function (events, f) {
events.split(" ").forEach(function (event) {
this.listeners[event] = this.listeners[event] || [];
this.listeners[event].push(f);
}.bind(this));
2014-09-16 09:06:30 +00:00
};
2014-11-28 15:03:56 +00:00
EventEmitter.prototype.removeListener = function (events, f) {
if (!(events in this.listeners)) {
2014-09-16 09:06:30 +00:00
return false;
}
2014-11-28 15:03:56 +00:00
events.split(" ").forEach(function (event) {
var index = this.listeners[event].indexOf(f);
if (index >= 0) {
this.listeners[event].splice(index, 1);
}
}.bind(this));
2014-09-16 09:06:30 +00:00
};
function _SettingsStore() {
EventEmitter.call(this);
//FIXME: What do we do if we haven't requested anything from the server yet?
this.settings = {
version: "0.12",
showEventLog: true,
mode: "transparent",
2014-09-17 00:13:37 +00:00
};
2014-09-16 09:06:30 +00:00
}
_.extend(_SettingsStore.prototype, EventEmitter.prototype, {
2014-09-17 00:13:37 +00:00
getAll: function () {
2014-09-15 22:56:43 +00:00
return this.settings;
2014-09-16 09:06:30 +00:00
},
2014-09-17 00:13:37 +00:00
handle: function (action) {
2014-09-17 13:22:42 +00:00
switch (action.type) {
case ActionTypes.UPDATE_SETTINGS:
2014-09-15 22:56:43 +00:00
this.settings = action.settings;
this.emit("change");
break;
default:
return;
}
2014-09-16 09:06:30 +00:00
}
});
2014-09-15 16:08:26 +00:00
var SettingsStore = new _SettingsStore();
AppDispatcher.register(SettingsStore.handle.bind(SettingsStore));
2014-09-15 22:56:43 +00:00
//
// We have an EventLogView and an EventLogStore:
// The basic architecture is that one can request views on the event log
// from the store, which returns a view object and then deals with getting the data required for the view.
// The view object is accessed by React components and distributes updates etc.
//
// See also: components/EventLog.react.js
2014-09-16 09:06:30 +00:00
function EventLogView(store, live) {
EventEmitter.call(this);
2014-09-17 13:22:42 +00:00
this._store = store;
2014-09-16 09:06:30 +00:00
this.live = live;
this.log = [];
2014-09-15 16:08:26 +00:00
2014-09-16 09:06:30 +00:00
this.add = this.add.bind(this);
2014-09-15 22:56:43 +00:00
2014-09-16 09:06:30 +00:00
if (live) {
2014-09-17 13:22:42 +00:00
this._store.addListener(ActionTypes.ADD_EVENT, this.add);
2014-09-15 22:56:43 +00:00
}
2014-09-16 09:06:30 +00:00
}
_.extend(EventLogView.prototype, EventEmitter.prototype, {
2014-09-17 00:13:37 +00:00
close: function () {
2014-09-17 13:22:42 +00:00
this._store.removeListener(ActionTypes.ADD_EVENT, this.add);
2014-09-16 09:06:30 +00:00
},
2014-09-17 00:13:37 +00:00
getAll: function () {
2014-09-15 22:56:43 +00:00
return this.log;
2014-09-16 09:06:30 +00:00
},
2014-09-17 00:13:37 +00:00
add: function (entry) {
2014-09-15 22:56:43 +00:00
this.log.push(entry);
2014-11-27 00:40:26 +00:00
if (this.log.length > 200) {
2014-09-21 23:44:46 +00:00
this.log.shift();
}
2014-09-15 22:56:43 +00:00
this.emit("change");
2014-09-16 09:06:30 +00:00
},
2014-09-17 00:13:37 +00:00
add_bulk: function (messages) {
2014-09-15 22:56:43 +00:00
var log = messages;
var last_id = log[log.length - 1].id;
2014-09-17 00:13:37 +00:00
var to_add = _.filter(this.log, function (entry) {
return entry.id > last_id;
});
2014-09-15 22:56:43 +00:00
this.log = log.concat(to_add);
this.emit("change");
2014-09-16 09:06:30 +00:00
}
});
2014-09-15 22:05:06 +00:00
2014-09-17 00:13:37 +00:00
function _EventLogStore() {
2014-09-16 09:06:30 +00:00
EventEmitter.call(this);
}
_.extend(_EventLogStore.prototype, EventEmitter.prototype, {
2014-09-17 00:13:37 +00:00
getView: function (since) {
2014-09-15 22:56:43 +00:00
var view = new EventLogView(this, !since);
2014-09-17 13:22:42 +00:00
return view;
/*
2014-11-27 00:40:26 +00:00
//TODO: Really do bulk retrieval of last messages.
window.setTimeout(function () {
view.add_bulk([
{
id: 1,
message: "Hello World"
},
{
id: 2,
message: "I was already transmitted as an event."
}
]);
}, 100);
var id = 2;
view.add({
id: id++,
message: "I was already transmitted as an event."
});
view.add({
id: id++,
message: "I was only transmitted as an event before the bulk was added.."
});
window.setInterval(function () {
view.add({
id: id++,
message: "."
});
}, 1000);
return view;
*/
2014-09-16 09:06:30 +00:00
},
2014-09-17 00:13:37 +00:00
handle: function (action) {
2014-09-17 13:22:42 +00:00
switch (action.type) {
case ActionTypes.ADD_EVENT:
this.emit(ActionTypes.ADD_EVENT, action.data);
2014-09-15 22:56:43 +00:00
break;
default:
return;
}
2014-09-16 09:06:30 +00:00
}
});
2014-09-15 16:08:26 +00:00
var EventLogStore = new _EventLogStore();
AppDispatcher.register(EventLogStore.handle.bind(EventLogStore));
function FlowStore(endpoint) {
this._views = [];
this.reset();
2014-09-17 15:30:19 +00:00
}
_.extend(FlowStore.prototype, {
add: function (flow) {
this._pos_map[flow.id] = this._flow_list.length;
this._flow_list.push(flow);
for (var i = 0; i < this._views.length; i++) {
this._views[i].add(flow);
}
2014-09-17 15:30:19 +00:00
},
update: function (flow) {
this._flow_list[this._pos_map[flow.id]] = flow;
for (var i = 0; i < this._views.length; i++) {
this._views[i].update(flow);
}
2014-09-17 15:30:19 +00:00
},
remove: function (flow_id) {
this._flow_list.splice(this._pos_map[flow_id], 1);
this._build_map();
for (var i = 0; i < this._views.length; i++) {
this._views[i].remove(flow_id);
}
2014-09-17 15:30:19 +00:00
},
reset: function (flows) {
this._flow_list = flows || [];
this._build_map();
for (var i = 0; i < this._views.length; i++) {
this._views[i].recalculate(this._flow_list);
}
},
_build_map: function () {
this._pos_map = {};
for (var i = 0; i < this._flow_list.length; i++) {
var flow = this._flow_list[i];
this._pos_map[flow.id] = i;
}
},
2014-11-27 00:40:26 +00:00
get: function (flow_id) {
2014-11-27 00:38:30 +00:00
return this._flow_list[this._pos_map[flow_id]];
}
});
2014-09-17 15:30:19 +00:00
function LiveFlowStore(endpoint) {
FlowStore.call(this);
2014-11-28 18:16:47 +00:00
this.updates_before_fetch = undefined;
this._fetchxhr = false;
this.endpoint = endpoint || "/flows";
this.conn = new Connection(this.endpoint + "/updates");
this.conn.onopen = this._onopen.bind(this);
this.conn.onmessage = function (e) {
var message = JSON.parse(e.data);
this.handle_update(message.type, message.data);
}.bind(this);
}
_.extend(LiveFlowStore.prototype, FlowStore.prototype, {
2014-11-27 00:40:26 +00:00
close: function () {
2014-11-27 00:38:30 +00:00
this.conn.close();
},
2014-11-27 00:40:26 +00:00
add: function (flow) {
2014-11-27 00:38:30 +00:00
// Make sure that deferred adds don't add an element twice.
2014-11-28 18:16:47 +00:00
if (!(flow.id in this._pos_map)) {
2014-11-27 00:38:30 +00:00
FlowStore.prototype.add.call(this, flow);
}
},
2014-11-28 18:16:47 +00:00
_onopen: function () {
//Update stream openend, fetch list of flows.
console.log("Update Connection opened, fetching flows...");
this.fetch();
},
fetch: function () {
if (this._fetchxhr) {
this._fetchxhr.abort();
}
this._fetchxhr = $.getJSON(this.endpoint, this.handle_fetch.bind(this));
this.updates_before_fetch = []; // (JS: empty array is true)
},
handle_update: function (type, data) {
console.log("LiveFlowStore.handle_update", type, data);
2014-11-28 18:16:47 +00:00
if (type === "reset") {
return this.fetch();
}
if (this.updates_before_fetch) {
console.log("defer update", type, data);
2014-11-28 18:16:47 +00:00
this.updates_before_fetch.push(arguments);
2014-09-17 15:30:19 +00:00
} else {
this[type](data);
2014-09-17 15:30:19 +00:00
}
},
handle_fetch: function (data) {
2014-11-28 18:16:47 +00:00
this._fetchxhr = false;
2014-11-29 02:25:07 +00:00
console.log("Flows fetched.", this.updates_before_fetch);
this.reset(data.flows);
2014-11-28 18:16:47 +00:00
var updates = this.updates_before_fetch;
this.updates_before_fetch = false;
for (var i = 0; i < updates.length; i++) {
this.handle_update.apply(this, updates[i]);
}
},
2014-09-17 15:30:19 +00:00
});
function SortByInsertionOrder() {
this.i = 0;
this.map = {};
this.key = this.key.bind(this);
}
SortByInsertionOrder.prototype.key = function (flow) {
if (!(flow.id in this.map)) {
this.i++;
this.map[flow.id] = this.i;
}
return this.map[flow.id];
};
2014-09-17 15:30:19 +00:00
var default_sort = (new SortByInsertionOrder()).key;
2014-11-27 01:34:03 +00:00
function FlowView(store, filt, sortfun) {
2014-09-17 15:30:19 +00:00
EventEmitter.call(this);
filt = filt || function (flow) {
return true;
};
2014-11-27 01:34:03 +00:00
sortfun = sortfun || default_sort;
2014-11-27 00:38:30 +00:00
this.store = store;
this.store._views.push(this);
2014-11-27 01:34:03 +00:00
this.recalculate(this.store._flow_list, filt, sortfun);
2014-09-17 15:30:19 +00:00
}
_.extend(FlowView.prototype, EventEmitter.prototype, {
2014-11-27 00:40:26 +00:00
close: function () {
2014-11-27 00:38:30 +00:00
this.store._views = _.without(this.store._views, this);
},
2014-11-27 01:34:03 +00:00
recalculate: function (flows, filt, sortfun) {
if (filt) {
this.filt = filt;
}
2014-11-27 01:34:03 +00:00
if (sortfun) {
this.sortfun = sortfun;
}
2014-11-27 01:34:03 +00:00
//Ugly workaround: Call .sortfun() for each flow once in order,
//so that SortByInsertionOrder make sense.
2014-11-28 19:54:52 +00:00
for (var i = 0; i < flows.length; i++) {
2014-11-27 01:34:03 +00:00
this.sortfun(flows[i]);
}
this.flows = flows.filter(this.filt);
this.flows.sort(function (a, b) {
2014-11-28 18:16:47 +00:00
return this.sortfun(a) - this.sortfun(b);
}.bind(this));
this.emit("recalculate");
},
2014-11-28 18:16:47 +00:00
index: function (flow) {
return _.sortedIndex(this.flows, flow, this.sortfun);
},
add: function (flow) {
if (this.filt(flow)) {
2014-11-28 18:16:47 +00:00
var idx = this.index(flow);
if (idx === this.flows.length) { //happens often, .push is way faster.
this.flows.push(flow);
} else {
this.flows.splice(idx, 0, flow);
}
this.emit("add", flow, idx);
}
},
update: function (flow) {
var idx;
var i = this.flows.length;
// Search from the back, we usually update the latest flows.
while (i--) {
if (this.flows[i].id === flow.id) {
idx = i;
break;
}
}
if (idx === -1) { //not contained in list
this.add(flow);
} else if (!this.filt(flow)) {
this.remove(flow.id);
} else {
2014-11-27 01:34:03 +00:00
if (this.sortfun(this.flows[idx]) !== this.sortfun(flow)) { //sortpos has changed
this.remove(this.flows[idx]);
this.add(flow);
} else {
this.flows[idx] = flow;
this.emit("update", flow, idx);
}
}
2014-09-17 15:30:19 +00:00
},
remove: function (flow_id) {
var i = this.flows.length;
while (i--) {
if (this.flows[i].id === flow_id) {
this.flows.splice(i, 1);
this.emit("remove", flow_id, i);
2014-09-17 15:30:19 +00:00
break;
}
2014-09-17 15:30:19 +00:00
}
}
});
function Connection(url) {
2014-11-27 00:40:26 +00:00
if (url[0] != "/") {
this.url = url;
} else {
this.url = location.origin.replace("http", "ws") + url;
}
var ws = new WebSocket(this.url);
2014-11-27 00:40:26 +00:00
ws.onopen = function () {
this.onopen.apply(this, arguments);
}.bind(this);
2014-11-27 00:40:26 +00:00
ws.onmessage = function () {
this.onmessage.apply(this, arguments);
}.bind(this);
2014-11-27 00:40:26 +00:00
ws.onerror = function () {
this.onerror.apply(this, arguments);
}.bind(this);
2014-11-27 00:40:26 +00:00
ws.onclose = function () {
this.onclose.apply(this, arguments);
}.bind(this);
this.ws = ws;
}
Connection.prototype.onopen = function (open) {
2014-09-22 01:06:19 +00:00
console.debug("onopen", this, arguments);
2014-09-16 09:06:30 +00:00
};
Connection.prototype.onmessage = function (message) {
console.warn("onmessage (not implemented)", this, message.data);
2014-09-16 09:06:30 +00:00
};
Connection.prototype.onerror = function (error) {
2014-09-17 15:30:19 +00:00
EventLogActions.add_event("WebSocket Connection Error.");
2014-09-22 01:06:19 +00:00
console.debug("onerror", this, arguments);
2014-09-16 09:06:30 +00:00
};
Connection.prototype.onclose = function (close) {
2014-09-17 15:30:19 +00:00
EventLogActions.add_event("WebSocket Connection closed.");
2014-09-22 01:06:19 +00:00
console.debug("onclose", this, arguments);
2014-09-16 09:06:30 +00:00
};
2014-11-27 00:40:26 +00:00
Connection.prototype.close = function () {
this.ws.close();
};
2014-09-18 21:22:02 +00:00
//React utils. For other utilities, see ../utils.js
var Splitter = React.createClass({displayName: 'Splitter',
getDefaultProps: function () {
2014-09-19 15:56:54 +00:00
return {
axis: "x"
};
2014-09-18 21:22:02 +00:00
},
2014-11-27 00:40:26 +00:00
getInitialState: function () {
2014-09-18 21:22:02 +00:00
return {
applied: false,
startX: false,
startY: false
};
},
2014-11-27 00:40:26 +00:00
onMouseDown: function (e) {
2014-09-18 21:22:02 +00:00
this.setState({
startX: e.pageX,
startY: e.pageY
});
2014-11-27 00:40:26 +00:00
window.addEventListener("mousemove", this.onMouseMove);
window.addEventListener("mouseup", this.onMouseUp);
2014-09-18 21:47:54 +00:00
// Occasionally, only a dragEnd event is triggered, but no mouseUp.
2014-11-27 00:40:26 +00:00
window.addEventListener("dragend", this.onDragEnd);
2014-09-18 21:22:02 +00:00
},
2014-11-27 00:40:26 +00:00
onDragEnd: function () {
this.getDOMNode().style.transform = "";
window.removeEventListener("dragend", this.onDragEnd);
window.removeEventListener("mouseup", this.onMouseUp);
window.removeEventListener("mousemove", this.onMouseMove);
2014-09-18 21:47:54 +00:00
},
2014-11-27 00:40:26 +00:00
onMouseUp: function (e) {
2014-09-18 21:47:54 +00:00
this.onDragEnd();
2014-09-18 21:22:02 +00:00
var node = this.getDOMNode();
var prev = node.previousElementSibling;
var next = node.nextElementSibling;
2014-11-27 00:40:26 +00:00
var dX = e.pageX - this.state.startX;
var dY = e.pageY - this.state.startY;
2014-09-18 21:22:02 +00:00
var flexBasis;
2014-11-27 00:40:26 +00:00
if (this.props.axis === "x") {
2014-09-18 21:22:02 +00:00
flexBasis = prev.offsetWidth + dX;
} else {
flexBasis = prev.offsetHeight + dY;
}
2014-11-27 00:40:26 +00:00
prev.style.flex = "0 0 " + Math.max(0, flexBasis) + "px";
2014-09-18 21:22:02 +00:00
next.style.flex = "1 1 auto";
this.setState({
applied: true
});
},
2014-11-27 00:40:26 +00:00
onMouseMove: function (e) {
2014-09-18 21:22:02 +00:00
var dX = 0, dY = 0;
2014-11-27 00:40:26 +00:00
if (this.props.axis === "x") {
dX = e.pageX - this.state.startX;
2014-09-18 21:22:02 +00:00
} else {
2014-11-27 00:40:26 +00:00
dY = e.pageY - this.state.startY;
2014-09-18 21:22:02 +00:00
}
2014-11-27 00:40:26 +00:00
this.getDOMNode().style.transform = "translate(" + dX + "px," + dY + "px)";
2014-09-18 21:22:02 +00:00
},
2014-11-27 00:40:26 +00:00
reset: function (willUnmount) {
2014-09-18 21:47:54 +00:00
if (!this.state.applied) {
2014-09-18 21:22:02 +00:00
return;
}
var node = this.getDOMNode();
var prev = node.previousElementSibling;
var next = node.nextElementSibling;
2014-11-27 00:40:26 +00:00
2014-09-18 21:22:02 +00:00
prev.style.flex = "";
next.style.flex = "";
2014-09-18 21:47:54 +00:00
2014-11-27 00:40:26 +00:00
if (!willUnmount) {
2014-09-18 21:47:54 +00:00
this.setState({
applied: false
});
}
},
2014-11-27 00:40:26 +00:00
componentWillUnmount: function () {
2014-09-18 21:47:54 +00:00
this.reset(true);
2014-09-18 21:22:02 +00:00
},
2014-11-27 00:40:26 +00:00
render: function () {
2014-09-18 21:22:02 +00:00
var className = "splitter";
2014-11-27 00:40:26 +00:00
if (this.props.axis === "x") {
2014-09-18 21:22:02 +00:00
className += " splitter-x";
} else {
className += " splitter-y";
}
2014-09-18 21:47:54 +00:00
return (
2014-11-27 00:38:30 +00:00
React.createElement("div", {className: className},
React.createElement("div", {onMouseDown: this.onMouseDown, draggable: "true"})
2014-09-18 21:47:54 +00:00
)
);
2014-09-18 21:22:02 +00:00
}
});
2014-11-28 18:16:47 +00:00
function getCookie(name) {
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
return r ? r[1] : undefined;
}
var xsrf = $.param({_xsrf: getCookie("_xsrf")});
//Tornado XSRF Protection.
$.ajaxPrefilter(function(options){
if(options.type === "post" && options.url[0] === "/"){
if(options.data){
options.data += ("&" + xsrf);
} else {
options.data = xsrf;
}
}
});
2014-11-28 19:03:04 +00:00
var VirtualScrollMixin = {
getInitialState: function () {
return {
start: 0,
stop: 0
2014-11-29 02:25:07 +00:00
};
2014-11-28 19:03:04 +00:00
},
2014-11-28 19:54:52 +00:00
componentWillMount: function(){
if(!this.props.rowHeight){
console.warn("VirtualScrollMixin: No rowHeight specified", this);
}
},
2014-11-28 19:03:04 +00:00
getPlaceholderTop: function () {
2014-11-28 19:54:52 +00:00
var Tag = this.props.placeholderTagName || "tr";
2014-11-28 19:03:04 +00:00
var style = {
height: this.state.start * this.props.rowHeight
};
2014-11-28 19:54:52 +00:00
var spacer = React.createElement(Tag, {key: "placeholder-top", style: style});
2014-11-28 19:03:04 +00:00
if (this.state.start % 2 === 1) {
// fix even/odd rows
2014-11-28 19:54:52 +00:00
return [spacer, React.createElement(Tag, {key: "placeholder-top-2"})];
2014-11-28 19:03:04 +00:00
} else {
return spacer;
}
},
getPlaceholderBottom: function (total) {
2014-11-28 19:54:52 +00:00
var Tag = this.props.placeholderTagName || "tr";
2014-11-28 19:03:04 +00:00
var style = {
height: Math.max(0, total - this.state.stop) * this.props.rowHeight
};
2014-11-28 19:54:52 +00:00
return React.createElement(Tag, {key: "placeholder-bottom", style: style});
},
componentDidMount: function () {
this.onScroll();
2014-11-28 19:03:04 +00:00
},
onScroll: function () {
var viewport = this.getDOMNode();
var top = viewport.scrollTop;
var height = viewport.offsetHeight;
var start = Math.floor(top / this.props.rowHeight);
2014-11-28 19:54:52 +00:00
var stop = start + Math.ceil(height / (this.props.rowHeightMin || this.props.rowHeight));
2014-11-28 19:03:04 +00:00
this.setState({
start: start,
stop: stop
});
2014-11-28 19:54:52 +00:00
},
renderRows: function(elems){
var rows = [];
var max = Math.min(elems.length, this.state.stop);
for (var i = this.state.start; i < max; i++) {
var elem = elems[i];
rows.push(this.renderRow(elem));
}
return rows;
2014-11-28 19:03:04 +00:00
},
scrollRowIntoView: function(index, head_height){
var row_top = (index * this.props.rowHeight) + head_height;
var row_bottom = row_top + this.props.rowHeight;
var viewport = this.getDOMNode();
var viewport_top = viewport.scrollTop;
var viewport_bottom = viewport_top + viewport.offsetHeight;
// Account for pinned thead
if (row_top - head_height < viewport_top) {
viewport.scrollTop = row_top - head_height;
} else if (row_bottom > viewport_bottom) {
viewport.scrollTop = row_bottom - viewport.offsetHeight;
}
},
};
2014-09-14 00:44:13 +00:00
var MainMenu = React.createClass({displayName: 'MainMenu',
2014-09-18 19:13:50 +00:00
statics: {
title: "Traffic",
route: "flows"
},
2014-09-17 00:13:37 +00:00
toggleEventLog: function () {
2014-09-15 16:08:26 +00:00
SettingsActions.update({
2014-09-15 22:05:06 +00:00
showEventLog: !this.props.settings.showEventLog
2014-09-15 16:08:26 +00:00
});
},
2014-11-28 18:16:47 +00:00
clearFlows: function(){
$.post("/flows/clear");
},
2014-09-17 00:13:37 +00:00
render: function () {
2014-09-15 22:56:43 +00:00
return (
2014-11-27 00:38:30 +00:00
React.createElement("div", null,
React.createElement("button", {className: "btn " + (this.props.settings.showEventLog ? "btn-primary" : "btn-default"), onClick: this.toggleEventLog},
2014-11-28 18:16:47 +00:00
React.createElement("i", {className: "fa fa-database"}), " Display Event Log"
), " ",
React.createElement("button", {className: "btn btn-default", onClick: this.clearFlows},
React.createElement("i", {className: "fa fa-eraser"}), " Clear Flows"
2014-09-15 22:56:43 +00:00
)
2014-09-15 16:08:26 +00:00
)
2014-11-27 00:40:26 +00:00
);
2014-09-14 00:44:13 +00:00
}
});
2014-09-18 19:13:50 +00:00
2014-09-14 00:44:13 +00:00
var ToolsMenu = React.createClass({displayName: 'ToolsMenu',
2014-09-18 19:13:50 +00:00
statics: {
title: "Tools",
route: "flows"
},
2014-09-17 00:13:37 +00:00
render: function () {
2014-11-27 00:38:30 +00:00
return React.createElement("div", null, "Tools Menu");
2014-09-14 00:44:13 +00:00
}
});
2014-09-18 19:13:50 +00:00
2014-09-14 00:44:13 +00:00
var ReportsMenu = React.createClass({displayName: 'ReportsMenu',
2014-09-18 19:13:50 +00:00
statics: {
title: "Visualization",
route: "reports"
},
2014-09-17 00:13:37 +00:00
render: function () {
2014-11-27 00:38:30 +00:00
return React.createElement("div", null, "Reports Menu");
2014-09-14 00:44:13 +00:00
}
});
2014-09-15 16:08:26 +00:00
2014-09-18 19:13:50 +00:00
var header_entries = [MainMenu, ToolsMenu, ReportsMenu];
2014-09-14 00:44:13 +00:00
var Header = React.createClass({displayName: 'Header',
2014-11-27 00:38:30 +00:00
mixins: [ReactRouter.Navigation],
2014-09-17 00:13:37 +00:00
getInitialState: function () {
2014-09-15 16:08:26 +00:00
return {
2014-09-18 19:13:50 +00:00
active: header_entries[0]
2014-09-15 16:08:26 +00:00
};
2014-09-14 00:44:13 +00:00
},
2014-11-27 00:38:30 +00:00
handleClick: function (active, e) {
e.preventDefault();
this.transitionTo(active.route);
2014-09-14 00:44:13 +00:00
this.setState({active: active});
},
2014-09-17 00:13:37 +00:00
handleFileClick: function () {
2014-09-14 00:44:13 +00:00
console.log("File click");
},
2014-09-17 00:13:37 +00:00
render: function () {
2014-11-27 00:40:26 +00:00
var header = header_entries.map(function (entry, i) {
2014-09-18 19:13:50 +00:00
var classes = React.addons.classSet({
active: entry == this.state.active
});
return (
2014-11-27 00:38:30 +00:00
React.createElement("a", {key: i,
2014-11-27 00:40:26 +00:00
href: "#",
className: classes,
onClick: this.handleClick.bind(this, entry)
2014-09-18 19:13:50 +00:00
},
entry.title
)
2014-11-27 00:40:26 +00:00
);
2014-09-18 19:13:50 +00:00
}.bind(this));
2014-11-27 00:40:26 +00:00
2014-09-14 00:44:13 +00:00
return (
2014-11-27 00:38:30 +00:00
React.createElement("header", null,
React.createElement("div", {className: "title-bar"},
2014-11-27 00:40:26 +00:00
"mitmproxy ", this.props.settings.version
2014-09-15 16:08:26 +00:00
),
2014-11-27 00:38:30 +00:00
React.createElement("nav", {className: "nav-tabs nav-tabs-lg"},
React.createElement("a", {href: "#", className: "special", onClick: this.handleFileClick}, " File "),
2014-09-15 16:08:26 +00:00
header
),
2014-11-27 00:38:30 +00:00
React.createElement("div", {className: "menu"},
React.createElement(this.state.active, {settings: this.props.settings})
2014-09-15 16:08:26 +00:00
)
2014-09-15 22:56:43 +00:00
)
2014-11-27 00:40:26 +00:00
);
2014-09-14 00:44:13 +00:00
}
});
var TLSColumn = React.createClass({displayName: 'TLSColumn',
statics: {
2014-11-27 00:40:26 +00:00
renderTitle: function () {
2014-11-27 00:38:30 +00:00
return React.createElement("th", {key: "tls", className: "col-tls"});
}
},
2014-11-27 00:40:26 +00:00
render: function () {
var flow = this.props.flow;
var ssl = (flow.request.scheme == "https");
2014-09-21 23:44:46 +00:00
var classes;
2014-11-27 00:40:26 +00:00
if (ssl) {
2014-09-21 23:44:46 +00:00
classes = "col-tls col-tls-https";
} else {
classes = "col-tls col-tls-http";
}
2014-11-27 00:38:30 +00:00
return React.createElement("td", {className: classes});
}
});
var IconColumn = React.createClass({displayName: 'IconColumn',
statics: {
2014-11-27 00:40:26 +00:00
renderTitle: function () {
2014-11-27 00:38:30 +00:00
return React.createElement("th", {key: "icon", className: "col-icon"});
}
},
2014-11-27 00:40:26 +00:00
render: function () {
var flow = this.props.flow;
2014-09-18 23:57:50 +00:00
var icon;
2014-11-27 00:40:26 +00:00
if (flow.response) {
2014-09-19 15:56:54 +00:00
var contentType = ResponseUtils.getContentType(flow.response);
//TODO: We should assign a type to the flow somewhere else.
2014-11-27 00:40:26 +00:00
if (flow.response.code == 304) {
2014-09-19 15:56:54 +00:00
icon = "resource-icon-not-modified";
2014-11-27 00:40:26 +00:00
} else if (300 <= flow.response.code && flow.response.code < 400) {
2014-09-19 15:56:54 +00:00
icon = "resource-icon-redirect";
2014-11-27 00:40:26 +00:00
} else if (contentType && contentType.indexOf("image") >= 0) {
2014-09-19 15:56:54 +00:00
icon = "resource-icon-image";
2014-09-19 22:25:40 +00:00
} else if (contentType && contentType.indexOf("javascript") >= 0) {
2014-09-19 15:56:54 +00:00
icon = "resource-icon-js";
2014-09-19 22:25:40 +00:00
} else if (contentType && contentType.indexOf("css") >= 0) {
2014-09-19 15:56:54 +00:00
icon = "resource-icon-css";
2014-09-19 22:25:40 +00:00
} else if (contentType && contentType.indexOf("html") >= 0) {
2014-09-19 15:56:54 +00:00
icon = "resource-icon-document";
}
}
2014-11-27 00:40:26 +00:00
if (!icon) {
2014-09-18 23:57:50 +00:00
icon = "resource-icon-plain";
}
2014-09-19 15:56:54 +00:00
2014-09-18 23:57:50 +00:00
icon += " resource-icon";
2014-11-27 00:40:26 +00:00
return React.createElement("td", {className: "col-icon"},
React.createElement("div", {className: icon})
);
}
});
2014-09-17 15:30:19 +00:00
var PathColumn = React.createClass({displayName: 'PathColumn',
statics: {
2014-11-27 00:40:26 +00:00
renderTitle: function () {
2014-11-27 00:38:30 +00:00
return React.createElement("th", {key: "path", className: "col-path"}, "Path");
2014-09-17 15:30:19 +00:00
}
},
2014-11-27 00:40:26 +00:00
render: function () {
2014-09-17 15:30:19 +00:00
var flow = this.props.flow;
2014-11-27 00:38:30 +00:00
return React.createElement("td", {className: "col-path"}, flow.request.scheme + "://" + flow.request.host + flow.request.path);
2014-09-17 15:30:19 +00:00
}
});
2014-09-17 15:30:19 +00:00
var MethodColumn = React.createClass({displayName: 'MethodColumn',
statics: {
2014-11-27 00:40:26 +00:00
renderTitle: function () {
2014-11-27 00:38:30 +00:00
return React.createElement("th", {key: "method", className: "col-method"}, "Method");
2014-09-17 15:30:19 +00:00
}
},
2014-11-27 00:40:26 +00:00
render: function () {
2014-09-17 15:30:19 +00:00
var flow = this.props.flow;
2014-11-27 00:38:30 +00:00
return React.createElement("td", {className: "col-method"}, flow.request.method);
2014-09-17 15:30:19 +00:00
}
});
2014-09-17 15:30:19 +00:00
var StatusColumn = React.createClass({displayName: 'StatusColumn',
statics: {
2014-11-27 00:40:26 +00:00
renderTitle: function () {
2014-11-27 00:38:30 +00:00
return React.createElement("th", {key: "status", className: "col-status"}, "Status");
2014-09-17 15:30:19 +00:00
}
},
2014-11-27 00:40:26 +00:00
render: function () {
2014-09-17 15:30:19 +00:00
var flow = this.props.flow;
var status;
2014-11-27 00:40:26 +00:00
if (flow.response) {
status = flow.response.code;
2014-09-17 15:30:19 +00:00
} else {
status = null;
}
2014-11-27 00:38:30 +00:00
return React.createElement("td", {className: "col-status"}, status);
2014-09-17 15:30:19 +00:00
}
});
2014-09-18 23:35:36 +00:00
var SizeColumn = React.createClass({displayName: 'SizeColumn',
statics: {
2014-11-27 00:40:26 +00:00
renderTitle: function () {
2014-11-27 00:38:30 +00:00
return React.createElement("th", {key: "size", className: "col-size"}, "Size");
2014-09-18 23:35:36 +00:00
}
},
2014-11-27 00:40:26 +00:00
render: function () {
2014-09-18 23:35:36 +00:00
var flow = this.props.flow;
2014-09-21 21:43:27 +00:00
2014-09-19 22:25:40 +00:00
var total = flow.request.contentLength;
2014-11-27 00:40:26 +00:00
if (flow.response) {
2014-09-21 21:43:27 +00:00
total += flow.response.contentLength || 0;
2014-09-19 22:25:40 +00:00
}
var size = formatSize(total);
2014-11-27 00:38:30 +00:00
return React.createElement("td", {className: "col-size"}, size);
2014-09-18 23:35:36 +00:00
}
});
2014-09-17 15:30:19 +00:00
var TimeColumn = React.createClass({displayName: 'TimeColumn',
statics: {
2014-11-27 00:40:26 +00:00
renderTitle: function () {
2014-11-27 00:38:30 +00:00
return React.createElement("th", {key: "time", className: "col-time"}, "Time");
2014-09-17 15:30:19 +00:00
}
},
2014-11-27 00:40:26 +00:00
render: function () {
2014-09-17 15:30:19 +00:00
var flow = this.props.flow;
var time;
2014-11-27 00:40:26 +00:00
if (flow.response) {
2014-09-19 15:56:54 +00:00
time = formatTimeDelta(1000 * (flow.response.timestamp_end - flow.request.timestamp_start));
2014-09-17 15:30:19 +00:00
} else {
time = "...";
}
2014-11-27 00:38:30 +00:00
return React.createElement("td", {className: "col-time"}, time);
2014-09-17 15:30:19 +00:00
}
});
2014-09-18 23:35:36 +00:00
var all_columns = [
TLSColumn,
IconColumn,
PathColumn,
MethodColumn,
StatusColumn,
SizeColumn,
TimeColumn];
2014-09-17 15:30:19 +00:00
var FlowRow = React.createClass({displayName: 'FlowRow',
2014-11-27 00:40:26 +00:00
render: function () {
var flow = this.props.flow;
2014-11-27 00:40:26 +00:00
var columns = this.props.columns.map(function (Column) {
2014-11-27 00:38:30 +00:00
return React.createElement(Column, {key: Column.displayName, flow: flow});
}.bind(this));
var className = "";
2014-11-27 00:40:26 +00:00
if (this.props.selected) {
className += "selected";
}
return (
2014-11-27 00:38:30 +00:00
React.createElement("tr", {className: className, onClick: this.props.selectFlow.bind(null, flow)},
columns
));
2014-09-21 23:44:46 +00:00
},
2014-11-27 00:40:26 +00:00
shouldComponentUpdate: function (nextProps) {
2014-11-28 15:03:56 +00:00
return true;
// Further optimization could be done here
// by calling forceUpdate on flow updates, selection changes and column changes.
//return (
//(this.props.columns.length !== nextProps.columns.length) ||
//(this.props.selected !== nextProps.selected)
//);
}
});
var FlowTableHead = React.createClass({displayName: 'FlowTableHead',
2014-11-27 00:40:26 +00:00
render: function () {
var columns = this.props.columns.map(function (column) {
return column.renderTitle();
}.bind(this));
2014-11-27 00:40:26 +00:00
return React.createElement("thead", null,
React.createElement("tr", null, columns)
);
}
});
2014-11-28 15:03:56 +00:00
var ROW_HEIGHT = 32;
2014-09-17 15:30:19 +00:00
var FlowTable = React.createClass({displayName: 'FlowTable',
2014-11-28 19:03:04 +00:00
mixins: [StickyHeadMixin, AutoScrollMixin, VirtualScrollMixin],
2014-09-17 00:13:37 +00:00
getInitialState: function () {
2014-09-14 00:44:13 +00:00
return {
2014-11-28 19:03:04 +00:00
columns: all_columns
2014-09-14 00:44:13 +00:00
};
},
2014-11-28 15:03:56 +00:00
componentWillMount: function () {
if (this.props.view) {
this.props.view.addListener("add update remove recalculate", this.onChange);
}
},
componentWillReceiveProps: function (nextProps) {
if (nextProps.view !== this.props.view) {
if (this.props.view) {
this.props.view.removeListener("add update remove recalculate");
}
nextProps.view.addListener("add update remove recalculate", this.onChange);
}
},
2014-11-28 19:03:04 +00:00
getDefaultProps: function () {
return {
rowHeight: ROW_HEIGHT
};
},
2014-11-29 02:25:07 +00:00
onScrollFlowTable: function () {
2014-11-28 15:03:56 +00:00
this.adjustHead();
2014-11-28 19:03:04 +00:00
this.onScroll();
2014-11-28 15:03:56 +00:00
},
onChange: function () {
this.forceUpdate();
},
2014-11-27 00:40:26 +00:00
scrollIntoView: function (flow) {
2014-11-28 19:03:04 +00:00
this.scrollRowIntoView(
this.props.view.index(flow),
this.refs.body.getDOMNode().offsetTop
);
},
2014-11-28 19:54:52 +00:00
renderRow: function (flow) {
var selected = (flow === this.props.selected);
return React.createElement(FlowRow, {key: flow.id,
ref: flow.id,
flow: flow,
columns: this.state.columns,
selected: selected,
selectFlow: this.props.selectFlow}
);
},
2014-09-17 00:13:37 +00:00
render: function () {
2014-11-29 02:25:07 +00:00
//console.log("render flowtable", this.state.start, this.state.stop, this.props.selected);
2014-11-28 19:54:52 +00:00
var flows = this.props.view ? this.props.view.flows : [];
var rows = this.renderRows(flows);
2014-11-28 15:03:56 +00:00
2014-09-17 00:13:37 +00:00
return (
2014-11-29 02:25:07 +00:00
React.createElement("div", {className: "flow-table", onScroll: this.onScrollFlowTable},
2014-11-27 00:38:30 +00:00
React.createElement("table", null,
React.createElement(FlowTableHead, {ref: "head",
2014-11-27 00:40:26 +00:00
columns: this.state.columns}),
2014-11-28 18:16:47 +00:00
React.createElement("tbody", {ref: "body"},
2014-11-28 19:03:04 +00:00
this.getPlaceholderTop(),
2014-11-28 15:03:56 +00:00
rows,
2014-11-28 19:03:04 +00:00
this.getPlaceholderBottom(flows.length)
2014-11-28 15:03:56 +00:00
)
2014-09-18 19:13:50 +00:00
)
2014-09-17 15:30:19 +00:00
)
2014-11-27 00:40:26 +00:00
);
2014-09-15 22:56:43 +00:00
}
2014-09-14 00:44:13 +00:00
});
2014-09-18 19:13:50 +00:00
var FlowDetailNav = React.createClass({displayName: 'FlowDetailNav',
2014-11-27 00:38:30 +00:00
render: function () {
2014-09-18 19:13:50 +00:00
2014-11-27 00:38:30 +00:00
var items = this.props.tabs.map(function (e) {
2014-09-18 19:13:50 +00:00
var str = e.charAt(0).toUpperCase() + e.slice(1);
var className = this.props.active === e ? "active" : "";
2014-11-28 18:16:47 +00:00
var onClick = function (event) {
2014-09-18 19:13:50 +00:00
this.props.selectTab(e);
2014-11-28 18:16:47 +00:00
event.preventDefault();
2014-09-18 19:13:50 +00:00
}.bind(this);
2014-11-27 00:38:30 +00:00
return React.createElement("a", {key: e,
href: "#",
className: className,
onClick: onClick}, str);
2014-09-18 19:13:50 +00:00
}.bind(this));
return (
2014-11-27 00:38:30 +00:00
React.createElement("nav", {ref: "head", className: "nav-tabs nav-tabs-sm"},
2014-09-18 19:13:50 +00:00
items
)
);
2014-11-27 00:38:30 +00:00
}
2014-09-18 19:13:50 +00:00
});
2014-09-18 23:35:36 +00:00
var Headers = React.createClass({displayName: 'Headers',
2014-11-27 00:38:30 +00:00
render: function () {
var rows = this.props.message.headers.map(function (header, i) {
2014-09-18 23:35:36 +00:00
return (
2014-11-27 00:38:30 +00:00
React.createElement("tr", {key: i},
React.createElement("td", {className: "header-name"}, header[0] + ":"),
React.createElement("td", {className: "header-value"}, header[1])
2014-09-18 23:35:36 +00:00
)
);
2014-09-19 15:56:54 +00:00
});
2014-09-18 23:35:36 +00:00
return (
2014-11-27 00:38:30 +00:00
React.createElement("table", {className: "header-table"},
React.createElement("tbody", null,
2014-09-18 23:35:36 +00:00
rows
)
)
);
}
2014-09-19 15:56:54 +00:00
});
2014-09-18 23:35:36 +00:00
2014-09-18 19:13:50 +00:00
var FlowDetailRequest = React.createClass({displayName: 'FlowDetailRequest',
2014-11-27 00:38:30 +00:00
render: function () {
2014-09-18 23:35:36 +00:00
var flow = this.props.flow;
2014-09-18 23:57:50 +00:00
var first_line = [
2014-11-27 00:38:30 +00:00
flow.request.method,
RequestUtils.pretty_url(flow.request),
2014-11-29 02:25:07 +00:00
"HTTP/" + flow.request.httpversion.join(".")
2014-11-27 00:38:30 +00:00
].join(" ");
2014-09-18 23:35:36 +00:00
var content = null;
2014-11-27 00:38:30 +00:00
if (flow.request.contentLength > 0) {
content = "Request Content Size: " + formatSize(flow.request.contentLength);
2014-09-18 23:35:36 +00:00
} else {
2014-11-27 00:38:30 +00:00
content = React.createElement("div", {className: "alert alert-info"}, "No Content");
2014-09-18 23:35:36 +00:00
}
//TODO: Styling
return (
2014-11-27 00:38:30 +00:00
React.createElement("section", null,
React.createElement("div", {className: "first-line"}, first_line ),
React.createElement(Headers, {message: flow.request}),
React.createElement("hr", null),
2014-09-18 23:35:36 +00:00
content
)
);
2014-09-18 19:13:50 +00:00
}
});
var FlowDetailResponse = React.createClass({displayName: 'FlowDetailResponse',
2014-11-27 00:38:30 +00:00
render: function () {
2014-09-18 23:57:50 +00:00
var flow = this.props.flow;
var first_line = [
2014-11-27 00:38:30 +00:00
"HTTP/" + flow.response.httpversion.join("."),
flow.response.code,
flow.response.msg
].join(" ");
2014-09-18 23:57:50 +00:00
var content = null;
2014-11-27 00:38:30 +00:00
if (flow.response.contentLength > 0) {
content = "Response Content Size: " + formatSize(flow.response.contentLength);
2014-09-18 23:57:50 +00:00
} else {
2014-11-27 00:38:30 +00:00
content = React.createElement("div", {className: "alert alert-info"}, "No Content");
2014-09-18 23:57:50 +00:00
}
//TODO: Styling
return (
2014-11-27 00:38:30 +00:00
React.createElement("section", null,
React.createElement("div", {className: "first-line"}, first_line ),
React.createElement(Headers, {message: flow.response}),
React.createElement("hr", null),
2014-09-18 23:57:50 +00:00
content
)
);
2014-09-18 19:13:50 +00:00
}
});
2014-11-29 02:25:07 +00:00
var FlowDetailError = React.createClass({displayName: 'FlowDetailError',
render: function () {
var flow = this.props.flow;
return (
React.createElement("section", null,
React.createElement("div", {className: "alert alert-warning"},
flow.error.msg,
React.createElement("div", null, React.createElement("small", null, formatTimeStamp(flow.error.timestamp) ))
)
)
);
}
});
2014-09-19 15:56:54 +00:00
var TimeStamp = React.createClass({displayName: 'TimeStamp',
2014-11-27 00:38:30 +00:00
render: function () {
2014-09-19 15:56:54 +00:00
2014-11-27 00:38:30 +00:00
if (!this.props.t) {
2014-09-19 15:56:54 +00:00
//should be return null, but that triggers a React bug.
2014-11-27 00:38:30 +00:00
return React.createElement("tr", null);
2014-09-21 21:43:27 +00:00
}
2014-11-29 02:25:07 +00:00
var ts = formatTimeStamp(this.props.t);
2014-09-21 21:43:27 +00:00
var delta;
2014-11-27 00:38:30 +00:00
if (this.props.deltaTo) {
delta = formatTimeDelta(1000 * (this.props.t - this.props.deltaTo));
delta = React.createElement("span", {className: "text-muted"}, "(" + delta + ")");
2014-09-19 15:56:54 +00:00
} else {
2014-09-21 21:43:27 +00:00
delta = null;
2014-09-19 15:56:54 +00:00
}
2014-11-27 00:38:30 +00:00
return React.createElement("tr", null,
React.createElement("td", null, this.props.title + ":"),
React.createElement("td", null, ts, " ", delta)
);
2014-09-19 15:56:54 +00:00
}
});
var ConnectionInfo = React.createClass({displayName: 'ConnectionInfo',
2014-11-27 00:38:30 +00:00
render: function () {
2014-09-19 15:56:54 +00:00
var conn = this.props.conn;
var address = conn.address.address.join(":");
2014-11-27 00:38:30 +00:00
var sni = React.createElement("tr", {key: "sni"}); //should be null, but that triggers a React bug.
if (conn.sni) {
sni = React.createElement("tr", {key: "sni"},
React.createElement("td", null,
React.createElement("abbr", {title: "TLS Server Name Indication"}, "TLS SNI:")
),
React.createElement("td", null, conn.sni)
);
2014-09-19 15:56:54 +00:00
}
return (
2014-11-27 00:38:30 +00:00
React.createElement("table", {className: "connection-table"},
React.createElement("tbody", null,
React.createElement("tr", {key: "address"},
React.createElement("td", null, "Address:"),
React.createElement("td", null, address)
),
2014-09-21 21:43:27 +00:00
sni
2014-09-19 15:56:54 +00:00
)
)
);
}
});
var CertificateInfo = React.createClass({displayName: 'CertificateInfo',
2014-11-27 00:38:30 +00:00
render: function () {
2014-09-19 15:56:54 +00:00
//TODO: We should fetch human-readable certificate representation
// from the server
var flow = this.props.flow;
var client_conn = flow.client_conn;
var server_conn = flow.server_conn;
2014-09-21 21:43:27 +00:00
var preStyle = {maxHeight: 100};
2014-09-19 15:56:54 +00:00
return (
2014-11-27 00:38:30 +00:00
React.createElement("div", null,
client_conn.cert ? React.createElement("h4", null, "Client Certificate") : null,
client_conn.cert ? React.createElement("pre", {style: preStyle}, client_conn.cert) : null,
2014-09-19 15:56:54 +00:00
2014-11-27 00:38:30 +00:00
server_conn.cert ? React.createElement("h4", null, "Server Certificate") : null,
server_conn.cert ? React.createElement("pre", {style: preStyle}, server_conn.cert) : null
2014-09-21 21:43:27 +00:00
)
);
}
});
var Timing = React.createClass({displayName: 'Timing',
2014-11-27 00:38:30 +00:00
render: function () {
2014-09-21 21:43:27 +00:00
var flow = this.props.flow;
var sc = flow.server_conn;
var cc = flow.client_conn;
var req = flow.request;
var resp = flow.response;
var timestamps = [
{
title: "Server conn. initiated",
t: sc.timestamp_start,
deltaTo: req.timestamp_start
}, {
title: "Server conn. TCP handshake",
t: sc.timestamp_tcp_setup,
deltaTo: req.timestamp_start
}, {
title: "Server conn. SSL handshake",
t: sc.timestamp_ssl_setup,
deltaTo: req.timestamp_start
}, {
title: "Client conn. established",
t: cc.timestamp_start,
deltaTo: req.timestamp_start
}, {
title: "Client conn. SSL handshake",
t: cc.timestamp_ssl_setup,
deltaTo: req.timestamp_start
}, {
title: "First request byte",
t: req.timestamp_start,
}, {
title: "Request complete",
t: req.timestamp_end,
deltaTo: req.timestamp_start
}
];
if (flow.response) {
timestamps.push(
{
title: "First response byte",
t: resp.timestamp_start,
deltaTo: req.timestamp_start
}, {
title: "Response complete",
t: resp.timestamp_end,
deltaTo: req.timestamp_start
}
);
}
//Add unique key for each row.
2014-11-27 00:38:30 +00:00
timestamps.forEach(function (e) {
2014-09-21 21:43:27 +00:00
e.key = e.title;
});
timestamps = _.sortBy(timestamps, 't');
2014-11-27 00:38:30 +00:00
var rows = timestamps.map(function (e) {
return React.createElement(TimeStamp, React.__spread({}, e));
2014-09-21 21:43:27 +00:00
});
return (
2014-11-27 00:38:30 +00:00
React.createElement("div", null,
React.createElement("h4", null, "Timing"),
React.createElement("table", {className: "timing-table"},
React.createElement("tbody", null,
2014-09-21 21:43:27 +00:00
rows
2014-11-27 00:38:30 +00:00
)
2014-09-21 21:43:27 +00:00
)
)
2014-09-19 15:56:54 +00:00
);
}
});
2014-09-18 19:13:50 +00:00
var FlowDetailConnectionInfo = React.createClass({displayName: 'FlowDetailConnectionInfo',
2014-11-27 00:38:30 +00:00
render: function () {
2014-09-19 15:56:54 +00:00
var flow = this.props.flow;
var client_conn = flow.client_conn;
var server_conn = flow.server_conn;
return (
2014-11-27 00:38:30 +00:00
React.createElement("section", null,
2014-09-19 15:56:54 +00:00
2014-11-27 00:38:30 +00:00
React.createElement("h4", null, "Client Connection"),
React.createElement(ConnectionInfo, {conn: client_conn}),
2014-09-19 15:56:54 +00:00
2014-11-27 00:38:30 +00:00
React.createElement("h4", null, "Server Connection"),
React.createElement(ConnectionInfo, {conn: server_conn}),
2014-09-19 15:56:54 +00:00
2014-11-27 00:38:30 +00:00
React.createElement(CertificateInfo, {flow: flow}),
2014-09-21 21:43:27 +00:00
2014-11-27 00:38:30 +00:00
React.createElement(Timing, {flow: flow})
2014-09-19 15:56:54 +00:00
)
);
2014-09-18 19:13:50 +00:00
}
2014-09-18 21:22:02 +00:00
});
2014-09-18 19:13:50 +00:00
2014-11-29 02:25:07 +00:00
var allTabs = {
2014-09-18 19:13:50 +00:00
request: FlowDetailRequest,
response: FlowDetailResponse,
2014-11-29 02:25:07 +00:00
error: FlowDetailError,
2014-09-18 19:13:50 +00:00
details: FlowDetailConnectionInfo
2014-09-18 21:22:02 +00:00
};
2014-09-18 19:13:50 +00:00
var FlowDetail = React.createClass({displayName: 'FlowDetail',
2014-11-27 00:38:30 +00:00
mixins: [StickyHeadMixin, ReactRouter.Navigation, ReactRouter.State],
2014-11-29 02:25:07 +00:00
getTabs: function (flow) {
var tabs = [];
["request", "response", "error"].forEach(function (e) {
if (flow[e]) {
tabs.push(e);
}
});
tabs.push("details");
return tabs;
},
2014-11-27 00:38:30 +00:00
nextTab: function (i) {
2014-11-29 02:25:07 +00:00
var tabs = this.getTabs();
var currentIndex = tabs.indexOf(this.getParams().detailTab);
2014-09-19 15:56:54 +00:00
// JS modulo operator doesn't correct negative numbers, make sure that we are positive.
2014-11-29 02:25:07 +00:00
var nextIndex = (currentIndex + i + tabs.length) % tabs.length;
this.selectTab(tabs[nextIndex]);
2014-09-19 15:56:54 +00:00
},
2014-11-27 00:38:30 +00:00
selectTab: function (panel) {
this.replaceWith(
"flow",
{
flowId: this.getParams().flowId,
detailTab: panel
}
);
},
render: function () {
2014-11-29 02:25:07 +00:00
var flow = this.props.flow;
var tabs = this.getTabs(flow);
var active = this.getParams().detailTab;
if (!_.contains(tabs, active)) {
if (active === "response" && flow.error) {
active = "error";
} else if (active === "error" && flow.response) {
active = "response";
} else {
active = tabs[0];
}
this.selectTab(active);
}
var Tab = allTabs[active];
2014-09-18 19:13:50 +00:00
return (
2014-11-27 00:38:30 +00:00
React.createElement("div", {className: "flow-detail", onScroll: this.adjustHead},
React.createElement(FlowDetailNav, {ref: "head",
2014-11-29 02:25:07 +00:00
tabs: tabs,
active: active,
2014-11-27 00:38:30 +00:00
selectTab: this.selectTab}),
2014-11-29 02:25:07 +00:00
React.createElement(Tab, {flow: flow})
2014-09-18 19:13:50 +00:00
)
2014-11-27 00:38:30 +00:00
);
}
2014-09-18 19:13:50 +00:00
});
var MainView = React.createClass({displayName: 'MainView',
2014-11-27 00:38:30 +00:00
mixins: [ReactRouter.Navigation, ReactRouter.State],
getInitialState: function () {
2014-09-18 19:13:50 +00:00
return {
2014-11-27 00:38:30 +00:00
flows: []
2014-09-18 19:13:50 +00:00
};
},
2014-11-27 00:38:30 +00:00
componentWillReceiveProps: function (nextProps) {
if (nextProps.flowStore !== this.props.flowStore) {
this.closeView();
this.openView(nextProps.flowStore);
}
},
openView: function (store) {
var view = new FlowView(store);
this.setState({
view: view
});
2014-11-29 02:25:07 +00:00
view.addListener("recalculate", this.onRecalculate);
view.addListener("add update remove", this.onUpdate);
},
onRecalculate: function(){
this.forceUpdate();
var selected = this.getSelected();
if(selected){
this.refs.flowTable.scrollIntoView();
}
},
onUpdate: function (flow) {
if (flow.id === this.getParams().flowId) {
this.forceUpdate();
}
2014-11-27 00:38:30 +00:00
},
closeView: function () {
this.state.view.close();
},
2014-11-28 15:03:56 +00:00
componentWillMount: function () {
2014-11-27 00:38:30 +00:00
this.openView(this.props.flowStore);
2014-09-18 19:13:50 +00:00
},
componentWillUnmount: function () {
2014-11-27 00:38:30 +00:00
this.closeView();
2014-09-18 19:13:50 +00:00
},
2014-11-27 00:38:30 +00:00
selectFlow: function (flow) {
if (flow) {
this.replaceWith(
"flow",
2014-09-18 19:13:50 +00:00
{
flowId: flow.id,
2014-11-27 00:38:30 +00:00
detailTab: this.getParams().detailTab || "request"
2014-09-18 19:13:50 +00:00
}
);
2014-11-28 18:16:47 +00:00
this.refs.flowTable.scrollIntoView(flow);
2014-09-18 19:13:50 +00:00
} else {
2014-11-27 00:38:30 +00:00
this.replaceWith("flows");
2014-09-18 19:13:50 +00:00
}
},
2014-11-27 01:34:03 +00:00
selectFlowRelative: function (shift) {
2014-11-27 00:38:30 +00:00
var flows = this.state.view.flows;
2014-09-19 15:56:54 +00:00
var index;
2014-11-27 00:38:30 +00:00
if (!this.getParams().flowId) {
2014-11-27 01:34:03 +00:00
if (shift > 0) {
2014-11-27 00:38:30 +00:00
index = flows.length - 1;
2014-09-19 15:56:54 +00:00
} else {
index = 0;
2014-09-18 19:13:50 +00:00
}
2014-09-19 15:56:54 +00:00
} else {
2014-11-27 00:38:30 +00:00
var currFlowId = this.getParams().flowId;
2014-11-27 01:34:03 +00:00
var i = flows.length;
2014-11-27 00:38:30 +00:00
while (i--) {
if (flows[i].id === currFlowId) {
index = i;
break;
}
}
index = Math.min(
2014-11-27 01:34:03 +00:00
Math.max(0, index + shift),
2014-11-27 00:38:30 +00:00
flows.length - 1);
2014-09-19 15:56:54 +00:00
}
2014-11-27 00:38:30 +00:00
this.selectFlow(flows[index]);
2014-09-19 15:56:54 +00:00
},
2014-11-27 00:38:30 +00:00
onKeyDown: function (e) {
switch (e.keyCode) {
2014-09-19 15:56:54 +00:00
case Key.K:
case Key.UP:
this.selectFlowRelative(-1);
break;
case Key.J:
case Key.DOWN:
this.selectFlowRelative(+1);
break;
case Key.SPACE:
case Key.PAGE_DOWN:
this.selectFlowRelative(+10);
break;
case Key.PAGE_UP:
this.selectFlowRelative(-10);
break;
case Key.ESC:
this.selectFlow(null);
break;
case Key.H:
case Key.LEFT:
2014-11-27 00:38:30 +00:00
if (this.refs.flowDetails) {
2014-09-19 15:56:54 +00:00
this.refs.flowDetails.nextTab(-1);
}
break;
case Key.L:
case Key.TAB:
case Key.RIGHT:
2014-11-27 00:38:30 +00:00
if (this.refs.flowDetails) {
2014-09-19 15:56:54 +00:00
this.refs.flowDetails.nextTab(+1);
}
break;
default:
console.debug("keydown", e.keyCode);
return;
}
2014-11-27 00:38:30 +00:00
e.preventDefault();
2014-09-18 19:13:50 +00:00
},
2014-11-29 02:25:07 +00:00
getSelected: function(){
return this.props.flowStore.get(this.getParams().flowId);
},
2014-11-27 00:38:30 +00:00
render: function () {
2014-11-29 02:25:07 +00:00
var selected = this.getSelected();
2014-09-18 19:13:50 +00:00
2014-09-19 15:56:54 +00:00
var details;
2014-11-27 00:38:30 +00:00
if (selected) {
2014-11-29 02:25:07 +00:00
details = [
React.createElement(Splitter, {key: "splitter"}),
React.createElement(FlowDetail, {key: "flowDetails", ref: "flowDetails", flow: selected})
];
2014-09-19 15:56:54 +00:00
} else {
details = null;
2014-09-18 19:13:50 +00:00
}
return (
2014-11-27 00:38:30 +00:00
React.createElement("div", {className: "main-view", onKeyDown: this.onKeyDown, tabIndex: "0"},
React.createElement(FlowTable, {ref: "flowTable",
2014-11-28 15:03:56 +00:00
view: this.state.view,
2014-11-27 00:38:30 +00:00
selectFlow: this.selectFlow,
selected: selected}),
2014-09-18 19:13:50 +00:00
details
)
);
}
});
2014-09-22 01:06:19 +00:00
var LogMessage = React.createClass({displayName: 'LogMessage',
2014-11-27 00:40:26 +00:00
render: function () {
2014-09-22 01:06:19 +00:00
var entry = this.props.entry;
var indicator;
2014-11-27 00:40:26 +00:00
switch (entry.level) {
2014-09-22 01:06:19 +00:00
case "web":
2014-11-27 00:38:30 +00:00
indicator = React.createElement("i", {className: "fa fa-fw fa-html5"});
2014-09-22 01:06:19 +00:00
break;
case "debug":
2014-11-27 00:38:30 +00:00
indicator = React.createElement("i", {className: "fa fa-fw fa-bug"});
2014-09-22 01:06:19 +00:00
break;
default:
2014-11-27 00:38:30 +00:00
indicator = React.createElement("i", {className: "fa fa-fw fa-info"});
2014-09-22 01:06:19 +00:00
}
return (
2014-11-27 00:38:30 +00:00
React.createElement("div", null,
2014-09-22 01:06:19 +00:00
indicator, " ", entry.message
)
);
},
2014-11-27 00:40:26 +00:00
shouldComponentUpdate: function () {
2014-09-22 01:06:19 +00:00
return false; // log entries are immutable.
}
});
var EventLogContents = React.createClass({displayName: 'EventLogContents',
2014-11-28 19:54:52 +00:00
mixins: [AutoScrollMixin, VirtualScrollMixin],
2014-09-17 00:13:37 +00:00
getInitialState: function () {
2014-09-15 22:56:43 +00:00
return {
log: []
};
},
2014-09-17 00:13:37 +00:00
componentDidMount: function () {
2014-09-15 22:56:43 +00:00
this.log = EventLogStore.getView();
this.log.addListener("change", this.onEventLogChange);
},
2014-09-17 00:13:37 +00:00
componentWillUnmount: function () {
2014-09-15 22:56:43 +00:00
this.log.removeListener("change", this.onEventLogChange);
this.log.close();
},
2014-09-17 00:13:37 +00:00
onEventLogChange: function () {
2014-11-28 19:54:52 +00:00
var log = this.log.getAll().filter(function (entry) {
return this.props.filter[entry.level];
}.bind(this));
2014-09-15 22:56:43 +00:00
this.setState({
2014-11-28 19:54:52 +00:00
log: log
2014-09-15 22:56:43 +00:00
});
},
2014-11-28 19:54:52 +00:00
componentWillReceiveProps: function () {
if (this.log) {
this.onEventLogChange();
}
},
getDefaultProps: function () {
return {
rowHeight: 45,
rowHeightMin: 15,
placeholderTagName: "div"
};
},
renderRow: function(elem){
return React.createElement(LogMessage, {key: elem.id, entry: elem});
},
2014-09-22 01:06:19 +00:00
render: function () {
2014-11-28 19:54:52 +00:00
var rows = this.renderRows(this.state.log);
return React.createElement("pre", {onScroll: this.onScroll},
this.getPlaceholderTop(),
rows,
this.getPlaceholderBottom(this.state.log.length)
);
2014-09-22 01:06:19 +00:00
}
});
var ToggleFilter = React.createClass({displayName: 'ToggleFilter',
2014-11-27 00:40:26 +00:00
toggle: function (e) {
2014-11-27 00:38:30 +00:00
e.preventDefault();
2014-09-22 01:06:19 +00:00
return this.props.toggleLevel(this.props.name);
},
2014-11-27 00:40:26 +00:00
render: function () {
2014-09-22 01:06:19 +00:00
var className = "label ";
if (this.props.active) {
className += "label-primary";
} else {
className += "label-default";
}
return (
2014-11-27 00:38:30 +00:00
React.createElement("a", {
2014-09-22 01:06:19 +00:00
href: "#",
className: className,
onClick: this.toggle},
this.props.name
)
);
2014-11-27 00:40:26 +00:00
}
2014-09-22 01:06:19 +00:00
});
var EventLog = React.createClass({displayName: 'EventLog',
2014-11-27 00:40:26 +00:00
getInitialState: function () {
2014-09-22 01:06:19 +00:00
return {
filter: {
"debug": false,
"info": true,
"web": true
}
};
},
2014-09-17 00:13:37 +00:00
close: function () {
2014-09-15 22:56:43 +00:00
SettingsActions.update({
showEventLog: false
});
},
2014-11-27 00:40:26 +00:00
toggleLevel: function (level) {
2014-09-22 01:06:19 +00:00
var filter = this.state.filter;
filter[level] = !filter[level];
this.setState({filter: filter});
},
2014-09-17 00:13:37 +00:00
render: function () {
2014-09-22 01:06:19 +00:00
return (
2014-11-27 00:38:30 +00:00
React.createElement("div", {className: "eventlog"},
React.createElement("div", null,
2014-11-28 19:54:52 +00:00
"Eventlog",
2014-11-27 00:38:30 +00:00
React.createElement("div", {className: "pull-right"},
React.createElement(ToggleFilter, {name: "debug", active: this.state.filter.debug, toggleLevel: this.toggleLevel}),
React.createElement(ToggleFilter, {name: "info", active: this.state.filter.info, toggleLevel: this.toggleLevel}),
React.createElement(ToggleFilter, {name: "web", active: this.state.filter.web, toggleLevel: this.toggleLevel}),
React.createElement("i", {onClick: this.close, className: "fa fa-close"})
2014-09-22 01:06:19 +00:00
)
),
2014-11-27 00:38:30 +00:00
React.createElement(EventLogContents, {filter: this.state.filter})
2014-09-22 01:06:19 +00:00
)
);
2014-09-15 16:08:26 +00:00
}
});
var Footer = React.createClass({displayName: 'Footer',
2014-09-17 00:13:37 +00:00
render: function () {
2014-09-15 23:05:29 +00:00
var mode = this.props.settings.mode;
2014-09-15 16:08:26 +00:00
return (
2014-11-27 00:38:30 +00:00
React.createElement("footer", null,
mode != "regular" ? React.createElement("span", {className: "label label-success"}, mode, " mode") : null
2014-09-15 16:08:26 +00:00
)
2014-11-27 00:40:26 +00:00
);
2014-09-15 16:08:26 +00:00
}
});
2014-09-15 16:08:26 +00:00
//TODO: Move out of here, just a stub.
2014-09-14 00:44:13 +00:00
var Reports = React.createClass({displayName: 'Reports',
2014-09-17 00:13:37 +00:00
render: function () {
2014-11-27 00:38:30 +00:00
return React.createElement("div", null, "ReportEditor");
2014-09-15 22:56:43 +00:00
}
2014-09-14 00:44:13 +00:00
});
2014-09-15 16:08:26 +00:00
var ProxyAppMain = React.createClass({displayName: 'ProxyAppMain',
2014-09-17 00:13:37 +00:00
getInitialState: function () {
2014-11-27 00:38:30 +00:00
return {
settings: SettingsStore.getAll(),
flowStore: new LiveFlowStore()
};
2014-09-15 22:05:06 +00:00
},
2014-09-17 00:13:37 +00:00
componentDidMount: function () {
2014-09-15 22:56:43 +00:00
SettingsStore.addListener("change", this.onSettingsChange);
2014-09-15 22:05:06 +00:00
},
2014-09-17 00:13:37 +00:00
componentWillUnmount: function () {
2014-09-15 22:56:43 +00:00
SettingsStore.removeListener("change", this.onSettingsChange);
2014-09-15 22:05:06 +00:00
},
2014-09-17 00:13:37 +00:00
onSettingsChange: function () {
2014-09-15 22:56:43 +00:00
this.setState({settings: SettingsStore.getAll()});
2014-09-15 22:05:06 +00:00
},
2014-09-17 00:13:37 +00:00
render: function () {
2014-09-15 22:56:43 +00:00
return (
2014-11-27 00:38:30 +00:00
React.createElement("div", {id: "container"},
React.createElement(Header, {settings: this.state.settings}),
React.createElement(RouteHandler, {settings: this.state.settings, flowStore: this.state.flowStore}),
this.state.settings.showEventLog ? React.createElement(Splitter, {axis: "y"}) : null,
this.state.settings.showEventLog ? React.createElement(EventLog, null) : null,
React.createElement(Footer, {settings: this.state.settings})
2014-09-15 22:56:43 +00:00
)
2014-11-27 00:38:30 +00:00
);
2014-09-15 16:08:26 +00:00
}
});
2014-09-18 19:13:50 +00:00
var Route = ReactRouter.Route;
2014-11-27 00:38:30 +00:00
var RouteHandler = ReactRouter.RouteHandler;
2014-09-18 19:13:50 +00:00
var Redirect = ReactRouter.Redirect;
var DefaultRoute = ReactRouter.DefaultRoute;
var NotFoundRoute = ReactRouter.NotFoundRoute;
2014-11-27 00:38:30 +00:00
var routes = (
React.createElement(Route, {path: "/", handler: ProxyAppMain},
React.createElement(Route, {name: "flows", path: "flows", handler: MainView}),
React.createElement(Route, {name: "flow", path: "flows/:flowId/:detailTab", handler: MainView}),
React.createElement(Route, {name: "reports", handler: Reports}),
React.createElement(Redirect, {path: "/", to: "flows"})
2014-09-14 00:44:13 +00:00
)
2014-11-27 00:38:30 +00:00
);
2014-09-17 00:13:37 +00:00
$(function () {
2014-11-27 00:38:30 +00:00
ReactRouter.run(routes, function (Handler) {
React.render(React.createElement(Handler, null), document.body);
});
var UpdateConnection = new Connection("/updates");
UpdateConnection.onmessage = function (message) {
var m = JSON.parse(message.data);
AppDispatcher.dispatchServerAction(m);
};
2014-09-15 16:08:26 +00:00
});
2014-09-14 00:44:13 +00:00
//# sourceMappingURL=app.js.map