diff --git a/src/filters/exchangeRate.js b/src/filters/exchangeRate.js
new file mode 100644
index 00000000..b886e200
--- /dev/null
+++ b/src/filters/exchangeRate.js
@@ -0,0 +1,32 @@
+export default function (oldRate, currentCurrency, allExchangeRates) {
+ const exchangeRateMap = {};
+
+ for (let i = 0; i < allExchangeRates.length; i++) {
+ const exchangeRate = allExchangeRates[i];
+ exchangeRateMap[exchangeRate.currency] = exchangeRate;
+ }
+
+ const toCurrencyExchangeRate = exchangeRateMap[currentCurrency];
+
+ if (!toCurrencyExchangeRate) {
+ return '';
+ }
+
+ const newRate = parseFloat(oldRate) / parseFloat(toCurrencyExchangeRate.rate);
+ const newRateStr = newRate.toString();
+
+ if (newRateStr.indexOf('.') < 0) {
+ return newRateStr;
+ } else {
+ let firstNonZeroPos = 0;
+
+ for (let i = 0; i < newRateStr.length; i++) {
+ if (newRateStr.charAt(i) !== '.' && newRateStr.charAt(i) !== '0') {
+ firstNonZeroPos = Math.min(i + 4, newRateStr.length);
+ break;
+ }
+ }
+
+ return newRateStr.substr(0, Math.max(6, Math.max(firstNonZeroPos, newRateStr.indexOf('.') + 2)));
+ }
+}
diff --git a/src/filters/optionName.js b/src/filters/optionName.js
index 0cc05adb..35f1c4ad 100644
--- a/src/filters/optionName.js
+++ b/src/filters/optionName.js
@@ -1,27 +1,43 @@
import utils from '../lib/utils.js';
-export default function (value, options, keyName, valueName) {
+export default function (value, options, keyField, nameField, defaultName) {
if (utils.isArray(options)) {
- for (let i = 0; i < options.length; i++) {
- const option = options[i];
+ if (keyField) {
+ for (let i = 0; i < options.length; i++) {
+ const option = options[i];
- if (option[keyName] === value) {
- return option[valueName];
+ if (option[keyField] === value) {
+ return option[nameField];
+ }
+ }
+ } else {
+ if (options[value]) {
+ const option = options[value];
+
+ return option[nameField];
}
}
} else if (utils.isObject(options)) {
- for (let key in options) {
- if (!Object.prototype.hasOwnProperty.call(options, key)) {
- continue;
+ if (keyField) {
+ for (let key in options) {
+ if (!Object.prototype.hasOwnProperty.call(options, key)) {
+ continue;
+ }
+
+ const option = options[key];
+
+ if (option[keyField] === value) {
+ return option[nameField];
+ }
}
+ } else {
+ if (options[value]) {
+ const option = options[value];
- const option = options[key];
-
- if (option[keyName] === value) {
- return option[valueName];
+ return option[nameField];
}
}
}
- return '';
+ return defaultName;
}
diff --git a/src/mobile-main.js b/src/mobile-main.js
index 1274789f..c084f201 100644
--- a/src/mobile-main.js
+++ b/src/mobile-main.js
@@ -77,6 +77,7 @@ import optionNameFilter from './filters/optionName.js';
import itemFieldContentFilter from './filters/itemFieldContent.js';
import languageNameFilter from './filters/languageName.js';
import currencyFilter from './filters/currency.js';
+import exchangeRateFilter from './filters/exchangeRate.js';
import utcOffsetFilter from './filters/utcOffset.js';
import textLimitFilter from './filters/textLimit.js';
import iconFilter from './filters/icon.js';
@@ -161,10 +162,11 @@ Vue.filter('localized', (value, options) => localizedFilter({ i18n }, value, opt
Vue.filter('moment', (value, format, options) => momentFilter(value, format, options));
Vue.filter('percent', (value, precision, lowPrecisionValue) => percentFilter(value, precision, lowPrecisionValue));
Vue.filter('format', (value, format) => formatFilter(value, format));
-Vue.filter('optionName', (value, options, keyName, valueName) => optionNameFilter(value, options, keyName, valueName));
+Vue.filter('optionName', (value, options, keyField, nameField, defaultName) => optionNameFilter(value, options, keyField, nameField, defaultName));
Vue.filter('itemFieldContent', (value, fieldName, defaultValue, translate) => itemFieldContentFilter({ i18n }, value, fieldName, defaultValue, translate));
Vue.filter('languageName', (languageCode) => languageNameFilter(languageCode));
Vue.filter('currency', (value, currencyCode) => currencyFilter({ i18n }, value, currencyCode));
+Vue.filter('exchangeRate', (value, currentCurrency, allExchangeRates) => exchangeRateFilter(value, currentCurrency, allExchangeRates));
Vue.filter('utcOffset', (value) => utcOffsetFilter(value));
Vue.filter('textLimit', (value, maxLength) => textLimitFilter(value, maxLength));
Vue.filter('icon', (value, iconType) => iconFilter(value, iconType));
diff --git a/src/views/mobile/ExchangeRates.vue b/src/views/mobile/ExchangeRates.vue
index d97d7dd3..9320eb9f 100644
--- a/src/views/mobile/ExchangeRates.vue
+++ b/src/views/mobile/ExchangeRates.vue
@@ -34,7 +34,7 @@
+ :after="exchangeRate.rate | exchangeRate(baseCurrency, exchangeRatesData.exchangeRates)">
@@ -145,40 +145,6 @@ export default {
}
});
}
- },
- filters: {
- exchangeRate(oldRate, exchangeRates, currentCurrency) {
- const exchangeRateMap = {};
-
- for (let i = 0; i < exchangeRates.length; i++) {
- const exchangeRate = exchangeRates[i];
- exchangeRateMap[exchangeRate.currency] = exchangeRate;
- }
-
- const toCurrencyExchangeRate = exchangeRateMap[currentCurrency];
-
- if (!toCurrencyExchangeRate) {
- return '';
- }
-
- const newRate = parseFloat(oldRate) / parseFloat(toCurrencyExchangeRate.rate);
- const newRateStr = newRate.toString();
-
- if (newRateStr.indexOf('.') < 0) {
- return newRateStr;
- } else {
- let firstNonZeroPos = 0;
-
- for (let i = 0; i < newRateStr.length; i++) {
- if (newRateStr.charAt(i) !== '.' && newRateStr.charAt(i) !== '0') {
- firstNonZeroPos = Math.min(i + 4, newRateStr.length);
- break;
- }
- }
-
- return newRateStr.substr(0, Math.max(6, Math.max(firstNonZeroPos, newRateStr.indexOf('.') + 2)));
- }
- }
}
}
diff --git a/src/views/mobile/Home.vue b/src/views/mobile/Home.vue
index c14b72a8..3d357b6f 100644
--- a/src/views/mobile/Home.vue
+++ b/src/views/mobile/Home.vue
@@ -13,7 +13,7 @@
Expense
@@ -301,9 +301,6 @@ export default {
}
return amount + (incomplete ? '+' : '');
- },
- monthNameLocalizedKey(monthName) {
- return `datetime.${monthName}.long`;
}
}
}
diff --git a/src/views/mobile/accounts/Edit.vue b/src/views/mobile/accounts/Edit.vue
index 5757a27e..c3dabb7a 100644
--- a/src/views/mobile/accounts/Edit.vue
+++ b/src/views/mobile/accounts/Edit.vue
@@ -25,7 +25,7 @@
class="list-item-with-header-and-title"
link="#"
:header="$t('Account Category')"
- :title="account.category | accountCategoryName(allAccountCategories) | localized"
+ :title="account.category | optionName(allAccountCategories, 'id', 'name') | localized"
@click="showAccountCategorySheet = true"
>
@@ -390,6 +390,15 @@ export default {
allAccountCategories() {
return this.$constants.account.allCategories;
},
+ allAccountTypes() {
+ return [{
+ id: 1,
+ name: 'Single Account'
+ }, {
+ id: 2,
+ name: 'Multi Sub Accounts'
+ }];
+ },
allAccountIcons() {
return this.$constants.icons.allAccountIcons;
},
@@ -668,26 +677,6 @@ export default {
return null;
}
}
- },
- filters: {
- accountCategoryName(categoryId, allCategories) {
- for (let i = 0; i < allCategories.length; i++) {
- if (allCategories[i].id === categoryId) {
- return allCategories[i].name;
- }
- }
-
- return '';
- },
- accountTypeName(type) {
- if (type === 1) {
- return 'Single Account';
- } else if (type === 2) {
- return 'Multi Sub Accounts';
- }
-
- return '';
- }
}
}
diff --git a/src/views/mobile/statistics/Transaction.vue b/src/views/mobile/statistics/Transaction.vue
index ba4de4df..35ace98b 100644
--- a/src/views/mobile/statistics/Transaction.vue
+++ b/src/views/mobile/statistics/Transaction.vue
@@ -4,7 +4,7 @@
- {{ query.chartDataType | chartDataTypeName(allChartDataTypes) | localized }}
+ {{ query.chartDataType | optionName(allChartDataTypes, 'type', 'name', 'Statistics') | localized }}
@@ -622,19 +622,6 @@ export default {
return amount;
},
- chartDataTypeName(dataType, allChartDataTypes) {
- for (let chartDataTypeField in allChartDataTypes) {
- if (!Object.prototype.hasOwnProperty.call(allChartDataTypes, chartDataTypeField)) {
- return;
- }
-
- if (allChartDataTypes[chartDataTypeField].type === dataType) {
- return allChartDataTypes[chartDataTypeField].name;
- }
- }
-
- return 'Statistics';
- },
totalAmountName(dataType, allChartDataTypes) {
if (dataType === allChartDataTypes.IncomeByAccount.type || dataType === allChartDataTypes.IncomeByPrimaryCategory.type || dataType === allChartDataTypes.IncomeBySecondaryCategory.type) {
return 'Total Income';
diff --git a/src/views/mobile/transactions/Edit.vue b/src/views/mobile/transactions/Edit.vue
index df980021..e6ded0da 100644
--- a/src/views/mobile/transactions/Edit.vue
+++ b/src/views/mobile/transactions/Edit.vue
@@ -154,7 +154,7 @@
link="#"
:class="{ 'disabled': !allVisibleAccounts.length }"
:header="$t(sourceAccountName)"
- :title="transaction.sourceAccountId | accountName(allAccounts)"
+ :title="transaction.sourceAccountId | optionName(allAccounts, 'id', 'name')"
@click="showSourceAccountSheet = true"
>
@@ -225,7 +225,7 @@
{{ transaction.utcOffset | utcOffset }}
- {{ transaction.timeZone | timeZoneName(allTimezones) }}
+ {{ transaction.timeZone | optionName(allTimezones, 'name', 'displayName') }}
@@ -243,7 +243,7 @@
+ :text="tagId | optionName(allTags, 'id', 'name')">
@@ -861,33 +861,6 @@ export default {
}
}
- return '';
- },
- accountName(accountId, allAccounts) {
- for (let i = 0; i < allAccounts.length; i++) {
- if (allAccounts[i].id === accountId) {
- return allAccounts[i].name;
- }
- }
-
- return '';
- },
- timeZoneName(timeZoneName, allTimezones) {
- for (let i = 0; i < allTimezones.length; i++) {
- if (allTimezones[i].name === timeZoneName) {
- return allTimezones[i].displayName;
- }
- }
-
- return '';
- },
- tagName(tagId, allTags) {
- for (let i = 0; i < allTags.length; i++) {
- if (allTags[i].id === tagId) {
- return allTags[i].name;
- }
- }
-
return '';
}
}
diff --git a/src/views/mobile/transactions/List.vue b/src/views/mobile/transactions/List.vue
index dddfc02a..68a86ad4 100644
--- a/src/views/mobile/transactions/List.vue
+++ b/src/views/mobile/transactions/List.vue
@@ -32,10 +32,10 @@
{{ query.type | typeName('Type') | localized }}
- {{ query.categoryId | categoryName(allCategories, $t('Category')) }}
+ {{ query.categoryId | optionName(allCategories, null, 'name', $t('Category')) }}
- {{ query.accountId | accountName(allAccounts, $t('Account')) }}
+ {{ query.accountId | optionName(allAccounts, null, 'name', $t('Account')) }}
@@ -903,20 +903,6 @@ export default {
return defaultName;
}
},
- categoryName(categoryId, allCategories, defaultName) {
- if (allCategories[categoryId]) {
- return allCategories[categoryId].name;
- }
-
- return defaultName;
- },
- accountName(accountId, allAccounts, defaultName) {
- if (allAccounts[accountId]) {
- return allAccounts[accountId].name;
- }
-
- return defaultName;
- },
categoryListItemCheckedClass(category, queryCategoryId) {
if (category.id === queryCategoryId) {
return {
diff --git a/src/views/mobile/users/UserProfile.vue b/src/views/mobile/users/UserProfile.vue
index beb940b8..c77428ed 100644
--- a/src/views/mobile/users/UserProfile.vue
+++ b/src/views/mobile/users/UserProfile.vue
@@ -173,22 +173,22 @@ export default {
return [{
value: 0,
name: 'None'
- },{
+ }, {
value: 1,
name: 'All'
- },{
+ }, {
value: 2,
name: 'Today or later'
- },{
+ }, {
value: 3,
name: 'Recent 24 hours or later'
- },{
+ }, {
value: 4,
name: 'This week or later'
- },{
+ }, {
value: 5,
name: 'This month or later'
- },{
+ }, {
value: 6,
name: 'This year or later'
}];