Skip to content

Commit aff88d4

Browse files
committed
WIP: enable to show legend map, added null check
Signed-off-by: Taro Matsuzawa <[email protected]>
1 parent 1ae6a20 commit aff88d4

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

src/components/gtt-client.ts

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -298,21 +298,18 @@ export class GttClient {
298298
// Because Redmine filter functions are applied later, the Window onload
299299
// event provides a workaround to have filters loaded before executing
300300
// 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)
315310
})
311+
this.zoomToExtent()
312+
this.map.on('moveend', this.updateFilter.bind(this))
316313

317314
// To fix an issue with empty map after changing the tracker type
318315
document.querySelectorAll('select#issue_tracker_id').forEach(element => {
@@ -776,9 +773,13 @@ export class GttClient {
776773
const fieldset = document.querySelector('fieldset#location') as HTMLFieldSetElement
777774
fieldset.dataset.center = JSON.stringify(center)
778775
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+
}
780779
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+
}
782783

783784
// Set Permalink as Cookie
784785
const cookie = []
@@ -792,8 +793,11 @@ export class GttClient {
792793

793794
const extent_str = transformExtent(extent,'EPSG:3857','EPSG:4326').join('|')
794795
// 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+
}
797801
// adjust the value of the 'On map' option tag
798802
// Also adjust the JSON data that's the basis for building the filter row
799803
// html (this is relevant if the map is moved first and then the filter is
@@ -1157,11 +1161,16 @@ export class GttClient {
11571161
}
11581162

11591163
toggleAndLoadMap(el: HTMLLegendElement) {
1160-
const fieldset = el.parentElement.querySelector('fieldset')
1164+
const fieldset = el.parentElement
11611165
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')
11631168
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+
}
11651174
this.maps.forEach(function (m) {
11661175
m.updateSize()
11671176
})
@@ -1252,11 +1261,11 @@ window.buildFilterRow = function(field, operator, values) {
12521261
if (field == 'distance') {
12531262
buildDistanceFilterRow(operator, values)
12541263
} else {
1255-
buildFilterRowWithoutDistanceFilter(field, operator, values)
1264+
window.buildFilterRowWithoutDistanceFilter(field, operator, values)
12561265
}
12571266
}
12581267

1259-
const buildFilterRowWithoutDistanceFilter = (feild: any, operator: any, values: any):void => {
1268+
const buildDistanceFilterRow = (operator: any, values: any):void => {
12601269
const field = 'distance'
12611270
const fieldId = field
12621271
const filterTable = document.querySelector('#filters-table') as HTMLTableElement
@@ -1329,6 +1338,6 @@ const buildFilterRowWithoutDistanceFilter = (feild: any, operator: any, values:
13291338
x = xy[0]
13301339
y = xy[1]
13311340
}
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;
13341343
}

0 commit comments

Comments
 (0)