From 820f5c59ef120b916c503d4b73d9bfa5668adc45 Mon Sep 17 00:00:00 2001 From: Tobias Neitzel Date: Thu, 25 Jul 2024 13:10:46 +0200 Subject: [PATCH] Improve filter logic --- frontend/src/components/InterfacePane.vue | 113 ++++++++++++-- frontend/src/components/ProcessTableRow.vue | 162 +++++++++++--------- 2 files changed, 184 insertions(+), 91 deletions(-) diff --git a/frontend/src/components/InterfacePane.vue b/frontend/src/components/InterfacePane.vue index b69c311..6981896 100644 --- a/frontend/src/components/InterfacePane.vue +++ b/frontend/src/components/InterfacePane.vue @@ -32,31 +32,112 @@ this.selectedInterface = intf; }, - applyFilter(filter, intf) + casualFilter(intf, filter) { - if (!filter) + let inverse = false; + + if (filter.startsWith('!')) { - return true; + filter = filter.substring(1); + inverse = true; } - filter = filter.toLowerCase(); + return (intf.id.toLowerCase().includes(filter) || intf.location.toLowerCase().includes(filter) || + intf.description.toLowerCase().includes(filter) || intf.name.toLowerCase().includes(filter) || + intf.annotation.toLowerCase().includes(filter)) != inverse; + }, - if (!filter.includes(':')) + getInterfaces: function*(filter) + { + for (const intf of this.selectedProcess.rpc_info.interface_infos) { - let inverse = false; - - if (filter.startsWith('!')) + if (filter) { - filter = filter.substring(1); - inverse = true; + let match = true; + filter = filter.toLowerCase(); + + if (!filter.includes(':') && !this.casualFilter(intf, filter)) + { + match = false; + } + + else + { + const filterArray = filter.split(/\s*\|\s*/); + + for (const entry of filterArray) + { + let key, value; + let inverse = false; + + [key, value] = entry.split(':', 2); + + if (key === 'uuid') + { + key = 'id'; + } + + if (value === undefined) + { + if (!this.casualFilter(intf, key)) + { + match = false; + break; + } + + continue; + } + + if (value.startsWith('!')) + { + value = value.substring(1); + inverse = true; + } + + if (Object.hasOwn(intf, key)) + { + const propValue = intf[key]; + + if (Array.isArray(propValue)) + { + let found = false; + + for (const item of propValue) + { + if (String(item).toLowerCase().includes(value)) + { + found = true; + break; + } + } + + if (!found != inverse) + { + match = false; + break; + } + } + + else + { + if (String(propValue).toLowerCase().includes(value) == inverse) + { + match = false; + break; + } + } + } + } + } + + if (!match) + { + continue; + } } - return (intf.uuid.toLowerCase().includes(filter) || intf.location.toLowerCase().includes(filter) || - intf.decs.toLowerCase().includes(filter) || intf.name.toLowerCase().includes(filter) || - intf.annotation.toLowerCase().includes(filter)) != inverse; + yield intf; } - - return true; }, interfaceClick(e, item) @@ -106,7 +187,7 @@ Annotation EpRegistred - {{ intf.typ.toUpperCase() }} diff --git a/frontend/src/components/ProcessTableRow.vue b/frontend/src/components/ProcessTableRow.vue index 6895d15..9562492 100644 --- a/frontend/src/components/ProcessTableRow.vue +++ b/frontend/src/components/ProcessTableRow.vue @@ -27,115 +27,127 @@ this.selectedInterface = null; }, - applyFilter(filter, process) + casualFilter(process, filter) { - if (!filter) - { - return true; - } - - filter = filter.toLowerCase(); + let inverse = false; - if (!filter.includes(':')) + if (filter.startsWith('!')) { - let inverse = false; - - if (filter.startsWith('!')) - { - filter = filter.substring(1); - inverse = true; - } - - return (process.path.toLowerCase().includes(filter) || process.cmdline.toLowerCase().includes(filter) || - process.user.toLowerCase().includes(filter) || process.pid == filter) != inverse; + filter = filter.substring(1); + inverse = true; } - let result = true; - const filterArray = filter.split(/\s*\|\s*/); + return (process.path.toLowerCase().includes(filter) || process.cmdline.toLowerCase().includes(filter) || + process.user.toLowerCase().includes(filter) || process.pid == filter) != inverse; + }, - for (const entry of filterArray) + applyFilter(filter, process) + { + if (filter) { - let key, value; - let inverse = false; - - [key, value] = entry.split(':', 2); - - if (value === undefined) - { - key = key.toLowerCase(); - result = result && (process.path.toLowerCase().includes(key) || process.cmdline.toLowerCase().includes(key) || - process.user.toLowerCase().includes(key) || process.pid == key); - continue; - } + filter = filter.toLowerCase(); - if (value.startsWith('!')) + if (!filter.includes(':') && !this.casualFilter(process, filter)) { - value = value.substring(1); - inverse = true; + return false; } - if (key === 'uuid' || key === 'id' || key == 'location') + else { - let found = false; + const filterArray = filter.split(/\s*\|\s*/); - if (key === 'uuid') + for (const entry of filterArray) { - key = 'id'; - } + let key, value; + let inverse = false; - for (const intf of process.rpc_info.interface_infos) - { - if (String(intf[key]).toLowerCase().includes(value) != inverse) + [key, value] = entry.split(':', 2); + + if (key === 'uuid') { - found = true + key = 'id'; } - } - result = result && found; - } - - else if (key === 'endpoint') - { - let found = false; + if (value === undefined) + { + if (!this.casualFilter(process, key)) + { + return false; + } - for (const endpoint of process.rpc_info.server_info.endpoints) - { - const mergedEndpoint = `${endpoint.protocol}:${endpoint.name}`; + continue; + } - if (mergedEndpoint.toLowerCase().includes(value) != inverse) + if (value.startsWith('!')) { - found = true + value = value.substring(1); + inverse = true; } - } - result = result && found; - } + let propValue = null; - else if (key === 'flags') - { - let found = false; + if (Object.hasOwn(process, key)) + { + propValue = process[key]; + } - for (const intf of process.rpc_info.interface_infos) - { - for (const flag of intf.flags) + else if (Object.hasOwn(process.rpc_info.server_info, key)) { - if (flag.toLowerCase().includes(value) != inverse) + propValue = process.server_info[key]; + } + + else if (process.rpc_info.interface_infos.length > 0) + { + if (Object.hasOwn(process.rpc_info.interface_infos[0], key)) { - found = true + propValue = []; + + for (const intf of process.rpc_info.interface_infos) + { + propValue.push(intf[key]); + } } } - } - result = result && found; - } + else + { + return false; + } - else - { - result = result && (Object.hasOwn(process, key) && String(process[key]).toLowerCase().includes(value) != inverse); + if (propValue !== null) + { + if (Array.isArray(propValue)) + { + let found = false; + + for (const item of propValue) + { + if (String(item).toLowerCase().includes(value)) + { + found = true; + break; + } + } + + if (!found != inverse) + { + return false; + } + } + + else + { + if (String(propValue).toLowerCase().includes(value) == inverse) + { + return false; + } + } + } + } } } - return result; + return true; } }, }