forked from mozilla-necko/logan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logan-ui.js
1399 lines (1205 loc) · 42.8 KB
/
logan-ui.js
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function() {
// Configuration of the UI
const LOAD_LINES_ON_SCROLL = true;
const ON_SCROLL_LINES_COUNT = 20;
const AUTO_FETCH_INITIAL_DELAY = 250;
const AUTO_FETCH_DELAY_DECAY = 32;
const ALWAYS_SHOW_HIDDEN_LINES_ARROWS = true;
// -----------------------
function ensure(array, itemName, def = {}) {
if (!(itemName in array)) {
array[itemName] = (typeof def === "function") ? def() : def;
}
return array[itemName];
}
function withAlpha(colorString, alpha) {
let match = colorString.match(/#?([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})/);
return "rgba(" + parseInt(match[1], 16) + "," + parseInt(match[2], 16) + "," + parseInt(match[3], 16) + "," + alpha + ")";
}
(function() {
var timeouts = [];
var messageName = "zero-timeout-message";
// Like setTimeout, but only takes a function argument. There's
// no time argument (always zero) and no arguments (you have to
// use a closure).
function setZeroTimeout(fn) {
timeouts.push(fn);
window.postMessage(messageName, "*");
}
function handleMessage(event) {
if (event.source == window && event.data == messageName) {
event.stopPropagation();
if (timeouts.length > 0) {
var fn = timeouts.shift();
fn();
}
}
}
window.addEventListener("message", handleMessage, true);
// Add the one thing we want added to the window object.
window.setZeroTimeout = setZeroTimeout;
})();
const entityMap = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": ''',
'/': '/',
'`': '`',
'=': '='
};
const CLOSE_CROSS = "\u274C"; // "\u2A2F" = VECTOR OR CROSS PRODUCT (too small?);
let HIGHLIGHTSET = [
'#ffffb3', '#bebada', '#fb8072', '#80b1d3', '#fdb462', '#b3de69', '#fccde5', '#d9d9d9', '#bc80bd', '#ccebc5', '#ffed6f', '#8dd3c7',
"#d7653b", "#a391a9", "#bdf324", "#16bce1", "#aa766a", "#e51e8c", "#7063fd", "#e3d4f4", "#f73a31", "#e4fcc0", "#e7c272", "#07d4fe",
"#acc423", "#8d97ea", "#80f592", "#b39d2f", "#ffc1af", "#87ba35", "#eb5d32", "#60bdf0", "#85d3c4", "#0ab233", "#65feeb", "#e61a08",
"#d738ae", "#42fc09", "#cd939c", "#e60be8", "#b3d5e2", "#9291fa", "#ec5294", "#f19f7f", "#9bd264", "#d5fbaa", "#b36704", "#c7f23b"];
function nextHighlightColor() {
let result = HIGHLIGHTSET[0];
HIGHLIGHTSET.push(HIGHLIGHTSET.shift());
return result;
}
let SEARCHHIGHLIGH = ['#1b9e77', '#d95f02', '#7570b3', '#e7298a', '#66a61e', '#e6ab02', '#a6761d', '#666666'];
function nextSearchColor() {
let result = SEARCHHIGHLIGH[0];
SEARCHHIGHLIGH.push(SEARCHHIGHLIGH.shift());
return result;
}
let SEARCH_INDEXER = 0;
let BREADCRUMB_INDEXER = 0;
function parseHash() {
let hash = unescape(location.hash.substr(1));
try {
return json = JSON.parse(hash);
} catch (ex) {
return {};
}
}
function updateHash(json) {
let hash = parseHash();
for (let prop in json) {
hash[prop] = json[prop];
}
location.hash = escape(JSON.stringify(hash));
}
function clearHash(name) {
let hash = parseHash();
delete hash[name];
location.hash = escape(JSON.stringify(hash));
}
let UI = {
searches: [],
breadcrumbs: [],
expandedElement: null,
expanders: {},
loadWhole: new Set(),
warnings: {},
display: {},
dynamicStyle: {},
activeRevealeres: 0,
objColors: {},
maxProgress: 0,
currentProgress: 0,
searchDisableCount: 0,
mousedown: false,
lastIncrement: 0,
autoFetchDelay: AUTO_FETCH_INITIAL_DELAY,
relativeTS: null,
escapeHtml: function(string) {
return String(string).replace(/[&<>"'`=\/]/g, function(s) {
return entityMap[s];
});
},
ISOTime: function(time) {
return time ? time.toISOString().replace(/[TZ]/g, " ").trim() : "";
},
resetProgress: function() {
this.maxProgress = 0;
this.currentProgress = 0;
this.loadProgress(0);
$("#load_progress").text('');
},
addToMaxProgress: function(size) {
this.maxProgress += size;
},
addToLoadProgress: function(size) {
this.currentProgress += size;
this.loadProgress(this.currentProgress);
},
loadProgress: function(prog) {
if (prog && this.maxProgress) {
$("#load_progress").removeClass("phase")
.show().css("width", (prog * 100.0 / this.maxProgress) + "%");
} else {
$("#load_progress").hide();
}
},
loadPhase: function(phase) {
$("#load_progress").addClass("phase").text(phase);
},
title: function(title) {
document.title = (title + " - Logan");
},
warn: function(message) {
if (message in this.warnings) {
return;
}
this.warnings[message] = true;
$("#warnings").show().text(Object.keys(this.warnings).join(" | "));
},
isPastEdge: function(element, up) {
let top = $(window).scrollTop();
let bottom = top + $(window).height();
let elementTop = element.offset().top;
const margin = 100;
return up ? (elementTop > (top - margin)) : (elementTop < (bottom + margin));
},
setInitialView: function() {
$("#file_load_section").removeClass().addClass("section").show();
$("#searches").hide();
$("#error_section").empty().hide();
$("#search_section").hide();
$("#netdiag_section").hide();
$("#seek").hide();
$("#breadcrumbs").hide();
this.createQueryForm();
},
setSearchView: function(reset) {
$("#file_load_section").removeClass().addClass("topbar").show();
$("#searches").hide();
$("#error_section").empty().hide();
$("#search_section").show();
$("#netdiag_section").hide();
$("#seek").hide();
$("#breadcrumbs").hide();
if (reset) {
$("#search_className").empty();
$(".search_By").empty();
$("#results_section").empty();
this.seekTo(0);
this.objColors = {};
}
},
searchingEnabled: function(enabled) {
this.searchDisableCount += (enabled ? -1 : +1);
$("#search_button").prop('disabled', !!this.searchDisableCount);
$("#files").prop('disabled', !!this.searchDisableCount);
$("#select_schema").prop('disabled', !!this.searchDisableCount);
},
setResultsView: function() {
$("#search_section").removeClass().addClass("topbar").show();
$("#searches").show();
$("#error_section").hide();
$("#results_section").show();
$("#netdiag_section").hide();
$("#seek").show();
$("#breadcrumbs").show();
$(".search_By").change();
},
setDiagnoseView: function() {
$("#search_section").hide();
$("#searches").hide();
$("#error_section").hide();
$("#results_section").hide();
$("#netdiag_section").show();
$("#seek").hide();
$("#breadcrumbs").hide();
},
resetResultsView: function() {
$("#results_section").empty();
for (let expander of Object.values(this.expanders)) {
expander("cleanup");
}
this.expanders = {};
this.loadWhole = new Set();
this.display = {};
this.relativeTS = null;
},
clearResultsView: function() {
$("#warnings").hide().empty();
this.warnings = {};
this.resetResultsView();
$("#active_searches").empty();
this.searches = [];
$("#breadcrumbs > #list").empty();
this.breadcrumbs = [];
this.killer = null;
$("#dynamic_style").empty();
this.dynamicStyle = {};
this.activeRevealeres = 0;
this.inFocus = null;
netdiagUI.reset();
},
addQueryRow: function(form, first = false) {
const row = $("<span>");
form.append(row);
const label =
$("<label>").text("having");
const search_By =
$("<select>").addClass("search_By").on("change", (event) => {
if (event.originalEvent) {
// a hacky way to recognize this is not a call to .change()
// but that actually comes from a user interaction.
search_By.data('cache', search_By.val());
}
}).change();
const search_Matching =
$("<select>").addClass("search_Matching").addClass("narrow")
.append($("<option>").attr("value", '!!').text('present'))
.append($("<option>").attr("value", '!').text('not present'))
.append($("<option>").attr("value", '==').text('exactly'))
.append($("<option>").attr("value", '>').text('greater than'))
.append($("<option>").attr("value", '<').text('less than'))
.append($("<option>").attr("value", 'contains').text('containing'))
.append($("<option>").attr("value", '!contains').text('not containing'))
.append($("<option>").attr("value", 'rx').text('regexp'))
.append($("<option>").attr("value", '!rx').text('not regexp'));
const search_PropValue =
$("<input>").addClass("search_PropValue").attr("type", "text");
const add_Query =
$("<input>").attr("type", "button").addClass("button icon")
.attr("value", "+").attr("title", "Add condition").click(() => {
if (this.searchDisableCount) return;
this.addQueryRow(form);
});
const remove_Query =
$("<input>").attr("type", "button").addClass("button icon")
.attr("value", "-").attr("title", "Remove condition").click(() => {
if (this.searchDisableCount) return;
row.remove();
if (form.children().length == 0) {
this.addQueryRow(form);
}
});
const br = $("<br>");
search_Matching.on("change", (event) => {
(event.target.value === "!!" || event.target.value === "!")
? search_PropValue.hide() : search_PropValue.show();
}).change();
[label, search_By, search_Matching, search_PropValue, add_Query, remove_Query, br].forEach((el, index) => {
if (el) {
row.append(el);
row.append(" ");
}
});
if (!first) {
this.fillSearchBy();
}
},
createQueryForm: function() {
const form = $("#query_form").empty();
this.addQueryRow(form, true);
},
seekTo: function(seekId) {
if (seekId) {
$("#seek_to_tail").show();
} else {
$("#seek_to_tail").hide();
$("#seek_to").val("tail");
}
logan.seekId = seekId;
this.redoSearches();
},
fillClassNames: function(classNames) {
let select = $("#search_className");
for (let className of Object.keys(classNames).sort()) {
if (className !== "null") {
select.append($("<option>").attr("value", className).text(className));
}
}
select.append($("<option>").attr("value", '*').text('*'));
},
fillSearchBy: function(props) {
if (!props) {
props = logan.searchProps[$("#search_className").val()] || {};
}
props = Array.from(new Set(
Object.keys(props).concat([CAPTURED_LINE_LABEL, "pointer", "state"])
)).sort();
$(".search_By").each(function() {
const select = $(this).empty();
let use = "state";
for (let prop of props) {
select.append($("<option>").attr("value", prop).text(prop));
if (prop == select.data('cache')) {
use = prop;
}
}
select.val(use);
});
},
loaded: function() {
let show = parseHash().show;
if (show) {
let highlight = 0;
this.setResultsView();
for (let rec of show) {
for (let obj of logan.objects) {
if (obj.props.className === rec.name && obj.props.ordernum === rec.on) {
let index = HIGHLIGHTSET.indexOf(rec.clr) + 1;
highlight = Math.max(index, highlight);
this.objColors[obj.id] = rec.clr;
let element = this.addResult(obj);
element.children(".checker").click();
}
}
}
while (highlight--) {
nextHighlightColor();
}
}
},
closeDetails: function() {
if (this.bc_details) {
this.bc_details.remove();
}
this.bc_details = null;
},
addSearch: function(search) {
search.id = ++SEARCH_INDEXER;
this.searches.push(search);
if (search.color === undefined) {
search.color = nextSearchColor();
}
if (search.seekId === undefined) {
search.seekId = logan.seekId;
search.seekTime = $("#seek_to").val();
}
let descr = search.className;
let queryDescr = "";
for (const query of search.queries) {
console.log(query);
if (queryDescr) {
queryDescr += ' && ';
}
if (query.search_Matching === "!!") {
queryDescr += `has ${query.search_By}`;
} else if (query.search_Matching === "!") {
queryDescr += `without ${query.search_By}`;
} else {
queryDescr += `${query.search_By} ${query.search_Matching} '${query.search_PropValue}'`;
}
}
descr += ` {${queryDescr}}`;
if (search.seekId !== 0) {
descr += " @ " + search.seekTime;
}
let element = $("<div>")
.addClass("search")
.attr("id", "search-" + search.id)
.css("color", search.color)
.text(descr)
.append($("<input>")
.attr("type", "button")
.val(CLOSE_CROSS)
.addClass("button icon red")
.click(function() { this.removeSearch(search); }.bind(this))
);
$("#active_searches").append(element);
logan.search(
this,
search.className,
search.queries,
search.seekId,
search.color
);
return search;
},
removeSearch: function(search) {
// This clears the UI and performs all remaining search again
let index = this.searches.findIndex((item) => item.id == search.id);
this.searches.splice(index, 1);
this.redoSearches();
},
redoSearches: function() {
let searches = this.searches.slice();
let expanders = this.expanders;
this.clearResultsView();
for (search of searches) {
this.addSearch(search);
}
this.expanders = expanders;
for (let expander of Object.values(expanders)) {
expander(true);
}
},
objColor: function(obj) {
return ensure(this.objColors, obj.id, nextHighlightColor);
},
highlight: function(input, at = 0, ignore = null) {
if (typeof input === "object") {
return "<span class='obj-" + input.id + "'>" + input.props.pointer + "</span>";
}
return input.replace(GREP_REGEXP, function(ptr) {
const ptr_trim = pointerTrim(ptr);
if (ignore.props.pointer == ptr_trim || Object.keys(ignore.aliases).includes(ptr_trim)) {
return ptr;
}
let obj = logan.find(ptr, at);
if (obj && obj !== ignore) {
return `<span class='obj-${obj.id} inline-revealer' onclick='window.logan_inlineExpand(this, ${obj.id}, ${at});'>${ptr}</span>`;
}
return ptr;
}.bind(this));
},
objHighlighter: function(obj, source = null, set) {
source = source || obj;
let color = this.objColor(source);
let style = ".obj-" + obj.id + " { background-color: " + color + " !important; color: black }";
return function(event) {
if (set === true) {
this.changeDynamicStyle("obj-" + obj.id, style);
}
// Deliberatly leaving the obj highlight in the style...
/* else if (set === false) {
this.changeDynamicStyle("obj-" + obj.id);
} else {
this.toggleDynamicStyle("obj-" + obj.id, style);
} */
}.bind(this);
},
summaryProps: function(props) {
var custom = logan._summaryProps[props.className] || [];
return ["className", "pointer", "state"].concat(custom);
},
summary: function(obj, propKeys = this.summaryProps, generate = (source, props) => {
let summary = "";
summary += this.ISOTime(obj.placement.time);
for (let prop of props) {
if (summary) summary += " \u2043 ";
if (["className", "pointer", "state"].indexOf(prop) < 0) {
summary += prop + "=";
}
summary += source.props[prop] == undefined ? "n/a" : source.props[prop];
}
return summary;
}) {
let props = propKeys(obj.props);
if (!logan.seekId || obj.captures.last().id < logan.seekId) {
// Object is younger than the seek point, just pick the final props state
return generate(obj, props);
}
// Must collect properties manually
// TODO - could be optimized by walking backwards until
// all summary propeties are found
let objAt = {
props: {
className: obj.props.className,
pointer: obj.props.pointer,
ordernum: obj.props.ordernum,
},
placement: obj.placement,
};
for (let capture of obj.captures) {
if (capture.id > logan.seekId) {
break;
}
if (typeof capture.what === "object" && capture.what.prop) {
objAt.props[capture.what.prop] = capture.what.value;
}
}
return generate(objAt, props);
},
quick: function(obj) {
return (obj.props.className || "?:" + obj.id) + " @" + this.highlight(obj);
},
closeExpansion: function(newElement = null) {
if (this.expandedElement) {
this.expandedElement.remove();
}
this.expandedElement = newElement;
},
// this method is mostly meaningless, but leaving it in case
// I invent something smart here...
// the plan to interleave child processes is to process lines
// as put one by one sorted by timestamp (naive)
position: function(capture) {
if (!capture) {
return 0;
}
return capture.id;
},
place: function(capture, element) {
if (logan.seekId && capture.id > logan.seekId) {
element.addClass("past_capture_limit");
}
let position = this.position(capture);
if (this.display[position]) {
// When a link revealer is turned on, it is readded (the object has the same capture)
// Removing it would leave an element that is unchecked.
this.display[position].__refs++;
// XXX: there is no way to remove the added classes when the line is dereferenced
// but still left in the view
this.display[position].addClass(element.attr("class"));
return this.display[position];
}
element.attr("id", capture.id);
let keys = Object.keys(this.display);
keys.sort((a, b) => parseInt(a) - parseInt(b));
let following = keys.find((a) => parseInt(a) > parseInt(position));
if (following === undefined) { // can be last
$("#results_section").append(element);
} else { // has to be placed before
element.insertBefore(this.display[following]);
}
element.__refs = 1;
element.data("capture", capture);
return (this.display[position] = element);
},
addCaptures: function(obj, captureid, totop = true, tobottom = true) {
if (!obj._extraCaptures) {
obj._extraCaptures = {};
}
if (!LOAD_LINES_ON_SCROLL) {
for (let capture of obj.captures) {
this.addCapture(obj, capture);
}
for (let capture of Object.values(obj._extraCaptures)) {
this.addCapture(obj, capture, true);
}
return;
}
let process = (origin, up, handlername) => {
let filter = (captures, extra) => {
let index = captures.findIndex(c => c.id > origin);
let slice = up
? captures.slice(0, index < 0 ? (captures.length - 1) : index)
: captures.slice(index < 0 ? captures.length : index);
return slice.map(capture => ({ capture, extra }));
} // filter()
let regular = filter(obj.captures, false);
let extra = filter(Object.values(obj._extraCaptures), true);
let captures = regular.concat(extra).sort((a, b) => a.capture.id - b.capture.id);
let observer = ensure(obj, handlername, () => {
return $("<div>").addClass("scroll-observer").on("custom", () => {
if (this.loadWhole.has(obj.id) || this.isPastEdge(observer, up)) {
this.addCaptures(obj, observer.data("nextid"), up, !up);
}
});
});
// Can't use the observer, since it's moving up as we add new capture lines
let scrollanchor = observer.next(".log_line");
scrollanchor = scrollanchor.length && $(scrollanchor[0]);
let scrolloffset = scrollanchor && (scrollanchor.offset().top - $(window).scrollTop());
let id, element;
let count = ON_SCROLL_LINES_COUNT;
while (count && captures.length) {
let capture = up ? captures.pop() : captures.shift();
let added = this.addCapture(obj, capture.capture, capture.extra);
id = capture.capture.id;
element = added || element;
if (added) {
// we've added an actual line!
count--;
}
}
if (!element) {
if (obj[handlername]) {
obj[handlername].remove();
delete obj[handlername];
}
return;
}
if (up) {
if (totop != tobottom && scrollanchor) {
$(window).scrollTop(scrollanchor.offset().top - scrolloffset);
}
observer.insertBefore(element);
observer.data("nextid", id - 1);
} else {
observer.data("nextid", id);
observer.insertAfter(element);
}
setZeroTimeout(() => observer.trigger("custom"));
} // process()
if (totop) {
process(captureid, true, "scrollHandlerTop");
}
if (tobottom) {
process(captureid, false, "scrollHandlerBottom");
}
},
objExpander: function(element, obj, placement, includeSummary, relation = {}) {
return function() {
let expander = this.expanders[obj.id];
if (expander) {
delete this.expanders[obj.id];
expander(false);
return;
}
expander = (expand, scrollanch = element) => {
if (expand === "cleanup") {
for (let handler of ["scrollHandlerTop", "scrollHandlerBottom"]) {
if (handler in obj) {
obj[handler].remove();
delete obj[handler];
}
}
return;
}
let scrolloffset = scrollanch.offset().top - $(window).scrollTop();
// Must call in this order, since onExpansion wants to get the same color
this.objColor(obj);
this.objHighlighter(obj, obj, expand)();
this.onExpansion(obj, relation, element, placement, expand);
let spanselector = "span[objid='" + obj.id + "'";
if (expand === true) {
if (includeSummary && obj.props.className) {
this.addSummary(obj);
}
element.addClass("checked");
logan.deferReadCapture();
try {
this.addCaptures(obj, placement.id);
} finally {
logan.commitReadCapture();
}
// Makes sure any newly added expanders on already expanded objects are checked
$(spanselector).addClass("expanded");
for (let objid in this.expanders) {
spanselector = "span[objid='" + objid + "'";
$(spanselector).addClass("expanded");
}
} else if (expand === false) {
$(spanselector).removeClass("expanded");
if (includeSummary && obj.props.className) {
this.removeLine(this.position(obj.placement));
}
element.removeClass("checked");
for (let capture of obj.captures) {
this.removeLine(this.position(capture));
}
for (let capture of Object.values(obj._extraCaptures)) {
this.removeLine(this.position(capture));
}
expander("cleanup");
}
$(window).scrollTop(scrollanch.offset().top - scrolloffset);
updateHash({
show: Object.keys(this.expanders).map(function(id) {
let obj = logan.objects[id];
return { name: obj.props.className, on: obj.props.ordernum, clr: this.objColor(obj) };
}, this)
});
}
this.expanders[obj.id] = expander;
expander(true);
}.bind(this);
},
addRevealer: function(obj, builder, placement = null, includeSummary = false, relation = {}) {
placement = placement || obj.placement;
let element = $("<div>");
element
.addClass("log_line")
.addClass(() => includeSummary ? "" : "summary")
.append($("<span>").attr("objid", obj.id).addClass("checker")
.click(this.objExpander(element, obj, placement, includeSummary, relation))
);
builder(element);
return this.place(placement, element);
},
addResult: function(obj, searchProp) {
return this.addRevealer(obj, (element) => {
element
.append($("<span>")
.addClass("obj-" + obj.id).addClass("pre")
.text(this.summary(obj, (props) => {
// This prepends the property we searched the object by
let result = this.summaryProps(props);
if (searchProp && result.indexOf(searchProp) < 0 && searchProp !== CAPTURED_LINE_LABEL) {
result.unshift(searchProp);
}
return result;
})))
;
});
},
addSummary: function(obj) {
let element = $("<div>")
.addClass("log_line expanded summary obj-" + obj.id)
.append($("<span>").addClass("pre")
.text(this.summary(obj)))
;
return this.place(obj.placement, element);
},
addCapture: function(obj, capture, extra = false) {
if (!capture.what) {
return;
}
let nextOnThread = (id, increment) => {
// Next on the same thread.
id += increment;
let next;
while ((next = logan.captures[id])) {
if ((next.what.file || (typeof next.what === "string")) && next.thread === capture.thread) {
break;
}
id += increment;
next = null;
}
return next;
}
let showArrow = (capture, increment) => {
if (ALWAYS_SHOW_HIDDEN_LINES_ARROWS) {
return true;
}
const next = nextOnThread(capture.id, increment);
return next && capture.obj !== next.obj && !(next.id in this.display);
}
let showEvent = (capture) => {
return capture.eventspan && capture.eventspan !== capture.obj;
}
let controller = () => {
let fetch = (element, increment) => {
// To loop
UI.lastIncrement = increment;
let fromTop = $(element).parents(".log_line");
if (fromTop && fromTop.offset()) {
fromTop = fromTop.offset().top - $(window).scrollTop();
fromTop |= 1; // to fix the jumping effect in Firefox
}
let id = capture.id;
let next = nextOnThread(id, increment);
if (!next) {
return;
}
let position = this.position(next);
if (position in obj._extraCaptures) {
// Already added as part of this object.
return;
}
obj._extraCaptures[position] = next;
if (position in this.display) {
// Already on the screen, but added via a different path, add a ref
this.place(next, this.display[position]);
return;
}
element = this.addCapture(obj, next, true);
if (increment > 0 && fromTop) {
$(window).scrollTop(element.offset().top - fromTop);
}
return position;
}
let up = showArrow(capture, -1) && $("<span>")
.attr('title', 'Fetch previous line on this thread')
.text('\u02c4')
.mousedown(function() {
fetch(this, -1);
this.remove();
});
let down = showArrow(capture, +1) && $("<span>")
.attr('title', 'Fetch next line on this thread')
.text('\u02c5')
.mousedown(function() {
fetch(this, +1);
this.remove();
});
let eventspan = showEvent(capture) && $("<span>")
.attr('title', 'Expand the event this is executed within')
.text('e')
.mousedown(function() {
const event = capture.eventspan;
if (!event) {
alert("Sorry, no event tracked calling this line; we don't know them all yet.");
return;
}
if (!UI.expanders[event.id]) {
UI.addResult(event).find(".checker").click();
} else {
alert(`ALREADY OPEN: event ${event.props.pointer.toUpperCase()}`);
}
});
const relative_ts_text = (this_capture, source_capture) => {
let relative_ts = this_capture.time.getTime() - source_capture.time.getTime();
relative_ts = `${relative_ts > 0 ? '+' : ''}${relative_ts}`;
return relative_ts;
};
const relativeTS = $("<span>")
.addClass("relative_ts");
if (UI.relativeTS) {
const relative_ts = relative_ts_text(capture, UI.relativeTS);
relativeTS.text(relative_ts);
}
let zeroTS = $("<span>")
.attr('title', 'Sets this line as 0-time for relative timestamp display')
.text('\u23F2')
.click(function() {
UI.relativeTS = capture;
for (const disp of Object.values(UI.display)) {
const that = disp.data("capture");
const relative_ts = relative_ts_text(that, UI.relativeTS);
let target = $(disp).children(".relative_ts");
if (!target.length) {
continue;
}
target.text(relative_ts);
}
});
if (UI.mousedown) {
setTimeout(() => {
if (UI.lastIncrement != 0) {
let target = UI.lastIncrement > 0 ? down : up;
if (target && UI.mousedown) {
fetch(target, UI.lastIncrement);
target.remove();
UI.autoFetchDelay -= AUTO_FETCH_DELAY_DECAY;
if (UI.autoFetchDelay < 0) UI.autoFetchDelay = 0;
}
}
}, UI.autoFetchDelay);
}
return [
$("<span>")
.addClass("line_controller")
.append(eventspan)
.append(up)
.append(down)
.append(zeroTS)
.mousedown((e) => {
e.preventDefault();