Skip to content
Snippets Groups Projects
Commit 0531065d authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Render the device dropdown in the template

parent 3a3198ce
No related branches found
No related tags found
No related merge requests found
...@@ -74,7 +74,6 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { ...@@ -74,7 +74,6 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
this.askPermission = false; this.askPermission = false;
this.videoRunning = false; this.videoRunning = false;
this.notSupported = false;
this.front = false; this.front = false;
this.loading = false; this.loading = false;
...@@ -86,6 +85,7 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { ...@@ -86,6 +85,7 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
this.sourceChanged = false; this.sourceChanged = false;
this.clipMask = false; this.clipMask = false;
this._devices = new Map();
} }
static get scopedElements() { static get scopedElements() {
...@@ -103,7 +103,6 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { ...@@ -103,7 +103,6 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
lang: { type: String }, lang: { type: String },
askPermission: { type: Boolean, attribute: false }, askPermission: { type: Boolean, attribute: false },
videoRunning: { type: Boolean, attribute: false }, videoRunning: { type: Boolean, attribute: false },
notSupported: { type: Boolean, attribute: false },
front: { type: Boolean, attribute: false }, front: { type: Boolean, attribute: false },
loading: { type: Boolean, attribute: false }, loading: { type: Boolean, attribute: false },
scanIsOk: { type: Boolean, attribute: 'scan-is-ok' }, scanIsOk: { type: Boolean, attribute: 'scan-is-ok' },
...@@ -111,7 +110,8 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { ...@@ -111,7 +110,8 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
stopScan: { type: Boolean, attribute: 'stop-scan' }, stopScan: { type: Boolean, attribute: 'stop-scan' },
activeCamera: { type: String, attribute: false }, activeCamera: { type: String, attribute: false },
sourceChanged: { type: Boolean, attribute: false }, sourceChanged: { type: Boolean, attribute: false },
clipMask: { type: Boolean, attribute: 'clip-mask' } clipMask: { type: Boolean, attribute: 'clip-mask' },
_devices: { type: Map, attribute: false}
}; };
} }
...@@ -121,15 +121,8 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { ...@@ -121,15 +121,8 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
this.updateComplete.then(async ()=>{ this.updateComplete.then(async ()=>{
let devices = await getVideoDevices(); let devices = await getVideoDevices();
this.notSupported = !devices.size;
this.activeCamera = getPrimaryDevice(devices) || ''; this.activeCamera = getPrimaryDevice(devices) || '';
this._devices = devices;
for (let [id, label] of devices) {
let opt = document.createElement("option");
opt.value = id;
opt.text = label;
this._('#videoSource').appendChild(opt);
}
if (!this.stopScan) { if (!this.stopScan) {
this.qrCodeScannerInit(); this.qrCodeScannerInit();
...@@ -476,18 +469,22 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { ...@@ -476,18 +469,22 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
} }
render() { render() {
let hasDevices = this._devices.size > 0;
return html` return html`
<div class="columns"> <div class="columns">
<div class="column" id="qr"> <div class="column" id="qr">
<div class="${classMap({hidden: this.notSupported})}"> <div class="${classMap({hidden: !hasDevices})}">
<div class="button-wrapper"> <div class="button-wrapper">
<button class="start button is-primary ${classMap({hidden: this.videoRunning})}" @click="${() => this.qrCodeScannerInit(this)}" title="${i18n.t('start-scan')}">${i18n.t('start-scan')}</button> <button class="start button is-primary ${classMap({hidden: this.videoRunning})}" @click="${() => this.qrCodeScannerInit(this)}" title="${i18n.t('start-scan')}">${i18n.t('start-scan')}</button>
<button class="stop button is-primary ${classMap({hidden: !this.videoRunning})}" @click="${() => this.stopScanning()}" title="${i18n.t('stop-scan')}">${i18n.t('stop-scan')}</button> <button class="stop button is-primary ${classMap({hidden: !this.videoRunning})}" @click="${() => this.stopScanning()}" title="${i18n.t('stop-scan')}">${i18n.t('stop-scan')}</button>
<select id="videoSource" class="button" @change=${this.updateSource}></select> <select id="videoSource" class="button" @change=${this.updateSource}>
${Array.from(this._devices).map(item => html`<option value="${item[0]}">${item[1]}</option>`)}
</select>
</div> </div>
...@@ -505,7 +502,7 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) { ...@@ -505,7 +502,7 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
<div hidden><b>${i18n.t('data')}:</b> <span id="outputData"></span></div> <div hidden><b>${i18n.t('data')}:</b> <span id="outputData"></span></div>
</div> </div>
</div> </div>
<div class="${classMap({hidden: !this.notSupported})}"> <div class="${classMap({hidden: hasDevices})}">
${i18n.t('no-support')} ${i18n.t('no-support')}
</div> </div>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment