diff --git a/src/lib/category.js b/src/lib/category.js index d1f496c4..e6cbba5f 100644 --- a/src/lib/category.js +++ b/src/lib/category.js @@ -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)) { diff --git a/src/lib/tag.js b/src/lib/tag.js new file mode 100644 index 00000000..6938ec94 --- /dev/null +++ b/src/lib/tag.js @@ -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; +} diff --git a/src/lib/template.js b/src/lib/template.js new file mode 100644 index 00000000..b895c517 --- /dev/null +++ b/src/lib/template.js @@ -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; +} diff --git a/src/views/desktop/categories/ListPage.vue b/src/views/desktop/categories/ListPage.vue index 76e2cb30..080a9ce4 100644 --- a/src/views/desktop/categories/ListPage.vue +++ b/src/views/desktop/categories/ListPage.vue @@ -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() { diff --git a/src/views/desktop/tags/ListPage.vue b/src/views/desktop/tags/ListPage.vue index a9bac625..65c66c6e 100644 --- a/src/views/desktop/tags/ListPage.vue +++ b/src/views/desktop/tags/ListPage.vue @@ -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 !== '')); diff --git a/src/views/desktop/templates/ListPage.vue b/src/views/desktop/templates/ListPage.vue index 1dd262f9..6891f7f7 100644 --- a/src/views/desktop/templates/ListPage.vue +++ b/src/views/desktop/templates/ListPage.vue @@ -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; diff --git a/src/views/mobile/categories/ListPage.vue b/src/views/mobile/categories/ListPage.vue index c3b46cea..264cd7f5 100644 --- a/src/views/mobile/categories/ListPage.vue +++ b/src/views/mobile/categories/ListPage.vue @@ -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; diff --git a/src/views/mobile/tags/ListPage.vue b/src/views/mobile/tags/ListPage.vue index a74701db..f0882dfc 100644 --- a/src/views/mobile/tags/ListPage.vue +++ b/src/views/mobile/tags/ListPage.vue @@ -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 !== '')); diff --git a/src/views/mobile/templates/ListPage.vue b/src/views/mobile/templates/ListPage.vue index c466b2fe..c6e11006 100644 --- a/src/views/mobile/templates/ListPage.vue +++ b/src/views/mobile/templates/ListPage.vue @@ -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;