Merged in feature/HIMA-16-scanning-component (pull request #52)

Feature/HIMA-16 scanning component
This commit is contained in:
Peter Skrlj
2019-02-13 17:13:24 +00:00
committed by Eraldo Hasanaj
6 changed files with 39 additions and 9 deletions

View File

@@ -89,6 +89,7 @@
.recent-search-content {
display: grid;
grid-template-columns: auto;
min-height: 50px;
}
.recent-searches-label {

View File

@@ -4,6 +4,7 @@
Scannen Sie den Artikel um Informationen zu erhalten.
</caption>
<app-barcode-scanner-scandit
#scanner
(scan)="triggerSearch($event)"
></app-barcode-scanner-scandit>

View File

@@ -7,6 +7,7 @@
border-radius: 5px;
box-shadow: 0px -2px 24px 0px rgba(220, 226, 233, 0.8);
user-select: none;
margin-bottom: 90px;
h1 {
font-family: 'Open Sans';

View File

@@ -1,16 +1,21 @@
import { BarcodeScannerScanditComponent } from './components/barcode-scanner-scandit/barcode-scanner-scandit.component';
import { ProductMapping } from './../../core/mappings/product.mapping';
import { Product } from 'src/app/core/models/product.model';
import {
AllowProductLoad,
AddSearch,
ChangeCurrentRoute,
AddProcess
} from '../../core/store/actions/process.actions';
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, ViewChild } from '@angular/core';
import { Search } from 'src/app/core/models/search.model';
import { Router } from '@angular/router';
import { Store } from '@ngxs/store';
import { Process } from 'src/app/core/models/process.model';
import { getRandomPic } from 'src/app/core/utils/process.util';
import { Breadcrumb } from 'src/app/core/models/breadcrumb.model';
import { ProductService } from 'src/app/core/services/product.service';
import { AddSelectedProduct } from 'src/app/core/store/actions/product.actions';
@Component({
selector: 'app-barcode-search',
@@ -18,7 +23,12 @@ import { Breadcrumb } from 'src/app/core/models/breadcrumb.model';
styleUrls: ['barcode-search.component.scss']
})
export class BarcodeSearchComponent implements OnInit {
constructor(private store: Store, private router: Router) {}
@ViewChild('scanner') scanner: BarcodeScannerScanditComponent;
constructor(
private store: Store,
private router: Router,
protected productService: ProductService
) {}
ngOnInit() {}
@@ -31,10 +41,17 @@ export class BarcodeSearchComponent implements OnInit {
skip: 0,
firstLoad: true
};
this.store.dispatch(new AllowProductLoad());
this.store.dispatch(new AddSearch(search));
this.store.dispatch(new ChangeCurrentRoute('/search-results#start'));
this.router.navigate(['/search-results#start']);
this.productService.searchItems(search).subscribe(items => {
if (items.length > 0) {
const product = new ProductMapping().fromItemDTO(items[0]);
this.store.dispatch(new AddSelectedProduct(items[0]));
const currentRoute = 'product-details/' + product.id;
this.store.dispatch(new ChangeCurrentRoute(currentRoute));
this.router.navigate([currentRoute]);
} else {
this.scanner.scanToggle();
}
});
}
createProcess() {

View File

@@ -4,7 +4,8 @@ import {
ViewChild,
EventEmitter,
Output,
AfterViewInit
AfterViewInit,
ChangeDetectorRef
} from '@angular/core';
import { BarcodeFormat, Result } from '@zxing/library';
import { ZXingScannerComponent } from '@zxing/ngx-scanner';
@@ -34,7 +35,10 @@ export class BarcodeScannerScanditComponent implements AfterViewInit {
@ViewChild('scanner') scanner: ScanditSdkBarcodePickerComponent;
log = 'tst';
constructor(private cameraError: CameraErrorHandler) {}
constructor(
private cameraError: CameraErrorHandler,
private cdRef: ChangeDetectorRef
) {}
ngAfterViewInit() {
this.cameraError.notAllowed.subscribe(v => (this.errorAccess = v));
@@ -54,12 +58,15 @@ export class BarcodeScannerScanditComponent implements AfterViewInit {
if (result.barcodes.length > 0) {
this.code = result.barcodes[0].data;
this.enabled = false;
this.search();
}
}
scanToggle() {
this.enabled = !this.enabled;
this.enabled = true;
this.ready = false;
this.cdRef.detectChanges();
setTimeout(() => this.cdRef.detectChanges(), 200);
}
search() {
@@ -72,6 +79,7 @@ export class BarcodeScannerScanditComponent implements AfterViewInit {
.picker as any;
this.errorOther = !picker.scanner.isReadyToWork;
picker.cameraManager.cameraSwitcherEnabled = false;
picker.barcodePickerGui.cameraSwitcherElement = null;
picker.cameraManager.triggerFatalError = e => {
console.error(e);
this.errorOther = true;
@@ -82,6 +90,8 @@ export class BarcodeScannerScanditComponent implements AfterViewInit {
const imageElement = element.childNodes[0].childNodes[0]
.childNodes[6] as any;
imageElement.src = '';
this.cdRef.detectChanges();
}
scanErrorHandler($event) {