Skip to content

Commit feb8aaf

Browse files
authored
Merge pull request #269 from nexB/perf-fix
New filter generation system
2 parents 49474fe + e2a2d51 commit feb8aaf

File tree

2 files changed

+93
-22
lines changed

2 files changed

+93
-22
lines changed

assets/app/js/controllers/aboutCodeClueDataTable.js

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class AboutCodeClueDataTable extends Controller {
7373

7474
// Get the column's filter select box
7575
const select = $(`select#clue-${columnName}`);
76+
select.empty().append(`<option value="">All</option>`);
77+
78+
// Add the chart value options and select it.
79+
select.append(`<option value="${value}">${value}</option>`);
7680
select.val(value).change();
7781
}
7882

@@ -101,6 +105,7 @@ class AboutCodeClueDataTable extends Controller {
101105
scrollX: true,
102106
scrollResize: true,
103107
deferRender: true,
108+
initComplete: () => this._initComplete(),
104109
drawCallback: () => this._drawCallback(),
105110
buttons: [
106111
{ // Do not allow the first column to be hidden
@@ -279,42 +284,94 @@ class AboutCodeClueDataTable extends Controller {
279284
});
280285
}
281286

287+
_initComplete() {
288+
const pathCol = this.dataTable().columns(0);
289+
290+
const footer = $(pathCol.footer());
291+
// keep the buttons horizontally aligned
292+
footer.css('white-space', 'nowrap');
293+
294+
const genFiltersButton = $(`<button id="gen-filters-button" type="button">Generate Filters</button>`);
295+
const clearFiltersButton = $(`<button id="clear-filters-button" type="button">Clear Filters</button>`);
296+
297+
footer.append(genFiltersButton);
298+
footer.append(clearFiltersButton);
299+
300+
this.dataTable().columns().every(function (columnIndex) {
301+
const columnInfo = AboutCodeClueDataTable.TABLE_COLUMNS[columnIndex];
302+
303+
if ('skipFilter' in columnInfo && columnInfo.skipFilter) {
304+
return;
305+
}
306+
307+
const column = this;
308+
const footer = $(column.footer());
309+
const columnName = columnInfo.name;
310+
311+
const select = $(`<select id="clue-${columnName}"></select>`)
312+
.on('change', function () {
313+
const val = $(this).val();
314+
column
315+
.search(val, false, false)
316+
.draw();
317+
});
318+
319+
footer.append(select);
320+
});
321+
}
322+
282323
_drawCallback() {
283324
$('.dataTables_scrollBody').scrollTop(0);
284325
}
285326

286-
setColumnFilters() {
327+
resetColumnFilters() {
328+
$.each(AboutCodeClueDataTable.TABLE_COLUMNS, (i, column) => {
329+
const columnSelect = $(`select#clue-${column.name}`);
330+
columnSelect.empty();
331+
columnSelect.val('');
332+
this.dataTable()
333+
.column(`${column.name}:name`)
334+
.search('', false, false);
335+
});
336+
// clear the global search box
337+
this.dataTable().search('').columns().search('').draw();
338+
}
339+
340+
genFilters() {
341+
this.resetColumnFilters();
287342
const that = this;
288-
const pathCol = this.dataTable().columns(0);
289343

290-
// Add a select element to each column's footer
291344
this.dataTable().columns().every(function (columnIndex) {
292345
const columnInfo = AboutCodeClueDataTable.TABLE_COLUMNS[columnIndex];
346+
const currentColumn = that.dataTable().columns(columnIndex);
293347

294348
if ('skipFilter' in columnInfo && columnInfo.skipFilter) {
295349
return;
296350
}
297351

352+
// skip columns that are not currently visible
353+
if (currentColumn.visible()[0] === false) {
354+
return;
355+
}
356+
298357
const column = this;
299358
const footer = $(column.footer());
300359
const columnName = columnInfo.name;
301360

302361
footer.empty();
303-
const select = $(`<select id="clue-${columnName}"></select>`)
362+
363+
const select = $('#clue-' + columnName)
304364
.empty()
305-
.appendTo(footer)
306365
.on('change', function () {
307366
const val = $(this).val();
308367
column
309368
.search(val, false, false)
310369
.draw();
311370
});
312371

313-
const currPath = pathCol.search()[0];
372+
const currPath = that._selectedPath;
314373
const where = { path: { $like: `${currPath}%`} };
315-
316-
where[columnName] = {$ne: null};
317-
374+
318375
that.db().sync.then((db) => db.FlatFile.findAll({
319376
attributes: [
320377
Sequelize.fn('TRIM', Sequelize.col(columnName)),
@@ -342,6 +399,7 @@ class AboutCodeClueDataTable extends Controller {
342399
select.append(`<option value="${filterValue}">${filterValue}</option>`);
343400
});
344401
});
402+
footer.append(select);
345403
});
346404
}
347405

assets/app/js/renderer.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,19 @@ $(document).ready(() => {
8989
const jstree = new AboutCodeJsTree('#jstree', aboutCodeDB)
9090
.on('node-edit', (node) => componentDialog.show(node.id))
9191
.on('node-selected', (node) => {
92-
cluesTable.columns(0).search(node.id);
93-
cluesTable.setColumnFilters();
94-
95-
// update all views with the new selected path.
96-
componentDialog.selectedPath(node.id);
97-
dejaCodeExportDialog.selectedPath(node.id);
98-
jstree.selectedPath(node.id);
99-
cluesTable.selectedPath(node.id);
100-
componentsTable.selectedPath(node.id);
101-
dashboard.selectedPath(node.id);
102-
barChart.selectedPath(node.id);
103-
104-
redrawCurrentView();
92+
updateViewsByPath(node.id);
10593
});
10694

95+
$(document).on('click', '#gen-filters-button', () => {
96+
cluesTable.genFilters();
97+
updateViewsByPath(cluesTable._selectedPath);
98+
});
99+
100+
$(document).on('click', '#clear-filters-button', () => {
101+
cluesTable.resetColumnFilters();
102+
updateViewsByPath(cluesTable._selectedPath);
103+
});
104+
107105
const splitter = new Splitter('#leftCol', '#rightCol')
108106
.on('drag-end', () => redrawCurrentView());
109107

@@ -164,6 +162,21 @@ $(document).ready(() => {
164162
// Opens the dashboard view when the app is first opened
165163
showDashboardButton.trigger('click');
166164

165+
function updateViewsByPath(path) {
166+
// Update all the views with the given path string
167+
cluesTable.columns(0).search(path);
168+
169+
componentDialog.selectedPath(path);
170+
dejaCodeExportDialog.selectedPath(path);
171+
jstree.selectedPath(path);
172+
cluesTable.selectedPath(path);
173+
componentsTable.selectedPath(path);
174+
dashboard.selectedPath(path);
175+
barChart.selectedPath(path);
176+
177+
redrawCurrentView();
178+
}
179+
167180
/** Creates the database and all View objects from a SQLite file */
168181
function loadDatabase(fileName) {
169182
// Create a new database when importing a json file

0 commit comments

Comments
 (0)