-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8963852
commit 2344ed1
Showing
7 changed files
with
241 additions
and
18 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<ng-container *ngIf="!scanning"> | ||
<div class="row my-5"> | ||
<div class="col-md-12"> | ||
<button class="btn btn-primary" (click)="scanBadge()" (touchend)="scanBadge()">Scan</button> | ||
</div> | ||
</div> | ||
</ng-container> | ||
|
||
<ng-container [style.visibility]="!scanning"> | ||
<video style="width: 350px; height: auto; object-fit: contain;" #videoElement></video> | ||
<button class="btn btn-sm btn-danger" (click)="cancel()">X</button> | ||
</ng-container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { QrScannerComponent } from './qr-scanner.component'; | ||
|
||
describe('QrScannerComponent', () => { | ||
let component: QrScannerComponent; | ||
let fixture: ComponentFixture<QrScannerComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ QrScannerComponent ] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(QrScannerComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {Component, ElementRef, EventEmitter, NgZone, OnDestroy, OnInit, Output, ViewChild} from '@angular/core'; | ||
import QrScanner from "qr-scanner"; | ||
import {WsComponent} from "@worldskills/worldskills-angular-lib"; | ||
import {AppService} from "../../services/app/app.service"; | ||
|
||
@Component({ | ||
selector: 'app-qr-scanner', | ||
templateUrl: './qr-scanner.component.html', | ||
styleUrls: ['./qr-scanner.component.css'] | ||
}) | ||
export class QrScannerComponent extends WsComponent implements OnInit, OnDestroy { | ||
|
||
@Output() scanResult: EventEmitter<string> = new EventEmitter<string>(); | ||
@ViewChild('videoElement') videoElement: ElementRef; | ||
|
||
scanning = false; | ||
qrScanner: QrScanner; | ||
|
||
constructor(private ngZone: NgZone) { | ||
super(); | ||
} | ||
|
||
ngOnInit(): void { | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
this.qrScanner = new QrScanner( | ||
this.videoElement.nativeElement, | ||
result => { | ||
// this.qrScanner.stop(); | ||
// this.scanning = false; | ||
this.ngZone.run(() => { | ||
console.log(result.data); | ||
this.scanResult.emit(result.data); | ||
}); | ||
}, | ||
{ | ||
highlightScanRegion: true, | ||
}, | ||
); | ||
this.scanBadge(); | ||
} | ||
|
||
scanBadge() { | ||
this.scanning = true; | ||
this.qrScanner.start(); | ||
} | ||
|
||
cancel() { | ||
this.qrScanner.stop(); | ||
this.scanning = false; | ||
} | ||
|
||
override ngOnDestroy() { | ||
super.ngOnDestroy(); | ||
this.qrScanner.destroy(); | ||
} | ||
} |