2022-01-02 20:30:22 +03:00
|
|
|
function TimePicker({ fromDate, toDate, timeSelection }) {
|
|
|
|
return {
|
|
|
|
$template: '#time-picker-template',
|
|
|
|
$delimiters: ['${', '}'],
|
|
|
|
state: {
|
|
|
|
showDropdownTimepicker: false
|
|
|
|
},
|
|
|
|
fromDate: fromDate,
|
|
|
|
toDate: toDate,
|
|
|
|
timeSelection: timeSelection,
|
2022-01-02 22:04:29 +03:00
|
|
|
intervalLink(interval) {
|
|
|
|
const queryParams = new URLSearchParams(window.location.search)
|
|
|
|
queryParams.set('interval', interval)
|
|
|
|
return `summary?${queryParams.toString()}`
|
|
|
|
},
|
2022-01-02 20:30:22 +03:00
|
|
|
onDateUpdated() {
|
|
|
|
document.getElementById('time-picker-form').submit()
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
window.addEventListener('click', (e) => {
|
|
|
|
const skip = findParentAttribute(e.target, 'data-trigger-for')?.value
|
|
|
|
Object.keys(this.state).filter(k => k !== skip).forEach(k => this.state[k] = false)
|
|
|
|
})
|
2022-01-02 16:30:28 +03:00
|
|
|
|
2022-01-02 20:30:22 +03:00
|
|
|
const query = new URLSearchParams(window.location.search)
|
2022-11-05 21:23:30 +03:00
|
|
|
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}`)
|
2022-01-02 20:30:22 +03:00
|
|
|
this.timeSelection = refEl ? refEl.innerText : 'Unknown'
|
|
|
|
}
|
2021-12-19 13:23:09 +03:00
|
|
|
}
|
|
|
|
}
|
2022-01-02 20:30:22 +03:00
|
|
|
}
|