Skip to content

Commit a309b0a

Browse files
author
Gary Keeble
committed
Filter bar for configuration file
Add filter feature to configuration file review.
1 parent 56ef5af commit a309b0a

File tree

3 files changed

+106
-36
lines changed

3 files changed

+106
-36
lines changed

css/main.css

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,21 +342,29 @@ html:not(.has-marker) .marker-offset {
342342
padding: 5px;
343343
}
344344

345+
.configuration-close {
346+
float: right;
347+
color: #bbb;
348+
cursor: pointer;
349+
}
350+
345351
html.has-config .configuration-file {
346352
position:absolute;
347353
top: 10%;
348354
left: 10%;
349355
width: 78.5%;
350356
padding:10px;
351-
height:580px;
352-
overflow:hidden;
353-
overflow-y:scroll;
354357
background-color: white;
355358
border: #337ab7;
356359
border-style: groove;
357360
z-index: 11;
358361
}
359362

363+
html.has-config .configuration-list {
364+
height:580px;
365+
overflow:hidden;
366+
overflow-y:scroll;
367+
}
360368

361369
.graph-legend-field {
362370
padding-bottom:0.1em;

js/configuration.js

Lines changed: 79 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,94 @@
88
*/
99

1010

11-
function Configuration(file) {
11+
function Configuration(file, showConfigFile) {
1212

1313
// Private Variables
1414
var that = this; // generic pointer back to this function
1515
var fileData; // configuration file information
16+
var fileLinesArray; // Store the contents of the file globally
1617

18+
function renderFileContentList(configurationList, filter) {
19+
var li;
20+
21+
// Clear the contents of the list
22+
$('li',configurationList).remove();
23+
24+
for(var i=0; i<fileLinesArray.length; i++) {
25+
if(!filter || filter.length<1) { //Everything
26+
li = $('<li class="configuration-row">' + fileLinesArray[i] + '</li>');
27+
configurationList.append(li);
28+
} else {
29+
var regFilter = new RegExp('(.*)(' + filter + ')(.*)','i');
30+
var highLight = fileLinesArray[i].match(regFilter);
31+
if(highLight!=null) { // dont include blank lines
32+
li = $('<li class="configuration-row">' + highLight[1] + '<b>' + highLight[2] + '</b>' + highLight[3] + '</li>');
33+
configurationList.append(li);
34+
}
35+
}
36+
}
37+
}
38+
39+
function renderFileContents(filter) {
40+
41+
var
42+
configurationElem = ('.configuration-file'), // point to the actual element in index.html
43+
configurationDiv = $('<div class="configuration-file">'
44+
+ '<div class="configuration-header">'
45+
+ '<h3>' + file.name
46+
+ '<span class="configuration-close glyphicon glyphicon-remove"></span>'
47+
+ '</h3>'
48+
+ '<input type="text" class="form-control configuration-filter" placeholder="Enter filter" size="5"/>'
49+
+ '</div>'
50+
+ '<div><ul class="list-unstyled configuration-list"></ul></div>'
51+
+'</div>'),
52+
configurationTitle = $('h3', configurationDiv),
53+
li;
54+
55+
// now replace the element in the index.html with the loaded file information
56+
$(configurationElem).replaceWith(configurationDiv);
57+
58+
var configurationList = $('.configuration-list');
59+
renderFileContentList(configurationList, null);
60+
61+
//configurationTitle.text(file.name);
62+
$("#status-bar .configuration-file-name").text(file.name);
63+
64+
// now replace the element in the index.html with the loaded file information
65+
$(configurationElem).replaceWith(configurationDiv);
66+
67+
68+
// Add close icon
69+
$(".configuration-close").click(function() {
70+
if(showConfigFile) showConfigFile(false); // hide the config file
71+
});
72+
73+
74+
}
75+
1776
function loadFile(file) {
1877

1978
var reader = new FileReader();
2079
fileData = file; // Store the data locally;
80+
2181

2282
reader.onload = function(e) {
23-
24-
var
25-
configurationElem = ('.configuration-file'), // point to the actual element in index.html
26-
configurationDiv = $('<div class="configuration-file"><h3></h3><ul class="list-unstyled configuration-list"></ul></div>'),
27-
configurationTitle = $('h3', configurationDiv),
28-
configurationList = $('ul', configurationDiv),
29-
li;
30-
31-
var data = e.target.result; // all the data
32-
var lines = data.split('\n'); // separate into lines
33-
34-
for(var i=0; i<lines.length; i++) {
35-
li = $('<li class="configuration-row">' + lines[i] + '</li>');
36-
configurationList.append(li);
37-
}
38-
39-
configurationTitle.text(file.name);
40-
$("#status-bar .configuration-file-name").text(file.name);
41-
42-
// now replace the element in the index.html with the loaded file information
43-
$(configurationElem).replaceWith(configurationDiv);
44-
83+
84+
var data = e.target.result; // all the data
85+
86+
fileLinesArray = data.split('\n'); // separated into lines
87+
88+
renderFileContents();
89+
90+
// Add user configurable file filter
91+
$(".configuration-filter").keyup(function() {
92+
93+
var newFilter = $(".configuration-filter").val();
94+
95+
var configurationList = $('.configuration-list');
96+
renderFileContentList(configurationList, newFilter);
97+
98+
});
4599

46100
};
47101

@@ -55,4 +109,6 @@ function Configuration(file) {
55109

56110
loadFile(file); // configuration file loaded
57111

112+
// Add filter
113+
58114
}

js/main.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,17 @@ function BlackboxLogViewer() {
448448
}
449449
}
450450

451+
function showConfigFile(state) {
452+
if(hasConfig) {
453+
if(state == null) { // no state specified, just toggle
454+
hasConfigOverlay = !hasConfigOverlay;
455+
} else { //state defined, just set item
456+
hasConfigOverlay = (state)?true:false;
457+
}
458+
(hasConfigOverlay)?$("html").addClass("has-config-overlay"):$("html").removeClass("has-config-overlay");
459+
}
460+
}
461+
451462
/**
452463
* Set the index of the log from the log file that should be viewed. Pass "null" as the index to open the first
453464
* available log.
@@ -538,9 +549,10 @@ function BlackboxLogViewer() {
538549

539550
if(fileContents.match(/# dump/i)) { // this is actually a configuration file
540551
try{
541-
configuration = new Configuration(file); // the configuration class will actually re-open the file as a text object.
552+
configuration = new Configuration(file, showConfigFile); // the configuration class will actually re-open the file as a text object.
542553
hasConfig = true;
543554
(hasConfig)?$("html").addClass("has-config"):$("html").removeClass("has-config");
555+
544556
} catch(e) {
545557
configuration = null;
546558
hasConfig = false;
@@ -1133,13 +1145,10 @@ function BlackboxLogViewer() {
11331145
});
11341146

11351147
$('#status-bar .configuration-file-name').click(function(e) {
1136-
if(hasConfig) {
1137-
hasConfigOverlay = !hasConfigOverlay;
1138-
(hasConfigOverlay)?$("html").addClass("has-config-overlay"):$("html").removeClass("has-config-overlay");
1139-
}
1148+
showConfigFile(true); // show the config file
11401149
e.preventDefault();
11411150
});
1142-
1151+
11431152
$(".btn-workspaces-export").click(function(e) {
11441153
setGraphState(GRAPH_STATE_PAUSED);
11451154
saveWorkspaces();
@@ -1246,10 +1255,7 @@ function BlackboxLogViewer() {
12461255
break;
12471256

12481257
case "C".charCodeAt(0):
1249-
if(hasConfig) {
1250-
hasConfigOverlay = !hasConfigOverlay;
1251-
(hasConfigOverlay)?$("html").addClass("has-config-overlay"):$("html").removeClass("has-config-overlay");
1252-
}
1258+
showConfigFile(); // toggle the config file popup
12531259
e.preventDefault();
12541260
break;
12551261

0 commit comments

Comments
 (0)