Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Toolkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
digital blueprint
Web Component Framework
Toolkit
Commits
76c217b4
Commit
76c217b4
authored
4 years ago
by
Steinwender, Tamara
Browse files
Options
Downloads
Patches
Plain Diff
Add color border to QR code scanner, Update README for QR code scanner
parent
c862e755
No related branches found
No related tags found
No related merge requests found
Pipeline
#13332
passed
4 years ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/qr-code-scanner/README.md
+24
-2
24 additions, 2 deletions
packages/qr-code-scanner/README.md
packages/qr-code-scanner/src/qr-code-scanner.js
+11
-15
11 additions, 15 deletions
packages/qr-code-scanner/src/qr-code-scanner.js
with
35 additions
and
17 deletions
packages/qr-code-scanner/README.md
+
24
−
2
View file @
76c217b4
# Q
r C
ode Scanner Web Component
# Q
R c
ode Scanner Web Component
[
GitLab Repository
](
https://gitlab.tugraz.at/dbp/web-components/qr-code-scanner
)
[
GitLab Repository
](
https://gitlab.tugraz.at/dbp/web-components/qr-code-scanner
)
...
@@ -11,11 +11,29 @@
...
@@ -11,11 +11,29 @@
<dbp-qr-code-scanner></dbp-qr-code-scanner>
<dbp-qr-code-scanner></dbp-qr-code-scanner>
```
```
The QR code Scanner Web Component uses a camera device, which you can select(if you have more than one).
With this camera device you can scan a QR code. If a QR code is detected a event will be fired named:
`'dbp-qr-code-scanner-data'`
.
In this event you can read the data of the qr code with:
`'event.detail'`
.
## Attributes
## Attributes
-
`lang`
(optional, default:
`de`
): set to
`de`
or
`en`
for German or English
-
`lang`
(optional, default:
`de`
): set to
`de`
or
`en`
for German or English
-
example
`<dbp-qr-code-scanner lang="de" client-id="my-client-id"></dbp-notification>`
-
example
`<dbp-qr-code-scanner lang="de"></dbp-qr-code-scanner>`
-
`scan-is-ok`
(optional, default:
`false`
): set to
`true`
or
`false`
for green or red border of the QR code.
The colors are from css vars (
`--dbp-success-bg-color`
and
`--dbp-danger-bg-color`
)
-
example
`<dbp-person-select scan-is-ok></dbp-person-select>`
-
`show-output`
(optional, default:
`false`
): set to
`true`
for showing
a box under the video canvas with the read QR code data
-
example
`<dbp-qr-code-scanner show-output></dbp-qr-code-scanner>`
-
`stop-scan`
(optional, default:
`false`
): set to
`true`
when you don't want to start the QR code reader immediatly
after loaded. This attribute is also used to stop the QR code reader if you don't need it anymore.
-
example
`<dbp-qr-code-scanner stop-scan></dbp-qr-code-scanner>`
## Events
-
`'dbp-qr-code-scanner-data'`
: Outgoing Event which is fired if a QR code is detected. The data of the detected QR code is in
`event.detail`
.
## Local development
## Local development
...
@@ -54,3 +72,7 @@ You can try the webcomponent with this example QR Code.
...
@@ -54,3 +72,7 @@ You can try the webcomponent with this example QR Code.


