Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add eslint, custom search & fix mem leak #448

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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