Projekt

Obecné

Profil

« Předchozí | Další » 

Revize bf634c97

Přidáno uživatelem Tomáš před více než 3 roky(ů)

fixed

Zobrazit rozdíly:

website/public/js/index.js
69 69

  
70 70

  
71 71

  
72
function onDocumentReady() {
72
const onDocumentReady = () => {
73 73
  $('#dropdown-dataset').on('click', function (e) {
74 74
    e.stopPropagation()
75 75
  })
......
85 85

  
86 86

  
87 87
/* ------------ DATA FETCHERS ------------ */
88

  
89
const fetchByNameDate = async (baseRoute, name, date, currentTime) => {
88
const genericFetch = async (route, method) => {
90 89
  const headers = new Headers()
91
  const myRequest = new Request(baseRoute + '/' + name + '/' + date + '/' + currentTime, {
92
    method: 'GET',
90
  const myRequest = new Request(route, {
91
    method: method,
93 92
    headers: headers
94 93
  })
95 94
  const beforeJson = await fetch(myRequest)
96 95

  
97 96
  return beforeJson.json()
98 97
}
98
const fetchByNameDate = async (baseRoute, name, date, currentTime) => {
99
  return await genericFetch(baseRoute + '/' + name + '/' + date + '/' + currentTime, 'GET')
100
}
99 101

  
100 102
const fetchDataSourceMarks = async (positionRoute, datasetName) => {
101
  const headers = new Headers()
102
  const myRequest = new Request(positionRoute + '/' + datasetName, {
103
    method: 'GET',
104
    headers: headers
105
  })
106
  const beforeJson = await fetch(myRequest)
107

  
108
  return beforeJson.json()
103
    return await genericFetch(positionRoute + '/' + datasetName, 'GET')
109 104
}
110 105

  
111
async function preload(time, change, date) {
106
preload = async (time, change, date) => {
112 107
  loadingY()
113 108

  
114 109
  for (let nTime = time + change; nTime >= 0 && nTime <= 23; nTime = nTime + change) {
......
170 165
 * Checks dataset availibility
171 166
 * @param {string} route authority for datasets availibility checks
172 167
 */
173
const checkDataSetsAvailability = (route) => {
174
  $.ajax({
175
    type: 'POST',
176
    // Todo it might be good idea to change db collections format
177
    url: route + '/' + currentDateToString(),
178
    success: function (result) {
179
      updateAvailableDataSets(result)
180
    }
181
  })
168
const checkDataSetsAvailability = async (route) => {
169
  const result = await genericFetch(route + '/' + currentDateToString(), 'POST')
170
  updateAvailableDataSets(result)
182 171
}
183 172

  
184 173

  
......
204 193
  mymap.on('click', function (e) { showInfo(e) })
205 194
}
206 195

  
207
function setMapView(latitude, longitude, zoom) {
196
const setMapView = (latitude, longitude, zoom) => {
208 197
  localStorage.setItem('lat', latitude)
209 198
  localStorage.setItem('lng', longitude)
210 199
  localStorage.setItem('zoom', zoom)
......
725 714
  $('#dropdownMenuButtonTime').html(formatTime(currentTime, true))
726 715
}
727 716

  
728
const initDatepicker = (availableDatesSource) => {
717
const initDatepicker = async (availableDatesSource) => {
729 718
  var availableDates = ''
730

  
731
  $.ajax({
732
    type: 'GET',
733
    url: availableDatesSource,
734
    success: function (result) {
735
      availableDates = String(result).split(',')
736
    }
737
  }).then(function () {
738
    $('#date').datepicker({
739
      format: 'yyyy-mm-dd',
740
      language: 'cs',
741
      beforeShowDay: function (date) {
742
        if (availableDates.indexOf(formatDate(date)) < 0) {
743
          return { enabled: false, tooltip: 'Žádná data' }
744
        } else {
745
          return { enabled: true }
746
        }
747
      },
748
      autoclose: true
749
    })
719
  const result = await genericFetch(availableDatesSource, 'GET')
720
  availableDates = String(result).split(',')
721
  $('#date').datepicker({
722
    format: 'yyyy-mm-dd',
723
    language: 'cs',
724
    beforeShowDay: function (date) {
725
      if (availableDates.indexOf(formatDate(date)) < 0) {
726
        return { enabled: false, tooltip: 'Žádná data' }
727
      } else {
728
        return { enabled: true }
729
      }
730
    },
731
    autoclose: true
750 732
  })
751 733
}
752 734

  

Také k dispozici: Unified diff