Merge lp:~juliank/merge-o-matic/javascript-query into lp:merge-o-matic

Proposed by Julian Andres Klode
Status: Merged
Merged at revision: 309
Proposed branch: lp:~juliank/merge-o-matic/javascript-query
Merge into: lp:merge-o-matic
Diff against target: 84 lines (+61/-0)
1 file modified
merge-status.py (+61/-0)
To merge this branch: bzr merge lp:~juliank/merge-o-matic/javascript-query
Reviewer Review Type Date Requested Status
Julian Andres Klode Approve
Colin Watson Approve
Review via email: mp+336671@code.launchpad.net

Description of the change

This adds a search box and two check boxes for:

- merges with uploads in proposed
- merges without them

This uses the history modification API thingy, and replaces the search part of the URL, so you end up with queries like:

https://merges.ubuntu.com/main.html?query=foundations-bugs&showProposed=false&showMergeNeeded=true

I tested that the JavaScript and HTML works, but I might have messed up the integration into the Python script. I lack the files to test the merge-status.py script on my system.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
313. By Julian Andres Klode

use === instead of == and fix an empty line that got inserted somehow

314. By Julian Andres Klode

Some more == to === fixes

Revision history for this message
Julian Andres Klode (juliank) wrote :

Verified that it generates the same output as my test file, so it's good to go.

review: Approve
Revision history for this message
Tiago Stürmer Daitx (tdaitx) wrote :

Case insensitive search can be done by using toUpperCase() - or toLowerCase().

Example: !rows[i].textContent.toUpperCase().match(query.value.toUpperCase()).

Revision history for this message
Julian Andres Klode (juliank) wrote :

Might be better to just make the regex case insensitive, AKA

new RegExp(query.value, "i")

but that will be a new MP :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'merge-status.py'
--- merge-status.py 2018-01-26 12:58:47 +0000
+++ merge-status.py 2018-01-26 13:35:55 +0000
@@ -26,6 +26,7 @@
26import os26import os
27import re27import re
28from rfc822 import parseaddr28from rfc822 import parseaddr
29import textwrap
29import time30import time
3031
31from deb.controlfile import ControlFile32from deb.controlfile import ControlFile
@@ -249,6 +250,14 @@
249 print("<img src=\".img/ubuntulogo-100.png\" id=\"ubuntu\">",250 print("<img src=\".img/ubuntulogo-100.png\" id=\"ubuntu\">",
250 file=status)251 file=status)
251 print("<h1>Ubuntu Merge-o-Matic: %s</h1>" % component, file=status)252 print("<h1>Ubuntu Merge-o-Matic: %s</h1>" % component, file=status)
253
254 print("<div id=\"filters\">", file=status)
255 print("<b>Filters:</b>", file=status)
256 print("<input id=\"query\" name=\"query\"/>", file=status)
257 print("<input id=\"showProposed\" checked=\"checked\" type=\"checkbox\">Show merges with something in proposed</input>", file=status)
258 print("<input id=\"showMergeNeeded\" checked=\"checked\" type=\"checkbox\">Show merges without something in proposed</input>", file=status)
259 print("</div>", file=status)
260
252261
253 for section in SECTIONS:262 for section in SECTIONS:
254 section_merges = [ m for m in merges if m[0] == section ]263 section_merges = [ m for m in merges if m[0] == section ]
@@ -285,6 +294,58 @@
285 % component, file=status)294 % component, file=status)
286 print("<p><small>Generated at %s.</small></p>" %295 print("<p><small>Generated at %s.</small></p>" %
287 time.strftime('%Y-%m-%d %H:%M:%S %Z'), file=status)296 time.strftime('%Y-%m-%d %H:%M:%S %Z'), file=status)
297
298 print(textwrap.dedent("""
299 <script type="text/javascript">
300 (function() {
301 var query = document.getElementById("query");
302 var showProposed = document.getElementById("showProposed");
303 var showMergeNeeded = document.getElementById("showMergeNeeded");
304
305 // Function to filter stuff
306 function filterText() {
307 var tables=document.getElementsByTagName("table");
308 for (var t=0; t < tables.length; t++) {
309 var rows=tables[t].getElementsByTagName("tr");
310 for (var i=2; i < rows.length; i += 2) {
311 var hide = (query.value && !rows[i].textContent.match(query.value)) ||
312 (!showProposed.checked && rows[i].bgColor === '#d0d0d0') ||
313 (!showMergeNeeded.checked && rows[i].bgColor !== '#d0d0d0');
314 rows[i].hidden=rows[i+1].hidden=hide;
315 }
316 }
317
318 var search = (query.value ? "query=" + encodeURIComponent(query.value) + "&": "") + "showProposed=" + encodeURIComponent(showProposed.checked) + "&showMergeNeeded=" + encodeURIComponent(showMergeNeeded.checked);
319
320 history.replaceState({"query": query.value, "showProposed": showProposed.checked, "showMergeNeeded": showMergeNeeded.checked}, "", "?" + search);
321
322 }
323
324 // Set initial filter state from search part of URL
325 var initState = location.search.substring(1).split("&");
326 for (var i = 0; i < initState.length; i++) {
327 var kv = initState[i].split("=");
328 switch (decodeURIComponent(kv[0])) {
329 case "query":
330 query.value = decodeURIComponent(kv[1]);
331 break;
332 case "showProposed":
333 showProposed.checked = ("true" === decodeURIComponent(kv[1]))
334 break;
335 case "showMergeNeeded":
336 showMergeNeeded.checked = ("true" === decodeURIComponent(kv[1]));
337 break;
338 }
339 }
340
341 filterText();
342
343 // Add event listeners
344 query.addEventListener('input', filterText);
345 showProposed.addEventListener('change', filterText);
346 showMergeNeeded.addEventListener('change', filterText);
347 })();
348 </script>"""), file=status)
288 print("</body>", file=status)349 print("</body>", file=status)
289 print("</html>", file=status)350 print("</html>", file=status)
290351

Subscribers

People subscribed via source and target branches

to status/vote changes: