Skip to content
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 barcode_scanner/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"assets": {
"web.assets_backend": [
"barcode_scanner/static/src/components/DebugWidget/*.*",
"barcode_scanner/static/src/scss/barcode_scanner.scss",
"barcode_scanner/static/src/xml/barcode_scanner_templates.xml",
"barcode_scanner/static/src/js/registries.esm.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {Component, useState} from "@odoo/owl";
import {barcodeAppWidgets} from "@barcode_scanner/js/registries.esm";
import {useService} from "@web/core/utils/hooks";

export class DebugWidget extends Component {
static template = "barcode_scanner.DebugWidget";
static props = {};

setup() {
this.barcode = useService("barcodeScannerBarcode");
this.readers = useState(this.barcode.readers);
this.state = useState({open: false, input: ""});
}

get isVisible() {
return Boolean(this.env.debug) && this.readers.count > 0;
}

toggle() {
this.state.open = !this.state.open;
}

onKeydown(ev) {
if (ev.key === "Enter") {
ev.preventDefault();
this.simulateScan();
}
}

simulateScan() {
const barcode = this.state.input.trim();
if (!barcode) {
return;
}
this.barcode.bus.trigger("barcode_scanned", {
barcode,
parsed: this.barcode.parseBarcode(barcode),
source: "debug",
});
}
}

barcodeAppWidgets.add("debug_widget", {component: DebugWidget});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.barcode-debug-widget {
position: fixed;
left: calc(env(safe-area-inset-left) + 1.25rem);
bottom: calc(env(safe-area-inset-bottom) + 80px + 1rem);
z-index: 1100;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 0.5rem;
}

.barcode-debug-widget__panel {
background: var(--ilx-surface-container-lowest);
}

.barcode-debug-widget__fab.ilx-fab {
border: 0;
background: var(--bs-danger, #dc3545);
}
30 changes: 30 additions & 0 deletions barcode_scanner/static/src/components/DebugWidget/debug_widget.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<t t-name="barcode_scanner.DebugWidget">
<div t-if="isVisible" class="barcode-debug-widget">
<div
t-if="state.open"
class="barcode-debug-widget__panel d-flex gap-2 p-2 shadow rounded"
>
<input
t-model="state.input"
type="text"
class="form-control"
placeholder="Barcode"
t-on-keydown="onKeydown"
/>
<button
type="button"
class="btn btn-primary"
t-on-click="simulateScan"
>Scan</button>
</div>
<button
type="button"
class="barcode-debug-widget__fab ilx-fab"
title="Debug"
aria-label="Debug"
t-on-click="toggle"
>
<i class="fa fa-bug" aria-hidden="true" />
</button>
</div>
</t>
Loading