Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: devtools-panel.js

Issue 29362522: Issue 4644 - Filter requests in devtools panel by search string (Closed)
Patch Set: Allow filtering by request type Created Nov. 14, 2016, 8:03 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | skin/devtools-panel.css » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: devtools-panel.js
diff --git a/devtools-panel.js b/devtools-panel.js
index 85068dd5c1ed8a02309a7370b841b84f7e134df6..c35347be9e0c255b328050c57a928203387ea3cc 100644
--- a/devtools-panel.js
+++ b/devtools-panel.js
@@ -17,6 +17,8 @@
"use strict";
+var lastFilterQuery = null;
+
function generateFilter(request, domainSpecific)
{
var filter = request.url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||");
@@ -120,6 +122,40 @@ function createRecord(request, filter, template)
return row;
}
+function shouldFilterRow(row, query)
+{
+ var filtered = true;
+ var elementsToSearch = [
+ row.getElementsByClassName("url"),
+ row.getElementsByClassName("filter"),
+ row.getElementsByClassName("origin"),
+ row.getElementsByClassName("type")
+ ];
+
+ for (var elements of elementsToSearch)
+ for (var element of elements)
+ if (element.innerText.search(query) != -1)
+ return false;
+ return true;
+}
+
+function performSearch(table, query)
+{
+ for (var row of table.rows)
+ {
+ if (shouldFilterRow(row, query))
+ row.classList.add("filtered-by-search");
+ else
+ row.classList.remove("filtered-by-search");
+ }
+}
+
+function cancelSearch(table)
+{
+ for (var row of table.rows)
+ row.classList.remove("filtered-by-search");
+}
+
document.addEventListener("DOMContentLoaded", function()
{
var container = document.getElementById("items");
@@ -146,7 +182,10 @@ document.addEventListener("DOMContentLoaded", function()
switch (message.type)
{
case "add-record":
- table.appendChild(createRecord(message.request, message.filter, template));
+ var record = createRecord(message.request, message.filter, template);
+ if (lastFilterQuery && shouldFilterRow(record, lastFilterQuery))
+ record.add("filtered-by-search");
+ table.appendChild(record);
break;
case "update-record":
@@ -169,4 +208,18 @@ document.addEventListener("DOMContentLoaded", function()
break;
}
});
+ window.addEventListener("message", function(event)
+ {
+ switch(event.data.type)
+ {
+ case "performSearch":
+ performSearch(table, event.data.queryString);
+ lastFilterQuery = event.data.queryString;
+ break;
+ case "cancelSearch":
+ cancelSearch(table);
+ lastFilterQuery = null;
+ break;
+ }
+ });
}, false);
« no previous file with comments | « no previous file | skin/devtools-panel.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld