Restore selected date-range for transaction list
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
217ddbbf44
commit
81b50f9dc7
2 changed files with 25 additions and 2 deletions
|
@ -17,6 +17,7 @@
|
||||||
<div class="col d-flex align-items-center justify-content-end">
|
<div class="col d-flex align-items-center justify-content-end">
|
||||||
<range-selector
|
<range-selector
|
||||||
v-model="timeRange"
|
v-model="timeRange"
|
||||||
|
store-key="account-overview"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -84,8 +84,14 @@ export default {
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
const date = new Date()
|
const date = new Date()
|
||||||
const start = this.modelValue.start || new Date(date.getFullYear(), date.getMonth(), 1)
|
let start = this.modelValue.start || new Date(date.getFullYear(), date.getMonth(), 1)
|
||||||
const end = this.modelValue.end || new Date(date.getFullYear(), date.getMonth() + 1, 0)
|
let end = this.modelValue.end || new Date(date.getFullYear(), date.getMonth() + 1, 0)
|
||||||
|
|
||||||
|
if (this.storeKey && localStorage.getItem(`accounting:range-select:${this.storeKey}`)) {
|
||||||
|
const stored = JSON.parse(localStorage.getItem(`accounting:range-select:${this.storeKey}`))
|
||||||
|
start = new Date(stored.start)
|
||||||
|
end = new Date(stored.end)
|
||||||
|
}
|
||||||
|
|
||||||
this.dateComponents = {
|
this.dateComponents = {
|
||||||
fromMonth: start.getMonth(),
|
fromMonth: start.getMonth(),
|
||||||
|
@ -116,6 +122,17 @@ export default {
|
||||||
} else {
|
} else {
|
||||||
this.end = new Date(this.dateComponents.fromYear, this.dateComponents.fromMonth + 1, 1, 0)
|
this.end = new Date(this.dateComponents.fromYear, this.dateComponents.fromMonth + 1, 1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.storeKey) {
|
||||||
|
localStorage.setItem(
|
||||||
|
`accounting:range-select:${this.storeKey}`,
|
||||||
|
JSON.stringify({
|
||||||
|
end: new Date(this.dateComponents.toYear, this.dateComponents.toMonth, 1),
|
||||||
|
start: new Date(this.dateComponents.fromYear, this.dateComponents.fromMonth, 1),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
this.$emit('update:modelValue', { end: this.end, start: this.start })
|
this.$emit('update:modelValue', { end: this.end, start: this.start })
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -146,6 +163,11 @@ export default {
|
||||||
default: 2020,
|
default: 2020,
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
storeKey: {
|
||||||
|
default: null,
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
|
|
Loading…
Reference in a new issue