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