Skip to content

Commit

Permalink
shopfloor: support barcode that do not send end of line
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaudoux committed Sep 10, 2021
1 parent 20f6d0c commit 26ef467
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
1 change: 1 addition & 0 deletions shopfloor_mobile_base/README.rst
Expand Up @@ -199,6 +199,7 @@ Contributors
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Raphaël Reverdy <raphael.reverdy@akretion.com>
* Sébastien Beau <sebastien.beau@akretion.com>
* Jacques-Etienne Baudoux <je@bcim.be>

Design
~~~~~~
Expand Down
1 change: 1 addition & 0 deletions shopfloor_mobile_base/readme/CONTRIBUTORS.rst
Expand Up @@ -3,6 +3,7 @@
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Raphaël Reverdy <raphael.reverdy@akretion.com>
* Sébastien Beau <sebastien.beau@akretion.com>
* Jacques-Etienne Baudoux <je@bcim.be>

Design
~~~~~~
Expand Down
Expand Up @@ -4,13 +4,16 @@
* @author Raphaël Reverdy <raphael.reverdy@akretion.com>
* Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
* @author Simone Orsi <simahawk@gmail.com>
* Copyright 2021 BCIM (http://www.bcim.be)
* @author Jacques-Etienne Baudoux <je@bcim.be>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/

Vue.component("searchbar", {
data: function() {
return {
entered: "",
debounceWait: this.autosearch,
};
},
props: {
Expand All @@ -33,19 +36,74 @@ Vue.component("searchbar", {
type: Boolean,
default: true,
},
// remove leading/trailing spaces from input before searching
autotrim: {
type: Boolean,
default: true,
},
// on scanned input without end of line, the search will run after 50ms. Set to 0 to disable
autosearch: {
type: Number,
default: 50,
},
// on manually typed input, the search will run after 1.5s to provide time for typing
autosearch_typing: {
type: Number,
default: 1500,
},
},
mounted: function() {
this.$root.event_hub.$on("screen:reload", this.on_screen_reload);
},
computed: {
// defined as computed property to put a new instance in cache each
// time the reactive debounceWait is modified
debouncedSearch () {
return _.debounce(function(e) {
if (
this.entered.length == 1 &&
this.debounceWait != this.autosearch_typing
) {
this.debounceWait = this.autosearch_typing
return this.debouncedSearch()
}
return this.search(e);
}, this.debounceWait);
},
},
watch: {
entered: function(val) {
if (this.autotrim) {
let trimmed = val.trim();
if (trimmed !== val) {
this.entered = trimmed;
return;
}
}
if (!this.autosearch) return;
if (val.length == 0) {
this.debouncedSearch.cancel();
this.debounceWait = this.autosearch;
return;
}
return this.debouncedSearch();
},
},
methods: {
search: function(e) {
e.preventDefault();
// Talk to parent
if (!this.entered) return;
this.$emit("found", {
text: this.entered,
type: e.target.dataset.type,
});
if (this.reset_on_submit) this.reset();
type: String,
})
if (this.debounceWait === this.autosearch && this.reset_on_submit)
this.reset();
},
on_submit: function (e) {
e.preventDefault();
this.debouncedSearch.cancel();
this.search(e);
},
reset: function() {
this.entered = "";
Expand All @@ -60,7 +118,7 @@ Vue.component("searchbar", {

template: `
<v-form
v-on:submit="search"
v-on:submit="on_submit"
:data-type="input_data_type"
ref="form"
class="searchform"
Expand Down

0 comments on commit 26ef467

Please sign in to comment.