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
1=== modified file 'merge-status.py'
2--- merge-status.py 2018-01-26 12:58:47 +0000
3+++ merge-status.py 2018-01-26 13:35:55 +0000
4@@ -26,6 +26,7 @@
5 import os
6 import re
7 from rfc822 import parseaddr
8+import textwrap
9 import time
10
11 from deb.controlfile import ControlFile
12@@ -249,6 +250,14 @@
13 print("<img src=\".img/ubuntulogo-100.png\" id=\"ubuntu\">",
14 file=status)
15 print("<h1>Ubuntu Merge-o-Matic: %s</h1>" % component, file=status)
16+
17+ print("<div id=\"filters\">", file=status)
18+ print("<b>Filters:</b>", file=status)
19+ print("<input id=\"query\" name=\"query\"/>", file=status)
20+ print("<input id=\"showProposed\" checked=\"checked\" type=\"checkbox\">Show merges with something in proposed</input>", file=status)
21+ print("<input id=\"showMergeNeeded\" checked=\"checked\" type=\"checkbox\">Show merges without something in proposed</input>", file=status)
22+ print("</div>", file=status)
23+
24
25 for section in SECTIONS:
26 section_merges = [ m for m in merges if m[0] == section ]
27@@ -285,6 +294,58 @@
28 % component, file=status)
29 print("<p><small>Generated at %s.</small></p>" %
30 time.strftime('%Y-%m-%d %H:%M:%S %Z'), file=status)
31+
32+ print(textwrap.dedent("""
33+ <script type="text/javascript">
34+ (function() {
35+ var query = document.getElementById("query");
36+ var showProposed = document.getElementById("showProposed");
37+ var showMergeNeeded = document.getElementById("showMergeNeeded");
38+
39+ // Function to filter stuff
40+ function filterText() {
41+ var tables=document.getElementsByTagName("table");
42+ for (var t=0; t < tables.length; t++) {
43+ var rows=tables[t].getElementsByTagName("tr");
44+ for (var i=2; i < rows.length; i += 2) {
45+ var hide = (query.value && !rows[i].textContent.match(query.value)) ||
46+ (!showProposed.checked && rows[i].bgColor === '#d0d0d0') ||
47+ (!showMergeNeeded.checked && rows[i].bgColor !== '#d0d0d0');
48+ rows[i].hidden=rows[i+1].hidden=hide;
49+ }
50+ }
51+
52+ var search = (query.value ? "query=" + encodeURIComponent(query.value) + "&": "") + "showProposed=" + encodeURIComponent(showProposed.checked) + "&showMergeNeeded=" + encodeURIComponent(showMergeNeeded.checked);
53+
54+ history.replaceState({"query": query.value, "showProposed": showProposed.checked, "showMergeNeeded": showMergeNeeded.checked}, "", "?" + search);
55+
56+ }
57+
58+ // Set initial filter state from search part of URL
59+ var initState = location.search.substring(1).split("&");
60+ for (var i = 0; i < initState.length; i++) {
61+ var kv = initState[i].split("=");
62+ switch (decodeURIComponent(kv[0])) {
63+ case "query":
64+ query.value = decodeURIComponent(kv[1]);
65+ break;
66+ case "showProposed":
67+ showProposed.checked = ("true" === decodeURIComponent(kv[1]))
68+ break;
69+ case "showMergeNeeded":
70+ showMergeNeeded.checked = ("true" === decodeURIComponent(kv[1]));
71+ break;
72+ }
73+ }
74+
75+ filterText();
76+
77+ // Add event listeners
78+ query.addEventListener('input', filterText);
79+ showProposed.addEventListener('change', filterText);
80+ showMergeNeeded.addEventListener('change', filterText);
81+ })();
82+ </script>"""), file=status)
83 print("</body>", file=status)
84 print("</html>", file=status)
85

Subscribers

People subscribed via source and target branches

to status/vote changes: