Import qr-scanner the rails way.
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
import { Controller } from "@hotwired/stimulus";
|
import { Controller } from "@hotwired/stimulus";
|
||||||
|
|
||||||
|
//import QrScanner from "qr-scanner"; // Rails findet jetzt über die Importmap deine Datei unter vendor/javascript/
|
||||||
|
// KORREKTUR: Lädt das Modul ohne Namens-Zuweisung, da die Legacy-Datei keinen Default-Export besitzt
|
||||||
|
import "qr-scanner";
|
||||||
|
|
||||||
export default class extends Controller {
|
export default class extends Controller {
|
||||||
static targets = ["input", "preview", "modal"];
|
static targets = ["input", "preview", "modal"];
|
||||||
|
|
||||||
@@ -13,7 +17,9 @@ export default class extends Controller {
|
|||||||
|
|
||||||
const videoElement = this.previewTarget;
|
const videoElement = this.previewTarget;
|
||||||
|
|
||||||
// Greift fehlerfrei auf die Klasse aus dem public-Ordner zu
|
// Scanner initialisieren (Direkt über die importierte Klasse ohne 'window.')
|
||||||
|
//this.qrScanner = new QrScanner(
|
||||||
|
// Greift jetzt absolut fehlerfrei auf die geladene Klasse zu
|
||||||
this.qrScanner = new window.QrScanner(
|
this.qrScanner = new window.QrScanner(
|
||||||
videoElement,
|
videoElement,
|
||||||
(result) => { this.handleScanSuccess(result.data); },
|
(result) => { this.handleScanSuccess(result.data); },
|
||||||
@@ -26,8 +32,8 @@ export default class extends Controller {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.qrScanner.start().catch((err) => {
|
this.qrScanner.start().catch((err) => {
|
||||||
|
alert("Kamera-Zugriff blockiert! Bitte prüfe die Browser-Berechtigungen.");
|
||||||
console.error("Kamera-Fehler:", err);
|
console.error("Kamera-Fehler:", err);
|
||||||
alert("Kamera konnte nicht gestartet werden.");
|
|
||||||
this.modalTarget.classList.add("hidden");
|
this.modalTarget.classList.add("hidden");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,6 @@
|
|||||||
<link rel="icon" href="/icon.svg" type="image/svg+xml">
|
<link rel="icon" href="/icon.svg" type="image/svg+xml">
|
||||||
<link rel="apple-touch-icon" href="/icon.png">
|
<link rel="apple-touch-icon" href="/icon.png">
|
||||||
|
|
||||||
<!-- Lädt die lokale Legacy-Datei direkt aus dem public-Ordner ohne Rails-Asset-Pipeline -->
|
|
||||||
<script src="/qr-scanner.js" data-turbo-track="reload"></script>
|
|
||||||
|
|
||||||
<%# Includes all stylesheet files in app/assets/stylesheets %>
|
<%# Includes all stylesheet files in app/assets/stylesheets %>
|
||||||
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
|
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
|
||||||
<%= javascript_importmap_tags %>
|
<%= javascript_importmap_tags %>
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ pin "@hotwired/turbo-rails", to: "turbo.min.js"
|
|||||||
pin "@hotwired/stimulus", to: "stimulus.min.js"
|
pin "@hotwired/stimulus", to: "stimulus.min.js"
|
||||||
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
|
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
|
||||||
pin_all_from "app/javascript/controllers", under: "controllers"
|
pin_all_from "app/javascript/controllers", under: "controllers"
|
||||||
|
pin "qr-scanner", to: "qr-scanner.js"
|
||||||
|
|||||||
Reference in New Issue
Block a user