Skip to content

Commit dd96bfa

Browse files
committed
feat: make it possible to specify the starting month of a year
closes #45
1 parent 3200363 commit dd96bfa

File tree

21 files changed

+100
-32
lines changed

21 files changed

+100
-32
lines changed

src/app/components/base/select/Select.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div :class="$style.select">
33
<label :for="fieldId" :class="$style.label">{{ label }}</label>
44

5-
<ContextMenu tooltip-position="bottom" :options="options" position="bottom" @select="modelValue = $event.id">
5+
<ContextMenu tooltip-position="bottom" :options="options" position="bottom-start" @select="modelValue = $event.id">
66
<template #default="{ toggle }">
77
<button :id="fieldId" :class="$style.btn" type="button" @click="toggle">
88
{{ currentValue }}

src/app/components/feature/BudgetGroups.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,18 @@ import { computed } from 'vue';
6868
import { useI18n } from 'vue-i18n';
6969
import BudgetGroup from './BudgetGroup.vue';
7070
import type { Component } from 'vue';
71+
import { useSettingsStore } from '@store/settings';
7172
7273
const props = defineProps<{
7374
type: 'expenses' | 'income';
7475
}>();
7576
7677
const { state, moveBudgetGroup, moveBudgetIntoGroup, addBudgetGroup, getBudgetGroup, isCurrentMonth } = useDataStore();
78+
const { state: settings } = useSettingsStore();
7779
const { t } = useI18n();
7880
7981
const groups = computed(() => state[props.type]);
80-
const months = useMonthNames();
82+
const months = useMonthNames('long', () => settings.general.monthOffset);
8183
8284
const totals = computed(() => {
8385
const totals = new Array(12).fill(0);
@@ -146,7 +148,7 @@ const reorder = (evt: ReorderEvent) => {
146148
147149
position: sticky;
148150
position: -webkit-sticky;
149-
top: 0px;
151+
top: 0;
150152
background: var(--app-background);
151153
border: 2px var(--app-background);
152154

src/app/pages/dashboard/summary/widgets/charts/DevelopmentChart.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ import { computed } from 'vue';
1313
import { useI18n } from 'vue-i18n';
1414
import { LineChartConfig } from './line-chart/LineChart.types';
1515
import LineChart from './line-chart/LineChart.vue';
16+
import { useSettingsStore } from '@store/settings';
1617
1718
const props = defineProps<{
1819
class?: ClassNames;
1920
}>();
2021
21-
const months = useMonthNames();
2222
const { state } = useDataStore();
23+
const { state: settings } = useSettingsStore();
2324
const { t, locale } = useI18n();
25+
const months = useMonthNames('long', () => settings.general.monthOffset);
2426
2527
const classes = computed(() => props.class);
2628
const isEmpty = computed(() => {

src/app/pages/dashboard/summary/widgets/tables/GroupsSummaryTable.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { average, ClassNames, sum, add } from '@utils';
5757
import { DeepReadonly, computed } from 'vue';
5858
import { useI18n } from 'vue-i18n';
5959
import SummaryTable from './SummaryTable.vue';
60+
import { useSettingsStore } from '@store/settings';
6061
6162
const props = defineProps<{
6263
class?: ClassNames;
@@ -66,7 +67,8 @@ const props = defineProps<{
6667
6768
const { t, n } = useI18n();
6869
const { isCurrentMonth } = useDataStore();
69-
const months = useMonthNames();
70+
const { state: settings } = useSettingsStore();
71+
const months = useMonthNames('long', () => settings.general.monthOffset);
7072
7173
const flatted = computed(() => flatten(props.groups));
7274
</script>

src/app/pages/dashboard/summary/widgets/tables/TotalsSummaryTable.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import { aggregate, average, subtract, sum } from '@utils';
7171
import { computed } from 'vue';
7272
import { useI18n } from 'vue-i18n';
7373
import SummaryTable from './SummaryTable.vue';
74+
import { useSettingsStore } from '@store/settings';
7475
7576
const props = withDefaults(
7677
defineProps<{
@@ -85,7 +86,8 @@ const props = withDefaults(
8586
8687
const { t, n } = useI18n();
8788
const { isCurrentMonth } = useDataStore();
88-
const months = useMonthNames();
89+
const { state: settings } = useSettingsStore();
90+
const months = useMonthNames('long', () => settings.general.monthOffset);
8991
9092
const netSavings = computed(() => subtract(props.income, props.expenses));
9193
const endingBalance = computed(() => aggregate(netSavings.value));

src/app/pages/navigation/settings/SettingsDialog.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
:options="currencies"
1515
@update:model-value="changeCurrency($event as AvailableCurrency)"
1616
/>
17+
18+
<Select
19+
:model-value="settings.general.monthOffset"
20+
:label="t('navigation.settings.firstMonthOfYear')"
21+
:options="months"
22+
@update:model-value="setMonthOffset($event as number)"
23+
/>
1724
</div>
1825
</Dialog>
1926
</template>
@@ -28,6 +35,8 @@ import { useDataStore } from '@store/state';
2835
import { ContextMenuOption } from '@components/base/context-menu/ContextMenu.types.ts';
2936
import Select from '@components/base/select/Select.vue';
3037
import { availableCurrencies, AvailableCurrency } from '@store/state/types.ts';
38+
import { useSettingsStore } from '@store/settings';
39+
import { useMonthNames } from '@composables';
3140
3241
const emit = defineEmits<{
3342
(e: 'close'): void;
@@ -38,7 +47,9 @@ defineProps<{
3847
}>();
3948
4049
const { t, locale } = useI18n();
50+
const { setMonthOffset, state: settings } = useSettingsStore();
4151
const { changeCurrency, changeLocale, state } = useDataStore();
52+
const monthNames = useMonthNames();
4253
4354
const locales = computed<ContextMenuOption[]>(() => {
4455
const displayNames = new Intl.DisplayNames(initialLocale, { type: 'language' });
@@ -58,6 +69,14 @@ const currencies = computed<ContextMenuOption[]>(() =>
5869
}))
5970
);
6071
72+
const months = computed<ContextMenuOption[]>(() =>
73+
monthNames.value.map((value, index) => ({
74+
id: index,
75+
label: value,
76+
icon: settings.general.monthOffset === index ? RiCheckLine : undefined
77+
}))
78+
);
79+
6180
const formatNumber = (locale: string, currency: string, currencyDisplay?: Intl.NumberFormatOptionsCurrencyDisplay) => {
6281
const symbol = new Intl.NumberFormat(locale, {
6382
style: 'currency',

src/composables/useMonthNames.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import { computed, ComputedRef } from 'vue';
1+
import { computed, ComputedRef, MaybeRefOrGetter, toValue } from 'vue';
22
import { useI18n } from 'vue-i18n';
33

4-
export const useMonthNames = (format: Intl.DateTimeFormatOptions['month'] = 'long'): ComputedRef<string[]> => {
4+
export const useMonthNames = (
5+
format: Intl.DateTimeFormatOptions['month'] = 'long',
6+
offset: MaybeRefOrGetter<number> = 0
7+
): ComputedRef<string[]> => {
58
const { locale } = useI18n();
69

710
return computed(() => {
11+
const resolvedOffset = toValue(offset);
812
const list = [];
913

1014
for (let i = 0; i < 12; i++) {
1115
list.push(
12-
new Date(0, i).toLocaleDateString(locale.value, {
16+
new Date(0, (i + resolvedOffset) % 12).toLocaleDateString(locale.value, {
1317
month: format
1418
})
1519
);

src/i18n/locales/cze.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
"settings": {
8383
"settings": "Nastavení",
8484
"language": "Jazyk",
85-
"currency": "Měna"
85+
"currency": "Měna",
86+
"firstMonthOfYear": "První měsíc roku"
8687
}
8788
},
8889
"shared": {

src/i18n/locales/de.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
"settings": {
8383
"settings": "Einstellungen",
8484
"language": "Sprache",
85-
"currency": "Währung"
85+
"currency": "Währung",
86+
"firstMonthOfYear": "Erster Monat des Jahres"
8687
}
8788
},
8889
"shared": {

src/i18n/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
"settings": {
8383
"settings": "Settings",
8484
"language": "Language",
85-
"currency": "Currency"
85+
"currency": "Currency",
86+
"firstMonthOfYear": "First month of the year"
8687
}
8788
},
8889
"shared": {

0 commit comments

Comments
 (0)