Skip to content

Commit 37f6d2b

Browse files
committed
Added an HTML element for inputting license key
1 parent df8de62 commit 37f6d2b

File tree

9 files changed

+116
-64
lines changed

9 files changed

+116
-64
lines changed

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
3+
import { FormsModule } from '@angular/forms';
34

45
import { AppRoutingModule } from './app-routing.module';
56
import { AppComponent } from './app.component';
@@ -17,11 +18,12 @@ import { TopBarComponent } from './top-bar/top-bar.component';
1718
BarcodeScannerComponent,
1819
ProductListComponent,
1920
TopBarComponent,
20-
21+
2122
],
2223
imports: [
2324
BrowserModule,
2425
AppRoutingModule,
26+
FormsModule,
2527
],
2628
providers: [],
2729
bootstrap: [AppComponent]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<span id="loading-status" style="font-size:x-large" [hidden]="isLoaded"
1+
<!-- <span id="loading-status" style="font-size:x-large" [hidden]="isLoaded"
22
>Loading Library...</span
33
>
4-
<br />
4+
<br /> -->
55

66
<input type="file" id="file" accept="image/*" (change)="onChange($event)" />
77
<div>
@@ -11,4 +11,4 @@
1111
<div id="imageview">
1212
<img id="image" />
1313
<canvas id="overlay"></canvas>
14-
</div>
14+
</div>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<span id="loading-status" style="font-size:x-large" [hidden]="isLoaded"
1+
<!-- <span id="loading-status" style="font-size:x-large" [hidden]="isLoaded"
22
>Loading Library...</span
33
>
4-
<br />
4+
<br /> -->
55

66
<div class="select">
77
<label for="videoSource">Video source: </label>
@@ -11,4 +11,4 @@
1111
<div id="videoview">
1212
<div class="dce-video-container" id="videoContainer"></div>
1313
<canvas id="overlay"></canvas>
14-
</div>
14+
</div>
Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
<h2>Examples</h2>
2-
3-
<div *ngFor="let product of products">
4-
<h3>
5-
<div *ngIf="product.id === 'reader'; else elseBlock">
6-
<a [title]="product.name + ' details'" [routerLink]="['/barcode-reader']"
7-
>>
8-
{{ product.name }}
9-
</a>
10-
</div>
11-
<ng-template #elseBlock
12-
><a
13-
[title]="product.name + ' details'"
14-
[routerLink]="['/barcode-scanner']"
15-
>>
16-
{{ product.name }}
17-
</a></ng-template
18-
>
19-
</h3>
20-
21-
<p *ngIf="product.description">Description: {{ product.description }}</p>
1+
<div>
2+
<div>
3+
Get a License key from <a href="https://www.dynamsoft.com/customer/license/trialLicense" target="_blank">here</a>
4+
</div>
5+
<input type="text" [(ngModel)]="inputText" [placeholder]="placeholderText">
6+
<button (click)="activate()">Activate SDK</button>
227
</div>
238

24-
<!--
25-
Copyright Google LLC. All Rights Reserved.
26-
Use of this source code is governed by an MIT-style license that
27-
can be found in the LICENSE file at https://angular.io/license
28-
-->
9+
<div *ngIf="showDiv">
10+
<h2>Examples</h2>
11+
<div *ngFor="let product of products">
12+
<h3>
13+
<div *ngIf="product.id === 'reader'; else elseBlock">
14+
<a [title]="product.name + ' details'" [routerLink]="['/barcode-reader']">>
15+
{{ product.name }}
16+
</a>
17+
</div>
18+
<ng-template #elseBlock><a [title]="product.name + ' details'" [routerLink]="['/barcode-scanner']">>
19+
{{ product.name }}
20+
</a></ng-template>
21+
</h3>
22+
23+
<p *ngIf="product.description">Description: {{ product.description }}</p>
24+
</div>
25+
</div>

src/app/product-list/product-list.component.ts

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,57 @@ import { Component } from '@angular/core';
22

33
import { products } from '../products';
44

