|
@@ -25,18 +25,27 @@ export class queryService {
|
|
clearInterval(intervalId);
|
|
clearInterval(intervalId);
|
|
this.dataFromStorage.complete();
|
|
this.dataFromStorage.complete();
|
|
}
|
|
}
|
|
- }, 1000)
|
|
|
|
|
|
+ }, 250)
|
|
}
|
|
}
|
|
|
|
|
|
// Search and Filter: Pure Observables. To be moved out to become a separate service again.
|
|
// Search and Filter: Pure Observables. To be moved out to become a separate service again.
|
|
private filterFromObs(...conditions: Conditions[]) {
|
|
private filterFromObs(...conditions: Conditions[]) {
|
|
|
|
+ let enquiry = conditions[0]
|
|
|
|
+ let key = Object.keys(enquiry)[0]
|
|
this.dataFromStorage.subscribe({
|
|
this.dataFromStorage.subscribe({
|
|
next: element => {
|
|
next: element => {
|
|
- // Logic to check if data meets the conditions, if so, put it into result.next{}
|
|
|
|
- if (this.hasKeyAndValue(element, ...conditions)) {
|
|
|
|
- this.filteredResult.next(element)
|
|
|
|
|
|
+ if (key == "regex") {
|
|
|
|
+ if (this.filterViaRegex(element, enquiry)) {
|
|
|
|
+ this.filteredResult.next(element)
|
|
|
|
+ } else {
|
|
|
|
+ // console.log(`${element.header.messageName} does not match search criteria`)
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- // console.log(`${element.header.messageName} does not match search criteria`)
|
|
|
|
|
|
+ if (this.hasKeyAndValue(element, ...conditions)) {
|
|
|
|
+ this.filteredResult.next(element)
|
|
|
|
+ } else {
|
|
|
|
+ // console.log(`${element.header.messageName} does not match search criteria`)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -62,7 +71,7 @@ export class queryService {
|
|
|
|
|
|
// Logic 2: Success: More superior version than Logic 1 since it can perform flat searches like {messageID : 1234} without specifying its nested properties
|
|
// Logic 2: Success: More superior version than Logic 1 since it can perform flat searches like {messageID : 1234} without specifying its nested properties
|
|
private hasKeyAndValue(data, ...conditions): boolean {
|
|
private hasKeyAndValue(data, ...conditions): boolean {
|
|
- // Merge all condtions into searchObj
|
|
|
|
|
|
+ // Merge all conditions into searchObj
|
|
let searchObj = Object.assign({}, ...conditions)
|
|
let searchObj = Object.assign({}, ...conditions)
|
|
if (typeof data !== 'object' || typeof searchObj !== 'object') {
|
|
if (typeof data !== 'object' || typeof searchObj !== 'object') {
|
|
return false;
|
|
return false;
|
|
@@ -88,8 +97,6 @@ export class queryService {
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
let isObjectMatching = (object) => {
|
|
let isObjectMatching = (object) => {
|
|
if (typeof object !== 'object') {
|
|
if (typeof object !== 'object') {
|
|
return false;
|
|
return false;
|
|
@@ -114,6 +121,14 @@ export class queryService {
|
|
the conditions specified in searchObj.
|
|
the conditions specified in searchObj.
|
|
PS: this function is not my code. */
|
|
PS: this function is not my code. */
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private filterViaRegex(element: any, inquiry: any): boolean {
|
|
|
|
+ // create a new regular expression to use regex.test
|
|
|
|
+ const regex = new RegExp(inquiry.regex);
|
|
|
|
+ const hasMatchingSubstring = regex.test(JSON.stringify(element));
|
|
|
|
+ return hasMatchingSubstring;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -127,7 +142,8 @@ export interface Conditions {
|
|
msgDateTime?: Date | string,
|
|
msgDateTime?: Date | string,
|
|
msgTag?: string[],
|
|
msgTag?: string[],
|
|
msgPayload?: string,
|
|
msgPayload?: string,
|
|
- messageID?: string
|
|
|
|
|
|
+ messageID?: string,
|
|
|
|
+ regex?: string
|
|
}
|
|
}
|
|
|
|
|
|
export interface Storage {
|
|
export interface Storage {
|