Skip to content

Commit

Permalink
Restore old behaviour with new logic (hopefully less buggy)
Browse files Browse the repository at this point in the history
  • Loading branch information
Heath123 committed Dec 3, 2020
1 parent 50e2c5e commit 8bd0c6e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion html/mainPage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h3>Scripting (beta)</h3>
</div>

<div class="search">
<input type="text" class="filter" id="filter" placeholder="Filter by name, ID or content" onkeyup="updateFilter()">
<input type="text" class="filter" id="filter" placeholder="Filter by name, ID or content" onkeyup="updateFilterBox()">
</div>

<div class="container">
Expand Down
7 changes: 6 additions & 1 deletion html/mainPage/js/filteringLogic.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
exports.packetFilteredByFilterBox = function (packet, filter) {
exports.packetFilteredByFilterBox = function (packet, filter, hiddenPackets) {
if (hiddenPackets[packet.direction].includes(packet.meta.name)) {
return true
}

if (filter === '') {
return false
}

const comparisonString = packet.hexIdString + ' ' + packet.meta.name + ' ' + JSON.stringify(packet.data)
return !comparisonString.includes(filter)
}
36 changes: 22 additions & 14 deletions html/mainPage/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,36 @@ function toggleCheckbox (box, packetName, direction) {
// Add it to the hidden packets
sharedVars.hiddenPackets[direction].push(packetName)
}

updateFiltering()
}

function updateFilter () {
// TODO
function updateFilterBox () {
const newValue = filterInput.value
if (sharedVars.lastFilter !== newValue) {
sharedVars.lastFilter = newValue
deselectPacket()
sharedVars.allPacketsHTML.forEach(function(item, index, array) {
if (!filteringLogic.packetFilteredByFilterBox(sharedVars.allPackets[index], newValue)) {
// If it's hidden, show it
array[index] = [item[0].replace('filter-hidden', 'filter-shown')]
} else {
// If it's shown, hide it
array[index] = [item[0].replace('filter-shown', 'filter-hidden')]
}
})
wrappedClusterizeUpdate(sharedVars.allPacketsHTML)
clusterize.refresh()
updateFiltering()
}
}

setInterval(updateFilter, 100)
function updateFiltering () {
sharedVars.allPacketsHTML.forEach(function(item, index, array) {
if (!filteringLogic.packetFilteredByFilterBox(sharedVars.allPackets[index],
sharedVars.lastFilter,
sharedVars.hiddenPackets)) {
// If it's hidden, show it
array[index] = [item[0].replace('filter-hidden', 'filter-shown')]
} else {
// If it's shown, hide it
array[index] = [item[0].replace('filter-shown', 'filter-hidden')]
}
})
wrappedClusterizeUpdate(sharedVars.allPacketsHTML)
clusterize.refresh()
}

setInterval(updateFilterBox, 100)

/* let hiddenPackets = [
// TODO: Do this properly
Expand Down Expand Up @@ -305,6 +312,7 @@ function hideAll (id) {
checkbox.checked = false
checkbox.readOnly = false
checkbox.indeterminate = false
updateFiltering()
}

sharedVars.ipcRenderer.on('hideAllOfType', (event, arg) => { // Context menu
Expand Down
5 changes: 1 addition & 4 deletions html/mainPage/js/packetDom.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function trimData (data) { // Function to trim the size of stringified data for
function addPacketToDOM (packet) {
sharedVars.allPacketsHTML.push([
`<li id="packet${packet.uid}" onclick="packetClick(${packet.uid})" class="packet ${packet.direction} ${
filteringLogic.packetFilteredByFilterBox(packet, sharedVars.lastFilter) ? 'filter-hidden' : 'filter-shown'
filteringLogic.packetFilteredByFilterBox(packet, sharedVars.lastFilter, sharedVars.hiddenPackets) ? 'filter-hidden' : 'filter-shown'
}">
<span class="id">${escapeHtml(packet.hexIdString)}</span>
<span class="name">${escapeHtml(packet.meta.name)}</span>
Expand Down Expand Up @@ -85,9 +85,6 @@ exports.setup = function (passedSharedVars) {
}

exports.addPacket = function (data) {
if (sharedVars.hiddenPackets[data.direction].includes(data.meta.name)) {
return
}
sharedVars.allPackets.push(data)
data.uid = sharedVars.allPackets.length - 1
addPacketToDOM(data)
Expand Down

0 comments on commit 8bd0c6e

Please sign in to comment.