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