@@ -7,6 +7,7 @@ import '../../ui/components/cards/cards.js';
7
7
8
8
import * as Common from '../../core/common/common.js' ;
9
9
import * as i18n from '../../core/i18n/i18n.js' ;
10
+ import * as SDK from '../../core/sdk/sdk.js' ;
10
11
import * as Buttons from '../../ui/components/buttons/buttons.js' ;
11
12
import * as UI from '../../ui/legacy/legacy.js' ;
12
13
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js' ;
@@ -47,6 +48,10 @@ const UIStrings = {
47
48
*@description Label for text input for the longitude of a GPS position.
48
49
*/
49
50
longitude : 'Longitude' ,
51
+ /**
52
+ *@description Label for text input for the accuracy of a GPS position.
53
+ */
54
+ accuracy : 'Accuracy' ,
50
55
/**
51
56
*@description Error message in the Locations settings pane that declares the location name input must not be empty
52
57
*/
@@ -92,6 +97,15 @@ const UIStrings = {
92
97
*@description Error message in the Locations settings pane that declares locale input invalid
93
98
*/
94
99
localeMustContainAlphabetic : 'Locale must contain alphabetic characters' ,
100
+ /**
101
+ *@description Error message in the Locations settings pane that declares that the value for the accuracy input must be a number
102
+ */
103
+ accuracyMustBeANumber : 'Accuracy must be a number' ,
104
+ /**
105
+ *@description Error message in the Locations settings pane that declares the minimum value for the accuracy input
106
+ *@example {0} PH1
107
+ */
108
+ accuracyMustBeGreaterThanOrEqual : 'Accuracy must be greater than or equal to {PH1}' ,
95
109
/**
96
110
*@description Text of add locations button in Locations Settings Tab of the Device Toolbar
97
111
*/
@@ -182,7 +196,14 @@ export class LocationsSettingsTab extends UI.Widget.VBox implements UI.ListWidge
182
196
}
183
197
184
198
private addButtonClicked ( ) : void {
185
- this . list . addNewItem ( this . customSetting . get ( ) . length , { title : '' , lat : 0 , long : 0 , timezoneId : '' , locale : '' } ) ;
199
+ this . list . addNewItem ( this . customSetting . get ( ) . length , {
200
+ title : '' ,
201
+ lat : 0 ,
202
+ long : 0 ,
203
+ timezoneId : '' ,
204
+ locale : '' ,
205
+ accuracy : SDK . EmulationModel . Location . DEFAULT_ACCURACY
206
+ } ) ;
186
207
}
187
208
188
209
renderItem ( location : LocationDescription , _editable : boolean ) : Element {
@@ -210,6 +231,9 @@ export class LocationsSettingsTab extends UI.Widget.VBox implements UI.ListWidge
210
231
const locale = element . createChild ( 'div' , 'locations-list-text' ) ;
211
232
locale . textContent = location . locale ;
212
233
locale . role = 'cell' ;
234
+ element . createChild ( 'div' , 'locations-list-separator' ) ;
235
+ element . createChild ( 'div' , 'locations-list-text' ) . textContent =
236
+ String ( location . accuracy || SDK . EmulationModel . Location . DEFAULT_ACCURACY ) ;
213
237
return element ;
214
238
}
215
239
@@ -229,6 +253,8 @@ export class LocationsSettingsTab extends UI.Widget.VBox implements UI.ListWidge
229
253
location . timezoneId = timezoneId ;
230
254
const locale = editor . control ( 'locale' ) . value . trim ( ) ;
231
255
location . locale = locale ;
256
+ const accuracy = editor . control ( 'accuracy' ) . value . trim ( ) ;
257
+ location . accuracy = accuracy ? parseFloat ( accuracy ) : SDK . EmulationModel . Location . DEFAULT_ACCURACY ;
232
258
233
259
const list = this . customSetting . get ( ) ;
234
260
if ( isNew ) {
@@ -244,6 +270,7 @@ export class LocationsSettingsTab extends UI.Widget.VBox implements UI.ListWidge
244
270
editor . control ( 'long' ) . value = String ( location . long ) ;
245
271
editor . control ( 'timezone-id' ) . value = location . timezoneId ;
246
272
editor . control ( 'locale' ) . value = location . locale ;
273
+ editor . control ( 'accuracy' ) . value = String ( location . accuracy || SDK . EmulationModel . Location . DEFAULT_ACCURACY ) ;
247
274
return editor ;
248
275
}
249
276
@@ -267,6 +294,8 @@ export class LocationsSettingsTab extends UI.Widget.VBox implements UI.ListWidge
267
294
titles . createChild ( 'div' , 'locations-list-text' ) . textContent = i18nString ( UIStrings . timezoneId ) ;
268
295
titles . createChild ( 'div' , 'locations-list-separator locations-list-separator-invisible' ) ;
269
296
titles . createChild ( 'div' , 'locations-list-text' ) . textContent = i18nString ( UIStrings . locale ) ;
297
+ titles . createChild ( 'div' , 'locations-list-separator locations-list-separator-invisible' ) ;
298
+ titles . createChild ( 'div' , 'locations-list-text' ) . textContent = i18nString ( UIStrings . accuracy ) ;
270
299
271
300
const fields = content . createChild ( 'div' , 'locations-edit-row' ) ;
272
301
fields . createChild ( 'div' , 'locations-list-text locations-list-title locations-input-container' )
@@ -287,6 +316,10 @@ export class LocationsSettingsTab extends UI.Widget.VBox implements UI.ListWidge
287
316
288
317
cell = fields . createChild ( 'div' , 'locations-list-text locations-input-container' ) ;
289
318
cell . appendChild ( editor . createInput ( 'locale' , 'text' , i18nString ( UIStrings . locale ) , localeValidator ) ) ;
319
+ fields . createChild ( 'div' , 'locations-list-separator locations-list-separator-invisible' ) ;
320
+
321
+ cell = fields . createChild ( 'div' , 'locations-list-text locations-input-container' ) ;
322
+ cell . appendChild ( editor . createInput ( 'accuracy' , 'text' , i18nString ( UIStrings . accuracy ) , accuracyValidator ) ) ;
290
323
291
324
return editor ;
292
325
@@ -392,6 +425,29 @@ export class LocationsSettingsTab extends UI.Widget.VBox implements UI.ListWidge
392
425
const errorMessage = i18nString ( UIStrings . localeMustContainAlphabetic ) ;
393
426
return { valid : false , errorMessage} ;
394
427
}
428
+
429
+ function accuracyValidator (
430
+ _item : LocationDescription , _index : number , input : UI . ListWidget . EditorControl ) : UI . ListWidget . ValidatorResult {
431
+ const minAccuracy = 0 ;
432
+ const value = input . value . trim ( ) ;
433
+ const parsedValue = Number ( value ) ;
434
+
435
+ if ( ! value ) {
436
+ return { valid : true , errorMessage : undefined } ;
437
+ }
438
+
439
+ let errorMessage ;
440
+ if ( Number . isNaN ( parsedValue ) ) {
441
+ errorMessage = i18nString ( UIStrings . accuracyMustBeANumber ) ;
442
+ } else if ( parseFloat ( value ) < minAccuracy ) {
443
+ errorMessage = i18nString ( UIStrings . accuracyMustBeGreaterThanOrEqual , { PH1 : minAccuracy } ) ;
444
+ }
445
+
446
+ if ( errorMessage ) {
447
+ return { valid : false , errorMessage} ;
448
+ }
449
+ return { valid : true , errorMessage : undefined } ;
450
+ }
395
451
}
396
452
}
397
453
export interface LocationDescription {
@@ -400,4 +456,5 @@ export interface LocationDescription {
400
456
long : number ;
401
457
timezoneId : string ;
402
458
locale : string ;
459
+ accuracy ?: number ;
403
460
}
0 commit comments