|
|
@@ -13,14 +13,15 @@ export default (langName, lang) => new Elysia({ prefix: `/history` })
|
|
|
const dateMap = Meteostanica.getDateMap()
|
|
|
|
|
|
const years = Object.keys(dateMap)
|
|
|
- const months = Object.keys(dateMap[years[years.length - 1]])
|
|
|
- const days = dateMap[years[years.length - 1]][months[months.length - 1]]
|
|
|
+ const selectedYear = years.find(i => i === year) ?? years[years.length - 1]
|
|
|
|
|
|
- const lastYear = years[years.length - 1]
|
|
|
- const lastMonth = months[months.length - 1]
|
|
|
- const lastDay = days[days.length - 1]
|
|
|
+ const months = Object.keys(dateMap[selectedYear])
|
|
|
+ const selectedMonth = months.find(i => i === month) ?? months[months.length - 1]
|
|
|
|
|
|
- const data = Meteostanica.getDataPropertyDaily(property, `${year ?? lastYear}-${month ?? lastMonth}-${day ?? lastDay}`)
|
|
|
+ const days = dateMap[selectedYear][selectedMonth]
|
|
|
+ const selectedDay = days.find(i => i === day) ?? days[days.length - 1]
|
|
|
+
|
|
|
+ const data = Meteostanica.getDataPropertyDaily(property, `${selectedYear}-${selectedMonth}-${selectedDay}`)
|
|
|
|
|
|
if (!data) {
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
@@ -28,20 +29,21 @@ export default (langName, lang) => new Elysia({ prefix: `/history` })
|
|
|
}
|
|
|
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
- return eta.render(`${langName}/history/property`, { lang, dateMap: { years, months, days, raw: dateMap }, type: `daily`, property, data })
|
|
|
+ return eta.render(`${langName}/history/property`, { lang, selected: { day: selectedDay, month: selectedMonth, year: selectedYear }, dateMap: { years, months, days, raw: dateMap }, type: `daily`, property, data })
|
|
|
})
|
|
|
.get(`/:property/daily`, ({ params: { property }, query: { day, month, year }, set }) => {
|
|
|
const dateMap = Meteostanica.getDateMap()
|
|
|
|
|
|
const years = Object.keys(dateMap)
|
|
|
- const months = Object.keys(dateMap[years[years.length - 1]])
|
|
|
- const days = dateMap[years[years.length - 1]][months[months.length - 1]]
|
|
|
+ const selectedYear = years.find(i => i === year) ?? years[years.length - 1]
|
|
|
+
|
|
|
+ const months = Object.keys(dateMap[selectedYear])
|
|
|
+ const selectedMonth = months.find(i => i === month) ?? months[months.length - 1]
|
|
|
|
|
|
- const lastYear = years[years.length - 1]
|
|
|
- const lastMonth = months[months.length - 1]
|
|
|
- const lastDay = days[days.length - 1]
|
|
|
+ const days = dateMap[selectedYear][selectedMonth]
|
|
|
+ const selectedDay = days.find(i => i === day) ?? days[days.length - 1]
|
|
|
|
|
|
- const data = Meteostanica.getDataPropertyDaily(property, `${year ?? lastYear}-${month ?? lastMonth}-${day ?? lastDay}`)
|
|
|
+ const data = Meteostanica.getDataPropertyDaily(property, `${selectedYear}-${selectedMonth}-${selectedDay}`)
|
|
|
|
|
|
if (!data) {
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
@@ -49,18 +51,18 @@ export default (langName, lang) => new Elysia({ prefix: `/history` })
|
|
|
}
|
|
|
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
- return eta.render(`${langName}/history/property`, { lang, dateMap: { years, months, days, raw: dateMap }, type: `daily`, property, data })
|
|
|
+ return eta.render(`${langName}/history/property`, { lang, selected: { day: selectedDay, month: selectedMonth, year: selectedYear }, dateMap: { years, months, days, raw: dateMap }, type: `daily`, property, data })
|
|
|
})
|
|
|
.get(`/:property/monthly`, ({ params: { property }, query: { month, year }, set }) => {
|
|
|
const dateMap = Meteostanica.getDateMap()
|
|
|
|
|
|
const years = Object.keys(dateMap)
|
|
|
- const months = Object.keys(dateMap[years[years.length - 1]])
|
|
|
+ const selectedYear = years.find(i => i === year) ?? years[years.length - 1]
|
|
|
|
|
|
- const lastYear = years[years.length - 1]
|
|
|
- const lastMonth = months[months.length - 1]
|
|
|
+ const months = Object.keys(dateMap[selectedYear])
|
|
|
+ const selectedMonth = months.find(i => i === month) ?? months[months.length - 1]
|
|
|
|
|
|
- const data = Meteostanica.getDataPropertyMonthly(property, `${year ?? lastYear}-${month ?? lastMonth}`)
|
|
|
+ const data = Meteostanica.getDataPropertyMonthly(property, `${selectedYear}-${selectedMonth}`)
|
|
|
|
|
|
if (!data) {
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
@@ -68,16 +70,15 @@ export default (langName, lang) => new Elysia({ prefix: `/history` })
|
|
|
}
|
|
|
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
- return eta.render(`${langName}/history/property`, { lang, dateMap: { years, months, raw: dateMap }, type: `monthly`, property, data })
|
|
|
+ return eta.render(`${langName}/history/property`, { lang, selected: { month: selectedMonth, year: selectedYear }, dateMap: { years, months, raw: dateMap }, type: `monthly`, property, data })
|
|
|
})
|
|
|
.get(`/:property/yearly`, ({ params: { property }, query: { year }, set }) => {
|
|
|
const dateMap = Meteostanica.getDateMap()
|
|
|
|
|
|
const years = Object.keys(dateMap)
|
|
|
+ const selectedYear = years.find(i => i === year) ?? years[years.length - 1]
|
|
|
|
|
|
- const lastYear = years[years.length - 1]
|
|
|
-
|
|
|
- const data = Meteostanica.getDataPropertyYearly(property, year ?? lastYear)
|
|
|
+ const data = Meteostanica.getDataPropertyYearly(property, selectedYear)
|
|
|
|
|
|
if (!data) {
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
@@ -85,7 +86,7 @@ export default (langName, lang) => new Elysia({ prefix: `/history` })
|
|
|
}
|
|
|
|
|
|
set.headers['content-type'] = 'text/html; charset=utf8'
|
|
|
- return eta.render(`${langName}/history/property`, { lang, dateMap: { years, raw: dateMap }, type: `yearly`, property, data })
|
|
|
+ return eta.render(`${langName}/history/property`, { lang, selected: { year: selectedYear }, dateMap: { years, raw: dateMap }, type: `yearly`, property, data })
|
|
|
})
|
|
|
.get(`/:property/allTime`, ({ params: { property }, set }) => {
|
|
|
const data = Meteostanica.getDataPropertyAllTime(property)
|