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

Delta Between Two Patch Sets: devtools-panel.js

Issue 29362522: Issue 4644 - Filter requests in devtools panel by search string (Closed)
Left Patch Set: Fixed typo Created Nov. 15, 2016, 9:55 a.m.
Right Patch Set: Addressed feedback Created Nov. 30, 2016, 2:48 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | skin/devtools-panel.css » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 if (filter.userDefined) 112 if (filter.userDefined)
113 actionWrapper.appendChild(createActionButton( 113 actionWrapper.appendChild(createActionButton(
114 "remove", "Remove rule", filter.text 114 "remove", "Remove rule", filter.text
115 )); 115 ));
116 } 116 }
117 else 117 else
118 actionWrapper.appendChild(createActionButton( 118 actionWrapper.appendChild(createActionButton(
119 "add", "Block item", generateFilter(request, request.specificOnly) 119 "add", "Block item", generateFilter(request, request.specificOnly)
120 )); 120 ));
121 121
122 if (lastFilterQuery && shouldFilterRow(row, lastFilterQuery))
123 row.classList.add("filtered-by-search");
124
122 return row; 125 return row;
123 } 126 }
124 127
125 function shouldFilterRow(row, query) 128 function shouldFilterRow(row, query)
126 { 129 {
127 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.
128 var elementsToSearch = [ 130 var elementsToSearch = [
129 row.getElementsByClassName("url"), 131 row.getElementsByClassName("url"),
130 row.getElementsByClassName("filter"), 132 row.getElementsByClassName("filter"),
131 row.getElementsByClassName("origin"), 133 row.getElementsByClassName("origin"),
132 row.getElementsByClassName("type") 134 row.getElementsByClassName("type")
133 ]; 135 ];
134 136
135 for (var elements of elementsToSearch) 137 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!
138 {
136 for (var element of elements) 139 for (var element of elements)
140 {
137 if (element.innerText.search(query) != -1) 141 if (element.innerText.search(query) != -1)
138 return false; 142 return false;
143 }
144 }
139 return true; 145 return true;
140 } 146 }
141 147
142 function performSearch(table, query) 148 function performSearch(table, query)
143 { 149 {
144 for (var row of table.rows) 150 for (var row of table.rows)
145 { 151 {
146 if (shouldFilterRow(row, query)) 152 if (shouldFilterRow(row, query))
147 row.classList.add("filtered-by-search"); 153 row.classList.add("filtered-by-search");
148 else 154 else
(...skipping 26 matching lines...) Expand all
175 document.getElementById("filter-type").addEventListener("change", function(eve nt) 181 document.getElementById("filter-type").addEventListener("change", function(eve nt)
176 { 182 {
177 container.dataset.filterType = event.target.value; 183 container.dataset.filterType = event.target.value;
178 }, false); 184 }, false);
179 185
180 ext.onMessage.addListener(function(message) 186 ext.onMessage.addListener(function(message)
181 { 187 {
182 switch (message.type) 188 switch (message.type)
183 { 189 {
184 case "add-record": 190 case "add-record":
185 var record = createRecord(message.request, message.filter, template); 191 table.appendChild(createRecord(message.request, message.filter, template ));
186 if (lastFilterQuery && shouldFilterRow(record, lastFilterQuery))
187 record.classList.add("filtered-by-search");
188 table.appendChild(record);
189 break; 192 break;
190 193
191 case "update-record": 194 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.
192 var oldRow = table.getElementsByTagName("tr")[message.index]; 195 var oldRow = table.getElementsByTagName("tr")[message.index];
193 var newRow = createRecord(message.request, message.filter, template); 196 var newRow = createRecord(message.request, message.filter, template);
194 oldRow.parentNode.replaceChild(newRow, oldRow); 197 oldRow.parentNode.replaceChild(newRow, oldRow);
195 newRow.classList.add("changed"); 198 newRow.classList.add("changed");
196 container.classList.add("has-changes"); 199 container.classList.add("has-changes");
197 break; 200 break;
198 201
199 case "remove-record": 202 case "remove-record":
200 var row = table.getElementsByTagName("tr")[message.index]; 203 var row = table.getElementsByTagName("tr")[message.index];
201 row.parentNode.removeChild(row); 204 row.parentNode.removeChild(row);
202 container.classList.add("has-changes"); 205 container.classList.add("has-changes");
203 break; 206 break;
204 207
205 case "reset": 208 case "reset":
206 table.innerHTML = ""; 209 table.innerHTML = "";
207 container.classList.remove("has-changes"); 210 container.classList.remove("has-changes");
208 break; 211 break;
209 } 212 }
210 }); 213 });
214
211 window.addEventListener("message", function(event) 215 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.
212 { 216 {
213 switch(event.data.type) 217 switch(event.data.type)
214 { 218 {
215 case "performSearch": 219 case "performSearch":
216 performSearch(table, event.data.queryString); 220 performSearch(table, event.data.queryString);
217 lastFilterQuery = event.data.queryString; 221 lastFilterQuery = event.data.queryString;
218 break; 222 break;
219 case "cancelSearch": 223 case "cancelSearch":
220 cancelSearch(table); 224 cancelSearch(table);
221 lastFilterQuery = null; 225 lastFilterQuery = null;
222 break; 226 break;
223 } 227 }
224 }); 228 });
225 }, false); 229 }, false);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld