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

717 lines
20 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-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-09-17 00:13:37 +00:00
this.callbacks.forEach(function (callback) {
2014-09-16 09:06:30 +00:00
callback(payload);
});
};
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-17 15:30:19 +00:00
var EventLogActions = {
add_event: function(message, level){
AppDispatcher.dispatchViewAction({
type: ActionTypes.ADD_EVENT,
data: {
message: message,
level: level || "info",
source: "ui"
}
});
}
};
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-09-17 00:13:37 +00:00
EventEmitter.prototype.addListener = function (event, f) {
2014-09-16 09:06:30 +00:00
this.listeners[event] = this.listeners[event] || [];
this.listeners[event].push(f);
};
2014-09-17 00:13:37 +00:00
EventEmitter.prototype.removeListener = function (event, f) {
2014-09-16 09:06:30 +00:00
if (!(event in this.listeners)) {
return false;
}
var index = this.listeners[event].indexOf(f);
if (index >= 0) {
this.listeners[event].splice(index, 1);
2014-09-15 22:56:43 +00:00
}
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);
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-09-15 22:56:43 +00:00
//TODO: Really do bulk retrieval of last messages.
2014-09-17 00:13:37 +00:00
window.setTimeout(function () {
view.add_bulk([
{
id: 1,
message: "Hello World"
},
{
id: 2,
message: "I was already transmitted as an event."
}
]);
2014-09-15 22:56:43 +00:00
}, 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.."
});
2014-09-17 00:13:37 +00:00
window.setInterval(function () {
2014-09-15 22:56:43 +00:00
view.add({
id: id++,
message: "."
});
}, 1000);
return view;
2014-09-17 13:22:42 +00:00
*/
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));
2014-09-17 15:30:19 +00:00
function FlowView(store, live) {
EventEmitter.call(this);
this._store = store;
this.live = live;
this.flows = [];
this.add = this.add.bind(this);
this.update = this.update.bind(this);
if (live) {
this._store.addListener(ActionTypes.ADD_FLOW, this.add);
this._store.addListener(ActionTypes.UPDATE_FLOW, this.update);
}
}
_.extend(FlowView.prototype, EventEmitter.prototype, {
close: function () {
this._store.removeListener(ActionTypes.ADD_FLOW, this.add);
this._store.removeListener(ActionTypes.UPDATE_FLOW, this.update);
},
getAll: function () {
return this.flows;
},
add: function (flow) {
return this.update(flow);
},
add_bulk: function (flows) {
//Treat all previously received updates as newer than the bulk update.
//If they weren't newer, we're about to receive an update for them very soon.
var updates = this.flows;
this.flows = flows;
updates.forEach(function(flow){
this._update(flow);
2014-09-17 15:30:19 +00:00
}.bind(this));
this.emit("change");
2014-09-17 15:30:19 +00:00
},
_update: function(flow){
2014-09-17 15:30:19 +00:00
console.debug("FIXME: Use UUID");
var idx = _.findIndex(this.flows, function(f){
return flow.request.timestamp_start == f.request.timestamp_start;
2014-09-17 15:30:19 +00:00
});
if(idx < 0){
this.flows.push(flow);
} else {
this.flows[idx] = flow;
}
},
update: function(flow){
this._update(flow);
2014-09-17 15:30:19 +00:00
this.emit("change");
},
});
function _FlowStore() {
EventEmitter.call(this);
}
_.extend(_FlowStore.prototype, EventEmitter.prototype, {
getView: function (since) {
var view = new FlowView(this, !since);
$.getJSON("/static/flows.json", function(flows){
view.add_bulk(flows);
});
2014-09-17 15:30:19 +00:00
return view;
},
handle: function (action) {
switch (action.type) {
case ActionTypes.ADD_FLOW:
case ActionTypes.UPDATE_FLOW:
this.emit(action.type, action.data);
break;
default:
return;
}
}
});
var FlowStore = new _FlowStore();
AppDispatcher.register(FlowStore.handle.bind(FlowStore));
function _Connection(url) {
this.url = url;
}
2014-09-17 00:13:37 +00:00
_Connection.prototype.init = function () {
2014-09-16 09:06:30 +00:00
this.openWebSocketConnection();
};
2014-09-17 00:13:37 +00:00
_Connection.prototype.openWebSocketConnection = function () {
this.ws = new WebSocket(this.url.replace("http", "ws"));
2014-09-16 09:06:30 +00:00
var ws = this.ws;
ws.onopen = this.onopen.bind(this);
ws.onmessage = this.onmessage.bind(this);
ws.onerror = this.onerror.bind(this);
ws.onclose = this.onclose.bind(this);
};
2014-09-17 00:13:37 +00:00
_Connection.prototype.onopen = function (open) {
2014-09-16 09:06:30 +00:00
console.log("onopen", this, arguments);
};
2014-09-17 00:13:37 +00:00
_Connection.prototype.onmessage = function (message) {
2014-09-16 09:06:30 +00:00
//AppDispatcher.dispatchServerAction(...);
var m = JSON.parse(message.data);
2014-09-17 13:22:42 +00:00
AppDispatcher.dispatchServerAction(m);
2014-09-16 09:06:30 +00:00
};
2014-09-17 00:13:37 +00:00
_Connection.prototype.onerror = function (error) {
2014-09-17 15:30:19 +00:00
EventLogActions.add_event("WebSocket Connection Error.");
2014-09-16 09:06:30 +00:00
console.log("onerror", this, arguments);
};
2014-09-17 00:13:37 +00:00
_Connection.prototype.onclose = function (close) {
2014-09-17 15:30:19 +00:00
EventLogActions.add_event("WebSocket Connection closed.");
2014-09-16 09:06:30 +00:00
console.log("onclose", this, arguments);
};
2014-09-14 00:44:13 +00:00
var Connection = new _Connection(location.origin + "/updates");
2014-09-14 00:44:13 +00:00
/** @jsx React.DOM */
var MainMenu = React.createClass({displayName: 'MainMenu',
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-09-17 00:13:37 +00:00
render: function () {
2014-09-15 22:56:43 +00:00
return (
React.DOM.div(null,
React.DOM.button({className: "btn " + (this.props.settings.showEventLog ? "btn-primary" : "btn-default"), onClick: this.toggleEventLog},
2014-09-15 16:39:25 +00:00
React.DOM.i({className: "fa fa-database"}), " Display Event Log"
2014-09-15 22:56:43 +00:00
)
2014-09-15 16:08:26 +00:00
)
2014-09-17 00:13:37 +00:00
);
2014-09-14 00:44:13 +00:00
}
});
var ToolsMenu = React.createClass({displayName: 'ToolsMenu',
2014-09-17 00:13:37 +00:00
render: function () {
2014-09-15 22:56:43 +00:00
return React.DOM.div(null, "Tools Menu");
2014-09-14 00:44:13 +00:00
}
});
var ReportsMenu = React.createClass({displayName: 'ReportsMenu',
2014-09-17 00:13:37 +00:00
render: function () {
2014-09-15 22:56:43 +00:00
return React.DOM.div(null, "Reports Menu");
2014-09-14 00:44:13 +00:00
}
});
2014-09-15 16:08:26 +00:00
2014-09-14 00:44:13 +00:00
var _Header_Entries = {
main: {
title: "Traffic",
route: "main",
menu: MainMenu
},
tools: {
title: "Tools",
route: "main",
menu: ToolsMenu
},
reports: {
title: "Visualization",
route: "reports",
menu: ReportsMenu
}
};
var Header = React.createClass({displayName: 'Header',
2014-09-17 00:13:37 +00:00
getInitialState: function () {
2014-09-15 16:08:26 +00:00
return {
active: "main"
};
2014-09-14 00:44:13 +00:00
},
2014-09-17 00:13:37 +00:00
handleClick: function (active) {
2014-09-14 00:44:13 +00:00
this.setState({active: active});
ReactRouter.transitionTo(_Header_Entries[active].route);
return false;
},
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-09-14 00:44:13 +00:00
var header = [];
2014-09-17 00:13:37 +00:00
for (var item in _Header_Entries) {
2014-09-14 00:44:13 +00:00
var classes = this.state.active == item ? "active" : "";
header.push(React.DOM.a({key: item, href: "#", className: classes,
2014-09-15 16:08:26 +00:00
onClick: this.handleClick.bind(this, item)}, _Header_Entries[item].title));
2014-09-14 00:44:13 +00:00
}
2014-09-15 22:05:06 +00:00
var menu = _Header_Entries[this.state.active].menu({
settings: this.props.settings
});
2014-09-14 00:44:13 +00:00
return (
2014-09-15 16:08:26 +00:00
React.DOM.header(null,
React.DOM.div({className: "title-bar"},
2014-09-15 22:05:06 +00:00
"mitmproxy ", this.props.settings.version
2014-09-15 16:08:26 +00:00
),
React.DOM.nav(null,
React.DOM.a({href: "#", className: "special", onClick: this.handleFileClick}, " File "),
header
),
React.DOM.div({className: "menu"},
menu
)
2014-09-15 22:56:43 +00:00
)
2014-09-17 00:13:37 +00:00
);
2014-09-14 00:44:13 +00:00
}
});
2014-09-14 00:44:13 +00:00
/** @jsx React.DOM */
2014-09-17 15:30:19 +00:00
var FlowRow = React.createClass({displayName: 'FlowRow',
render: function(){
var flow = this.props.flow;
var columns = this.props.columns.map(function(column){
return column({
key: column.displayName,
flow: flow
});
2014-09-17 15:30:19 +00:00
}.bind(this));
return React.DOM.tr({onClick: this.props.onClick}, columns);
2014-09-17 15:30:19 +00:00
}
});
var FlowTableHead = React.createClass({displayName: 'FlowTableHead',
render: function(){
var columns = this.props.columns.map(function(column){
return column.renderTitle();
}.bind(this));
return React.DOM.thead(null, columns);
}
});
var FlowTableBody = React.createClass({displayName: 'FlowTableBody',
render: function(){
var rows = this.props.flows.map(function(flow){
//TODO: Add UUID
return FlowRow({onClick: this.props.onClick, flow: flow, columns: this.props.columns});
2014-09-17 15:30:19 +00:00
}.bind(this));
return React.DOM.tbody(null, rows);
}
});
var TLSColumn = React.createClass({displayName: 'TLSColumn',
statics: {
renderTitle: function(){
return React.DOM.th({key: "tls", className: "col-tls"});
}
},
render: function(){
var flow = this.props.flow;
var ssl = (flow.request.scheme == "https");
return React.DOM.td({className: ssl ? "col-tls-https" : "col-tls-http"});
}
});
var IconColumn = React.createClass({displayName: 'IconColumn',
statics: {
renderTitle: function(){
return React.DOM.th({key: "icon", className: "col-icon"});
}
},
render: function(){
var flow = this.props.flow;
return React.DOM.td({className: "resource-icon resource-icon-plain"});
}
});
2014-09-17 15:30:19 +00:00
var PathColumn = React.createClass({displayName: 'PathColumn',
statics: {
renderTitle: function(){
return React.DOM.th({key: "path", className: "col-path"}, "Path");
2014-09-17 15:30:19 +00:00
}
},
render: function(){
var flow = this.props.flow;
return React.DOM.td(null, 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: {
renderTitle: function(){
return React.DOM.th({key: "method", className: "col-method"}, "Method");
2014-09-17 15:30:19 +00:00
}
},
render: function(){
var flow = this.props.flow;
return React.DOM.td(null, 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: {
renderTitle: function(){
return React.DOM.th({key: "status", className: "col-status"}, "Status");
2014-09-17 15:30:19 +00:00
}
},
render: function(){
var flow = this.props.flow;
var status;
if(flow.response){
status = flow.response.code;
2014-09-17 15:30:19 +00:00
} else {
status = null;
}
return React.DOM.td(null, status);
2014-09-17 15:30:19 +00:00
}
});
2014-09-17 15:30:19 +00:00
var TimeColumn = React.createClass({displayName: 'TimeColumn',
statics: {
renderTitle: function(){
return React.DOM.th({key: "time", className: "col-time"}, "Time");
2014-09-17 15:30:19 +00:00
}
},
render: function(){
var flow = this.props.flow;
var time;
if(flow.response){
time = Math.round(1000 * (flow.response.timestamp_end - flow.request.timestamp_start))+"ms";
} else {
time = "...";
}
return React.DOM.td(null, time);
2014-09-17 15:30:19 +00:00
}
});
var all_columns = [TLSColumn, IconColumn, PathColumn, MethodColumn, StatusColumn, TimeColumn];
2014-09-17 15:30:19 +00:00
var FlowTable = React.createClass({displayName: 'FlowTable',
2014-09-17 00:13:37 +00:00
getInitialState: function () {
2014-09-14 00:44:13 +00:00
return {
2014-09-17 15:30:19 +00:00
flows: [],
columns: all_columns
2014-09-14 00:44:13 +00:00
};
},
2014-09-17 00:13:37 +00:00
componentDidMount: function () {
2014-09-17 15:30:19 +00:00
this.flowStore = FlowStore.getView();
this.flowStore.addListener("change",this.onFlowChange);
2014-09-15 22:05:06 +00:00
},
2014-09-17 00:13:37 +00:00
componentWillUnmount: function () {
2014-09-17 15:30:19 +00:00
this.flowStore.removeListener("change",this.onFlowChange);
this.flowStore.close();
2014-09-14 00:44:13 +00:00
},
2014-09-17 00:13:37 +00:00
onFlowChange: function () {
2014-09-15 22:05:06 +00:00
this.setState({
2014-09-17 15:30:19 +00:00
flows: this.flowStore.getAll()
2014-09-15 22:05:06 +00:00
});
2014-09-14 00:44:13 +00:00
},
onClick: function(e){
console.log("rowclick", e);
},
2014-09-17 00:13:37 +00:00
render: function () {
2014-09-17 15:30:19 +00:00
var flows = this.state.flows.map(function(flow){
return React.DOM.div(null, flow.request.method, " ", flow.request.scheme, "://", flow.request.host, flow.request.path);
});
2014-09-17 00:13:37 +00:00
return (
2014-09-17 15:30:19 +00:00
React.DOM.table({className: "flow-table"},
FlowTableHead({columns: this.state.columns}),
FlowTableBody({onClick: this.onClick, columns: this.state.columns, flows: this.state.flows})
2014-09-17 15:30:19 +00:00
)
2014-09-17 00:13:37 +00:00
);
2014-09-15 22:56:43 +00:00
}
2014-09-14 00:44:13 +00:00
});
2014-09-15 16:08:26 +00:00
/** @jsx React.DOM */
2014-09-14 00:44:13 +00:00
2014-09-15 16:08:26 +00:00
var EventLog = React.createClass({displayName: 'EventLog',
2014-09-17 13:22:42 +00:00
mixins:[AutoScrollMixin],
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-09-15 22:56:43 +00:00
this.setState({
log: this.log.getAll()
});
},
2014-09-17 00:13:37 +00:00
close: function () {
2014-09-15 22:56:43 +00:00
SettingsActions.update({
showEventLog: false
});
},
2014-09-17 00:13:37 +00:00
render: function () {
2014-09-17 13:22:42 +00:00
var messages = this.state.log.map(function(row) {
2014-09-17 15:30:19 +00:00
var indicator = null;
if(row.source === "ui"){
indicator = React.DOM.i({className: "fa fa-html5"});
}
return (
React.DOM.div({key: row.id},
indicator, " ", row.message
));
2014-09-17 13:22:42 +00:00
});
return React.DOM.pre({className: "eventlog"}, messages);
2014-09-15 16:08:26 +00:00
}
});
/** @jsx React.DOM */
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 (
React.DOM.footer(null,
2014-09-15 23:05:29 +00:00
mode != "regular" ? React.DOM.span({className: "label label-success"}, mode, " mode") : null
2014-09-15 16:08:26 +00:00
)
2014-09-17 00:13:37 +00:00
);
2014-09-15 16:08:26 +00:00
}
});
2014-09-15 16:08:26 +00:00
/** @jsx React.DOM */
//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 () {
return React.DOM.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-09-15 22:56:43 +00:00
return { settings: SettingsStore.getAll() };
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
console.log("onSettingsChange");
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 (
React.DOM.div({id: "container"},
Header({settings: this.state.settings}),
React.DOM.div({id: "main"}, this.props.activeRouteHandler(null)),
2014-09-17 13:22:42 +00:00
this.state.settings.showEventLog ? EventLog(null) : null,
Footer({settings: this.state.settings})
2014-09-15 22:56:43 +00:00
)
2014-09-17 00:13:37 +00:00
);
2014-09-15 16:08:26 +00:00
}
});
var ProxyApp = (
2014-09-15 22:56:43 +00:00
ReactRouter.Routes({location: "hash"},
ReactRouter.Route({name: "app", path: "/", handler: ProxyAppMain},
2014-09-17 15:30:19 +00:00
ReactRouter.Route({name: "main", handler: FlowTable}),
2014-09-15 22:56:43 +00:00
ReactRouter.Route({name: "reports", handler: Reports}),
ReactRouter.Redirect({to: "main"})
)
2014-09-14 00:44:13 +00:00
)
2014-09-17 00:13:37 +00:00
);
2014-09-15 16:08:26 +00:00
2014-09-17 00:13:37 +00:00
$(function () {
2014-09-15 22:56:43 +00:00
Connection.init();
app = React.renderComponent(ProxyApp, document.body);
2014-09-15 16:08:26 +00:00
});
2014-09-14 00:44:13 +00:00
//# sourceMappingURL=app.js.map