From 57fead84884c235afae55c7bc5d05e2bf5785662 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Mon, 22 Jan 2024 06:51:35 +0000 Subject: [PATCH] Add categories (#60) * add category filtering * have a category list * fix categories behaviour * fix filter behaviour * select ALL category button when categoryFilter is empty --------- Co-authored-by: Pavol Rusnak --- models.py | 1 + templates/tpos/index.html | 32 +++++++++++++++++++- templates/tpos/tpos.html | 63 ++++++++++++++++++++++++++++++++++----- 3 files changed, 87 insertions(+), 9 deletions(-) diff --git a/models.py b/models.py index 636a680..4240e55 100644 --- a/models.py +++ b/models.py @@ -116,6 +116,7 @@ class Item(BaseModel): description: Optional[str] tax: Optional[float] = 0.0 disabled: bool = False + categories: Optional[List[str]] = [] class CreateUpdateItemData(BaseModel): diff --git a/templates/tpos/index.html b/templates/tpos/index.html index 6fb20b9..f0c8ceb 100644 --- a/templates/tpos/index.html +++ b/templates/tpos/index.html @@ -363,7 +363,6 @@
{{SITE_TITLE}} TPoS extension
v-if="formDialog.data.tip_wallet" use-input use-chips - multiple hide-dropdown-icon input-debounce="0" new-value-mode="add-unique" @@ -459,6 +458,20 @@
{{SITE_TITLE}} TPoS extension
v-model.number="itemDialog.data.price" :label="`Price (${itemDialog.data.currency})*`" > + title: '', image: '', price: '', + categories: [], disabled: false } }, @@ -843,6 +857,21 @@
} } }, + computed: { + categoryList() { + return this.tposs.reduce((acc, tpos) => { + tpos.items.forEach(item => { + item.categories && + item.categories.forEach(category => { + if (!acc.includes(category)) { + acc.push(category) + } + }) + }) + return acc + }, []) + } + }, methods: { generatePIN() { // random 6 digit PIN @@ -1007,6 +1036,7 @@
title: '', image: '', price: '', + categories: [], disabled: false } }, diff --git a/templates/tpos/tpos.html b/templates/tpos/tpos.html index bace3f8..dc60435 100644 --- a/templates/tpos/tpos.html +++ b/templates/tpos/tpos.html @@ -322,6 +322,21 @@
${totalfsat} sat
+
+ +
showPoS: true, cartDrawer: this.$q.screen.width > 1200, searchTerm: '', + categoryFilter: '', cart: new Map() } }, @@ -811,14 +827,23 @@
return this.isFullScreen ? 'fullscreen_exit' : 'fullscreen' }, filteredItems() { - if (!this.searchTerm) return this.items.filter(item => !item.disabled) - - return this.items.filter(item => { - return ( - !item.disabled && - item.title.toLowerCase().includes(this.searchTerm.toLowerCase()) - ) - }) + // filter out disabled items + let items = this.items.filter(item => !item.disabled) + // if searchTerm entered, filter out items that don't match + if (this.searchTerm) { + items = items.filter(item => { + return item.title.toLowerCase().includes(this.searchTerm.toLowerCase()) + }) + } + // if categoryFilter entered, filter out items that don't match + if (this.categoryFilter) { + items = items.filter(item => { + return item.categories + .map(c => c.toLowerCase()) + .includes(this.categoryFilter.toLowerCase()) + }) + } + return items }, drawerWidth() { return this.$q.screen.width < 500 ? 375 : 450 @@ -1200,6 +1225,27 @@
}, handleColorScheme(val) { this.$q.localStorage.set('lnbits.tpos.color', val) + }, + extractCategories(items) { + let categories = new Set() + items + .map(item => { + item.categories && + item.categories.forEach(category => categories.add(category)) + }) + .filter(Boolean) + + if (categories.size) { + categories = ['All', ...categories] + } + return Array.from(categories) + }, + handleCategoryBtn(category) { + if (this.categoryFilter == category) { + this.categoryFilter = '' + } else { + this.categoryFilter = category == 'All' ? '' : category + } } }, created: function () { @@ -1225,6 +1271,7 @@
}) if (this.items.length > 0) { this.showPoS = false + this.categories = this.extractCategories(this.items) } window.addEventListener('keyup', event => {