Skip to content

Commit

Permalink
feat(ContributionAssistant): also display errored price tags (#1337)
Browse files Browse the repository at this point in the history
Co-authored-by: Raphael Odini <[email protected]>
TTalex and raphodn authored Jan 26, 2025
1 parent f2ee978 commit ac7458a
Showing 4 changed files with 21 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/components/ContributionAssistantDrawCanvas.vue
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
</template>

<script>
import constants from '../constants'
export default {
props: {
image: {
@@ -146,11 +147,19 @@
const width = endX - startX
const height = endY - startY
let text = ""
if (rect.status == 1) {
if (rect.status == constants.PRICE_TAG_STATUS_WITH_PRICE) {
ctx.strokeStyle = "green"
ctx.fillStyle = "green"
text = this.$t('ContributionAssistant.PriceTagLabels.PriceTagWithPrice')
} else if (rect.id) {
} else if (rect.status == constants.PRICE_TAG_STATUS_UNREADABLE) {
ctx.strokeStyle = "orange"
ctx.fillStyle = "orange"
text = this.$t('ContributionAssistant.PriceTagLabels.PriceTagUnreadable')
} else if (rect.status == constants.PRICE_TAG_STATUS_TRUNCATED) {
ctx.strokeStyle = "#883c1e"
ctx.fillStyle = "#883c1e"
text = this.$t('ContributionAssistant.PriceTagLabels.PriceTagTruncated')
} else if (rect.id) { // status == null
ctx.strokeStyle = "blue"
ctx.fillStyle = "blue"
text = this.$t('ContributionAssistant.PriceTagLabels.PriceTagWithoutPrice')
3 changes: 3 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -78,6 +78,9 @@ export default {
{key: PRICE_TYPE_PRODUCT, value: 'Barcode', icon: PRICE_TYPE_PRODUCT_ICON}, // PRICE_TYPE_PRODUCT
{key: PRICE_TYPE_CATEGORY, value: PRICE_TYPE_CATEGORY, icon: PRICE_TYPE_CATEGORY_ICON}
],
PRICE_TAG_STATUS_WITH_PRICE: 1,
PRICE_TAG_STATUS_UNREADABLE: 2,
PRICE_TAG_STATUS_TRUNCATED: 3,
PRODUCT_CATEGORY_LABEL_ORGANIC: PRODUCT_CATEGORY_LABEL_ORGANIC,
PRODUCT_QUANTITY_UNIT_G: 'g',
PRODUCT_QUANTITY_UNIT_ML: 'ml',
4 changes: 3 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
@@ -416,8 +416,10 @@
"DetectedBarcode": "Detected barcode: {barcode}",
"LabelProcessingErrorMessage": "Error: label automatic processing failed",
"PriceTagLabels": {
"PriceTagWithPrice": "Price tag with a price",
"PriceTagWithoutPrice": "Price tag without a price",
"PriceTagWithPrice": "Price tag with a price",
"PriceTagTruncated": "Price tag marked as truncated",
"PriceTagUnreadable": "Price tag marked as unreadable",
"NewPriceTag": "New price tag"
},
"OpenWithTheAssistant": "Open with the assistant"
8 changes: 4 additions & 4 deletions src/views/ContributionAssistant.vue
Original file line number Diff line number Diff line change
@@ -336,10 +336,10 @@ export default {
let tries = 0
const load = () => {
api.getPriceTags({proof_id: this.proofObject.id, size: 100}).then(data => {
const validPriceTags = data.items.filter(priceTag => priceTag.status == 1 || priceTag.status == null)
const numberOfPriceTagsWithPredictions = validPriceTags.filter(priceTag => priceTag.predictions.length).length
const priceTags = data.items
const numberOfPriceTagsWithPredictions = priceTags.filter(priceTag => priceTag.predictions.length).length
if (numberOfPriceTagsWithPredictions >= minNumberOfPriceTagWithPredictions) {
callback(validPriceTags)
callback(priceTags)
} else {
tries += 1
if (tries >= maxTries) {
@@ -399,7 +399,7 @@ export default {
}
},
handlePriceTags() {
this.priceTags.forEach(priceTag => {
this.priceTags.filter(priceTag => priceTag.status == constants.PRICE_TAG_STATUS_WITH_PRICE || priceTag.status == null).forEach(priceTag => {
const label = priceTag['predictions'][0]['data']
// remove anything that is not a number from label.barcode
const barcodeString = label.barcode ? utils.cleanBarcode(label.barcode.toString()) : ''

0 comments on commit ac7458a

Please sign in to comment.