From 0d1bfa9ddb332e2647648e5394f1e5319a2787ab Mon Sep 17 00:00:00 2001 From: Metehan Sever Date: Fri, 29 Nov 2024 17:51:08 +0100 Subject: [PATCH 1/2] Refactor searchContigs func --- anvio/data/interactive/js/search.js | 52 +++++++++++++++++++---------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/anvio/data/interactive/js/search.js b/anvio/data/interactive/js/search.js index 7c55c43057..2646ab2bb7 100644 --- a/anvio/data/interactive/js/search.js +++ b/anvio/data/interactive/js/search.js @@ -29,22 +29,6 @@ function searchContigs() search_column = (column == 0) ? 'Item Name' : layerdata[0][column]; var operator = $('#searchOperator').val(); - if (operator < 6) - { - var operator_text = $('#searchOperator option:selected').text(); - - // logical operator - var _pre = "layerdata["; - var _post = "][" + column + "] " + operator_text + " \"" + svalue.trim() + "\""; - - } - else if (operator == 6) - { - // contains - var _pre = "layerdata["; - var _post = "][" + column + "].toString().toLowerCase().indexOf(\"" + svalue + "\".toLowerCase()) != -1"; - } - var _len = layerdata.length; var _counter = 0; search_results = []; @@ -56,8 +40,40 @@ function searchContigs() if (layerdata[row][column]==null) continue; - if (eval(_pre + row + _post)){ - search_results.push({'split': layerdata[row][0], 'value': layerdata[row][column]}); + var cellValue = layerdata[row][column]; + var matchFound = false; + + var numericCellValue = parseFloat(cellValue); + var numericSValue = parseFloat(svalue); + + switch (operator) { + case '0': // exact match + matchFound = (cellValue === svalue.trim()); + break; + case '1': // not equal + matchFound = (cellValue != svalue.trim()); + break; + case '2': // greater than + matchFound = (numericCellValue > numericSValue); + break; + case '3': // less than + matchFound = (numericCellValue < numericSValue); + break; + case '4': // greater than or equal + matchFound = (numericCellValue >= numericSValue); + break; + case '5': // less than or equal + matchFound = (numericCellValue <= numericSValue); + break; + case '6': // contains + matchFound = cellValue.toString().toLowerCase().indexOf(svalue.toLowerCase()) !== -1; + break; + default: + break; + } + + if (matchFound) { + search_results.push({'split': layerdata[row][0], 'value': cellValue}); _counter++; } } From 5dbe740abad7b0f07d9c3ebf26c75d4781f77947 Mon Sep 17 00:00:00 2001 From: Metehan Sever Date: Fri, 29 Nov 2024 18:22:05 +0100 Subject: [PATCH 2/2] Fix case 0 without type check we are able to compare to values with that changes even if they are not the same type --- anvio/data/interactive/js/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anvio/data/interactive/js/search.js b/anvio/data/interactive/js/search.js index 2646ab2bb7..7be23de08f 100644 --- a/anvio/data/interactive/js/search.js +++ b/anvio/data/interactive/js/search.js @@ -48,7 +48,7 @@ function searchContigs() switch (operator) { case '0': // exact match - matchFound = (cellValue === svalue.trim()); + matchFound = (cellValue == svalue.trim()); break; case '1': // not equal matchFound = (cellValue != svalue.trim());