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: Fixed typo Created Nov. 15, 2016, 9:55 a.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..68cb324023fbd7667404ddd02523c8c19c0100cd 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;
Thomas Greiner 2016/11/29 12:17:06 Detail: Unused variable.
kzar 2016/11/30 14:50:18 Whoops well spotted, done.
+ var elementsToSearch = [
+ row.getElementsByClassName("url"),
+ row.getElementsByClassName("filter"),
+ row.getElementsByClassName("origin"),
+ row.getElementsByClassName("type")
+ ];
+
+ for (var elements of elementsToSearch)
Thomas Greiner 2016/11/29 12:17:07 Detail: For consistency and to reduce the potentia
kzar 2016/11/30 14:50:20 Done.
Thomas Greiner 2016/11/30 15:40:16 Thanks!
+ 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.classList.add("filtered-by-search");
+ table.appendChild(record);
break;
case "update-record":
Thomas Greiner 2016/11/29 12:17:07 Since you're adapting "add-record" to ensure that
kzar 2016/11/30 14:50:18 Done.
@@ -169,4 +208,18 @@ document.addEventListener("DOMContentLoaded", function()
break;
}
});
+ window.addEventListener("message", function(event)
Thomas Greiner 2016/11/29 12:17:07 Detail: Separating those two listeners by a newlin
kzar 2016/11/30 14:50:20 Done.
+ {
+ 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