1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
var React = require("react");
var common = require("./common.js");
var Query = require("../actions.js").Query;
var VirtualScrollMixin = require("./virtualscroll.js");
var views = require("../store/view.js");
var _ = require("lodash");
var LogMessage = React.createClass({
render: function () {
var entry = this.props.entry;
var indicator;
switch (entry.level) {
case "web":
indicator = <i className="fa fa-fw fa-html5"></i>;
break;
case "debug":
indicator = <i className="fa fa-fw fa-bug"></i>;
break;
default:
indicator = <i className="fa fa-fw fa-info"></i>;
}
return (
<div>
{ indicator } {entry.message}
</div>
);
},
shouldComponentUpdate: function () {
return false; // log entries are immutable.
}
});
var EventLogContents = React.createClass({
contextTypes: {
eventStore: React.PropTypes.object.isRequired
},
mixins: [common.AutoScrollMixin, VirtualScrollMixin],
getInitialState: function () {
var filterFn = function (entry) {
return this.props.filter[entry.level];
};
var view = new views.StoreView(this.context.eventStore, filterFn.bind(this));
view.addListener("add", this.onEventLogChange);
view.addListener("recalculate", this.onEventLogChange);
return {
view: view
};
},
componentWillUnmount: function () {
this.state.view.close();
},
filter: function (entry) {
return this.props.filter[entry.level];
},
onEventLogChange: function () {
this.forceUpdate();
},
componentWillReceiveProps: function (nextProps) {
if (nextProps.filter !== this.props.filter) {
this.props.filter = nextProps.filter; // Dirty: Make sure that view filter sees the update.
this.state.view.recalculate();
}
},
getDefaultProps: function () {
return {
rowHeight: 45,
rowHeightMin: 15,
placeholderTagName: "div"
};
},
renderRow: function (elem) {
return <LogMessage key={elem.id} entry={elem}/>;
},
render: function () {
var entries = this.state.view.list;
var rows = this.renderRows(entries);
return <pre onScroll={this.onScroll}>
{ this.getPlaceholderTop(entries.length) }
{rows}
{ this.getPlaceholderBottom(entries.length) }
</pre>;
}
});
var ToggleFilter = React.createClass({
toggle: function (e) {
e.preventDefault();
return this.props.toggleLevel(this.props.name);
},
render: function () {
var className = "label ";
if (this.props.active) {
className += "label-primary";
} else {
className += "label-default";
}
return (
<a
href="#"
className={className}
onClick={this.toggle}>
{this.props.name}
</a>
);
}
});
var EventLog = React.createClass({
mixins: [common.Navigation],
getInitialState: function () {
return {
filter: {
"debug": false,
"info": true,
"web": true
}
};
},
close: function () {
var d = {};
d[Query.SHOW_EVENTLOG] = undefined;
this.setQuery(d);
},
toggleLevel: function (level) {
var filter = _.extend({}, this.state.filter);
filter[level] = !filter[level];
this.setState({filter: filter});
},
render: function () {
return (
<div className="eventlog">
<div>
Eventlog
<div className="pull-right">
<ToggleFilter name="debug" active={this.state.filter.debug} toggleLevel={this.toggleLevel}/>
<ToggleFilter name="info" active={this.state.filter.info} toggleLevel={this.toggleLevel}/>
<ToggleFilter name="web" active={this.state.filter.web} toggleLevel={this.toggleLevel}/>
<i onClick={this.close} className="fa fa-close"></i>
</div>
</div>
<EventLogContents filter={this.state.filter}/>
</div>
);
}
});
module.exports = EventLog;
|