mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-17 16:24:25 +08:00
support changing sorting type in statistics page
This commit is contained in:
@@ -44,10 +44,20 @@ const allChartDataTypes = {
|
|||||||
|
|
||||||
const defaultChartDataType = allChartDataTypes.ExpenseByPrimaryCategory;
|
const defaultChartDataType = allChartDataTypes.ExpenseByPrimaryCategory;
|
||||||
|
|
||||||
|
const allSortingTypes = {
|
||||||
|
ByAmount: 0,
|
||||||
|
ByDisplayOrder: 1,
|
||||||
|
ByName: 2
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultSortingType = allSortingTypes.ByAmount;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
allChartTypes: allChartTypes,
|
allChartTypes: allChartTypes,
|
||||||
defaultChartType: defaultChartType,
|
defaultChartType: defaultChartType,
|
||||||
allChartDataTypes: allChartDataTypes,
|
allChartDataTypes: allChartDataTypes,
|
||||||
defaultChartDataType: defaultChartDataType,
|
defaultChartDataType: defaultChartDataType,
|
||||||
defaultDataRangeType: datetime.allDateRanges.ThisMonth.type,
|
defaultDataRangeType: datetime.allDateRanges.ThisMonth.type,
|
||||||
|
allSortingTypes: allSortingTypes,
|
||||||
|
defaultSortingType: defaultSortingType,
|
||||||
};
|
};
|
||||||
|
|||||||
+4
-1
@@ -18,7 +18,8 @@ const defaultSettings = {
|
|||||||
statistics: {
|
statistics: {
|
||||||
defaultChartType: statisticsConstants.defaultChartType,
|
defaultChartType: statisticsConstants.defaultChartType,
|
||||||
defaultChartDataType: statisticsConstants.defaultChartDataType,
|
defaultChartDataType: statisticsConstants.defaultChartDataType,
|
||||||
defaultDataRangeType: statisticsConstants.defaultDataRangeType
|
defaultDataRangeType: statisticsConstants.defaultDataRangeType,
|
||||||
|
sortingType: statisticsConstants.defaultSortingType
|
||||||
},
|
},
|
||||||
animate: true,
|
animate: true,
|
||||||
autoDarkMode: true
|
autoDarkMode: true
|
||||||
@@ -133,6 +134,8 @@ export default {
|
|||||||
setStatisticsDefaultChartDataType: value => setSubOption('statistics', 'defaultChartDataType', value),
|
setStatisticsDefaultChartDataType: value => setSubOption('statistics', 'defaultChartDataType', value),
|
||||||
getStatisticsDefaultDateRange: () => getSubOption('statistics', 'defaultDataRangeType'),
|
getStatisticsDefaultDateRange: () => getSubOption('statistics', 'defaultDataRangeType'),
|
||||||
setStatisticsDefaultDateRange: value => setSubOption('statistics', 'defaultDataRangeType', value),
|
setStatisticsDefaultDateRange: value => setSubOption('statistics', 'defaultDataRangeType', value),
|
||||||
|
getStatisticsSortingType: () => getSubOption('statistics', 'sortingType'),
|
||||||
|
setStatisticsSortingType: value => setSubOption('statistics', 'sortingType', value),
|
||||||
isEnableAnimate: () => getOption('animate'),
|
isEnableAnimate: () => getOption('animate'),
|
||||||
setEnableAnimate: value => setOption('animate', value),
|
setEnableAnimate: value => setOption('animate', value),
|
||||||
isEnableAutoDarkMode: () => getOption('autoDarkMode'),
|
isEnableAutoDarkMode: () => getOption('autoDarkMode'),
|
||||||
|
|||||||
@@ -669,6 +669,10 @@ export default {
|
|||||||
'Default Chart Type': 'Default Chart Type',
|
'Default Chart Type': 'Default Chart Type',
|
||||||
'Default Chart Data Type': 'Default Chart Data Type',
|
'Default Chart Data Type': 'Default Chart Data Type',
|
||||||
'Default Date Range': 'Default Date Range',
|
'Default Date Range': 'Default Date Range',
|
||||||
|
'Sort By': 'Sort By',
|
||||||
|
'By Amount': 'By Amount',
|
||||||
|
'By Display Order': 'By Display Order',
|
||||||
|
'By Name': 'By Name',
|
||||||
'Filter Accounts': 'Filter Accounts',
|
'Filter Accounts': 'Filter Accounts',
|
||||||
'Filter Transaction Categories': 'Filter Transaction Categories',
|
'Filter Transaction Categories': 'Filter Transaction Categories',
|
||||||
'User Profile': 'User Profile',
|
'User Profile': 'User Profile',
|
||||||
|
|||||||
@@ -669,6 +669,10 @@ export default {
|
|||||||
'Default Chart Type': '默认图表类型',
|
'Default Chart Type': '默认图表类型',
|
||||||
'Default Chart Data Type': '默认图表数据类型',
|
'Default Chart Data Type': '默认图表数据类型',
|
||||||
'Default Date Range': '默认时间范围',
|
'Default Date Range': '默认时间范围',
|
||||||
|
'Sort By': '排序方式',
|
||||||
|
'By Amount': '金额',
|
||||||
|
'By Display Order': '显示顺序',
|
||||||
|
'By Name': '名称',
|
||||||
'Filter Accounts': '过滤账户',
|
'Filter Accounts': '过滤账户',
|
||||||
'Filter Transaction Categories': '过滤交易类型',
|
'Filter Transaction Categories': '过滤交易类型',
|
||||||
'User Profile': '用户信息',
|
'User Profile': '用户信息',
|
||||||
|
|||||||
@@ -33,6 +33,16 @@
|
|||||||
:value="dateRange.type">{{ dateRange.name | localized }}</option>
|
:value="dateRange.type">{{ dateRange.name | localized }}</option>
|
||||||
</select>
|
</select>
|
||||||
</f7-list-item>
|
</f7-list-item>
|
||||||
|
|
||||||
|
<f7-list-item
|
||||||
|
:title="$t('Sort By')"
|
||||||
|
smart-select :smart-select-params="{ openIn: 'sheet', closeOnSelect: true, sheetCloseLinkText: $t('Done'), scrollToSelectedItem: true }">
|
||||||
|
<select v-model="sortBy">
|
||||||
|
<option :value="$constants.statistics.allSortingTypes.ByAmount">{{ $t('By Amount') }}</option>
|
||||||
|
<option :value="$constants.statistics.allSortingTypes.ByDisplayOrder">{{ $t('By Display Order') }}</option>
|
||||||
|
<option :value="$constants.statistics.allSortingTypes.ByName">{{ $t('By Name') }}</option>
|
||||||
|
</select>
|
||||||
|
</f7-list-item>
|
||||||
</f7-list>
|
</f7-list>
|
||||||
</f7-card-content>
|
</f7-card-content>
|
||||||
</f7-card>
|
</f7-card>
|
||||||
@@ -85,6 +95,14 @@ export default {
|
|||||||
set: function (value) {
|
set: function (value) {
|
||||||
this.$settings.setStatisticsDefaultDateRange(value);
|
this.$settings.setStatisticsDefaultDateRange(value);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
sortBy: {
|
||||||
|
get: function () {
|
||||||
|
return this.$settings.getStatisticsSortingType();
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.$settings.setStatisticsSortingType(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -248,8 +248,11 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
|
const self = this;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
loading: true,
|
loading: true,
|
||||||
|
sortBy: self.$settings.getStatisticsSortingType(),
|
||||||
showChartDataTypePopover: false,
|
showChartDataTypePopover: false,
|
||||||
showDatePopover: false,
|
showDatePopover: false,
|
||||||
showCustomDateRangeSheet: false,
|
showCustomDateRangeSheet: false,
|
||||||
@@ -329,9 +332,38 @@ export default {
|
|||||||
allStatisticsItems.push(data);
|
allStatisticsItems.push(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
allStatisticsItems.sort(function (data1, data2) {
|
if (this.sortBy === this.$constants.statistics.allSortingTypes.ByDisplayOrder) {
|
||||||
return data2.totalAmount - data1.totalAmount;
|
allStatisticsItems.sort(function (data1, data2) {
|
||||||
});
|
for (let i = 0; i < Math.min(data1.displayOrders.length, data2.displayOrders.length); i++) {
|
||||||
|
if (data1.displayOrders[i] !== data2.displayOrders[i]) {
|
||||||
|
return data1.displayOrders[i] - data2.displayOrders[i]; // asc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return data1.name.localeCompare(data2.name, undefined, { // asc
|
||||||
|
numeric: true,
|
||||||
|
sensitivity: 'base'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else if (this.sortBy === this.$constants.statistics.allSortingTypes.ByName) {
|
||||||
|
allStatisticsItems.sort(function (data1, data2) {
|
||||||
|
return data1.name.localeCompare(data2.name, undefined, { // asc
|
||||||
|
numeric: true,
|
||||||
|
sensitivity: 'base'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
allStatisticsItems.sort(function (data1, data2) {
|
||||||
|
if (data1.totalAmount !== data2.totalAmount) {
|
||||||
|
return data2.totalAmount - data1.totalAmount; // desc
|
||||||
|
}
|
||||||
|
|
||||||
|
return data1.name.localeCompare(data2.name, undefined, { // asc
|
||||||
|
numeric: true,
|
||||||
|
sensitivity: 'base'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalAmount: combinedData.totalAmount,
|
totalAmount: combinedData.totalAmount,
|
||||||
@@ -391,6 +423,10 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onPageAfterIn() {
|
onPageAfterIn() {
|
||||||
|
if (this.sortBy !== this.$settings.getStatisticsSortingType()) {
|
||||||
|
this.sortBy = this.$settings.getStatisticsSortingType();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.$store.state.transactionStatisticsStateInvalid && !this.loading) {
|
if (this.$store.state.transactionStatisticsStateInvalid && !this.loading) {
|
||||||
this.reload(null);
|
this.reload(null);
|
||||||
}
|
}
|
||||||
@@ -608,6 +644,7 @@ export default {
|
|||||||
icon: item.account.icon || this.$constants.icons.defaultAccountIcon.icon,
|
icon: item.account.icon || this.$constants.icons.defaultAccountIcon.icon,
|
||||||
color: item.account.color || this.$constants.colors.defaultAccountColor,
|
color: item.account.color || this.$constants.colors.defaultAccountColor,
|
||||||
hidden: item.primaryAccount.hidden || item.account.hidden,
|
hidden: item.primaryAccount.hidden || item.account.hidden,
|
||||||
|
displayOrders: [item.primaryAccount.category, item.primaryAccount.displayOrder, item.account.displayOrder],
|
||||||
totalAmount: item.amountInDefaultCurrency
|
totalAmount: item.amountInDefaultCurrency
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -635,6 +672,7 @@ export default {
|
|||||||
icon: item.primaryCategory.icon || this.$constants.icons.defaultCategoryIcon.icon,
|
icon: item.primaryCategory.icon || this.$constants.icons.defaultCategoryIcon.icon,
|
||||||
color: item.primaryCategory.color || this.$constants.colors.defaultCategoryColor,
|
color: item.primaryCategory.color || this.$constants.colors.defaultCategoryColor,
|
||||||
hidden: item.primaryCategory.hidden,
|
hidden: item.primaryCategory.hidden,
|
||||||
|
displayOrders: [item.primaryCategory.type, item.primaryCategory.displayOrder],
|
||||||
totalAmount: item.amountInDefaultCurrency
|
totalAmount: item.amountInDefaultCurrency
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -662,6 +700,7 @@ export default {
|
|||||||
icon: item.category.icon || this.$constants.icons.defaultCategoryIcon.icon,
|
icon: item.category.icon || this.$constants.icons.defaultCategoryIcon.icon,
|
||||||
color: item.category.color || this.$constants.colors.defaultCategoryColor,
|
color: item.category.color || this.$constants.colors.defaultCategoryColor,
|
||||||
hidden: item.primaryCategory.hidden || item.category.hidden,
|
hidden: item.primaryCategory.hidden || item.category.hidden,
|
||||||
|
displayOrders: [item.primaryCategory.type, item.primaryCategory.displayOrder, item.category.displayOrder],
|
||||||
totalAmount: item.amountInDefaultCurrency
|
totalAmount: item.amountInDefaultCurrency
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -732,6 +771,7 @@ export default {
|
|||||||
icon: account.icon || self.$constants.icons.defaultAccountIcon.icon,
|
icon: account.icon || self.$constants.icons.defaultAccountIcon.icon,
|
||||||
color: account.color || self.$constants.colors.defaultAccountColor,
|
color: account.color || self.$constants.colors.defaultAccountColor,
|
||||||
hidden: primaryAccount.hidden || account.hidden,
|
hidden: primaryAccount.hidden || account.hidden,
|
||||||
|
displayOrders: [primaryAccount.category, primaryAccount.displayOrder, account.displayOrder],
|
||||||
totalAmount: amount
|
totalAmount: amount
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user