### Hint
Add the attribute
`show-output`
for debugging propose.
-
example:
`<dbp-qr-code-scanner show-output></dbp-qr-code-scanner>`
This diff is collapsed.
Click to expand it.
packages/qr-code-scanner/src/qr-code-scanner.js
+
11
−
15
View file @
76c217b4
...
@@ -157,6 +157,7 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
...
@@ -157,6 +157,7 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
this
.
stopScan
=
false
;
this
.
stopScan
=
false
;
this
.
askPermission
=
true
;
this
.
askPermission
=
true
;
let
video
=
document
.
createElement
(
"
video
"
);
let
video
=
document
.
createElement
(
"
video
"
);
let
canvasElement
=
this
.
_
(
"
#canvas
"
);
let
canvasElement
=
this
.
_
(
"
#canvas
"
);
let
canvas
=
canvasElement
.
getContext
(
"
2d
"
);
let
canvas
=
canvasElement
.
getContext
(
"
2d
"
);
...
@@ -166,12 +167,10 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
...
@@ -166,12 +167,10 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
let
outputMessage
=
this
.
_
(
"
#outputMessage
"
);
let
outputMessage
=
this
.
_
(
"
#outputMessage
"
);
let
outputData
=
this
.
_
(
"
#outputData
"
);
let
outputData
=
this
.
_
(
"
#outputData
"
);
//TODO
let
color
=
this
.
scanIsOk
?
getComputedStyle
(
this
)
let
color
=
this
.
scanIsOk
?
getComputedStyle
(
document
.
documentElement
)
.
getPropertyValue
(
'
--dbp-success-bg-color
'
)
:
getComputedStyle
(
this
)
.
getPropertyValue
(
'
--dbp-success-bg-color
'
)
:
getComputedStyle
(
document
.
documentElement
)
.
getPropertyValue
(
'
--dbp-danger-bg-color
'
);
.
getPropertyValue
(
'
--dbp-danger-bg-color
'
);
function
drawLine
(
begin
,
end
,
color
)
{
function
drawLine
(
begin
,
end
,
color
)
{
canvas
.
beginPath
();
canvas
.
beginPath
();
canvas
.
moveTo
(
begin
.
x
,
begin
.
y
);
canvas
.
moveTo
(
begin
.
x
,
begin
.
y
);
...
@@ -252,10 +251,10 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
...
@@ -252,10 +251,10 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
inversionAttempts
:
"
dontInvert
"
,
inversionAttempts
:
"
dontInvert
"
,
});
});
if
(
code
)
{
if
(
code
)
{
drawLine
(
code
.
location
.
topLeftCorner
,
code
.
location
.
topRightCorner
,
that
.
scanIsOk
?
'
green
'
:
'
red
'
);
drawLine
(
code
.
location
.
topLeftCorner
,
code
.
location
.
topRightCorner
,
color
);
drawLine
(
code
.
location
.
topRightCorner
,
code
.
location
.
bottomRightCorner
,
that
.
scanIsOk
?
'
green
'
:
'
red
'
);
drawLine
(
code
.
location
.
topRightCorner
,
code
.
location
.
bottomRightCorner
,
color
);
drawLine
(
code
.
location
.
bottomRightCorner
,
code
.
location
.
bottomLeftCorner
,
that
.
scanIsOk
?
'
green
'
:
'
red
'
);
drawLine
(
code
.
location
.
bottomRightCorner
,
code
.
location
.
bottomLeftCorner
,
color
);
drawLine
(
code
.
location
.
bottomLeftCorner
,
code
.
location
.
topLeftCorner
,
that
.
scanIsOk
?
'
green
'
:
'
red
'
);
drawLine
(
code
.
location
.
bottomLeftCorner
,
code
.
location
.
topLeftCorner
,
color
);
outputMessage
.
hidden
=
true
;
outputMessage
.
hidden
=
true
;
outputData
.
parentElement
.
hidden
=
false
;
outputData
.
parentElement
.
hidden
=
false
;
outputData
.
innerText
=
code
.
data
;
outputData
.
innerText
=
code
.
data
;
...
@@ -279,9 +278,9 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
...
@@ -279,9 +278,9 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
this
.
videoRunning
=
false
;
this
.
videoRunning
=
false
;
}
}
sendUrl
(
url
)
{
sendUrl
(
data
)
{
const
event
=
new
CustomEvent
(
"
dbp-qr-code-scanner-
url
"
,
const
event
=
new
CustomEvent
(
"
dbp-qr-code-scanner-
data
"
,
{
bubbles
:
true
,
composed
:
true
,
detail
:
url
});
{
bubbles
:
true
,
composed
:
true
,
detail
:
data
});
this
.
dispatchEvent
(
event
);
this
.
dispatchEvent
(
event
);
}
}
...
@@ -351,9 +350,6 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
...
@@ -351,9 +350,6 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
`
;
`
;
}
}
//doku
//demo
render
()
{
render
()
{
return
html
`
return
html
`
<div class="columns">
<div class="columns">
...
@@ -384,7 +380,7 @@ export class QrCodeScanner extends ScopedElementsMixin(DBPLitElement) {
...
@@ -384,7 +380,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="
border
${
classMap
({
hidden
:
!
this
.
notSupported
})}
">
<div class="
${
classMap
({
hidden
:
!
this
.
notSupported
})}
">
${
i18n
.
t
(
'
no-support
'
)}
${
i18n
.
t
(
'
no-support
'
)}
</div>
</div>
</div>
</div>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment