Skip to content

Commit 5abfeee

Browse files
committed
feat: remember the calendar time filter selection after page reload
Save the calendar range as dateFilterStart/dateFilterEnd options and restore it on load when the calendar mode is active. A bound at the edge of the data (and Reset) is saved as open so new data stays visible. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Area52_Nader <86432017+NaderArea52@users.noreply.github.com>
1 parent 552bb59 commit 5abfeee

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

‎src/components/map/DateRangeFilter.vue‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
<script>
3636
import { NcButton, NcDateTimePicker } from '@nextcloud/vue'
37+
import optionsController from '../../optionsController.js'
3738
3839
export default {
3940
name: 'DateRangeFilter',
@@ -102,22 +103,25 @@ export default {
102103
if (!date) {
103104
return
104105
}
105-
this.$emit('range-change', {
106-
start: Math.floor(startOfDay(date.getTime() / 1000).getTime() / 1000),
107-
end: this.end,
108-
})
106+
this.changeRange(Math.floor(startOfDay(date.getTime() / 1000).getTime() / 1000), this.end)
109107
},
110108
onEndChange(date) {
111109
if (!date) {
112110
return
113111
}
114-
this.$emit('range-change', {
115-
start: this.start,
116-
end: Math.floor(endOfDay(date.getTime() / 1000).getTime() / 1000),
117-
})
112+
this.changeRange(this.start, Math.floor(endOfDay(date.getTime() / 1000).getTime() / 1000))
118113
},
119114
onReset() {
120-
this.$emit('range-change', { start: this.rangeMin, end: this.rangeMax })
115+
this.changeRange(this.rangeMin, this.rangeMax)
116+
},
117+
changeRange(start, end) {
118+
// remember the selection, a bound at the edge of the data is saved as open ('')
119+
// so data added later (e.g. new device points) is still shown after a page reload
120+
optionsController.saveOptionValues({
121+
dateFilterStart: start <= this.rangeMin ? '' : String(start),
122+
dateFilterEnd: end >= this.rangeMax ? '' : String(end),
123+
})
124+
this.$emit('range-change', { start, end })
121125
},
122126
},
123127
}

‎src/views/App.vue‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,16 @@ import { generateUrl } from '@nextcloud/router'
248248
import { placeFileOrFolder } from '../utils/photoPicker.ts'
249249
import { getClient } from '@nextcloud/files/dav'
250250

251+
// the calendar time filter remembers its last selection (the slider does not)
252+
function getSavedCalendarTimestamp(key, defaultValue) {
253+
const optionValues = optionsController.optionValues
254+
if (optionValues.displaySlider !== 'true' || optionValues.timeFilterMode !== 'calendar') {
255+
return defaultValue
256+
}
257+
const timestamp = parseInt(optionValues[key])
258+
return isNaN(timestamp) ? defaultValue : timestamp
259+
}
260+
251261
export default {
252262
name: 'App',
253263

@@ -281,8 +291,8 @@ export default {
281291
// slider
282292
sliderEnabled: optionsController.optionValues.displaySlider === 'true',
283293
timeFilterMode: optionsController.optionValues.timeFilterMode === 'calendar' ? 'calendar' : 'slider',
284-
sliderStart: 0,
285-
sliderEnd: moment().unix(),
294+
sliderStart: getSavedCalendarTimestamp('dateFilterStart', 0),
295+
sliderEnd: getSavedCalendarTimestamp('dateFilterEnd', moment().unix()),
286296
// action history
287297
lastActions: [],
288298
lastCanceledActions: [],

0 commit comments

Comments
 (0)