Skip to content

Commit b985e56

Browse files
committed
getBreakDown block > add dropdown perios options similar to future transactions 7 30 90 180 #106.562
1 parent 4968196 commit b985e56

5 files changed

Lines changed: 220 additions & 121 deletions

File tree

client/dist/desktop/assets/app.js

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/dist/mobile/assets/app.js

Lines changed: 36 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/components/Dashboard/DetailsDashboard.vue

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
{{ dates }}
2626
</div>
2727
<div v-else>
28-
{{ $t(currentPeriod === 'from' ? rangeLabelFrom : rangeLabelTo) }}
28+
{{ rangeDisplayLabel }}
2929
</div>
3030
</div>
3131

@@ -35,14 +35,29 @@
3535
<span class="icon"><i class="fas fa-ellipsis-v" /></span>
3636
</button>
3737
</template>
38-
<ul class="menu">
38+
<ul class="menu custom-mb-0">
3939
<li>
4040
<a @click.prevent="setPeriod('from')"><span>{{ $t(rangeLabelFrom) }}</span></a>
4141
</li>
4242
<li>
4343
<a @click.prevent="setPeriod('to')"><span>{{ $t(rangeLabelTo) }}</span></a>
4444
</li>
4545
</ul>
46+
<hr class="custom-m-0">
47+
<ul class="menu custom-mt-0">
48+
<li>
49+
<a @click.prevent="setLocalBreakdownPeriod(7)"><span>{{ $t("nextDays", { count: 7 }) }}</span></a>
50+
</li>
51+
<li>
52+
<a @click.prevent="setLocalBreakdownPeriod(30)"><span>{{ $t("nextDays", { count: 30 }) }}</span></a>
53+
</li>
54+
<li>
55+
<a @click.prevent="setLocalBreakdownPeriod(90)"><span>{{ $t("nextDays", { count: 90 }) }}</span></a>
56+
</li>
57+
<li>
58+
<a @click.prevent="setLocalBreakdownPeriod(180)"><span>{{ $t("nextDays", { count: 180 }) }}</span></a>
59+
</li>
60+
</ul>
4661
</DropdownWaFloating>
4762
</div>
4863
</div>
@@ -84,6 +99,11 @@ import DetailsDashboardItem from './DetailsDashboardItem.vue'
8499
import UpdateDetailsInterval from '@/components/Modals/UpdateDetailsInterval'
85100
import ExportButton from '@/components/Buttons/ExportButton'
86101
import { getIntervalFromLabel } from '@/utils/getDateFromLocalStorage'
102+
import {
103+
clearLocalBreakdownToDays,
104+
getLocalBreakdownToDays,
105+
setLocalBreakdownToDays
106+
} from '@/utils/breakdownLocalPeriod'
87107
import DetailsDashboardEmpty from '../ContentBlocks/DetailsDashboardEmpty.vue'
88108
import DropdownWaFloating from '../Inputs/DropdownWaFloating.vue'
89109
@@ -115,7 +135,9 @@ export default {
115135
isFetching: false,
116136
rangeLabelFrom: '',
117137
rangeLabelTo: '',
118-
dashboardCurrentPeriod: readCurrentPeriodFromStorage()
138+
dashboardCurrentPeriod: readCurrentPeriodFromStorage(),
139+
suppressLocalBreakdownClear: false,
140+
localBreakdownToDays: getLocalBreakdownToDays()
119141
}
120142
},
121143
@@ -157,13 +179,35 @@ export default {
157179
}
158180
},
159181
160-
breakdownWatchKey () {
182+
breakdownIntervalKey () {
161183
const { from, to } = this.detailsInterval
162-
return `${from}|${to}|${this.queryParams.filter}`
184+
return `${from}|${to}`
185+
},
186+
187+
breakdownWatchKey () {
188+
return `${this.breakdownIntervalKey}|${this.queryParams.filter}`
189+
},
190+
191+
rangeDisplayLabel () {
192+
if (this.currentPeriod === 'from') {
193+
return this.$t(this.rangeLabelFrom)
194+
}
195+
if (this.localBreakdownToDays != null && this.isDefaultRange) {
196+
return this.$t('nextDays', { count: this.localBreakdownToDays })
197+
}
198+
return this.$t(this.rangeLabelTo)
163199
}
164200
},
165201
166202
watch: {
203+
breakdownIntervalKey (newKey, oldKey) {
204+
if (this.suppressLocalBreakdownClear) return
205+
if (oldKey != null && newKey !== oldKey) {
206+
clearLocalBreakdownToDays()
207+
this.localBreakdownToDays = null
208+
}
209+
},
210+
167211
breakdownWatchKey: {
168212
handler () {
169213
this.fetchBreakDown()
@@ -176,12 +220,24 @@ export default {
176220
fetchBreakDown () {
177221
this.rangeLabelFrom = getIntervalFromLabel('from')
178222
this.rangeLabelTo = getIntervalFromLabel('to')
223+
this.localBreakdownToDays = getLocalBreakdownToDays()
179224
180-
const today = new Date()
181-
const currentDate = today.toISOString().split('T')[0]
225+
const currentDate = this.$moment().format('YYYY-MM-DD')
226+
const localToDays = this.localBreakdownToDays
182227
183-
const from = !this.isDefaultRange ? this.detailsInterval.from : this.currentPeriod === 'from' ? this.detailsInterval.from : currentDate
184-
const to = !this.isDefaultRange ? this.detailsInterval.to : this.currentPeriod === 'to' ? this.detailsInterval.to : currentDate
228+
let from
229+
let to
230+
231+
if (!this.isDefaultRange) {
232+
from = this.detailsInterval.from
233+
to = this.detailsInterval.to
234+
} else if (localToDays != null) {
235+
from = currentDate
236+
to = this.$moment().add(localToDays, 'days').format('YYYY-MM-DD')
237+
} else {
238+
from = this.currentPeriod === 'from' ? this.detailsInterval.from : currentDate
239+
to = this.currentPeriod === 'to' ? this.detailsInterval.to : currentDate
240+
}
185241
186242
this.isFetching = true
187243
api
@@ -201,12 +257,29 @@ export default {
201257
},
202258
203259
setPeriod (period) {
260+
clearLocalBreakdownToDays()
261+
this.localBreakdownToDays = null
204262
this.currentPeriod = period
205263
if (!this.isDefaultRange) {
206264
this.$store.dispatch('transaction/resetDetailsInterval')
207265
} else {
208266
this.fetchBreakDown()
209267
}
268+
},
269+
270+
setLocalBreakdownPeriod (days) {
271+
setLocalBreakdownToDays(days)
272+
this.localBreakdownToDays = days
273+
this.currentPeriod = 'to'
274+
if (!this.isDefaultRange) {
275+
this.suppressLocalBreakdownClear = true
276+
this.$store.dispatch('transaction/resetDetailsInterval')
277+
this.$nextTick(() => {
278+
this.suppressLocalBreakdownClear = false
279+
})
280+
return
281+
}
282+
this.fetchBreakDown()
210283
}
211284
212285
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const STORAGE_KEY = 'cash_breakdown_local_to_days'
2+
3+
export function getLocalBreakdownToDays () {
4+
try {
5+
const raw = localStorage.getItem(STORAGE_KEY)
6+
if (raw == null || raw === '') return null
7+
const days = Number(raw)
8+
return Number.isFinite(days) && days > 0 ? days : null
9+
} catch (_) {
10+
return null
11+
}
12+
}
13+
14+
export function setLocalBreakdownToDays (days) {
15+
const value = Number(days)
16+
if (!Number.isFinite(value) || value <= 0) return
17+
try {
18+
localStorage.setItem(STORAGE_KEY, String(value))
19+
} catch (_) {}
20+
}
21+
22+
export function clearLocalBreakdownToDays () {
23+
try {
24+
localStorage.removeItem(STORAGE_KEY)
25+
} catch (_) {}
26+
}

js/app.js

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)