-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevToolsView.js
More file actions
216 lines (201 loc) · 9.09 KB
/
Copy pathdevToolsView.js
File metadata and controls
216 lines (201 loc) · 9.09 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// notice_start
/*
* Copyright 2015 Dev Shop Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// notice_end
import $ from 'jquery';
import esp from 'esp-js';
import moment from 'moment';
import vis from 'vis';
import 'vis/dist/vis.css';
import './devToolsView.less'
import UpdateType from '../model/updateType';
import template from './devToolsView.template.html';
import DataPointType from '../model/dataPointType';
export default class DevToolsView extends esp.DisposableBase {
constructor(modelId, router) {
super();
this._router = router;
this._timelineGroups = new vis.DataSet();
this._timelineData = new vis.DataSet();
this._timeline = null;
this._autoscrollCheckbox = null;
this._captureEventsCheckbox = null;
this._logEventsConsoleCheckbox = null;
this._resetChartButton = null;
this._closeButton = null;
this._ringBufferSizeInput = null;
this._eventDetailsDescriptionP = null;
this._footer = null;
this._modelId = modelId;
}
start() {
this._createDevToolsElements();
let isStateOfTheWorld = true;
this.addDisposable(
this._router.getModelObservable(this._modelId)
.observe(model => {
if (isStateOfTheWorld || model.updateType.indexOf(UpdateType.modelsChanged) >= 0) {
for (let i = 0; i < model.registeredModels.length; i++) {
let registeredModel = model.registeredModels[i];
let groupStyle = registeredModel.isHalted
? 'background:red'
: '';
this._timelineGroups.update({
id: registeredModel.modelId,
content: registeredModel.modelId,
style:groupStyle
});
}
}
if (isStateOfTheWorld || model.updateType.indexOf(UpdateType.eventsChanged) >= 0) {
let points = isStateOfTheWorld
? model.dataPoints
: model.newDataPoints;
for (var i = 0; i < points.length; i++) {
var dataPoint = points[i];
let pointStyle = dataPoint.pointType == DataPointType.routerHalted
? 'background:red'
: '';
this._timelineData.add({
id: dataPoint.pointId,
group: dataPoint.modelId,
title: dataPoint.data,
start: dataPoint.publishedTime,
style: pointStyle
});
}
if(model.dataPointsIdsToRemove.length > 0) {
this._timelineData.remove(model.dataPointsIdsToRemove);
}
}
if (model.updateType.indexOf(UpdateType.reset) >= 0) {
this._timelineGroups.clear();
this._timelineData.clear();
}
if (this._timeline) {
this._timeline.setOptions({max: moment().add(2, 'm')})
if (model.shouldAutoScroll) {
this._setTimelineWindow();
}
if (this._autoscrollCheckbox.prop('checked') !== model.shouldAutoScroll) {
this._autoscrollCheckbox.prop('checked', model.shouldAutoScroll);
}
if (this._eventDetailsDescriptionP && model.selectedDataPoint) {
this._eventDetailsDescriptionP.html(JSON.stringify(model.selectedDataPoint));
}
if(this._ringBufferSizeInput && !this._ringBufferSizeInput.is(":focus")) {
this._ringBufferSizeInput.val(model.dataPointBufferSize);
}
this._footer.html(`Total events: ${model.processedDataPointCount}`);
}
isStateOfTheWorld = false;
})
);
}
_createDevToolsElements() {
let _this = this;
$(() => {
let container = $(template);
// note use of function so 'this' is the checkbox
this._autoscrollCheckbox = container.find('#autoscrollCheckbox');
this._autoscrollCheckbox.change(function () {
_this._router.publishEvent(_this._modelId, 'autoscrollToggled', {shouldAutoScroll: this.checked});
});
this.addDisposable(() => {this._autoscrollCheckbox.off();});
this._captureEventsCheckbox = container.find('#captureEvents');
this._captureEventsCheckbox.change(function () {
_this._router.publishEvent(_this._modelId,'captureEventsToggled', {shouldCaptureEvents: this.checked});
});
this.addDisposable(() => {this._captureEventsCheckbox.off();});
this._logEventsConsoleCheckbox = container.find('#logEventsConsole');
this._logEventsConsoleCheckbox.change(function () {
_this._router.publishEvent(_this._modelId,'logEventsConsoleToggled', {shouldLogToConsole: this.checked});
});
this.addDisposable(() => {this._logEventsConsoleCheckbox.off();});
this._resetChartButton = container.find('#resetChart');
this._resetChartButton.click(function () {
_this._router.publishEvent(_this._modelId,'resetChart', {});
});
this.addDisposable(() => {this._resetChartButton.off();});
this._closeButton = container.find('#closeButton');
this._closeButton.click(function () {
_this.dispose();
});
this.addDisposable(() => {this._closeButton.off();});
this._eventDetailsDescriptionP = container.find('#eventDetailsDescription');
this._footer = container.find('#footer');
this._ringBufferSizeInput = container.find('#ringBufferSize');
this._ringBufferSizeInput.change(function () {
_this._router.publishEvent(_this._modelId,'ringBufferSizeInputChanged', this.value);
});
this.addDisposable(() => {this._ringBufferSizeInput.off();});
let chartContainer = container.find('#chartContainer');
let options = {
groupOrder: 'content',
showCurrentTime: true,
selectable: true,
stack: false,
min: moment().subtract(1, 'm'),
max: moment().add(10, 'm')
};
this._timeline = new vis.Timeline(chartContainer[0]);
this.addDisposable(() => {this._timeline.destroy();}); // also cleans up event listeners
this._timeline.setOptions(options);
this._timeline.setGroups(this._timelineGroups);
this._timeline.setItems(this._timelineData);
this._wireUpTimelineEvents(this._timeline);
this._setTimelineWindow();
$('body').append(container);
// need to do this after it's been appended to the dome, else it addes a relative styling
container.draggable({
cursor: 'move',
handle: '#header'
});
this.addDisposable(() => {
container.remove();
});
});
}
_setTimelineWindow() {
this._timeline.setWindow(moment().subtract(1, 'm'), moment().add(20, 's'))
}
_wireUpTimelineEvents(timeline) {
timeline.on('select', properties => {
let pointId = properties.items[0];
this._router.publishEvent(
this._modelId,
'pointSelected', {
pointId: pointId
}
);
});
timeline.on('click', properties => {
this._disableAutoScroll()
});
timeline.on('doubleClick', properties => {
this._disableAutoScroll()
});
timeline.on('timechanged', properties => {
this._disableAutoScroll()
});
timeline.on('groupDragged', properties => {
this._disableAutoScroll()
});
}
_disableAutoScroll() {
this._router.publishEvent(this._modelId, 'disableAutoScroll', {});
}
}