only show categories with specified type in category filter dialog / page
This commit is contained in:
+9
-1
@@ -62,8 +62,12 @@ export function getTransactionSecondaryCategoryName(categoryId, allCategories) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function allVisibleTransactionCategories(allTransactionCategories) {
|
export function allVisibleTransactionCategories(allTransactionCategories, allowCategoryTypes) {
|
||||||
const ret = {};
|
const ret = {};
|
||||||
|
const hasAllowCategoryTypes = allowCategoryTypes
|
||||||
|
&& (allowCategoryTypes[categoryConstants.allCategoryTypes.Income.toString()]
|
||||||
|
|| allowCategoryTypes[categoryConstants.allCategoryTypes.Expense.toString()]
|
||||||
|
|| allowCategoryTypes[categoryConstants.allCategoryTypes.Transfer.toString()]);
|
||||||
|
|
||||||
for (let key in categoryConstants.allCategoryTypes) {
|
for (let key in categoryConstants.allCategoryTypes) {
|
||||||
if (!Object.prototype.hasOwnProperty.call(categoryConstants.allCategoryTypes, key)) {
|
if (!Object.prototype.hasOwnProperty.call(categoryConstants.allCategoryTypes, key)) {
|
||||||
@@ -76,6 +80,10 @@ export function allVisibleTransactionCategories(allTransactionCategories) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasAllowCategoryTypes && !allowCategoryTypes[categoryType]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const allCategories = allTransactionCategories[categoryType];
|
const allCategories = allTransactionCategories[categoryType];
|
||||||
const visibleCategories = [];
|
const visibleCategories = [];
|
||||||
const allVisibleSubCategories = {};
|
const allVisibleSubCategories = {};
|
||||||
|
|||||||
@@ -373,6 +373,16 @@ export function objectToArray(object) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function arrayItemToObjectField(array, value) {
|
||||||
|
const ret = {};
|
||||||
|
|
||||||
|
for (let i = 0; i < array.length; i++) {
|
||||||
|
ret[array[i]] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
export function categorizedArrayToPlainArray(object) {
|
export function categorizedArrayToPlainArray(object) {
|
||||||
const ret = [];
|
const ret = [];
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ import { useTransactionsStore } from '@/stores/transaction.js';
|
|||||||
import { useStatisticsStore } from '@/stores/statistics.js';
|
import { useStatisticsStore } from '@/stores/statistics.js';
|
||||||
|
|
||||||
import categoryConstants from '@/consts/category.js';
|
import categoryConstants from '@/consts/category.js';
|
||||||
import { copyObjectTo } from '@/lib/common.js';
|
import { copyObjectTo, arrayItemToObjectField } from '@/lib/common.js';
|
||||||
import {
|
import {
|
||||||
allVisibleTransactionCategories,
|
allVisibleTransactionCategories,
|
||||||
hasAnyAvailableCategory,
|
hasAnyAvailableCategory,
|
||||||
@@ -151,6 +151,7 @@ import {
|
|||||||
export default {
|
export default {
|
||||||
props: [
|
props: [
|
||||||
'dialogMode',
|
'dialogMode',
|
||||||
|
'categoryTypes',
|
||||||
'type',
|
'type',
|
||||||
'autoSave'
|
'autoSave'
|
||||||
],
|
],
|
||||||
@@ -190,8 +191,11 @@ export default {
|
|||||||
return 'Apply';
|
return 'Apply';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
allowCategoryTypes() {
|
||||||
|
return this.categoryTypes ? arrayItemToObjectField(this.categoryTypes.split(','), true) : null;
|
||||||
|
},
|
||||||
allVisibleTransactionCategories() {
|
allVisibleTransactionCategories() {
|
||||||
return allVisibleTransactionCategories(this.transactionCategoriesStore.allTransactionCategories);
|
return allVisibleTransactionCategories(this.transactionCategoriesStore.allTransactionCategories, this.allowCategoryTypes);
|
||||||
},
|
},
|
||||||
hasAnyAvailableCategory() {
|
hasAnyAvailableCategory() {
|
||||||
return hasAnyAvailableCategory(this.allVisibleTransactionCategories);
|
return hasAnyAvailableCategory(this.allVisibleTransactionCategories);
|
||||||
@@ -217,6 +221,10 @@ export default {
|
|||||||
|
|
||||||
const category = self.transactionCategoriesStore.allTransactionCategoriesMap[categoryId];
|
const category = self.transactionCategoriesStore.allTransactionCategoriesMap[categoryId];
|
||||||
|
|
||||||
|
if (self.allowCategoryTypes && !self.allowCategoryTypes[category.type]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.type === 'transactionListCurrent' && self.transactionsStore.allFilterCategoryIdsCount > 0) {
|
if (this.type === 'transactionListCurrent' && self.transactionsStore.allFilterCategoryIdsCount > 0) {
|
||||||
allCategoryIds[category.id] = true;
|
allCategoryIds[category.id] = true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -413,7 +413,7 @@
|
|||||||
</v-dialog>
|
</v-dialog>
|
||||||
|
|
||||||
<v-dialog width="800" v-model="showFilterCategoryDialog">
|
<v-dialog width="800" v-model="showFilterCategoryDialog">
|
||||||
<category-filter-settings-card type="transactionListCurrent" :dialog-mode="true"
|
<category-filter-settings-card type="transactionListCurrent" :dialog-mode="true" :category-types="allowCategoryTypes"
|
||||||
@settings:change="changeMultipleCategoriesFilter" />
|
@settings:change="changeMultipleCategoriesFilter" />
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
|
|
||||||
@@ -653,6 +653,13 @@ export default {
|
|||||||
queryMonthlyData() {
|
queryMonthlyData() {
|
||||||
return isDateRangeMatchOneMonth(this.query.minTime, this.query.maxTime);
|
return isDateRangeMatchOneMonth(this.query.minTime, this.query.maxTime);
|
||||||
},
|
},
|
||||||
|
allowCategoryTypes() {
|
||||||
|
if (this.allTransactionTypes.Income <= this.query.type && this.query.type <= this.allTransactionTypes.Transfer) {
|
||||||
|
return transactionTypeToCategoryType(this.query.type).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
},
|
||||||
countPerPage: {
|
countPerPage: {
|
||||||
get: function () {
|
get: function () {
|
||||||
if (this.temporaryCountPerPage) {
|
if (this.temporaryCountPerPage) {
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ import { useTransactionsStore } from '@/stores/transaction.js';
|
|||||||
import { useStatisticsStore } from '@/stores/statistics.js';
|
import { useStatisticsStore } from '@/stores/statistics.js';
|
||||||
|
|
||||||
import categoryConstants from '@/consts/category.js';
|
import categoryConstants from '@/consts/category.js';
|
||||||
import { copyObjectTo } from '@/lib/common.js';
|
import { copyObjectTo, arrayItemToObjectField } from '@/lib/common.js';
|
||||||
import {
|
import {
|
||||||
allVisibleTransactionCategories,
|
allVisibleTransactionCategories,
|
||||||
hasAnyAvailableCategory,
|
hasAnyAvailableCategory,
|
||||||
@@ -156,6 +156,7 @@ export default {
|
|||||||
loading: true,
|
loading: true,
|
||||||
loadingError: null,
|
loadingError: null,
|
||||||
type: null,
|
type: null,
|
||||||
|
allowCategoryTypes: null,
|
||||||
filterCategoryIds: {},
|
filterCategoryIds: {},
|
||||||
collapseStates: self.getCollapseStates(),
|
collapseStates: self.getCollapseStates(),
|
||||||
showMoreActionSheet: false
|
showMoreActionSheet: false
|
||||||
@@ -178,7 +179,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
allVisibleTransactionCategories() {
|
allVisibleTransactionCategories() {
|
||||||
return allVisibleTransactionCategories(this.transactionCategoriesStore.allTransactionCategories);
|
return allVisibleTransactionCategories(this.transactionCategoriesStore.allTransactionCategories, this.allowCategoryTypes);
|
||||||
},
|
},
|
||||||
hasAnyAvailableCategory() {
|
hasAnyAvailableCategory() {
|
||||||
return hasAnyAvailableCategory(this.allVisibleTransactionCategories);
|
return hasAnyAvailableCategory(this.allVisibleTransactionCategories);
|
||||||
@@ -192,6 +193,7 @@ export default {
|
|||||||
const query = self.f7route.query;
|
const query = self.f7route.query;
|
||||||
|
|
||||||
self.type = query.type;
|
self.type = query.type;
|
||||||
|
self.allowCategoryTypes = query.allowCategoryTypes ? arrayItemToObjectField(query.allowCategoryTypes.split(','), true) : null;
|
||||||
|
|
||||||
self.transactionCategoriesStore.loadAllCategories({
|
self.transactionCategoriesStore.loadAllCategories({
|
||||||
force: false
|
force: false
|
||||||
@@ -207,6 +209,10 @@ export default {
|
|||||||
|
|
||||||
const category = self.transactionCategoriesStore.allTransactionCategoriesMap[categoryId];
|
const category = self.transactionCategoriesStore.allTransactionCategoriesMap[categoryId];
|
||||||
|
|
||||||
|
if (self.allowCategoryTypes && !self.allowCategoryTypes[category.type]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.type === 'transactionListCurrent' && self.transactionsStore.allFilterCategoryIdsCount > 0) {
|
if (this.type === 'transactionListCurrent' && self.transactionsStore.allFilterCategoryIdsCount > 0) {
|
||||||
allCategoryIds[category.id] = true;
|
allCategoryIds[category.id] = true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -906,7 +906,13 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
filterMultipleCategories() {
|
filterMultipleCategories() {
|
||||||
this.f7router.navigate('/settings/filter/category?type=transactionListCurrent');
|
let navigateUrl = '/settings/filter/category?type=transactionListCurrent';
|
||||||
|
|
||||||
|
if (this.allTransactionTypes.Income <= this.query.type && this.query.type <= this.allTransactionTypes.Transfer) {
|
||||||
|
navigateUrl += '&allowCategoryTypes=' + transactionTypeToCategoryType(this.query.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.f7router.navigate(navigateUrl);
|
||||||
},
|
},
|
||||||
filterMultipleAccounts() {
|
filterMultipleAccounts() {
|
||||||
this.f7router.navigate('/settings/filter/account?type=transactionListCurrent');
|
this.f7router.navigate('/settings/filter/account?type=transactionListCurrent');
|
||||||
|
|||||||
Reference in New Issue
Block a user