Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Product Map): Add prices count and average to map #1009

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/LeafletMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<l-popup>
<h4>{{ getLocationTitle(location, true, false, false) }}</h4>
{{ getLocationTitle(location, false, true, true) }}<br>
<span v-if="location.info">{{ location.info }}<br></span>
<v-chip label size="small" density="comfortable">
{{ getLocationTag(location) }}
</v-chip>
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"AddPrice": "Add a price",
"AddToOFF": "Add to {name}",
"AdditionalInfo": "Additional information",
"Average": "Average",
"Brand": "Brand",
"Price": "Price",
"Prices": "Prices",
Expand Down
24 changes: 24 additions & 0 deletions src/views/ProductDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default {
productPriceTotal: 0,
productPricePage: 0,
priceLocationList: [],
priceLocationTotals: {},
loading: false,
// share
shareLinkCopySuccessMessage: false,
Expand Down Expand Up @@ -197,8 +198,10 @@ export default {
data.items.forEach((price) => {
if (price.location) {
utils.addObjectToArray(this.priceLocationList, price.location)
this.addPriceToLocationTotals(price)
}
})
this.addLocationsInfoToPriceLocationList()
this.loading = false
})
},
Expand All @@ -224,6 +227,27 @@ export default {
this.getProductPrices()
}
},
addPriceToLocationTotals(price) {
const locationId = utils.getLocationUniqueID(price.location)
if (!this.priceLocationTotals[locationId]) {
this.priceLocationTotals[locationId] = {total: 0, count: 0, currency: price.currency}
}
this.priceLocationTotals[locationId].total += price.price
this.priceLocationTotals[locationId].count += 1
},
addLocationsInfoToPriceLocationList() {
this.priceLocationList = this.priceLocationList.map(location => {
const locationId = utils.getLocationUniqueID(location)
const priceLocationTotal = this.priceLocationTotals[locationId]
if (priceLocationTotal) {
location.info = `
${this.$t('Common.PriceCount', { count: priceLocationTotal.count })}.
${this.$t('Common.Average')}: ${utils.prettyPrice(priceLocationTotal.total / priceLocationTotal.count, priceLocationTotal.currency)}.
`
}
return location
})
}
}
}
</script>
Loading