Skip to content

Commit 1506912

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 1506912

File tree

3 files changed

+115
-2
lines changed

3 files changed

+115
-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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,51 @@ 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+
var ns = window.location.pathname.split('/')[1];
34+
initSelector('#target-subsystem', '/' + ns + '/subsystems?json=1', curUrlParams.get('subsystem'))
35+
initSelector('#target-manager', '/' + ns + '/managers?json=1', curUrlParams.get('manager'))
36+
$("#only-unique").prop("checked", curUrlParams.get('subsystem') == "1");
37+
38+
$(document).ready(function() {
39+
$("#updateButton").click(function(event) {
40+
event.preventDefault(); // don't submit the form
41+
42+
var period = $("#target-period").val();
43+
var subsystem = $("#target-subsystem").val();
44+
var manager = $("#target-manager").val();
45+
var onlyUnique = $("#only-unique").prop("checked") ? "1" : "0";
46+
47+
var newLocation = new URL(window.location.href);
48+
newLocation.searchParams.set("period", period);
49+
newLocation.searchParams.set("subsystem", subsystem);
50+
newLocation.searchParams.set("manager", manager);
51+
newLocation.searchParams.set("unique-only", onlyUnique);
52+
window.location.href = newLocation.toString();
53+
});
54+
});
55+
}
56+
57+
$(document).ready(initUpdateForm);
58+
1459
// This handler is called when user clicks on the coverage percentage.
1560
// It downloads the kernel file coverage html block and adjust page to show it.
1661
// "#file-content-prev" and "#file-content-curr" are the file content <div>s.

pkg/cover/templates/heatmap.html

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,38 @@
104104
{{ end }}
105105

106106
{{ define "body" }}
107+
<div style="display:inline-block">
108+
<form>
109+
<div style="display:inline-block; vertical-align: top">
110+
<label for="target-period">Periods:</label>
111+
<br>
112+
<label for="target-subsystem">Subsystem:</label>
113+
<br>
114+
<label for="target-manager">Manager:</label>
115+
<br>
116+
<label for="only-unique">Only unique:</label>
117+
</div>
118+
<div style="display:inline-block; vertical-align: top">
119+
<select id="target-period">
120+
<option value="month">Month</option>
121+
<option value="day">Day</option>
122+
</select>
123+
<br>
124+
<select id="target-subsystem">
125+
<option value="">*</option>
126+
</select>
127+
<br>
128+
<select id="target-manager">
129+
<option value="">*</option>
130+
</select>
131+
<br>
132+
<input type="checkbox" id="only-unique" disabled>
133+
</div>
134+
<br>
135+
<button id="updateButton">Update</button>
136+
</form>
137+
</div>
138+
<hr>
107139
<div style="white-space: nowrap">
108140
<div style="display:inline-block">
109141
<ul id="collapsible-list">
@@ -138,12 +170,16 @@
138170
</ul>
139171
</div>
140172
<div style="display:inline-block; vertical-align: top">
141-
<pre id="file-details-curr"></pre>
173+
<div style="display:inline-block; vertical-align: top">
174+
<pre style="margin:0" id="file-details-curr"></pre>
175+
</div>
142176
<br>
143177
<div id="file-content-curr"></div>
144178
</div>
145179
<div style="display:inline-block; vertical-align: top">
146-
<pre id="file-details-prev"></pre>
180+
<div style="display:inline-block; vertical-align: top">
181+
<pre style="margin:0" id="file-details-prev"></pre>
182+
</div>
147183
<br>
148184
<div id="file-content-prev"></div>
149185
</div>

0 commit comments

Comments
 (0)