Skip to content

Commit 67a2b9c

Browse files
committed
dashboard/app: add targeting controls to the coverage page
It allows to control known parameters: 1. Period (months or days). 2. Target subsystem. 3. Target manager. And adds the disabled "Only unique" checkbox.
1 parent f3558db commit 67a2b9c

File tree

3 files changed

+113
-2
lines changed

3 files changed

+113
-2
lines changed

dashboard/app/main.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"net/url"
1414
"os"
1515
"regexp"
16+
"slices"
1617
"sort"
1718
"strconv"
1819
"strings"
@@ -76,6 +77,7 @@ func initHTTPHandlers() {
7677
http.Handle("/"+ns+"/repos", handlerWrapper(handleRepos))
7778
http.Handle("/"+ns+"/bug-summaries", handlerWrapper(handleBugSummaries))
7879
http.Handle("/"+ns+"/subsystems", handlerWrapper(handleSubsystemsList))
80+
http.Handle("/"+ns+"/managers", handlerWrapper(handleManagersList))
7981
http.Handle("/"+ns+"/backports", handlerWrapper(handleBackports))
8082
http.Handle("/"+ns+"/s/", handlerWrapper(handleSubsystemPage))
8183
http.Handle("/"+ns+"/manager/", handlerWrapper(handleManagerPage))
@@ -1423,6 +1425,23 @@ func findBugByID(c context.Context, r *http.Request) (*Bug, error) {
14231425
return nil, fmt.Errorf("mandatory parameter id/extid is missing")
14241426
}
14251427

1428+
func handleManagersList(c context.Context, w http.ResponseWriter, r *http.Request) error {
1429+
if r.FormValue("json") != "1" {
1430+
return ErrClientBadRequest
1431+
}
1432+
hdr, err := commonHeader(c, r, w, "")
1433+
if err != nil {
1434+
return err
1435+
}
1436+
managers, err := CachedManagerList(c, hdr.Namespace)
1437+
if err != nil {
1438+
return err
1439+
}
1440+
w.Header().Set("Content-Type", "application/json")
1441+
slices.Sort(managers)
1442+
return json.NewEncoder(w).Encode(managers)
1443+
}
1444+
14261445
func handleSubsystemsList(c context.Context, w http.ResponseWriter, r *http.Request) error {
14271446
hdr, err := commonHeader(c, r, w, "")
14281447
if err != nil {
@@ -1436,6 +1455,10 @@ func handleSubsystemsList(c context.Context, w http.ResponseWriter, r *http.Requ
14361455
if service == nil {
14371456
return fmt.Errorf("%w: the namespace does not have subsystems", ErrClientBadRequest)
14381457
}
1458+
if r.FormValue("json") == "1" {
1459+
w.Header().Set("Content-Type", "application/json")
1460+
return ssListJSON(service, w)
1461+
}
14391462
nonEmpty := r.FormValue("all") != "true"
14401463
list := []*uiSubsystem{}
14411464
someHidden := false
@@ -1468,6 +1491,15 @@ func handleSubsystemsList(c context.Context, w http.ResponseWriter, r *http.Requ
14681491
})
14691492
}
14701493

1494+
func ssListJSON(service *subsystem.Service, w http.ResponseWriter) error {
1495+
res := []string{}
1496+
for _, subsystem := range service.List() {
1497+
res = append(res, subsystem.Name)
1498+
}
1499+
slices.Sort(res)
1500+
return json.NewEncoder(w).Encode(res)
1501+
}
1502+
14711503
func createUISubsystem(ns string, item *subsystem.Subsystem, cached *Cached) *uiSubsystem {
14721504
stats := cached.Subsystems[item.Name]
14731505
return &uiSubsystem{

dashboard/app/static/coverage.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,50 @@ function initTogglers(){
1111
});
1212
}
1313

14+
function initSelector(controlId, url, defVal){
15+
$.ajax({
16+
url: url,
17+
method: 'GET',
18+
success: function(data) {
19+
data.forEach(item => {
20+
$(controlId).append(new Option(item, item));
21+
});
22+
$(controlId).val(defVal);
23+
},
24+
error: function() {
25+
log('failed to load ' + controlId + ' from ' + url);
26+
}
27+
});
28+
}
29+
30+
function initUpdateForm(){
31+
var curUrlParams = new URLSearchParams(window.location.search);
32+
$('#target-period').val(curUrlParams.get('period'));
33+
initSelector('#target-subsystem', '/upstream/subsystems?json=1', curUrlParams.get('subsystem'))
34+
initSelector('#target-manager', '/upstream/managers?json=1', curUrlParams.get('manager'))
35+
$("#only-unique").prop("checked", curUrlParams.get('subsystem') == "1");
36+
37+
$(document).ready(function() {
38+
$("#updateButton").click(function(event) {
39+
event.preventDefault(); // don't submit the form
40+
41+
var period = $("#target-period").val();
42+
var subsystem = $("#target-subsystem").val();
43+
var manager = $("#target-manager").val();
44+
var onlyUnique = $("#only-unique").prop("checked") ? "1" : "0";
45+
46+
var newLocation = new URL(window.location.href);
47+
newLocation.searchParams.set("period", period);
48+
newLocation.searchParams.set("subsystem", subsystem);
49+
newLocation.searchParams.set("manager", manager);
50+
newLocation.searchParams.set("unique-only", onlyUnique);
51+
window.location.href = newLocation.toString();
52+
});
53+
});
54+
}
55+
56+
$(document).ready(initUpdateForm);
57+
1458
// This handler is called when user clicks on the coverage percentage.
1559
// It downloads the kernel file coverage html block and adjust page to show it.
1660
// "#file-content-prev" and "#file-content-curr" are the file content <div>s.

pkg/cover/templates/heatmap.html

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,47 @@
138138
</ul>
139139
</div>
140140
<div style="display:inline-block; vertical-align: top">
141-
<pre id="file-details-curr"></pre>
141+
<div style="display:inline-block">
142+
<form>
143+
<div style="display:inline-block; vertical-align: top">
144+
<label for="target-period">Periods:</label>
145+
<br>
146+
<label for="target-subsystem">Subsystem:</label>
147+
<br>
148+
<label for="target-manager">Manager:</label>
149+
<br>
150+
<label for="only-unique">Only unique:</label>
151+
</div>
152+
<div style="display:inline-block; vertical-align: top">
153+
<select id="target-period">
154+
<option value="month">Month</option>
155+
<option value="day">Day</option>
156+
</select>
157+
<br>
158+
<select id="target-subsystem">
159+
<option value="">*</option>
160+
</select>
161+
<br>
162+
<select id="target-manager">
163+
<option value="">*</option>
164+
</select>
165+
<br>
166+
<input type="checkbox" id="only-unique" disabled>
167+
</div>
168+
<br>
169+
<button id="updateButton">Update</button>
170+
</form>
171+
</div>
172+
<div style="display:inline-block; vertical-align: top">
173+
<pre style="margin:0" id="file-details-curr"></pre>
174+
</div>
142175
<br>
143176
<div id="file-content-curr"></div>
144177
</div>
145178
<div style="display:inline-block; vertical-align: top">
146-
<pre id="file-details-prev"></pre>
179+
<div style="display:inline-block; vertical-align: top">
180+
<pre style="margin:0" id="file-details-prev"></pre>
181+
</div>
147182
<br>
148183
<div id="file-content-prev"></div>
149184
</div>

0 commit comments

Comments
 (0)