5+
import { CoreModule, LicenseManager } from 'dynamsoft-barcode-reader-bundle';
6+
7+
import { SharedService } from '../shared.service';
8+
59
@Component({
610
selector: 'app-product-list',
711
templateUrl: './product-list.component.html',
812
styleUrls: ['./product-list.component.css'],
913
})
1014
export class ProductListComponent {
1115
products = products;
12-
}
16+
inputText: string = '';
17+
processedText: string = '';
18+
placeholderText: string = 'DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==';
19+
20+
constructor(private sharedService: SharedService) { }
21+
22+
async activate(): Promise<void> {
23+
this.processedText = this.inputText.toUpperCase();
24+
// Configure the paths where the .wasm files and other necessary resources for modules are located.
25+
CoreModule.engineResourcePaths = {
26+
std: 'assets/dynamsoft-capture-vision-std/',
27+
dip: 'assets/dynamsoft-image-processing/',
28+
core: 'assets/dynamsoft-core/',
29+
license: 'assets/dynamsoft-license/',
30+
cvr: 'assets/dynamsoft-capture-vision-router/',
31+
dbr: 'assets/dynamsoft-barcode-reader/',
32+
dce: 'assets/dynamsoft-camera-enhancer/',
33+
};
34+
35+
try {
36+
// Visit https://www.dynamsoft.com/customer/license/trialLicense?utm_source=github&product=dbr to get a trial license.
37+
let licenseKey: string = this.inputText === '' ? this.placeholderText : this.inputText;
38+
await LicenseManager.initLicense(licenseKey, true);
1339

14-
/*
15-
Copyright Google LLC. All Rights Reserved.
16-
Use of this source code is governed by an MIT-style license that
17-
can be found in the LICENSE file at https://angular.io/license
18-
*/
40+
41+
// Preload "BarcodeReader" module for saving the time of loading it when needed.
42+
CoreModule.loadWasm(['DBR']);
43+
44+
this.toggleDivVisibility();
45+
} catch (error) {
46+
alert(error);
47+
}
48+
49+
}
50+
51+
toggleDivVisibility(): void {
52+
this.sharedService.toggleShowDiv();
53+
}
54+
55+
get showDiv(): boolean {
56+
return this.sharedService.getShowDiv();
57+
}
58+
}

src/app/products.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
// import { CoreModule } from 'dynamsoft-core';
2-
// import { LicenseManager } from 'dynamsoft-license';
3-
// import 'dynamsoft-barcode-reader';
4-
import { CoreModule, LicenseManager } from 'dynamsoft-barcode-reader-bundle';
5-
6-
// Configure the paths where the .wasm files and other necessary resources for modules are located.
7-
CoreModule.engineResourcePaths = {
8-
std: 'assets/dynamsoft-capture-vision-std/',
9-
dip: 'assets/dynamsoft-image-processing/',
10-
core: 'assets/dynamsoft-core/',
11-
license: 'assets/dynamsoft-license/',
12-
cvr: 'assets/dynamsoft-capture-vision-router/',
13-
dbr: 'assets/dynamsoft-barcode-reader/',
14-
dce: 'assets/dynamsoft-camera-enhancer/',
15-
};
16-
17-
// Visit https://www.dynamsoft.com/customer/license/trialLicense?utm_source=github&product=dbr to get a trial license.
18-
LicenseManager.initLicense('DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==', true);
19-
20-
21-
// Preload "BarcodeReader" module for saving the time of loading it when needed.
22-
CoreModule.loadWasm(['DBR']);
231

242
export interface Product {
253
id: string;

src/app/shared.service.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { SharedService } from './shared.service';
4+
5+
describe('SharedService', () => {
6+
let service: SharedService;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
service = TestBed.inject(SharedService);
11+
});
12+
13+
it('should be created', () => {
14+
expect(service).toBeTruthy();
15+
});
16+
});

src/app/shared.service.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Injectable } from '@angular/core';
2+
3+
@Injectable({
4+
providedIn: 'root'
5+
})
6+
export class SharedService {
7+
private showDiv: boolean = false;
8+
9+
getShowDiv(): boolean {
10+
return this.showDiv;
11+
}
12+
13+
setShowDiv(value: boolean): void {
14+
this.showDiv = value;
15+
}
16+
17+
toggleShowDiv(): void {
18+
this.showDiv = !this.showDiv;
19+
}
20+
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<a [routerLink]="['/']">
2-
<h1>Dynamsoft Barcode Reader and Scanner</h1>
3-
</a>
4-
2+
<h1>Dynamsoft Capture Vision SDK</h1>
3+
</a>

0 commit comments

Comments
 (0)