2525 {{ dates }}
2626 </div >
2727 <div v-else >
28- {{ $t(currentPeriod === 'from' ? rangeLabelFrom : rangeLabelTo) }}
28+ {{ rangeDisplayLabel }}
2929 </div >
3030 </div >
3131
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'
8499import UpdateDetailsInterval from ' @/components/Modals/UpdateDetailsInterval'
85100import ExportButton from ' @/components/Buttons/ExportButton'
86101import { getIntervalFromLabel } from ' @/utils/getDateFromLocalStorage'
102+ import {
103+ clearLocalBreakdownToDays ,
104+ getLocalBreakdownToDays ,
105+ setLocalBreakdownToDays
106+ } from ' @/utils/breakdownLocalPeriod'
87107import DetailsDashboardEmpty from ' ../ContentBlocks/DetailsDashboardEmpty.vue'
88108import 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 }
0 commit comments