Skip to content

Commit e15d202

Browse files
committed
Refactor query code
* Minor refactor for readability * Added additional code comment for clarity Signed-off-by: Jillian Daguil <[email protected]>
1 parent 9e186fa commit e15d202

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

assets/js/aboutCodeDataTables.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,26 @@ class AboutCodeDataTable {
7777
for (let i = 0; i < dataTablesInput.columns.length; i++) {
7878
let columnSearch = dataTablesInput.columns[i].search.value;
7979
if (columnSearch) {
80-
// Return all non empty values
81-
if (columnSearch === HAS_A_VALUE) {
82-
query.where.$and[dataTablesInput.columns[i].name] = {
80+
const columnName = dataTablesInput.columns[i].name;
81+
82+
if (i === 0) {
83+
// Column 0 is the "path", which should only match
84+
// wildcards at the end of the path.
85+
query.where.$and[columnName] = {
86+
$like: `${columnSearch}%`
87+
}
88+
} else if (columnSearch === HAS_A_VALUE) {
89+
// Return all non empty values
90+
query.where.$and[columnName] = {
8391
$and: [
8492
{ $ne: "[]" },
8593
{ $ne: "" },
8694
{ $ne: "{}" }
8795
]
8896
}
8997
} else {
90-
// Column 0 is the "path", which should only match wildcards
91-
// at the end of the path.
92-
query.where.$and[dataTablesInput.columns[i].name] = {
93-
$like: i === 0 ? `${columnSearch}%` : `%${columnSearch}%`
98+
query.where.$and[columnName] = {
99+
$like: `%${columnSearch}%`
94100
}
95101
}
96102
}

assets/js/renderer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ $(document).ready(function () {
9090
// Get the node id when selected
9191
.on('select_node.jstree', function (evt, data) {
9292
let barChartValue = chartAttributesSelect.val();
93+
94+
// Set the search value for the first column (path) equal to the
95+
// Selected jstree path and redraw the table
9396
cluesTable.columns(0).search(data.node.id).draw();
9497
nodeView.setRoot(data.node.id);
9598
barChart.showSummary(barChartValue, data.node.id);

0 commit comments

Comments
 (0)