|
@@ -33,18 +33,10 @@ export class queryService {
|
|
let searchObj = Object.assign({}, ...conditions)
|
|
let searchObj = Object.assign({}, ...conditions)
|
|
this.dataFromStorage.subscribe({
|
|
this.dataFromStorage.subscribe({
|
|
next: element => {
|
|
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 {
|
|
} 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
|
|
// Merge all conditions into searchObj
|
|
let searchObj = Object.assign({}, ...conditions)
|
|
let searchObj = Object.assign({}, ...conditions)
|
|
let dateCheck = true
|
|
let dateCheck = true
|
|
|
|
+ let regexCheck = true
|
|
if (searchObj.hasOwnProperty("dateRange")) {
|
|
if (searchObj.hasOwnProperty("dateRange")) {
|
|
dateCheck = this.filterByDateRange(data, searchObj.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
|
|
// 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
|
|
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') {
|
|
if (typeof data !== 'object' || typeof searchObj !== 'object') {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- if(dateCheck == true){
|
|
|
|
|
|
+ if (dateCheck == true && regexCheck == true) {
|
|
let matchKeys = Object.keys(searchObj);
|
|
let matchKeys = Object.keys(searchObj);
|
|
let isMatchingObject = (object) => {
|
|
let isMatchingObject = (object) => {
|
|
return matchKeys.every((key) => {
|
|
return matchKeys.every((key) => {
|
|
let lodashPath = key.replace(/\[(\w+)\]/g, '.$1').replace(/^\./, '');
|
|
let lodashPath = key.replace(/\[(\w+)\]/g, '.$1').replace(/^\./, '');
|
|
let objectValue = _.get(object, lodashPath);
|
|
let objectValue = _.get(object, lodashPath);
|
|
let searchValue = searchObj[key];
|
|
let searchValue = searchObj[key];
|
|
-
|
|
|
|
|
|
+
|
|
if (Array.isArray(searchValue) && key === 'msgTag') {
|
|
if (Array.isArray(searchValue) && key === 'msgTag') {
|
|
// Check if any of the search values are included in the object value
|
|
// Check if any of the search values are included in the object value
|
|
return searchValue.some((value) => {
|
|
return searchValue.some((value) => {
|
|
@@ -102,14 +100,14 @@ export class queryService {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
};
|
|
};
|
|
-
|
|
|
|
|
|
+
|
|
let isObjectMatching = (object) => {
|
|
let isObjectMatching = (object) => {
|
|
if (typeof object !== 'object') {
|
|
if (typeof object !== 'object') {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
return isMatchingObject(object) || Object.values(object).some(isObjectMatching);
|
|
return isMatchingObject(object) || Object.values(object).some(isObjectMatching);
|
|
};
|
|
};
|
|
-
|
|
|
|
|
|
+
|
|
return isObjectMatching(data);
|
|
return isObjectMatching(data);
|
|
} else {
|
|
} else {
|
|
return false
|
|
return false
|