mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 01:04:25 +08:00
code refactor
This commit is contained in:
@@ -279,6 +279,48 @@ export function getFirstAvailableSubCategoryId(categories, categoryId) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isNoAvailableCategory(categories, showHidden) {
|
||||||
|
for (let i = 0; i < categories.length; i++) {
|
||||||
|
if (showHidden || !categories[i].hidden) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAvailableCategoryCount(categories, showHidden) {
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < categories.length; i++) {
|
||||||
|
if (showHidden || !categories[i].hidden) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFirstShowingId(categories, showHidden) {
|
||||||
|
for (let i = 0; i < categories.length; i++) {
|
||||||
|
if (showHidden || !categories[i].hidden) {
|
||||||
|
return categories[i].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLastShowingId(categories, showHidden) {
|
||||||
|
for (let i = categories.length - 1; i >= 0; i--) {
|
||||||
|
if (showHidden || !categories[i].hidden) {
|
||||||
|
return categories[i].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export function hasAnyAvailableCategory(allTransactionCategories, showHidden) {
|
export function hasAnyAvailableCategory(allTransactionCategories, showHidden) {
|
||||||
for (let type in allTransactionCategories) {
|
for (let type in allTransactionCategories) {
|
||||||
if (!Object.prototype.hasOwnProperty.call(allTransactionCategories, type)) {
|
if (!Object.prototype.hasOwnProperty.call(allTransactionCategories, type)) {
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
export function isNoAvailableTag(tags, showHidden) {
|
||||||
|
for (let i = 0; i < tags.length; i++) {
|
||||||
|
if (showHidden || !tags[i].hidden) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAvailableTagCount(tags, showHidden) {
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < tags.length; i++) {
|
||||||
|
if (showHidden || !tags[i].hidden) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFirstShowingId(tags, showHidden) {
|
||||||
|
for (let i = 0; i < tags.length; i++) {
|
||||||
|
if (showHidden || !tags[i].hidden) {
|
||||||
|
return tags[i].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLastShowingId(tags, showHidden) {
|
||||||
|
for (let i = tags.length - 1; i >= 0; i--) {
|
||||||
|
if (showHidden || !tags[i].hidden) {
|
||||||
|
return tags[i].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
export function isNoAvailableTemplate(templates, showHidden) {
|
||||||
|
for (let i = 0; i < templates.length; i++) {
|
||||||
|
if (showHidden || !templates[i].hidden) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAvailableTemplateCount(templates, showHidden) {
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < templates.length; i++) {
|
||||||
|
if (showHidden || !templates[i].hidden) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFirstShowingId(templates, showHidden) {
|
||||||
|
for (let i = 0; i < templates.length; i++) {
|
||||||
|
if (showHidden || !templates[i].hidden) {
|
||||||
|
return templates[i].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLastShowingId(templates, showHidden) {
|
||||||
|
for (let i = templates.length - 1; i >= 0; i--) {
|
||||||
|
if (showHidden || !templates[i].hidden) {
|
||||||
|
return templates[i].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -201,6 +201,10 @@ import { mapStores } from 'pinia';
|
|||||||
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
|
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
|
||||||
|
|
||||||
import categoryConstants from '@/consts/category.js';
|
import categoryConstants from '@/consts/category.js';
|
||||||
|
import {
|
||||||
|
isNoAvailableCategory,
|
||||||
|
getAvailableCategoryCount
|
||||||
|
} from '@/lib/category.js';
|
||||||
import { getNavSideBarOuterHeight } from '@/lib/ui.desktop.js';
|
import { getNavSideBarOuterHeight } from '@/lib/ui.desktop.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -278,27 +282,13 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
noAvailableCategory() {
|
noAvailableCategory() {
|
||||||
for (let i = 0; i < this.categories.length; i++) {
|
return isNoAvailableCategory(this.categories, this.showHidden);
|
||||||
if (this.showHidden || !this.categories[i].hidden) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
noCategory() {
|
noCategory() {
|
||||||
return this.categories.length < 1;
|
return this.categories.length < 1;
|
||||||
},
|
},
|
||||||
availableCategoryCount() {
|
availableCategoryCount() {
|
||||||
let count = 0;
|
return getAvailableCategoryCount(this.categories, this.showHidden);
|
||||||
|
|
||||||
for (let i = 0; i < this.categories.length; i++) {
|
|
||||||
if (this.showHidden || !this.categories[i].hidden) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
|||||||
@@ -226,6 +226,11 @@
|
|||||||
import { mapStores } from 'pinia';
|
import { mapStores } from 'pinia';
|
||||||
import { useTransactionTagsStore } from '@/stores/transactionTag.js';
|
import { useTransactionTagsStore } from '@/stores/transactionTag.js';
|
||||||
|
|
||||||
|
import {
|
||||||
|
isNoAvailableTag,
|
||||||
|
getAvailableTagCount
|
||||||
|
} from '@/lib/tag.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
mdiRefresh,
|
mdiRefresh,
|
||||||
mdiPlus,
|
mdiPlus,
|
||||||
@@ -276,24 +281,10 @@ export default {
|
|||||||
return this.transactionTagsStore.allTransactionTags;
|
return this.transactionTagsStore.allTransactionTags;
|
||||||
},
|
},
|
||||||
noAvailableTag() {
|
noAvailableTag() {
|
||||||
for (let i = 0; i < this.tags.length; i++) {
|
return isNoAvailableTag(this.tags, this.showHidden);
|
||||||
if (this.showHidden || !this.tags[i].hidden) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
availableTagCount() {
|
availableTagCount() {
|
||||||
let count = 0;
|
return getAvailableTagCount(this.tags, this.showHidden);
|
||||||
|
|
||||||
for (let i = 0; i < this.tags.length; i++) {
|
|
||||||
if (this.showHidden || !this.tags[i].hidden) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
},
|
},
|
||||||
hasEditingTag() {
|
hasEditingTag() {
|
||||||
return !!(this.newTag || (this.editingTag.id && this.editingTag.id !== ''));
|
return !!(this.newTag || (this.editingTag.id && this.editingTag.id !== ''));
|
||||||
|
|||||||
@@ -152,6 +152,10 @@ import { mapStores } from 'pinia';
|
|||||||
import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
|
import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
|
||||||
|
|
||||||
import templateConstants from '@/consts/template.js';
|
import templateConstants from '@/consts/template.js';
|
||||||
|
import {
|
||||||
|
isNoAvailableTemplate,
|
||||||
|
getAvailableTemplateCount
|
||||||
|
} from '@/lib/template.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
mdiRefresh,
|
mdiRefresh,
|
||||||
@@ -206,24 +210,10 @@ export default {
|
|||||||
return this.transactionTemplatesStore.allTransactionTemplates[this.templateType] || [];
|
return this.transactionTemplatesStore.allTransactionTemplates[this.templateType] || [];
|
||||||
},
|
},
|
||||||
noAvailableTemplate() {
|
noAvailableTemplate() {
|
||||||
for (let i = 0; i < this.templates.length; i++) {
|
return isNoAvailableTemplate(this.templates, this.showHidden);
|
||||||
if (this.showHidden || !this.templates[i].hidden) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
availableTemplateCount() {
|
availableTemplateCount() {
|
||||||
let count = 0;
|
return getAvailableTemplateCount(this.templates, this.showHidden);
|
||||||
|
|
||||||
for (let i = 0; i < this.templates.length; i++) {
|
|
||||||
if (this.showHidden || !this.templates[i].hidden) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
},
|
},
|
||||||
allTemplateTypes() {
|
allTemplateTypes() {
|
||||||
return templateConstants.allTemplateTypes;
|
return templateConstants.allTemplateTypes;
|
||||||
|
|||||||
@@ -91,6 +91,11 @@ import { mapStores } from 'pinia';
|
|||||||
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
|
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
|
||||||
|
|
||||||
import categoryConstants from '@/consts/category.js';
|
import categoryConstants from '@/consts/category.js';
|
||||||
|
import {
|
||||||
|
isNoAvailableCategory,
|
||||||
|
getFirstShowingId,
|
||||||
|
getLastShowingId
|
||||||
|
} from '@/lib/category.js';
|
||||||
import { onSwipeoutDeleted } from '@/lib/ui.mobile.js';
|
import { onSwipeoutDeleted } from '@/lib/ui.mobile.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -163,31 +168,13 @@ export default {
|
|||||||
return title + ' Categories';
|
return title + ' Categories';
|
||||||
},
|
},
|
||||||
firstShowingId() {
|
firstShowingId() {
|
||||||
for (let i = 0; i < this.categories.length; i++) {
|
return getFirstShowingId(this.categories, this.showHidden);
|
||||||
if (this.showHidden || !this.categories[i].hidden) {
|
|
||||||
return this.categories[i].id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
lastShowingId() {
|
lastShowingId() {
|
||||||
for (let i = this.categories.length - 1; i >= 0; i--) {
|
return getLastShowingId(this.categories, this.showHidden);
|
||||||
if (this.showHidden || !this.categories[i].hidden) {
|
|
||||||
return this.categories[i].id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
noAvailableCategory() {
|
noAvailableCategory() {
|
||||||
for (let i = 0; i < this.categories.length; i++) {
|
return isNoAvailableCategory(this.categories, this.showHidden);
|
||||||
if (this.showHidden || !this.categories[i].hidden) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
noCategory() {
|
noCategory() {
|
||||||
return this.categories.length < 1;
|
return this.categories.length < 1;
|
||||||
|
|||||||
@@ -147,6 +147,11 @@
|
|||||||
import { mapStores } from 'pinia';
|
import { mapStores } from 'pinia';
|
||||||
import { useTransactionTagsStore } from '@/stores/transactionTag.js';
|
import { useTransactionTagsStore } from '@/stores/transactionTag.js';
|
||||||
|
|
||||||
|
import {
|
||||||
|
isNoAvailableTag,
|
||||||
|
getFirstShowingId,
|
||||||
|
getLastShowingId
|
||||||
|
} from '@/lib/tag.js';
|
||||||
import { onSwipeoutDeleted } from '@/lib/ui.mobile.js';
|
import { onSwipeoutDeleted } from '@/lib/ui.mobile.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -179,31 +184,13 @@ export default {
|
|||||||
return this.transactionTagsStore.allTransactionTags;
|
return this.transactionTagsStore.allTransactionTags;
|
||||||
},
|
},
|
||||||
firstShowingId() {
|
firstShowingId() {
|
||||||
for (let i = 0; i < this.tags.length; i++) {
|
return getFirstShowingId(this.tags, this.showHidden);
|
||||||
if (this.showHidden || !this.tags[i].hidden) {
|
|
||||||
return this.tags[i].id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
lastShowingId() {
|
lastShowingId() {
|
||||||
for (let i = this.tags.length - 1; i >= 0; i--) {
|
return getLastShowingId(this.tags, this.showHidden);
|
||||||
if (this.showHidden || !this.tags[i].hidden) {
|
|
||||||
return this.tags[i].id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
noAvailableTag() {
|
noAvailableTag() {
|
||||||
for (let i = 0; i < this.tags.length; i++) {
|
return isNoAvailableTag(this.tags, this.showHidden);
|
||||||
if (this.showHidden || !this.tags[i].hidden) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
hasEditingTag() {
|
hasEditingTag() {
|
||||||
return !!(this.newTag || (this.editingTag.id && this.editingTag.id !== ''));
|
return !!(this.newTag || (this.editingTag.id && this.editingTag.id !== ''));
|
||||||
|
|||||||
@@ -90,6 +90,11 @@ import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
|
|||||||
|
|
||||||
import templateConstants from '@/consts/template.js';
|
import templateConstants from '@/consts/template.js';
|
||||||
import { isDefined } from '@/lib/common.js';
|
import { isDefined } from '@/lib/common.js';
|
||||||
|
import {
|
||||||
|
isNoAvailableTemplate,
|
||||||
|
getFirstShowingId,
|
||||||
|
getLastShowingId
|
||||||
|
} from '@/lib/template.js';
|
||||||
import { onSwipeoutDeleted } from '@/lib/ui.mobile.js';
|
import { onSwipeoutDeleted } from '@/lib/ui.mobile.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -117,31 +122,13 @@ export default {
|
|||||||
return this.transactionTemplatesStore.allTransactionTemplates[this.templateType] || [];
|
return this.transactionTemplatesStore.allTransactionTemplates[this.templateType] || [];
|
||||||
},
|
},
|
||||||
firstShowingId() {
|
firstShowingId() {
|
||||||
for (let i = 0; i < this.templates.length; i++) {
|
return getFirstShowingId(this.templates, this.showHidden);
|
||||||
if (this.showHidden || !this.templates[i].hidden) {
|
|
||||||
return this.templates[i].id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
lastShowingId() {
|
lastShowingId() {
|
||||||
for (let i = this.templates.length - 1; i >= 0; i--) {
|
return getLastShowingId(this.templates, this.showHidden);
|
||||||
if (this.showHidden || !this.templates[i].hidden) {
|
|
||||||
return this.templates[i].id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
noAvailableTemplate() {
|
noAvailableTemplate() {
|
||||||
for (let i = 0; i < this.templates.length; i++) {
|
return isNoAvailableTemplate(this.templates, this.showHidden);
|
||||||
if (this.showHidden || !this.templates[i].hidden) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
allTemplateTypes() {
|
allTemplateTypes() {
|
||||||
return templateConstants.allTemplateTypes;
|
return templateConstants.allTemplateTypes;
|
||||||
|
|||||||
Reference in New Issue
Block a user