Skip to content

Commit

Permalink
feat(product card): new ProductCard, seperate with PriceCard (#131)
Browse files Browse the repository at this point in the history
* New ProductCard

* Use component in ProductList, ProductDetail, BrandDetail & AddPriceSingle

* Simplify a bit PriceCard
  • Loading branch information
raphodn authored Jan 12, 2024
1 parent ba861aa commit 3460119
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 22 deletions.
11 changes: 0 additions & 11 deletions src/components/PriceCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
<h3 v-if="!hideProductTitle" @click="goToProduct()">{{ getPriceProductTitle() }}</h3>

<p v-if="!hideProductDetails" class="mb-2">
<span v-if="!price">
<v-chip label size="small" density="comfortable" :color="getProductPriceCountColor" class="mr-1" @click="goToProduct()">
<v-icon start icon="mdi-tag-outline"></v-icon>
{{ product.price_count }}
</v-chip>
</span>
<span v-if="hasProductBrands">
<v-chip v-for="brand in getProductBrandsList" label size="small" density="comfortable" class="mr-1" @click="goToBrand(brand)">
{{ brand }}
Expand All @@ -37,10 +31,6 @@
<v-icon v-if="pl.icon" end :icon="pl.icon"></v-icon>
</v-chip>
</span>
<span v-if="!price && !hideProductCode">
<br />
<v-chip label size="small" density="comfortable" class="mr-1">{{ product.code }}</v-chip>
</span>
</p>

<v-sheet v-if="price">
Expand Down Expand Up @@ -86,7 +76,6 @@ export default {
'hideProductImage': false,
'hideProductTitle': false,
'hideProductDetails': false,
'hideProductCode': false,
'hidePriceLocation': false,
'readonly': false
},
Expand Down
95 changes: 95 additions & 0 deletions src/components/ProductCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<template>
<v-card>
<v-container class="pa-2">
<v-row>
<v-col style="max-width:25%">
<v-img v-if="product.image_url" :src="product.image_url" style="max-height:100px;width:100px" @click="goToProduct()"></v-img>
<v-img v-if="!product.image_url" :src="productImageDefault" style="height:100px;width:100px;filter:invert(.9);"></v-img>
</v-col>
<v-col style="max-width:75%">
<h3 @click="goToProduct()">{{ getProductTitle() }}</h3>

<p class="mb-2">
<span>
<v-chip label size="small" density="comfortable" :color="getProductPriceCountColor" class="mr-1" @click="goToProduct()">
<v-icon start icon="mdi-tag-outline"></v-icon>
{{ product.price_count }}
</v-chip>
</span>
<span v-if="hasProductBrands">
<v-chip v-for="brand in getProductBrandsList" label size="small" density="comfortable" class="mr-1" @click="goToBrand(brand)">
{{ brand }}
</v-chip>
</span>
<span v-if="hasProductQuantity">
<v-chip label size="small" density="comfortable" class="mr-1">
{{ product.product_quantity }} g
</v-chip>
</span>
<span>
<br />
<v-chip label size="small" density="comfortable" class="mr-1">{{ product.code }}</v-chip>
</span>
</p>
</v-col>
</v-row>
</v-container>
</v-card>
</template>

<script>
export default {
props: {
'product': null,
'readonly': false
},
data() {
return {
productImageDefault: 'https://world.openfoodfacts.org/images/icons/dist/packaging.svg',
}
},
mounted() {
},
computed: {
hasProductBrands() {
return !!this.product.brands
},
hasProductQuantity() {
return !!this.product.product_quantity
},
getProductPriceCountColor() {
if (this.product.price_count === 0) {
return 'error'
}
if (this.product.price_count === 1) {
return 'warning'
}
if (this.product.price_count > 1) {
return 'success'
}
},
getProductBrandsList() {
if (this.hasProductBrands) {
return this.product.brands.split(',')
}
}
},
methods: {
getProductTitle() {
return this.product.product_name || 'Unknown product name'
},
goToProduct() {
if (this.readonly) {
return
}
this.$router.push({ path: `/products/${this.product.code}` })
},
goToBrand(brand) {
if (this.readonly) {
return
}
this.$router.push({ path: `/brands/${brand}` })
},
}
}
</script>
6 changes: 3 additions & 3 deletions src/views/AddPriceSingle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
hide-details="auto"
@click:prepend="showBarcodeScanner"
></v-text-field>
<PriceCard v-if="product" class="mb-4" :product="product" :readonly="true" elevation="1"></PriceCard>
<ProductCard v-if="product" class="mb-4" :product="product" :readonly="true" elevation="1"></ProductCard>
</v-sheet>
<v-sheet v-if="productMode === 'category'">
<v-row>
Expand Down Expand Up @@ -189,7 +189,7 @@ import { mapStores } from 'pinia'
import { useAppStore } from '../store'
import api from '../services/api'
import utils from '../utils.js'
import PriceCard from '../components/PriceCard.vue'
import ProductCard from '../components/ProductCard.vue'
import BarcodeScanner from '../components/BarcodeScanner.vue'
import LocationSelector from '../components/LocationSelector.vue'
import CategoryTags from '../data/category-tags.json'
Expand All @@ -206,7 +206,7 @@ Compressor.setDefaults({
export default {
components: {
PriceCard,
ProductCard,
BarcodeScanner,
LocationSelector
},
Expand Down
8 changes: 4 additions & 4 deletions src/views/BrandDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<v-col cols="12" sm="6">
<v-card
:title="brand"
prepend-icon="mdi-database-outline">
prepend-icon="mdi-folder-outline">
</v-card>
</v-col>
</v-row>
Expand All @@ -26,7 +26,7 @@

<v-row>
<v-col cols="12" sm="6" md="4" v-for="product in brandProductList" :key="product">
<PriceCard :product="product" elevation="1" height="100%"></PriceCard>
<ProductCard :product="product" elevation="1" height="100%"></ProductCard>
</v-col>
</v-row>

Expand All @@ -39,11 +39,11 @@

<script>
import api from '../services/api'
import PriceCard from '../components/PriceCard.vue'
import ProductCard from '../components/ProductCard.vue'
export default {
components: {
PriceCard,
ProductCard,
},
data() {
return {
Expand Down
4 changes: 3 additions & 1 deletion src/views/ProductDetail.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<v-row>
<v-col cols="12" sm="6">
<PriceCard v-if="!loading && !productIsCategory" :product="product" :readonly="true" elevation="1"></PriceCard>
<ProductCard v-if="!loading && !productIsCategory" :product="product" elevation="1"></ProductCard>
<v-card v-if="!loading && productIsCategory" :title="getCategoryName" prepend-icon="mdi-fruit-watermelon" elevation="1"></v-card>
</v-col>
</v-row>
Expand Down Expand Up @@ -49,10 +49,12 @@
<script>
import utils from '../utils.js'
import api from '../services/api'
import ProductCard from '../components/ProductCard.vue'
import PriceCard from '../components/PriceCard.vue'
export default {
components: {
ProductCard,
PriceCard,
},
data() {
Expand Down
6 changes: 3 additions & 3 deletions src/views/ProductList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<v-row>
<v-col cols="12" sm="6" md="4" v-for="product in productList" :key="product">
<PriceCard :product="product" elevation="1" height="100%"></PriceCard>
<ProductCard :product="product" elevation="1" height="100%"></ProductCard>
</v-col>
</v-row>

Expand All @@ -45,11 +45,11 @@

<script>
import api from '../services/api'
import PriceCard from '../components/PriceCard.vue'
import ProductCard from '../components/ProductCard.vue'
export default {
components: {
PriceCard,
ProductCard,
},
data() {
return {
Expand Down

0 comments on commit 3460119

Please sign in to comment.