Skip to content

Commit

Permalink
Merge pull request #448 from lynchem/master
Browse files Browse the repository at this point in the history
add eslint, custom search & fix mem leak
  • Loading branch information
jankapunkt authored Nov 28, 2023
2 parents 35bbec0 + 53d5ba1 commit 0058f89
Show file tree
Hide file tree
Showing 11 changed files with 4,796 additions and 213 deletions.
37 changes: 37 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"env": {
"browser": true,
"es6": true,
"node": true,
"jquery": true
},
"parser": "@babel/eslint-parser",
"parserOptions": {
"requireConfigFile": false,
"ecmaVersion": 2020,
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module",
"allowImportExportEverywhere": true
},
"extends": [
"eslint:recommended",
"plugin:prettier/recommended"
],
"plugins": [
"prettier"
],
"rules": {
"prettier/prettier": [
"error",
{
"tabWidth": 2,
"printWidth": 100,
"trailingComma": "none",
"singleQuote": true
}
],
"space-before-function-paren:": 0
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.build*
.idea
.idea
node_modules
39 changes: 18 additions & 21 deletions client/getPubSelector.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { _ } from 'meteor/underscore';

function getPubSelector(
selector,
searchString,
searchFields,
searchCaseInsensitive,
splitSearchByWhitespace,
columns,
tableColumns,
) {

selector,
searchString,
searchFields,
searchCaseInsensitive,
splitSearchByWhitespace,
columns,
tableColumns
) {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// if search was invoked via .columns().search(), build a query off that
// https://datatables.net/reference/api/columns().search()
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let searchColumns = _.filter(columns, column => {
let searchColumns = _.filter(columns, (column) => {
return column.search && column.search.value !== '';
});

Expand All @@ -26,12 +25,12 @@ function getPubSelector(
if (searchColumns.length === 0) {
// normalize search fields array to mirror the structure
// as passed by the datatables ajax.data function
searchColumns = _.map(searchFields, field => {
searchColumns = _.map(searchFields, (field) => {
return {
data: field,
search: {
value: searchString
}
value: searchString,
},
};
});
}
Expand All @@ -43,7 +42,7 @@ function getPubSelector(
searchCaseInsensitive,
splitSearchByWhitespace,
columns,
tableColumns,
tableColumns
);
}

Expand All @@ -54,14 +53,14 @@ function createMongoSearchQuery(
searchCaseInsensitive,
splitSearchByWhitespace,
columns,
tableColumns,
tableColumns
) {
// See if we can resolve the search string to a number,
// in which case we use an extra query because $regex
// matches string fields only.
const searches = [];

_.each(searchColumns, field => {
_.each(searchColumns, (field) => {
// Get the column options from the Tabular.Table so we can check search options
const column = _.findWhere(tableColumns, { data: field.data });
const exactSearch = column && column.search && column.search.exact;
Expand All @@ -76,9 +75,7 @@ function createMongoSearchQuery(
searchValue = [searchValue];
}

_.each(searchValue, searchTerm => {
const m1 = {};

_.each(searchValue, (searchTerm) => {
// String search
if (exactSearch) {
if (numberSearch) {
Expand Down Expand Up @@ -111,9 +108,9 @@ function createMongoSearchQuery(

let result;
if (typeof selector === 'object' && selector !== null) {
result = {$and: [selector, {$or: searches}]};
result = { $and: [selector, { $or: searches }] };
} else if (searches.length > 1) {
result = {$or: searches};
result = { $or: searches };
} else {
result = searches[0] || {};
}
Expand Down
Loading

0 comments on commit 0058f89

Please sign in to comment.