migrate statistics setting page to composition API and typescript

This commit is contained in:
MaysWind
2025-01-12 11:48:14 +08:00
parent c3265c5bf6
commit 1414f54a12
6 changed files with 425 additions and 247 deletions
@@ -0,0 +1,83 @@
import { computed } from 'vue';
import { useI18n } from '@/locales/helpers.ts';
import { useSettingsStore } from '@/stores/setting.ts';
import type { TypeAndDisplayName } from '@/core/base.ts';
import { type LocalizedDateRange, DateRangeScene } from '@/core/datetime.ts';
import { StatisticsAnalysisType } from '@/core/statistics.ts';
export function useStatisticsSettingPageBase() {
const {
getAllDateRanges,
getAllTimezoneTypesUsedForStatistics,
getAllCategoricalChartTypes,
getAllTrendChartTypes,
getAllStatisticsChartDataTypes,
getAllStatisticsSortingTypes
} = useI18n();
const settingsStore = useSettingsStore();
const allChartDataTypes = computed<TypeAndDisplayName[]>(() => getAllStatisticsChartDataTypes(StatisticsAnalysisType.CategoricalAnalysis));
const allTimezoneTypesUsedForStatistics = computed<TypeAndDisplayName[]>(() => getAllTimezoneTypesUsedForStatistics());
const allSortingTypes = computed<TypeAndDisplayName[]>(() => getAllStatisticsSortingTypes());
const allCategoricalChartTypes = computed<TypeAndDisplayName[]>(() => getAllCategoricalChartTypes());
const allCategoricalChartDateRanges = computed<LocalizedDateRange[]>(() => getAllDateRanges(DateRangeScene.Normal, false));
const allTrendChartTypes = computed<LocalizedDateRange[]>(() => getAllTrendChartTypes());
const allTrendChartDateRanges = computed<LocalizedDateRange[]>(() => getAllDateRanges(DateRangeScene.TrendAnalysis, false));
const defaultChartDataType = computed<number>({
get: () => settingsStore.appSettings.statistics.defaultChartDataType,
set: (value: number) => settingsStore.setStatisticsDefaultChartDataType(value)
});
const defaultTimezoneType = computed<number>({
get: () => settingsStore.appSettings.statistics.defaultTimezoneType,
set: (value: number) => settingsStore.setStatisticsDefaultTimezoneType(value)
});
const defaultSortingType = computed<number>({
get: () => settingsStore.appSettings.statistics.defaultSortingType,
set: (value: number) => settingsStore.setStatisticsSortingType(value)
});
const defaultCategoricalChartType = computed<number>({
get: () => settingsStore.appSettings.statistics.defaultCategoricalChartType,
set: (value: number) => settingsStore.setStatisticsDefaultCategoricalChartType(value)
});
const defaultCategoricalChartDateRange = computed<number>({
get: () => settingsStore.appSettings.statistics.defaultCategoricalChartDataRangeType,
set: (value: number) => settingsStore.setStatisticsDefaultCategoricalChartDateRange(value)
});
const defaultTrendChartType = computed<number>({
get: () => settingsStore.appSettings.statistics.defaultTrendChartType,
set: (value: number) => settingsStore.setStatisticsDefaultTrendChartType(value)
});
const defaultTrendChartDateRange = computed<number>({
get: () => settingsStore.appSettings.statistics.defaultTrendChartDataRangeType,
set: (value: number) => settingsStore.setStatisticsDefaultTrendChartDateRange(value)
});
return {
// computed states
allChartDataTypes,
allTimezoneTypesUsedForStatistics,
allSortingTypes,
allCategoricalChartTypes,
allCategoricalChartDateRanges,
allTrendChartTypes,
allTrendChartDateRanges,
defaultChartDataType,
defaultTimezoneType,
defaultSortingType,
defaultCategoricalChartType,
defaultCategoricalChartDateRange,
defaultTrendChartType,
defaultTrendChartDateRange
};
}
@@ -1,7 +1,7 @@
<template>
<v-row>
<v-col cols="12">
<v-card :title="$t('Statistics Settings')">
<v-card :title="tt('Statistics Settings')">
<v-form>
<v-card-text>
<v-row>
@@ -10,8 +10,8 @@
item-title="displayName"
item-value="type"
persistent-placeholder
:label="$t('Default Chart Data Type')"
:placeholder="$t('Default Chart Data Type')"
:label="tt('Default Chart Data Type')"
:placeholder="tt('Default Chart Data Type')"
:items="allChartDataTypes"
v-model="defaultChartDataType"
/>
@@ -22,8 +22,8 @@
item-title="displayName"
item-value="type"
persistent-placeholder
:label="$t('Timezone Used for Date Range')"
:placeholder="$t('Timezone Used for Date Range')"
:label="tt('Timezone Used for Date Range')"
:placeholder="tt('Timezone Used for Date Range')"
:items="allTimezoneTypesUsedForStatistics"
v-model="defaultTimezoneType"
/>
@@ -34,8 +34,8 @@
item-title="displayName"
item-value="type"
persistent-placeholder
:label="$t('Default Sort Order')"
:placeholder="$t('Default Sort Order')"
:label="tt('Default Sort Order')"
:placeholder="tt('Default Sort Order')"
:items="allSortingTypes"
v-model="defaultSortingType"
/>
@@ -47,7 +47,7 @@
</v-col>
<v-col cols="12">
<v-card :title="$t('Categorical Analysis Settings')">
<v-card :title="tt('Categorical Analysis Settings')">
<v-form>
<v-card-text>
<v-row>
@@ -56,8 +56,8 @@
item-title="displayName"
item-value="type"
persistent-placeholder
:label="$t('Default Chart Type')"
:placeholder="$t('Default Chart Type')"
:label="tt('Default Chart Type')"
:placeholder="tt('Default Chart Type')"
:items="allCategoricalChartTypes"
v-model="defaultCategoricalChartType"
/>
@@ -68,8 +68,8 @@
item-title="displayName"
item-value="type"
persistent-placeholder
:label="$t('Default Date Range')"
:placeholder="$t('Default Date Range')"
:label="tt('Default Date Range')"
:placeholder="tt('Default Date Range')"
:items="allCategoricalChartDateRanges"
v-model="defaultCategoricalChartDateRange"
/>
@@ -81,7 +81,7 @@
</v-col>
<v-col cols="12">
<v-card :title="$t('Trend Analysis Settings')">
<v-card :title="tt('Trend Analysis Settings')">
<v-form>
<v-card-text>
<v-row>
@@ -90,8 +90,8 @@
item-title="displayName"
item-value="type"
persistent-placeholder
:label="$t('Default Chart Type')"
:placeholder="$t('Default Chart Type')"
:label="tt('Default Chart Type')"
:placeholder="tt('Default Chart Type')"
:items="allTrendChartTypes"
v-model="defaultTrendChartType"
/>
@@ -102,8 +102,8 @@
item-title="displayName"
item-value="type"
persistent-placeholder
:label="$t('Default Date Range')"
:placeholder="$t('Default Date Range')"
:label="tt('Default Date Range')"
:placeholder="tt('Default Date Range')"
:items="allTrendChartDateRanges"
v-model="defaultTrendChartDateRange"
/>
@@ -124,101 +124,29 @@
</v-row>
</template>
<script>
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.ts';
import { DateRangeScene } from '@/core/datetime.ts';
import { StatisticsAnalysisType } from '@/core/statistics.ts';
<script setup lang="ts">
import AccountFilterSettingsCard from '@/views/desktop/common/cards/AccountFilterSettingsCard.vue';
import CategoryFilterSettingsCard from '@/views/desktop/common/cards/CategoryFilterSettingsCard.vue';
export default {
components: {
AccountFilterSettingsCard,
CategoryFilterSettingsCard
},
computed: {
...mapStores(useSettingsStore),
allChartDataTypes() {
return this.$locale.getAllStatisticsChartDataTypes(StatisticsAnalysisType.CategoricalAnalysis);
},
allTimezoneTypesUsedForStatistics() {
return this.$locale.getAllTimezoneTypesUsedForStatistics();
},
allSortingTypes() {
return this.$locale.getAllStatisticsSortingTypes();
},
allCategoricalChartTypes() {
return this.$locale.getAllCategoricalChartTypes();
},
allCategoricalChartDateRanges() {
return this.$locale.getAllDateRanges(DateRangeScene.Normal, false);
},
allTrendChartTypes() {
return this.$locale.getAllTrendChartTypes();
},
allTrendChartDateRanges() {
return this.$locale.getAllDateRanges(DateRangeScene.TrendAnalysis, false);
},
defaultChartDataType: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultChartDataType;
},
set: function (value) {
this.settingsStore.setStatisticsDefaultChartDataType(value);
}
},
defaultTimezoneType: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultTimezoneType;
},
set: function (value) {
this.settingsStore.setStatisticsDefaultTimezoneType(value);
}
},
defaultSortingType: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultSortingType;
},
set: function (value) {
this.settingsStore.setStatisticsSortingType(value);
}
},
defaultCategoricalChartType: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultCategoricalChartType;
},
set: function (value) {
this.settingsStore.setStatisticsDefaultCategoricalChartType(value);
}
},
defaultCategoricalChartDateRange: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultCategoricalChartDataRangeType;
},
set: function (value) {
this.settingsStore.setStatisticsDefaultCategoricalChartDateRange(value);
}
},
defaultTrendChartType: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultTrendChartType;
},
set: function (value) {
this.settingsStore.setStatisticsDefaultTrendChartType(value);
}
},
defaultTrendChartDateRange: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultTrendChartDataRangeType;
},
set: function (value) {
this.settingsStore.setStatisticsDefaultTrendChartDateRange(value);
}
},
}
};
import { useI18n } from '@/locales/helpers.ts';
import { useStatisticsSettingPageBase } from '@/views/base/statistics/StatisticsSettingPageBase.ts';
const { tt } = useI18n();
const {
allChartDataTypes,
allTimezoneTypesUsedForStatistics,
allSortingTypes,
allCategoricalChartTypes,
allCategoricalChartDateRanges,
allTrendChartTypes,
allTrendChartDateRanges,
defaultChartDataType,
defaultTimezoneType,
defaultSortingType,
defaultCategoricalChartType,
defaultCategoricalChartDateRange,
defaultTrendChartType,
defaultTrendChartDateRange
} = useStatisticsSettingPageBase();
</script>
+36 -103
View File
@@ -1,12 +1,12 @@
<template>
<f7-page>
<f7-navbar :title="$t('Statistics Settings')" :back-link="$t('Back')"></f7-navbar>
<f7-navbar :title="tt('Statistics Settings')" :back-link="tt('Back')"></f7-navbar>
<f7-block-title class="margin-top">{{ $t('Common Settings') }}</f7-block-title>
<f7-block-title class="margin-top">{{ tt('Common Settings') }}</f7-block-title>
<f7-list strong inset dividers>
<f7-list-item
:title="$t('Default Chart Data Type')"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: $t('Chart Data Type'), searchbarDisableText: $t('Cancel'), appendSearchbarNotFound: $t('No results'), popupCloseLinkText: $t('Done') }">
:title="tt('Default Chart Data Type')"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: tt('Chart Data Type'), searchbarDisableText: tt('Cancel'), appendSearchbarNotFound: tt('No results'), popupCloseLinkText: tt('Done') }">
<select v-model="defaultChartDataType">
<option :value="chartDataType.type"
:key="chartDataType.type"
@@ -15,8 +15,8 @@
</f7-list-item>
<f7-list-item
:title="$t('Timezone Used for Date Range')"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: $t('Timezone Type'), searchbarDisableText: $t('Cancel'), appendSearchbarNotFound: $t('No results'), popupCloseLinkText: $t('Done') }">
:title="tt('Timezone Used for Date Range')"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: tt('Timezone Type'), searchbarDisableText: tt('Cancel'), appendSearchbarNotFound: tt('No results'), popupCloseLinkText: tt('Done') }">
<select v-model="defaultTimezoneType">
<option :value="timezoneType.type"
:key="timezoneType.type"
@@ -24,13 +24,13 @@
</select>
</f7-list-item>
<f7-list-item :title="$t('Default Account Filter')" link="/settings/filter/account?type=statisticsDefault"></f7-list-item>
<f7-list-item :title="tt('Default Account Filter')" link="/settings/filter/account?type=statisticsDefault"></f7-list-item>
<f7-list-item :title="$t('Default Transaction Category Filter')" link="/settings/filter/category?type=statisticsDefault"></f7-list-item>
<f7-list-item :title="tt('Default Transaction Category Filter')" link="/settings/filter/category?type=statisticsDefault"></f7-list-item>
<f7-list-item
:title="$t('Default Sort Order')"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: $t('Sort Order'), searchbarDisableText: $t('Cancel'), appendSearchbarNotFound: $t('No results'), popupCloseLinkText: $t('Done') }">
:title="tt('Default Sort Order')"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: tt('Sort Order'), searchbarDisableText: tt('Cancel'), appendSearchbarNotFound: tt('No results'), popupCloseLinkText: tt('Done') }">
<select v-model="defaultSortingType">
<option :value="sortingType.type"
:key="sortingType.type"
@@ -39,11 +39,11 @@
</f7-list-item>
</f7-list>
<f7-block-title>{{ $t('Categorical Analysis Settings') }}</f7-block-title>
<f7-block-title>{{ tt('Categorical Analysis Settings') }}</f7-block-title>
<f7-list strong inset dividers>
<f7-list-item
:title="$t('Default Chart Type')"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: $t('Chart Type'), searchbarDisableText: $t('Cancel'), appendSearchbarNotFound: $t('No results'), popupCloseLinkText: $t('Done') }">
:title="tt('Default Chart Type')"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: tt('Chart Type'), searchbarDisableText: tt('Cancel'), appendSearchbarNotFound: tt('No results'), popupCloseLinkText: tt('Done') }">
<select v-model="defaultCategoricalChartType">
<option :value="chartType.type"
:key="chartType.type"
@@ -52,8 +52,8 @@
</f7-list-item>
<f7-list-item
:title="$t('Default Date Range')"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: $t('Date Range'), searchbarDisableText: $t('Cancel'), appendSearchbarNotFound: $t('No results'), popupCloseLinkText: $t('Done') }">
:title="tt('Default Date Range')"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: tt('Date Range'), searchbarDisableText: tt('Cancel'), appendSearchbarNotFound: tt('No results'), popupCloseLinkText: tt('Done') }">
<select v-model="defaultCategoricalChartDateRange">
<option :value="dateRange.type"
:key="dateRange.type"
@@ -62,11 +62,11 @@
</f7-list-item>
</f7-list>
<f7-block-title>{{ $t('Trend Analysis Settings') }}</f7-block-title>
<f7-block-title>{{ tt('Trend Analysis Settings') }}</f7-block-title>
<f7-list strong inset dividers>
<f7-list-item
:title="$t('Default Date Range')"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: $t('Date Range'), searchbarDisableText: $t('Cancel'), appendSearchbarNotFound: $t('No results'), popupCloseLinkText: $t('Done') }">
:title="tt('Default Date Range')"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: tt('Date Range'), searchbarDisableText: tt('Cancel'), appendSearchbarNotFound: tt('No results'), popupCloseLinkText: tt('Done') }">
<select v-model="defaultTrendChartDateRange">
<option :value="dateRange.type"
:key="dateRange.type"
@@ -77,90 +77,23 @@
</f7-page>
</template>
<script>
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.ts';
<script setup lang="ts">
import { useI18n } from '@/locales/helpers.ts';
import { useStatisticsSettingPageBase } from '@/views/base/statistics/StatisticsSettingPageBase.ts';
import { DateRangeScene } from '@/core/datetime.ts';
import { StatisticsAnalysisType } from '@/core/statistics.ts';
export default {
computed: {
...mapStores(useSettingsStore),
allChartDataTypes() {
return this.$locale.getAllStatisticsChartDataTypes(StatisticsAnalysisType.CategoricalAnalysis);
},
allTimezoneTypesUsedForStatistics() {
return this.$locale.getAllTimezoneTypesUsedForStatistics();
},
allSortingTypes() {
return this.$locale.getAllStatisticsSortingTypes();
},
allCategoricalChartTypes() {
return this.$locale.getAllCategoricalChartTypes();
},
allCategoricalChartDateRanges() {
return this.$locale.getAllDateRanges(DateRangeScene.Normal, false);
},
allTrendChartDateRanges() {
return this.$locale.getAllDateRanges(DateRangeScene.TrendAnalysis, false);
},
defaultChartDataType: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultChartDataType;
},
set: function (value) {
this.settingsStore.setStatisticsDefaultChartDataType(value);
}
},
defaultTimezoneType: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultTimezoneType;
},
set: function (value) {
this.settingsStore.setStatisticsDefaultTimezoneType(value);
}
},
defaultSortingType: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultSortingType;
},
set: function (value) {
this.settingsStore.setStatisticsSortingType(value);
}
},
defaultCategoricalChartType: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultCategoricalChartType;
},
set: function (value) {
this.settingsStore.setStatisticsDefaultCategoricalChartType(value);
}
},
defaultCategoricalChartDateRange: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultCategoricalChartDataRangeType;
},
set: function (value) {
this.settingsStore.setStatisticsDefaultCategoricalChartDateRange(value);
}
},
defaultTrendChartType: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultTrendChartType;
},
set: function (value) {
this.settingsStore.setStatisticsDefaultTrendChartType(value);
}
},
defaultTrendChartDateRange: {
get: function () {
return this.settingsStore.appSettings.statistics.defaultTrendChartDataRangeType;
},
set: function (value) {
this.settingsStore.setStatisticsDefaultTrendChartDateRange(value);
}
},
}
};
const { tt } = useI18n();
const {
allChartDataTypes,
allTimezoneTypesUsedForStatistics,
allSortingTypes,
allCategoricalChartTypes,
allCategoricalChartDateRanges,
allTrendChartDateRanges,
defaultChartDataType,
defaultTimezoneType,
defaultSortingType,
defaultCategoricalChartType,
defaultCategoricalChartDateRange,
defaultTrendChartDateRange
} = useStatisticsSettingPageBase();
</script>