diff --git a/src/consts/currency.js b/src/consts/currency.js index 41f1dd6f..6fe3554a 100644 --- a/src/consts/currency.js +++ b/src/consts/currency.js @@ -1250,6 +1250,29 @@ const defaultCurrency = allCurrencies.USD.code; const defaultCurrencyDisplayType = allCurrencyDisplayType.SymbolBeforeAmount; const defaultCurrencyDisplayTypeValue = 0; +const allCurrencySortingTypes = { + Name: { + type: 0, + name: 'Currency Name' + }, + CurrencyCode: { + type: 1, + name: 'Currency Code' + }, + ExchangeRate: { + type: 2, + name: 'Exchange Rate' + } +}; + +const allCurrencySortingTypesArray = [ + allCurrencySortingTypes.Name, + allCurrencySortingTypes.CurrencyCode, + allCurrencySortingTypes.ExchangeRate +] + +const defaultCurrencySortingType = allCurrencySortingTypes.Name.type; + export default { parentAccountCurrencyPlaceholder: parentAccountCurrencyPlaceholder, defaultCurrencySymbol: defaultCurrencySymbol, @@ -1261,5 +1284,8 @@ export default { allCurrencyDisplayTypeArray: allCurrencyDisplayTypeArray, allCurrencyDisplayTypeMap: allCurrencyDisplayTypeMap, defaultCurrencyDisplayType: defaultCurrencyDisplayType, - defaultCurrencyDisplayTypeValue: defaultCurrencyDisplayTypeValue + defaultCurrencyDisplayTypeValue: defaultCurrencyDisplayTypeValue, + allCurrencySortingTypes: allCurrencySortingTypes, + allCurrencySortingTypesArray: allCurrencySortingTypesArray, + defaultCurrencySortingType: defaultCurrencySortingType }; diff --git a/src/lib/i18n.js b/src/lib/i18n.js index 8ce76941..29c6d467 100644 --- a/src/lib/i18n.js +++ b/src/lib/i18n.js @@ -872,6 +872,25 @@ function getAllCurrencyDisplayTypes(userStore, settingsStore, translateFn) { return ret; } +function getAllCurrencySortingTypes(translateFn) { + const allCurrencySortingTypes = []; + + for (const sortingTypeField in currencyConstants.allCurrencySortingTypes) { + if (!Object.prototype.hasOwnProperty.call(currencyConstants.allCurrencySortingTypes, sortingTypeField)) { + continue; + } + + const sortingType = currencyConstants.allCurrencySortingTypes[sortingTypeField]; + + allCurrencySortingTypes.push({ + type: sortingType.type, + displayName: translateFn(sortingType.name) + }); + } + + return allCurrencySortingTypes; +} + function getCurrentDecimalSeparator(translateFn, decimalSeparator) { let decimalSeparatorType = numeralConstants.allDecimalSeparatorMap[decimalSeparator]; @@ -1265,7 +1284,7 @@ function getAllTransactionDefaultCategories(categoryType, locale, translateFn) { return allCategories; } -function getAllDisplayExchangeRates(exchangeRatesData, translateFn) { +function getAllDisplayExchangeRates(settingsStore, exchangeRatesData, translateFn) { if (!exchangeRatesData || !exchangeRatesData.exchangeRates) { return []; } @@ -1282,9 +1301,28 @@ function getAllDisplayExchangeRates(exchangeRatesData, translateFn) { }); } - availableExchangeRates.sort(function(c1, c2) { - return c1.currencyDisplayName.localeCompare(c2.currencyDisplayName); - }) + if (settingsStore.appSettings.currencySortByInExchangeRatesPage === currencyConstants.allCurrencySortingTypes.Name.type) { + availableExchangeRates.sort(function(c1, c2) { + return c1.currencyDisplayName.localeCompare(c2.currencyDisplayName); + }); + } else if (settingsStore.appSettings.currencySortByInExchangeRatesPage === currencyConstants.allCurrencySortingTypes.CurrencyCode.type) { + availableExchangeRates.sort(function(c1, c2) { + return c1.currencyCode.localeCompare(c2.currencyCode); + }); + } else if (settingsStore.appSettings.currencySortByInExchangeRatesPage === currencyConstants.allCurrencySortingTypes.ExchangeRate.type) { + availableExchangeRates.sort(function(c1, c2) { + const rate1 = parseFloat(c1.rate); + const rate2 = parseFloat(c2.rate); + + if (rate1 > rate2) { + return 1; + } else if (rate1 < rate2) { + return -1; + } else { + return 0; + } + }); + } return availableExchangeRates; } @@ -1695,6 +1733,7 @@ export function i18nFunctions(i18nGlobal) { getAllDigitGroupingSymbols: () => getAllDigitGroupingSymbols(i18nGlobal.t), getAllDigitGroupingTypes: () => getAllDigitGroupingTypes(i18nGlobal.t), getAllCurrencyDisplayTypes: (settingsStore, userStore) => getAllCurrencyDisplayTypes(userStore, settingsStore, i18nGlobal.t), + getAllCurrencySortingTypes: () => getAllCurrencySortingTypes(i18nGlobal.t), getCurrentDecimalSeparator: (userStore) => getCurrentDecimalSeparator(i18nGlobal.t, userStore.currentUserDecimalSeparator), getCurrentDigitGroupingSymbol: (userStore) => getCurrentDigitGroupingSymbol(i18nGlobal.t, userStore.currentUserDigitGroupingSymbol), getCurrentDigitGroupingType: (userStore) => getCurrentDigitGroupingType(i18nGlobal.t, userStore.currentUserDigitGrouping), @@ -1717,7 +1756,7 @@ export function i18nFunctions(i18nGlobal) { getAllTransactionEditScopeTypes: () => getAllTransactionEditScopeTypes(i18nGlobal.t), getAllTransactionScheduledFrequencyTypes: () => getAllTransactionScheduledFrequencyTypes(i18nGlobal.t), getAllTransactionDefaultCategories: (categoryType, locale) => getAllTransactionDefaultCategories(categoryType, locale, i18nGlobal.t), - getAllDisplayExchangeRates: (exchangeRatesData) => getAllDisplayExchangeRates(exchangeRatesData, i18nGlobal.t), + getAllDisplayExchangeRates: (settingsStore, exchangeRatesData) => getAllDisplayExchangeRates(settingsStore, exchangeRatesData, i18nGlobal.t), getAllSupportedImportFileTypes: () => getAllSupportedImportFileTypes(i18nGlobal, i18nGlobal.t), getEnableDisableOptions: () => getEnableDisableOptions(i18nGlobal.t), getCategorizedAccountsWithDisplayBalance: (allVisibleAccounts, showAccountBalance, defaultCurrency, settingsStore, userStore, exchangeRatesStore) => getCategorizedAccountsWithDisplayBalance(allVisibleAccounts, showAccountBalance, defaultCurrency, userStore, settingsStore, exchangeRatesStore, i18nGlobal.t), diff --git a/src/lib/settings.js b/src/lib/settings.js index 7962b060..74ff0762 100644 --- a/src/lib/settings.js +++ b/src/lib/settings.js @@ -1,4 +1,5 @@ import timezoneConstants from '@/consts/timezone.js'; +import currencyConstants from '@/consts/currency.js'; import statisticsConstants from '@/consts/statistics.js'; const settingsLocalStorageKey = 'ebk_app_settings'; @@ -19,6 +20,7 @@ const defaultSettings = { showTotalAmountInTransactionListPage: true, showTagInTransactionListPage: true, showAccountBalance: true, + currencySortByInExchangeRatesPage: currencyConstants.defaultCurrencySortingType, statistics: { defaultChartDataType: statisticsConstants.defaultChartDataType, defaultTimezoneType: timezoneConstants.defaultTimezoneTypesUsedForStatistics, @@ -222,6 +224,14 @@ export function setShowAccountBalance(value) { setOption('showAccountBalance', value); } +export function getCurrencySortByInExchangeRatesPage() { + return getOption('currencySortByInExchangeRatesPage'); +} + +export function setCurrencySortByInExchangeRatesPage(value) { + setOption('currencySortByInExchangeRatesPage', value); +} + export function getStatisticsDefaultChartDataType() { return getSubOption('statistics', 'defaultChartDataType'); } diff --git a/src/locales/en.json b/src/locales/en.json index acb11f0f..8003a138 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1681,6 +1681,8 @@ "Automatically Save Draft": "Automatically Save Draft", "Show Confirmation Every Time": "Show Confirmation Every Time", "Automatically Add Geolocation": "Automatically Add Geolocation", + "Exchange Rates Data Page": "Exchange Rates Data Page", + "Exchange Rate": "Exchange Rate", "Enable Animation": "Enable Animation", "Basic Information": "Basic Information", "User Information": "User Information", diff --git a/src/locales/zh_Hans.json b/src/locales/zh_Hans.json index 114bf83c..7c71b834 100644 --- a/src/locales/zh_Hans.json +++ b/src/locales/zh_Hans.json @@ -1681,6 +1681,8 @@ "Automatically Save Draft": "自动保存草稿", "Show Confirmation Every Time": "每次提示确认", "Automatically Add Geolocation": "自动添加地理位置", + "Exchange Rates Data Page": "汇率数据页面", + "Exchange Rate": "汇率", "Enable Animation": "启用动画", "Basic Information": "基本信息", "User Information": "用户信息", diff --git a/src/stores/setting.js b/src/stores/setting.js index 28236905..f8f5b663 100644 --- a/src/stores/setting.js +++ b/src/stores/setting.js @@ -21,6 +21,7 @@ export const useSettingsStore = defineStore('settings', { showTotalAmountInTransactionListPage: settings.isShowTotalAmountInTransactionListPage(), showTagInTransactionListPage: settings.isShowTagInTransactionListPage(), showAccountBalance: settings.isShowAccountBalance(), + currencySortByInExchangeRatesPage: settings.getCurrencySortByInExchangeRatesPage(), statistics: { defaultChartDataType: settings.getStatisticsDefaultChartDataType(), defaultTimezoneType: settings.getStatisticsDefaultTimezoneType(), @@ -96,6 +97,10 @@ export const useSettingsStore = defineStore('settings', { settings.setShowAccountBalance(value); this.appSettings.showAccountBalance = value; }, + setCurrencySortByInExchangeRatesPage(value) { + settings.setCurrencySortByInExchangeRatesPage(value); + this.appSettings.currencySortByInExchangeRatesPage = value; + }, setStatisticsDefaultChartDataType(value) { settings.setStatisticsDefaultChartDataType(value); this.appSettings.statistics.defaultChartDataType = value; diff --git a/src/views/desktop/ExchangeRatesPage.vue b/src/views/desktop/ExchangeRatesPage.vue index 0b05b430..0d4d4c6e 100644 --- a/src/views/desktop/ExchangeRatesPage.vue +++ b/src/views/desktop/ExchangeRatesPage.vue @@ -176,7 +176,7 @@ export default { return exchangeRatesLastUpdateTime ? this.$locale.formatUnixTimeToLongDate(this.userStore, exchangeRatesLastUpdateTime) : ''; }, availableExchangeRates() { - return this.$locale.getAllDisplayExchangeRates(this.exchangeRatesData); + return this.$locale.getAllDisplayExchangeRates(this.settingsStore, this.exchangeRatesData); } }, created() { diff --git a/src/views/desktop/app/settings/tabs/AppBasicSettingTab.vue b/src/views/desktop/app/settings/tabs/AppBasicSettingTab.vue index 2728f801..2fff5519 100644 --- a/src/views/desktop/app/settings/tabs/AppBasicSettingTab.vue +++ b/src/views/desktop/app/settings/tabs/AppBasicSettingTab.vue @@ -177,6 +177,28 @@ + + + + + + + + + + + + + + @@ -206,6 +228,9 @@ export default { allTimezoneTypesUsedForStatistics() { return this.$locale.getAllTimezoneTypesUsedForStatistics(this.timeZone); }, + allCurrencySortingTypes() { + return this.$locale.getAllCurrencySortingTypes(); + }, theme: { get: function () { return this.settingsStore.appSettings.theme; @@ -310,6 +335,14 @@ export default { set: function (value) { this.settingsStore.setAutoGetCurrentGeoLocation(value); } + }, + currencySortByInExchangeRatesPage: { + get: function () { + return this.settingsStore.appSettings.currencySortByInExchangeRatesPage; + }, + set: function (value) { + this.settingsStore.setCurrencySortByInExchangeRatesPage(value); + } } }, setup() { diff --git a/src/views/mobile/ExchangeRatesPage.vue b/src/views/mobile/ExchangeRatesPage.vue index c74031a4..89434c06 100644 --- a/src/views/mobile/ExchangeRatesPage.vue +++ b/src/views/mobile/ExchangeRatesPage.vue @@ -120,7 +120,7 @@ export default { return exchangeRatesLastUpdateTime ? this.$locale.formatUnixTimeToLongDate(this.userStore, exchangeRatesLastUpdateTime) : ''; }, availableExchangeRates() { - return this.$locale.getAllDisplayExchangeRates(this.exchangeRatesData); + return this.$locale.getAllDisplayExchangeRates(this.settingsStore, this.exchangeRatesData); }, displayBaseAmount() { return this.$locale.formatAmount(this.userStore, this.baseAmount); diff --git a/src/views/mobile/settings/PageSettingsPage.vue b/src/views/mobile/settings/PageSettingsPage.vue index d5c97002..cfe1eb49 100644 --- a/src/views/mobile/settings/PageSettingsPage.vue +++ b/src/views/mobile/settings/PageSettingsPage.vue @@ -48,6 +48,19 @@ + + {{ $t('Exchange Rates Data Page') }} + + + + + @@ -63,6 +76,9 @@ export default { allTimezoneTypesUsedForStatistics() { return this.$locale.getAllTimezoneTypesUsedForStatistics(); }, + allCurrencySortingTypes() { + return this.$locale.getAllCurrencySortingTypes(); + }, showAmountInHomePage: { get: function () { return this.settingsStore.appSettings.showAmountInHomePage; @@ -115,6 +131,14 @@ export default { set: function (value) { this.settingsStore.setAutoGetCurrentGeoLocation(value); } + }, + currencySortByInExchangeRatesPage: { + get: function () { + return this.settingsStore.appSettings.currencySortByInExchangeRatesPage; + }, + set: function (value) { + this.settingsStore.setCurrencySortByInExchangeRatesPage(value); + } } } };