Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1cf1413d

Přidáno uživatelem Tomáš Ballák před téměř 4 roky(ů)

Feature Re #8184 ajax form

Zobrazit rozdíly:

website/public/js/zcu-heatmap.js
10 10
var startZoom = 17
11 11

  
12 12
var dataSourceRoute
13
let positionsSourceRoute
13 14
var currentTime
14 15

  
15 16
var timer
......
83 84
  ${genPopUpControls(maxPos > 1 ? [previousButton, posInfo, nextButton] : null)}
84 85
  `
85 86
}
87
const onCheckboxClicked = async (checkbox) => {
88
  if ($(checkbox).prop('checked')) {
89
    loadCurrentTimeHeatmap(dataSourceRoute, positionsSourceRoute)
90
    changeUrl()
91
  } else {
92
    loadCheckboxDatasetNameData()
93
    data.forEach((item, index) => {
94
      Object.keys(item).forEach((datasetName) => {
95
        if (datasetName === $(checkbox).val()) {
96
          delete data[index][datasetName]
97
        }
98
      })
99
      drawHeatmap(data[currentTime])
100
    })
101
    changeUrl()
102
  }
103
}
104
const debounce = (func, delay) => {
105
  let inDebounce
106
  return function () {
107
    const context = this
108
    const args = arguments
109
    clearTimeout(inDebounce)
110
    inDebounce = setTimeout(() => func.apply(context, args), delay)
111
  }
112
}
113
const onValueChangeRegister = () => {
114
  $('#date').change(function () {
115
    data = []
116
    loadCurrentTimeHeatmap(dataSourceRoute, positionsSourceRoute)
117
    console.log('VAL:', $(this).val())
118
    const date = new Date($(this).val())
119
    $('#player-date').html(`${date.getDate()}. ${date.getMonth() + 1}. ${date.getFullYear()}`)
120
  })
121
  $('#dataset-dropdown-time input[type="radio"]').each(function () {
122
    $(this).change(function () {
123
      currentTime = $(this).val()
124
      updateHeaderControls()
125
      setTimeline()
126
      drawHeatmap(data[currentTime])
127
    })
128
  })
129
  $('input[type=checkbox]').each(function () {
130
    $(this).change(
131
      debounce(() => onCheckboxClicked(this), 1000)
132
    )
133
  })
134
}
86 135
/**
87 136
 * Initialize leaflet map on start position which can be default or set based on user action
88 137
 */
......
280 329
}
281 330

  
282 331
function updateHeaderControls () {
283
  document.getElementById('time').value = currentTime
332
  $(`#time_${currentTime}`).prop('checked', true)
333
  $('#dropdownMenuButton-time').html(currentTime >= 10 ? `${currentTime}:00` : `0${currentTime}:00`)
284 334
}
285 335

  
286 336
function setTimeline () {
......
295 345
 */
296 346
// eslint-disable-next-line no-unused-vars
297 347
async function loadCurrentTimeHeatmap (opendataRoute, positionsRoute) {
348
  loadCheckboxDatasetNameData()
298 349
  dataSourceRoute = opendataRoute
299
  data = []
350
  positionsSourceRoute = positionsRoute
300 351
  const dataSourceMarks = {}
301 352
  const allPromises = []
302 353
  const date = $('#date').val()
303
  currentTime = parseInt($('#time').children('option:selected').val())
354
  currentTime = parseInt($('#dataset-dropdown-time input[type="radio"]:checked').val())
355

  
304 356
  setTimeline()
305 357
  data[currentTime] = {}
306 358
  const dataSelectedHandler = async (datasetName) => {
......
324 376

  
325 377
function drawDataSourceMarks (data) {
326 378
  if (marksLayer != null) {
327
    L.removeLayer(marksLayer)
379
    mymap.removeLayer(marksLayer)
328 380
  }
329 381
  marksLayer = L.layerGroup()
330 382
  Object.keys(data).forEach((key_) => {
......
350 402
  for (let nTime = time + change; nTime >= 0 && nTime <= 23; nTime = nTime + change) {
351 403
    if (!data[nTime]) {
352 404
      data[nTime] = {}
353
      datasetSelected.forEach(async (datasetName) => {
354
        data[nTime][datasetName] = await fetchByNameDate(dataSourceRoute, datasetName, date, nTime)
355
      })
356 405
    }
406
    datasetSelected.forEach(async (datasetName) => {
407
      if (!data[nTime][datasetName]) {
408
        data[nTime][datasetName] = await fetchByNameDate(dataSourceRoute, datasetName, date, nTime)
409
      }
410
    })
357 411
  }
358 412
}
359 413

  
......
496 550
  $('#dataset-dropdown').on('click', function (e) {
497 551
    e.stopPropagation()
498 552
  })
553

  
554
  $('#submit-btn').prop('name', '')
555
  onValueChangeRegister()
556
}
557
const loadCheckboxDatasetNameData = () => {
499 558
  datasetSelected = []
500 559
  $('#dataset-dropdown .dropdown-item').each(function () {
501 560
    const input = $(this).find('input')
......
505 564
    }
506 565
    datasetDictNameDisplayName[inputVal] = $(input).data('dataset-display-name')
507 566
  })
508
  $('#submit-btn').prop('name', '')
509 567
}

Také k dispozici: Unified diff