Skip to content

Commit d1bfe81

Browse files
committed
feat: improve timeline datepickers
- support start of week - add next/previous day buttons
1 parent 21c6744 commit d1bfe81

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/components/InputTimeInterval.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import 'vue-awesome/icons/arrow-left';
8787
import 'vue-awesome/icons/arrow-right';
8888
import { mapState } from 'pinia';
8989
import { useSettingsStore } from '~/stores/settings';
90+
import { get_first_day_of_week } from '~/util/time';
9091
9192
export default {
9293
name: 'input-timeinterval',
@@ -153,12 +154,7 @@ export default {
153154
return moment(this.start).add(this.maxDuration, 'seconds').isBefore(moment(this.end));
154155
},
155156
firstDayOfWeek() {
156-
const mapping = {
157-
Sunday: 0,
158-
Monday: 1,
159-
Saturday: 6,
160-
};
161-
return mapping[this.startOfWeek] !== undefined ? mapping[this.startOfWeek] : 1;
157+
return get_first_day_of_week(this.startOfWeek);
162158
},
163159
},
164160
mounted() {

src/components/QueryOptions.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import moment from 'moment';
1919
import { mapState } from 'pinia';
2020
import { useBucketsStore } from '~/stores/buckets';
2121
import { useSettingsStore } from '~/stores/settings';
22+
import { get_first_day_of_week } from '~/util/time';
2223
2324
export default Vue.extend({
2425
name: 'QueryOptions',
@@ -46,12 +47,7 @@ export default Vue.extend({
4647
return this.bucketsStore.hosts;
4748
},
4849
firstDayOfWeek() {
49-
const mapping = {
50-
Sunday: 0,
51-
Monday: 1,
52-
Saturday: 6,
53-
};
54-
return mapping[this.startOfWeek] !== undefined ? mapping[this.startOfWeek] : 1;
50+
return get_first_day_of_week(this.startOfWeek);
5551
},
5652
},
5753

src/util/time.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,12 @@ export function get_today_with_offset(offset?: string): string {
9494
const offset_dur = get_offset_duration(offset);
9595
return moment().subtract(offset_dur).startOf('day').format('YYYY-MM-DD');
9696
}
97+
98+
export function get_first_day_of_week(startOfWeek: string): number {
99+
const mapping: Record<string, number> = {
100+
Sunday: 0,
101+
Monday: 1,
102+
Saturday: 6,
103+
};
104+
return mapping[startOfWeek] !== undefined ? mapping[startOfWeek] : 1;
105+
}

0 commit comments

Comments
 (0)