Skip to content

Commit

Permalink
feat(Settings): new Barcode scanner default mode settings (scan or ty…
Browse files Browse the repository at this point in the history
…pe) (#1111)
  • Loading branch information
raphodn authored Dec 10, 2024
1 parent 3a4c905 commit faf86ce
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
26 changes: 23 additions & 3 deletions src/components/BarcodeScannerDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<script>
import { Html5Qrcode, Html5QrcodeScanType } from 'html5-qrcode'
import { defineAsyncComponent } from 'vue'
import { mapStores } from 'pinia'
import { useAppStore } from '../store'
import api from '../services/api'
import constants from '../constants'
Expand Down Expand Up @@ -102,24 +104,42 @@ export default {
product: null,
// config
displayItems: constants.PRODUCT_SELECTOR_DISPLAY_LIST,
currentDisplay: constants.PRODUCT_SELECTOR_DISPLAY_LIST[0].key, // scan
currentDisplay: null, // see mounted
HTML5_QRCODE_URL: 'https://github.com/mebjas/html5-qrcode',
HTML5_QRCODE_NAME: 'html5-qrcode'
}
},
computed: {
...mapStores(useAppStore),
barcodeManualInputRules() {
return [
(v) => !!v || '',
]
},
},
watch: {
currentDisplay(value) {
if (value === constants.PRODUCT_SELECTOR_DISPLAY_LIST[0].key) {
window.setTimeout(() => this.createQrcodeScanner(), 200)
} else { // type
window.setTimeout(() => this.$refs.barcodeManualInput.focus(), 200)
if (this.scanner) {
this.scanner.stop()
}
}
}
},
mounted() {
this.createQrcodeScanner()
if (this.preFillValue) {
this.barcodeManualForm.barcode = this.preFillValue
}
// this.$refs.barcodeManualInput.focus()
// init tab
if (this.appStore.user.barcode_scanner_default_mode === constants.PRODUCT_SELECTOR_DISPLAY_LIST[1].key) {
this.currentDisplay = constants.PRODUCT_SELECTOR_DISPLAY_LIST[1].key
} else {
// default to scan
this.currentDisplay = constants.PRODUCT_SELECTOR_DISPLAY_LIST[0].key
}
},
methods: {
createQrcodeScanner() {
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@
"CountryLabel": "Country",
"CurrencyLabel": "Currency",
"DisplayTitle": "Display",
"BarcodeScanner": "Barcode scanner",
"DefaultMode": "Default mode",
"FavoriteCurrencies": "Favorite currencies",
"CurrencyRequired": "At least one currency is required",
"LanguageLabel": "Languages",
Expand Down
3 changes: 2 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const useAppStore = defineStore('app', {
product_display_category_tag: false,
location_display_osm_id: false,
drawer_display_experiments: true,
preferedTheme: null
preferedTheme: null,
barcode_scanner_default_mode: constants.PRODUCT_SELECTOR_DISPLAY_LIST[0].key
},
}),
getters: {
Expand Down
17 changes: 15 additions & 2 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<v-row>
<v-col cols="12" sm="6">
<v-card :title="$t('UserSettings.DisplayTitle')" prepend-icon="mdi-laptop">
<v-card :title="$t('Common.Display')" prepend-icon="mdi-laptop">
<v-divider />
<v-card-text>
<!-- Theme -->
Expand Down Expand Up @@ -65,7 +65,7 @@

<!-- Prices -->
<v-col cols="12" sm="6">
<v-card :title="$t('Common.Prices')" prepend-icon="mdi-tag-multiple-outline">
<v-card :title="$t('UserSettings.AddingPrices')" prepend-icon="mdi-tag-multiple-outline">
<v-divider />
<v-card-text>
<h3 class="mb-1">
Expand All @@ -81,6 +81,18 @@
multiple
hide-details="auto"
/>
<!-- Barcode scanner -->
<h3 class="mt-4 mb-1">
{{ $t('UserSettings.BarcodeScanner') }}
</h3>
<v-select
v-model="appStore.user.barcode_scanner_default_mode"
:label="$t('UserSettings.DefaultMode')"
:items="barcodeScannerModeList"
:item-title="item => $t('Common.' + item.valueSmallScreen)"
:item-value="item => item.key"
hide-details="auto"
/>
</v-card-text>
</v-card>
</v-col>
Expand Down Expand Up @@ -159,6 +171,7 @@ export default {
countryList,
languageList,
// currencyList,
barcodeScannerModeList: constants.PRODUCT_SELECTOR_DISPLAY_LIST
}
},
computed: {
Expand Down

0 comments on commit faf86ce

Please sign in to comment.