Commit be80fccc authored by Emily Jensen's avatar Emily Jensen

Code cleanup

parent 5053de8d
Pipeline #61255828 passed with stage
in 6 minutes and 48 seconds
import { Injectable, ViewChild, ElementRef } from "@angular/core";
const ZXing = require("nativescript-zxing");
import { Image } from "tns-core-modules/ui/image";
const ImageSource = require("image-source");
@Injectable({
providedIn: "root"
})
export class BackupCodePdfService {
constructor() {}
@ViewChild("image") image: ElementRef;
@ViewChild("barcodeImg") barcodeImg: ElementRef;
barcodeText = "00381500107604446618";
/**
* Downloads PDF containing backup code string and matching QR Code
* @param code: 32 character backupcode string
*/
download(code: string) {
alert(code);
const barcodeImage = <Image>this.barcodeImg.nativeElement;
const zx = new ZXing();
const newImg = zx.createBarcode({
encode: this.barcodeText,
format: ZXing.QR_CODE
});
barcodeImage.imageSource = ImageSource.fromNativeSource(newImg);
}
// const zx = new ZXing();
// const img = zx.createBarcode({
// encode: "Something else",
// height: 300,
// width: 300,
// format: ZXing.QR_CODE
// });
// const image: Image = this.image.nativeElement;
// image.imageSource = img;
// image.src = img;
// image.height = 300;
// image.width = 300;
// }
}
<DockLayout stretchLastChild="true" class="auth-container">
<FlexboxLayout
#foo
dock="bottom"
class="auth-actions"
flexDirection="row"
justifyContent="space-between"
>
<!-- <app-button text="Print" type="text" (tap)="print()"></app-button> -->
<app-button text="Submit" (tap)="onSubmit()"></app-button>
</FlexboxLayout>
<Scrollview>
<StackLayout class="auth-form-body">
<Button
(tap)="generateBarcode()"
id="barcode"
text="GENERATE BARCODE"
></Button>
<app-text-field
#password
autocorrect="false"
autocapitalizationType="none"
type="password"
label="Verify Password"
returnKeyType="next"
[isFormSubmitted]="form.isSubmitted"
[ngrxFormControl]="form.controls.oldPassword"
></app-text-field>
<Label class="p-10 m-b-10" text="Backup Code: "></Label>
<Label class="p-10 m-b-10" [text]="backupCode"></Label>
<Image
#barcodeImg
id="barcode-img"
height="500"
stretch="aspectFill"
class="text-center"
></Image>
<image #image></image>
</StackLayout>
</Scrollview>
</DockLayout>
<Scrollview #printArea>
<StackLayout class="auth-form-body">
<app-text-field
#password
autocorrect="false"
autocapitalizationType="none"
type="password"
label="Step 1: Verify Password"
returnKeyType="next"
[isFormSubmitted]="form.isSubmitted"
[ngrxFormControl]="form.controls.oldPassword"
></app-text-field>
<app-button text="Step 2: Submit" (tap)="onSubmit()"></app-button>
<Label class="p-10 m-b-10" text="Backup Code: "></Label>
<Label class="p-10 m-b-10" [text]="backupCode"></Label>
<Button
(tap)="generateBarcode()"
id="barcode"
text="Step 3: Generate Backup Code Page"
></Button>
<Image
#barcodeImg
id="barcode-img"
height="500"
stretch="aspectFill"
class="text-center"
></Image>
<app-button text="Step 4: Print" type="text" (tap)="print()"></app-button>
</StackLayout>
</Scrollview>
......@@ -11,7 +11,6 @@ import {
import { FormGroupState } from "ngrx-forms";
import { IForm } from "./manage-backup-code.reducer";
import { Printer } from "nativescript-printer";
import { BackupCodePdfService } from "../backup-code-pdf.service";
import { Image } from "tns-core-modules/ui/image";
const ZXing = require("nativescript-zxing");
......@@ -28,61 +27,48 @@ const ImageSource = require("image-source");
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ManageBackupCodeComponent implements OnDestroy {
@Input()
form: FormGroupState<IForm>;
@Input()
errorMessage: string;
@Input()
hasStarted: boolean;
@Input()
hasFinished: boolean;
@Input()
nonFieldErrors: string[];
@Input()
backupCode: string;
@Input() form: FormGroupState<IForm>;
@Input() errorMessage: string;
@Input() hasStarted: boolean;
@Input() hasFinished: boolean;
@Input() nonFieldErrors: string[];
@Input() backupCode: string;
@Output()
newBackupCode = new EventEmitter();
@Output()
getBackupPDF = new EventEmitter();
@Output()
reset = new EventEmitter();
@Output()
toggleShowConfirm = new EventEmitter();
@Output() newBackupCode = new EventEmitter();
@Output() getBackupPDF = new EventEmitter();
@Output() reset = new EventEmitter();
@Output() toggleShowConfirm = new EventEmitter();
@ViewChild("foo") codeInput: ElementRef;
@ViewChild("printArea") printArea: ElementRef;
@ViewChild("barcodeImg") barcodeImg: ElementRef;
barcodeText = "00381500107604446618";
@ViewChild("passwordInput") passwordInput: ElementRef;
constructor(private backupCodeToPdf: BackupCodePdfService) {}
onSubmit() {
if (this.form.isValid) {
alert("submitted and valid");
this.newBackupCode.emit();
}
}
generateBarcode() {
// const barcodeImage = <Image>this.barcodeImg.nativeElement;
// const zx = new ZXing();
// const newImg = zx.createBarcode({
// encode: this.barcodeText,
// format: ZXing.QR_CODE
// });
// barcodeImage.imageSource = ImageSource.fromNativeSource(newImg);
this.backupCodeToPdf.download("whatever");
}
ngOnDestroy() {
this.reset.emit();
}
generateBarcode() {
const barcodeImage = <Image>this.barcodeImg.nativeElement;
const zx = new ZXing();
const newImg = zx.createBarcode({
encode: this.backupCode,
format: ZXing.QR_CODE
});
barcodeImage.imageSource = ImageSource.fromNativeSource(newImg);
}
print() {
alert("backup code: " + this.backupCode);
const printer = new Printer();
printer.isSupported().then((supported: boolean) => {
printer.printScreen({ view: this.codeInput.nativeElement });
printer.printScreen({ view: this.printArea.nativeElement });
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment