1
1
import Mustache from 'mustache' ;
2
+ import { buildRoute , readRoute , updateRoute } from './route.js' ;
3
+ import { ZERO_COVERAGE_FILTERS } from './zero_coverage_report.js' ;
2
4
3
5
export const REV_LATEST = 'latest' ;
4
6
5
- function assert ( condition , message ) {
6
- if ( ! condition ) {
7
- throw new Error ( message || "Assertion failed" ) ;
8
- }
9
- }
10
-
11
7
function domContentLoaded ( ) {
12
8
return new Promise ( resolve => document . addEventListener ( 'DOMContentLoaded' , resolve ) ) ;
13
9
}
14
10
export const DOM_READY = domContentLoaded ( ) ;
15
11
16
- export async function main ( load , display , opts ) {
17
- // Immediately listen to DOM event
18
-
12
+ export async function main ( load , display ) {
19
13
// Load initial data before DOM is available
20
14
let data = await load ( ) ;
21
15
22
16
// Wait for DOM to be ready before displaying
23
17
await DOM_READY ;
24
18
await display ( data ) ;
19
+ monitor_options ( ) ;
25
20
26
21
// Full workflow, loading then displaying data
27
22
// used for following updates
28
23
let full = async function ( ) {
29
24
let data = await load ( ) ;
30
25
await display ( data ) ;
26
+ monitor_options ( ) ;
31
27
} ;
32
- monitor_options ( opts , full ) ;
28
+
29
+ // React to url changes
33
30
window . onhashchange = full ;
34
31
}
35
32
36
-
37
33
// Coverage retrieval.
38
34
39
35
const COVERAGE_BACKEND_HOST = process . env . BACKEND_URL ;
@@ -64,8 +60,9 @@ function cache_set(cache, key, value) {
64
60
}
65
61
66
62
let path_coverage_cache = { } ;
67
- export async function get_path_coverage ( path , changeset ) {
68
- let data = cache_get ( path_coverage_cache , `${ changeset } _${ path } ` ) ;
63
+ export async function get_path_coverage ( path , changeset , platform , suite ) {
64
+ let cache_key = `${ changeset } _${ path } _${ platform } _${ suite } ` ;
65
+ let data = cache_get ( path_coverage_cache , cache_key ) ;
69
66
if ( data ) {
70
67
return data ;
71
68
}
@@ -74,33 +71,47 @@ export async function get_path_coverage(path, changeset) {
74
71
if ( changeset && changeset !== REV_LATEST ) {
75
72
params += `&changeset=${ changeset } ` ;
76
73
}
74
+ if ( platform && platform !== 'all' ) {
75
+ params += `&platform=${ platform } ` ;
76
+ }
77
+ if ( suite && suite !== 'all' ) {
78
+ params += `&suite=${ suite } ` ;
79
+ }
77
80
let response = await fetch ( `${ COVERAGE_BACKEND_HOST } /v2/path?${ params } ` ) . catch ( alert ) ;
78
81
if ( response . status !== 200 ) {
79
82
throw new Error ( response . status + ' - ' + response . statusText ) ;
80
83
}
81
84
data = await response . json ( ) ;
82
85
83
- cache_set ( path_coverage_cache , ` ${ changeset } _ ${ path } ` , data ) ;
86
+ cache_set ( path_coverage_cache , cache_key , data ) ;
84
87
85
88
return data ;
86
89
}
87
90
88
91
let history_cache = { } ;
89
- export async function get_history ( path ) {
92
+ export async function get_history ( path , platform , suite ) {
90
93
// Backend needs path without trailing /
91
94
if ( path && path . endsWith ( '/' ) ) {
92
95
path = path . substring ( 0 , path . length - 1 ) ;
93
96
}
94
97
95
- let data = cache_get ( history_cache , path ) ;
98
+ let cache_key = `${ path } _${ platform } _${ suite } ` ;
99
+ let data = cache_get ( history_cache , cache_key ) ;
96
100
if ( data ) {
97
101
return data ;
98
102
}
99
103
100
- let response = await fetch ( `${ COVERAGE_BACKEND_HOST } /v2/history?path=${ path } ` ) ;
104
+ let params = `path=${ path } ` ;
105
+ if ( platform && platform !== 'all' ) {
106
+ params += `&platform=${ platform } ` ;
107
+ }
108
+ if ( suite && suite !== 'all' ) {
109
+ params += `&suite=${ suite } ` ;
110
+ }
111
+ let response = await fetch ( `${ COVERAGE_BACKEND_HOST } /v2/history?${ params } ` ) ;
101
112
data = await response . json ( ) ;
102
113
103
- cache_set ( history_cache , path , data ) ;
114
+ cache_set ( history_cache , cache_key , data ) ;
104
115
105
116
// Check data has coverage values
106
117
// These values are missing when going above 2 levels right now
@@ -131,20 +142,62 @@ export async function get_zero_coverage_data() {
131
142
}
132
143
133
144
134
- // Option handling.
145
+ let filters_cache = { } ;
146
+ export async function get_filters ( ) {
147
+ let data = cache_get ( filters_cache , '' ) ;
148
+ if ( data ) {
149
+ return data ;
150
+ }
151
+
152
+ let response = await fetch ( `${ COVERAGE_BACKEND_HOST } /v2/filters` ) ;
153
+ data = await response . json ( ) ;
154
+
155
+ cache_set ( filters_cache , '' , data ) ;
135
156
136
- function is_enabled ( opt ) {
137
- let elem = document . getElementById ( opt ) ;
138
- return elem . checked ;
157
+ return data ;
139
158
}
140
159
141
- function monitor_options ( opts , callback ) {
142
- for ( let opt of opts ) {
143
- let elem = document . getElementById ( opt ) ;
144
- elem . onchange = callback ;
160
+
161
+ // Option handling.
162
+
163
+ export function is_enabled ( opt ) {
164
+ let route = readRoute ( ) ;
165
+ let value = 'off' ;
166
+ if ( route [ opt ] ) {
167
+ value = route [ opt ] ;
168
+ } else if ( ZERO_COVERAGE_FILTERS [ opt ] ) {
169
+ value = ZERO_COVERAGE_FILTERS [ opt ] . default_value ;
145
170
}
171
+ return value === 'on' ;
146
172
}
147
173
174
+ function monitor_options ( ) {
175
+ // Monitor input & select changes
176
+ let fields = document . querySelectorAll ( 'input, select' ) ;
177
+ for ( let field of fields ) {
178
+ if ( field . type == 'text' ) {
179
+ // React on enter
180
+ field . onkeydown = async ( evt ) => {
181
+ if ( evt . keyCode === 13 ) {
182
+ let params = { } ;
183
+ params [ evt . target . name ] = evt . target . value ;
184
+ updateRoute ( params ) ;
185
+ }
186
+ }
187
+ } else {
188
+ // React on change
189
+ field . onchange = async ( evt ) => {
190
+ let value = evt . target . value ;
191
+ if ( evt . target . type == 'checkbox' ) {
192
+ value = evt . target . checked ? 'on' : 'off' ;
193
+ }
194
+ let params = { } ;
195
+ params [ evt . target . name ] = value ;
196
+ updateRoute ( params ) ;
197
+ }
198
+ }
199
+ }
200
+ }
148
201
149
202
// hgmo.
150
203
@@ -267,14 +320,14 @@ export function build_navbar(path, revision) {
267
320
let links = [
268
321
{
269
322
'name' : 'mozilla-central' ,
270
- 'path ' : '' ,
323
+ 'route ' : buildRoute ( { path : '' , revision } )
271
324
}
272
325
] ;
273
326
return links . concat ( path . split ( '/' ) . map ( file => {
274
327
base += ( base ? '/' : '' ) + file ;
275
328
return {
276
329
'name' : file ,
277
- 'path ' : base ,
330
+ 'route ' : buildRoute ( { path : base , revision } )
278
331
} ;
279
332
} ) ) ;
280
333
}
0 commit comments