8000 Merge pull request #4617 from Neradoc/search-filter-in-support-matrix · tannewt/circuitpython@15f8b80 · GitHub
[go: up one dir, main page]

Skip to content

Commit 15f8b80

Browse files
authored
Merge pull request micropython#4617 from Neradoc/search-filter-in-support-matrix
Add a filter text field to the support matrix
2 parents f55d684 + 827f678 commit 15f8b80

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ def apply(self, **kwargs):
489489

490490
def setup(app):
491491
app.add_css_file("customstyle.css")
492+
app.add_css_file("filter.css")
493+
app.add_js_file("filter.js")
492494
app.add_config_value('redirects_file', 'redirects', 'env')
493495
app.connect('builder-inited', generate_redirects)
494496
app.add_transform(CoreModuleTransform)

docs/static/filter.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#support-matrix-filter-block { position: relative; }
2+
#support-matrix-filter {
3+
width: 100%;
4+
}
5+
#support-matrix-filter-num {
6+
position: absolute;
7+
right: 10px;
8+
top: 4px;
9+
}
10+
.support-matrix-table .this_module code,
11+
.support-matrix-table .this_module span {
12+
background: black;
13+
color: white;
14+
}
< 10000 /td>
15+
.support-matrix-table .board_hidden {
16+
display: none;
17+
}

docs/static/filter.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
$(() => {
2+
var urlTimeout = null;
3+
function setURL(query, value) {
4+
clearTimeout(urlTimeout);
5+
6+
urlTimeout = setTimeout(function() {
7+
var url = new URL(window.location.href);
8+
console.log(query,value,value.length,!value.length);
9+
if (!value.length) {
10+
console.log
11+
url.searchParams.delete(query);
12+
} else if (Array.isArray(value)) {
13+
url.searchParams.delete(query);
14+
value.forEach(function(v) {
15+
url.searchParams.append(query, v);
16+
})
17+
} else {
18+
url.searchParams.set(query, value);
19+
}
20+
21+
window.history.pushState(null, document.title, url.href);
22+
}, 1000);
23+
}
24+
25+
function handlePageLoad() {
26+
var url = new URL(window.location.href);
27+
//get values from URL
28+
var filters = url.searchParams.getAll('filter');
29+
search_terms = filters.join(" ");
30+
$("#support-matrix-filter").val(search_terms);
31+
run_filter();
32+
}
33+
34+
function filter_boards(search_string) {
35+
$(".board_hidden").removeClass("board_hidden");
36+
$(".this_module").removeClass("this_module");
37+
var nboards = $(".support-matrix-table tbody tr").length;
38+
if(search_string.trim() == "") {
39+
$("#support-matrix-filter-num").html("(all)");
40+
setURL("filter",[]);
41+
return;
42+
}
43+
var list_search = search_string.split(" ").filter(i => i);
44+
var nvisible = 0;
45+
$(".support-matrix-table tbody tr").each( (index,item) => {
46+
var name = $(item).find("td:first-child p").html();
47+
var modules = $(item).find("a.reference.internal");
48+
var matching_all = true;
49+
//
50+
list_search.forEach((sstring) => {
51+
var matching = (sstring[0] == "-");
52+
for(var modi = 0; modi < modules.length; ++modi) {
53+
module = modules[modi];
54+
var mod_name = module.firstChild.firstChild.textContent;
55+
if(sstring[0] == "-") {
56+
if(mod_name.match(sstring.substr(1))) {
57+
matching = false;
58+
break;
59+
}
60+
} else {
61+
if(mod_name.match(sstring)) {
62+
$(module).addClass("this_module");
63+
matching = true;
64+
}
65+
}
66+
}
67+
matching_all = matching_all && matching;
68+
});
69+
if(!matching_all) {
70+
$(item).addClass("board_hidden");
71+
} else {
72+
nvisible += 1;
73+
}
74+
});
75+
$("#support-matrix-filter-num").html(`(${nvisible}/${nboards})`);
76+
setURL("filter",list_search);
77+
}
78+
79+
function run_filter() {
80+
var search_string = $("#support-matrix-filter").val();
81+
filter_boards(search_string);
82+
}
83+
$("#support-matrix-filter").on("keyup", run_filter);
84+
// $(document).on("keyup", "#support-matrix-filter", run_filter);
85+
handlePageLoad();
86+
});

shared-bindings/support_matrix.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Module Support Matrix - Which Modules Are Available on Which Boards
66
The following table lists the available built-in modules for each CircuitPython
77
capable board.
88

9+
.. raw:: html
10+
11+
<p id="support-matrix-filter-block"><input placeholder="Filter the boards by available modules" id="support-matrix-filter" type="text"/><span id="support-matrix-filter-num">(all)</span></p>
12+
13+
.. rst-class:: support-matrix-table
914
.. list-table::
1015
:header-rows: 1
1116
:widths: 7, 50

0 commit comments

Comments
 (0)
0