@@ -298,21 +298,18 @@ export class GttClient {
298
298
// Because Redmine filter functions are applied later, the Window onload
299
299
// event provides a workaround to have filters loaded before executing
300
300
// the following code
301
- window . addEventListener ( 'load' , ( ) => {
302
- console . log ( 'loaded!' )
303
- if ( document . querySelectorAll ( 'tr#tr_bbox' ) . length > 0 ) {
304
- this . filters . location = true
305
- }
306
- if ( document . querySelectorAll ( 'tr#tr_distance' ) . length > 0 ) {
307
- this . filters . distance = true
308
- }
309
- document . querySelector ( 'fieldset#location legend' ) . addEventListener ( 'click' , ( evt ) => {
310
- const element = evt . currentTarget as HTMLLegendElement
311
- this . toggleAndLoadMap ( element )
312
- } )
313
- this . zoomToExtent ( )
314
- this . map . on ( 'moveend' , this . updateFilter )
301
+ if ( document . querySelectorAll ( 'tr#tr_bbox' ) . length > 0 ) {
302
+ this . filters . location = true
303
+ }
304
+ if ( document . querySelectorAll ( 'tr#tr_distance' ) . length > 0 ) {
305
+ this . filters . distance = true
306
+ }
307
+ document . querySelector ( 'fieldset#location legend' ) . addEventListener ( 'click' , ( evt ) => {
308
+ const element = evt . currentTarget as HTMLLegendElement
309
+ this . toggleAndLoadMap ( element )
315
310
} )
311
+ this . zoomToExtent ( )
312
+ this . map . on ( 'moveend' , this . updateFilter . bind ( this ) )
316
313
317
314
// To fix an issue with empty map after changing the tracker type
318
315
document . querySelectorAll ( 'select#issue_tracker_id' ) . forEach ( element => {
@@ -776,9 +773,13 @@ export class GttClient {
776
773
const fieldset = document . querySelector ( 'fieldset#location' ) as HTMLFieldSetElement
777
774
fieldset . dataset . center = JSON . stringify ( center )
778
775
const value_distance_3 = document . querySelector ( '#tr_distance #values_distance_3' ) as HTMLInputElement
779
- value_distance_3 . value = center [ 0 ] . toString ( )
776
+ if ( value_distance_3 ) {
777
+ value_distance_3 . value = center [ 0 ] . toString ( )
778
+ }
780
779
const value_distance_4 = document . querySelector ( '#tr_distance #values_distance_4' ) as HTMLInputElement
781
- value_distance_4 . value = center [ 1 ] . toString ( )
780
+ if ( value_distance_4 ) {
781
+ value_distance_4 . value = center [ 1 ] . toString ( )
782
+ }
782
783
783
784
// Set Permalink as Cookie
784
785
const cookie = [ ]
@@ -792,8 +793,11 @@ export class GttClient {
792
793
793
794
const extent_str = transformExtent ( extent , 'EPSG:3857' , 'EPSG:4326' ) . join ( '|' )
794
795
// console.log("Map Extent (WGS84): ",extent);
795
- const option = document . querySelector ( 'select[name="v[bbox][]"]' ) . querySelector ( 'option' ) as HTMLOptionElement
796
- option . value = extent_str
796
+ const bbox = document . querySelector ( 'select[name="v[bbox][]"]' )
797
+ if ( bbox ) {
798
+ const option = bbox . querySelector ( 'option' ) as HTMLOptionElement
799
+ option . value = extent_str
800
+ }
797
801
// adjust the value of the 'On map' option tag
798
802
// Also adjust the JSON data that's the basis for building the filter row
799
803
// html (this is relevant if the map is moved first and then the filter is
@@ -1157,11 +1161,16 @@ export class GttClient {
1157
1161
}
1158
1162
1159
1163
toggleAndLoadMap ( el : HTMLLegendElement ) {
1160
- const fieldset = el . parentElement . querySelector ( 'fieldset' )
1164
+ const fieldset = el . parentElement
1161
1165
fieldset . classList . toggle ( 'collapsed' )
1162
- fieldset . querySelector ( 'legend' ) . classList . toggle ( 'icon-expended icon-collapsed' ) ;
1166
+ el . classList . toggle ( 'icon-expended' )
1167
+ el . classList . toggle ( 'icon-collapsed' )
1163
1168
const div = fieldset . querySelector ( 'div' )
1164
- div . style . display = div . style . display === 'none' ? '' : 'none'
1169
+ if ( div . style . display !== 'block' ) {
1170
+ div . style . display = 'block'
1171
+ } else {
1172
+ div . style . display = 'none'
1173
+ }
1165
1174
this . maps . forEach ( function ( m ) {
1166
1175
m . updateSize ( )
1167
1176
} )
@@ -1252,11 +1261,11 @@ window.buildFilterRow = function(field, operator, values) {
1252
1261
if ( field == 'distance' ) {
1253
1262
buildDistanceFilterRow ( operator , values )
1254
1263
} else {
1255
- buildFilterRowWithoutDistanceFilter ( field , operator , values )
1264
+ window . buildFilterRowWithoutDistanceFilter ( field , operator , values )
1256
1265
}
1257
1266
}
1258
1267
1259
- const buildFilterRowWithoutDistanceFilter = ( feild : any , operator : any , values : any ) :void => {
1268
+ const buildDistanceFilterRow = ( operator : any , values : any ) :void => {
1260
1269
const field = 'distance'
1261
1270
const fieldId = field
1262
1271
const filterTable = document . querySelector ( '#filters-table' ) as HTMLTableElement
@@ -1329,6 +1338,6 @@ const buildFilterRowWithoutDistanceFilter = (feild: any, operator: any, values:
1329
1338
x = xy [ 0 ]
1330
1339
y = xy [ 1 ]
1331
1340
}
1332
- ( document . querySelector ( `#values_${ fieldId } _3` ) as HTMLInputElement ) . value = x
1333
- ( document . querySelector ( `#values_${ fieldId } _4` ) as HTMLInputElement ) . value = y
1341
+ ( document . querySelector ( `#values_${ fieldId } _3` ) as HTMLInputElement ) . value = x ;
1342
+ ( document . querySelector ( `#values_${ fieldId } _4` ) as HTMLInputElement ) . value = y ;
1334
1343
}
0 commit comments