1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Display persistent summary interval into the front-end time picker

This commit is contained in:
Daste 2022-11-05 19:23:30 +01:00
parent 9586dbf781
commit ba81c07345
2 changed files with 19 additions and 4 deletions

View File

@ -2,8 +2,15 @@ PetiteVue.createApp({
$delimiters: ['${', '}'],
get currentInterval() {
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has('interval')) return urlParams.get('interval')
if (!urlParams.has('from') && !urlParams.has('to')) return 'today'
const cookies = new URLSearchParams(document.cookie.replaceAll('; ', '&'))
if (urlParams.has('interval'))
return urlParams.get('interval')
if (cookies.has('wakapi_summary_interval'))
return cookies.get('wakapi_summary_interval')
if (!urlParams.has('from') && !urlParams.has('to'))
return 'today'
return null
}
}).mount('#summary-page')

View File

@ -23,8 +23,16 @@ function TimePicker({ fromDate, toDate, timeSelection }) {
})
const query = new URLSearchParams(window.location.search)
if (query.has('interval')) {
const refEl = document.getElementById(`time-option-${query.get('interval')}`)
const cookies = new URLSearchParams(document.cookie.replaceAll('; ', '&'))
let interval = undefined;
if (query.has('interval'))
interval = query.get('interval')
else if (cookies.has('wakapi_summary_interval'))
interval = cookies.get('wakapi_summary_interval')
if (interval) {
const refEl = document.getElementById(`time-option-${interval}`)
this.timeSelection = refEl ? refEl.innerText : 'Unknown'
}
}