|
@@ -33,18 +33,10 @@ export class queryService {
|
|
|
let searchObj = Object.assign({}, ...conditions)
|
|
|
this.dataFromStorage.subscribe({
|
|
|
next: element => {
|
|
|
- if (Object.keys(conditions).length == 1 && searchObj.hasOwnProperty('regex')) {
|
|
|
- if (this.filterViaRegex(element, searchObj.regex)) {
|
|
|
- this.filteredResult.next(element)
|
|
|
- } else {
|
|
|
- // console.log(`${element.header.messageName} does not match search criteria`)
|
|
|
- }
|
|
|
+ if (this.filterByKeyValue(element, ...conditions)) {
|
|
|
+ this.filteredResult.next(element)
|
|
|
} else {
|
|
|
- if (this.filterByKeyValue(element, ...conditions)) {
|
|
|
- this.filteredResult.next(element)
|
|
|
- } else {
|
|
|
- // console.log(`${element.header.messageName} does not match search criteria`)
|
|
|
- }
|
|
|
+ // console.log(`${element.header.messageName} does not match search criteria`)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
@@ -73,23 +65,29 @@ export class queryService {
|
|
|
// Merge all conditions into searchObj
|
|
|
let searchObj = Object.assign({}, ...conditions)
|
|
|
let dateCheck = true
|
|
|
+ let regexCheck = true
|
|
|
if (searchObj.hasOwnProperty("dateRange")) {
|
|
|
dateCheck = this.filterByDateRange(data, searchObj.dateRange)
|
|
|
// Must delete, otherwise the function below will attempt to match date range with the date property and it will inevitably returns false
|
|
|
delete searchObj.dateRange
|
|
|
- }
|
|
|
+ }
|
|
|
+ if (searchObj.hasOwnProperty("regex")) {
|
|
|
+ dateCheck = this.filterViaRegex(data, searchObj.regex)
|
|
|
+ // Must delete, otherwise the function below will attempt to match date range with the date property and it will inevitably returns false
|
|
|
+ delete searchObj.regex
|
|
|
+ }
|
|
|
if (typeof data !== 'object' || typeof searchObj !== 'object') {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if(dateCheck == true){
|
|
|
+ if (dateCheck == true && regexCheck == true) {
|
|
|
let matchKeys = Object.keys(searchObj);
|
|
|
let isMatchingObject = (object) => {
|
|
|
return matchKeys.every((key) => {
|
|
|
let lodashPath = key.replace(/\[(\w+)\]/g, '.$1').replace(/^\./, '');
|
|
|
let objectValue = _.get(object, lodashPath);
|
|
|
let searchValue = searchObj[key];
|
|
|
-
|
|
|
+
|
|
|
if (Array.isArray(searchValue) && key === 'msgTag') {
|
|
|
// Check if any of the search values are included in the object value
|
|
|
return searchValue.some((value) => {
|
|
@@ -102,14 +100,14 @@ export class queryService {
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
let isObjectMatching = (object) => {
|
|
|
if (typeof object !== 'object') {
|
|
|
return false;
|
|
|
}
|
|
|
return isMatchingObject(object) || Object.values(object).some(isObjectMatching);
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
return isObjectMatching(data);
|
|
|
} else {
|
|
|
return false
|