Skip to content

Commit

Permalink
refactor(Barcode scanner): new prop to allow hiding the scan tab. Use…
Browse files Browse the repository at this point in the history
… in CA & PV Assistants. ref #1044 & #1137
  • Loading branch information
raphodn committed Dec 25, 2024
1 parent 5ccaad4 commit 3b7d9f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/components/BarcodeScannerDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export default {
ProductCard: defineAsyncComponent(() => import('../components/ProductCard.vue')),
},
props: {
hideBarcodeScannerTab: {
type: Boolean,
default: false
},
barcodeManualInputMode: {
type: String,
default: 'search' // 'add'
Expand All @@ -104,14 +108,19 @@ export default {
barcodeManualFormValid: false,
product: null,
// config
displayItems: constants.PRODUCT_SELECTOR_DISPLAY_LIST,
currentDisplay: null, // see mounted
HTML5_QRCODE_URL: 'https://github.com/mebjas/html5-qrcode',
HTML5_QRCODE_NAME: 'html5-qrcode'
}
},
computed: {
...mapStores(useAppStore),
displayItems() {
if (this.hideBarcodeScannerTab) {
return constants.PRODUCT_SELECTOR_DISPLAY_LIST.filter(item => item.key !== constants.PRODUCT_SELECTOR_DISPLAY_LIST[0].key)
}
return constants.PRODUCT_SELECTOR_DISPLAY_LIST
},
barcodeManualInputRules() {
return [
(v) => !!v || '',
Expand All @@ -121,7 +130,11 @@ export default {
watch: {
currentDisplay(value) {
if (value === constants.PRODUCT_SELECTOR_DISPLAY_LIST[0].key) {
window.setTimeout(() => this.createQrcodeScanner(), 200)
if (this.hideBarcodeScannerTab) {
this.currentDisplay = constants.PRODUCT_SELECTOR_DISPLAY_LIST[1].key
} else {
window.setTimeout(() => this.createQrcodeScanner(), 200)
}
} else { // type
window.setTimeout(() => this.$refs.barcodeManualInput.focus(), 200)
if (this.scanner && this.scanner.getState() > 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ContributionAssistantPriceFormCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/>
</v-col>
</v-row>
<ProductInputRow :productForm="productPriceForm" :disableInitWhenSwitchingType="true" @filled="productFormFilled = $event" />
<ProductInputRow :productForm="productPriceForm" :disableInitWhenSwitchingType="true" :hideBarcodeScannerTab="true" @filled="productFormFilled = $event" />
<PriceInputRow class="mt-0" :priceForm="productPriceForm" :hideCurrencyChoice="true" @filled="pricePriceFormFilled = $event" />
</v-card-text>
<v-divider v-if="mode === 'Validation'" />
Expand Down
5 changes: 5 additions & 0 deletions src/components/ProductInputRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<BarcodeScannerDialog
v-if="barcodeScannerDialog"
v-model="barcodeScannerDialog"
:hideBarcodeScannerTab="hideBarcodeScannerTab"
:barcodeManualInputPrefillValue="productForm.product_code"
@barcode="setProductCode($event)"
@close="barcodeScannerDialog = false"
Expand Down Expand Up @@ -96,6 +97,10 @@ export default {
disableInitWhenSwitchingType: {
type: Boolean,
default: () => false
},
hideBarcodeScannerTab: {
type: Boolean,
default: false
}
},
emits: ['filled'],
Expand Down

0 comments on commit 3b7d9f9

Please sign in to comment.