Skip to content

Commit

Permalink
Refactor query code
Browse files Browse the repository at this point in the history
* Minor refactor for readability
* Added additional code comment for clarity

Signed-off-by: Jillian Daguil <[email protected]>
  • Loading branch information
jdaguil committed Aug 28, 2017
1 parent 9e186fa commit e15d202
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 13 additions & 7 deletions assets/js/aboutCodeDataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,26 @@ class AboutCodeDataTable {
for (let i = 0; i < dataTablesInput.columns.length; i++) {
let columnSearch = dataTablesInput.columns[i].search.value;
if (columnSearch) {
// Return all non empty values
if (columnSearch === HAS_A_VALUE) {
query.where.$and[dataTablesInput.columns[i].name] = {
const columnName = dataTablesInput.columns[i].name;

if (i === 0) {
// Column 0 is the "path", which should only match
// wildcards at the end of the path.
query.where.$and[columnName] = {
$like: `${columnSearch}%`
}
} else if (columnSearch === HAS_A_VALUE) {
// Return all non empty values
query.where.$and[columnName] = {
$and: [
{ $ne: "[]" },
{ $ne: "" },
{ $ne: "{}" }
]
}
} else {
// Column 0 is the "path", which should only match wildcards
// at the end of the path.
query.where.$and[dataTablesInput.columns[i].name] = {
$like: i === 0 ? `${columnSearch}%` : `%${columnSearch}%`
query.where.$and[columnName] = {
$like: `%${columnSearch}%`
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions assets/js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ $(document).ready(function () {
// Get the node id when selected
.on('select_node.jstree', function (evt, data) {
let barChartValue = chartAttributesSelect.val();

// Set the search value for the first column (path) equal to the
// Selected jstree path and redraw the table
cluesTable.columns(0).search(data.node.id).draw();
nodeView.setRoot(data.node.id);
barChart.showSummary(barChartValue, data.node.id);
Expand Down

0 comments on commit e15d202

Please sign in to comment.