diff --git a/package-lock.json b/package-lock.json index f91a41a..0fd8d31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4610,6 +4610,22 @@ } } }, + "jasmine": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-4.0.2.tgz", + "integrity": "sha512-YsrgxJQEggxzByYe4j68eQLOiQeSrPDYGv4sHhGBp3c6HHdq+uPXeAQ73kOAQpdLZ3/0zN7x/TZTloqeE1/qIA==", + "dev": true, + "requires": { + "glob": "^7.1.6", + "jasmine-core": "^4.0.0" + } + }, + "jasmine-core": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.0.1.tgz", + "integrity": "sha512-w+JDABxQCkxbGGxg+a2hUVZyqUS2JKngvIyLGu/xiw2ZwgsoSB0iiecLQsQORSeaKQ6iGrCyWG86RfNDuoA7Lg==", + "dev": true + }, "jest-worker": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.5.1.tgz", diff --git a/package.json b/package.json index 041ff88..377a52f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.0.0", "scripts": { "ng": "ng", + "test": "jasmine", "start": "ng serve", "build": "ng build", "watch": "ng build --watch --configuration development" @@ -26,6 +27,7 @@ "@angular/cli": "~13.2.2", "@angular/compiler-cli": "~13.2.0", "@types/node": "^12.11.1", + "jasmine": "^4.0.2", "typescript": "~4.5.2" } } diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json new file mode 100644 index 0000000..6afe603 --- /dev/null +++ b/spec/support/jasmine.json @@ -0,0 +1,13 @@ +{ + "spec_dir": "spec", + "spec_files": [ + "**/*[sS]pec.?(m)js" + ], + "helpers": [ + "helpers/**/*.?(m)js" + ], + "env": { + "stopSpecOnExpectationFailure": false, + "random": true + } +} diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index a0e2bc6..d703db0 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,11 +1,13 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { HomeComponent } from './home.component'; +import { ReportComponent } from './report.component'; import { ThanksComponent } from './thanks.component'; const routes: Routes = [ { path: '', component: HomeComponent }, - { path: 'thanks', component: ThanksComponent } + { path: 'thanks', component: ThanksComponent }, + { path: 'report', component: ReportComponent } ]; @NgModule({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8eee8ed..13af438 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -12,6 +12,7 @@ import { SignComponent } from './sign.component'; import { ThanksComponent } from './thanks.component'; import { AppRoutingModule } from './app-routing.module'; import { HomeComponent } from './home.component'; +import { ReportComponent } from './report.component'; @NgModule({ declarations: [ @@ -24,6 +25,7 @@ import { HomeComponent } from './home.component'; SignComponent, ThanksComponent, HomeComponent, + ReportComponent, ], imports: [ BrowserModule, diff --git a/src/app/camera.component.ts b/src/app/camera.component.ts index 975a293..a05b708 100644 --- a/src/app/camera.component.ts +++ b/src/app/camera.component.ts @@ -21,7 +21,7 @@ export class CameraComponent implements OnInit { video: HTMLVideoElement; - ngOnInit() { console.log("Smile!"); } + ngOnInit() { console.log("Camera", this.field.id); } ngAfterViewInit() { diff --git a/src/app/form.component.ts b/src/app/form.component.ts index 99422b7..7347f4f 100644 --- a/src/app/form.component.ts +++ b/src/app/form.component.ts @@ -36,15 +36,20 @@ import { Router } from '@angular/router'; }) export class FormComponent implements OnInit { - constructor(private route: Router) { } + constructor(private router: Router) { } @Input() template: Form; form: Form; - ngOnInit() { this.set() } + ngOnInit() { this.set(); } - set() { this.form = Object.assign({}, this.template); } + set() { + + /* Make a deep copy of the template */ + this.form = JSON.parse(JSON.stringify(this.template)); + + } next() { @@ -58,36 +63,33 @@ export class FormComponent implements OnInit { async submit() { - const results = {}; + const res = await fetch(this.form.submit, parseForm(this.form.steps)); - this.form.steps.forEach((s: Step) => { + res.ok ? + this.router.navigate(["/thanks"]) : + alert("Failed to connect to the backend."); - s.fields.forEach((f: Field) => { - - results[f.id] = f.value; - - }); - - }); - - try { - - const res = await fetch(this.form.submit, results); - - if (res.ok) { - - this.set(); - - this.route.navigate(["/thanks"]); - - } else { - - alert("Backend does't like you."); - - } - - } catch (e) { alert("Something went wrong."); } - } } + + + +/* Util to extract key, values from Form */ +const parseForm = (steps: Step[]) => { + + const results = {}; + + steps.forEach((s: Step) => { + + s.fields.forEach((f: Field) => { + + results[f.id] = f.value; + + }); + + }); + + return results; + +}; diff --git a/src/app/home.component.ts b/src/app/home.component.ts index 3471ba4..7b62035 100644 --- a/src/app/home.component.ts +++ b/src/app/home.component.ts @@ -16,6 +16,8 @@ import { checkin, checkout } from "src/assets/forms"; + Go To Report Page + ` }) diff --git a/src/app/radio.component.ts b/src/app/radio.component.ts index 4c5e014..32833d9 100644 --- a/src/app/radio.component.ts +++ b/src/app/radio.component.ts @@ -25,7 +25,7 @@ export class RadioComponent implements OnInit { @Input() field: Field; @Output() update: EventEmitter = new EventEmitter(); - ngOnInit() { console.log("Text", this.field.id); } + ngOnInit() { console.log("Radio", this.field.id); } check() { diff --git a/src/app/report.component.ts b/src/app/report.component.ts new file mode 100644 index 0000000..b6ec342 --- /dev/null +++ b/src/app/report.component.ts @@ -0,0 +1,53 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-report', + template: ` +
+ + + + + +
+ + {{ entry.name }} + +
+ +
+ +
+ `, + styles: [ + ] +}) +export class ReportComponent implements OnInit { + + data: Entry[]; + + ngOnInit() { + + this.data = data; + + // try { + + // const res = await fetch("url"); + + // } catch(e) { alert("Something went wrong."); } + + // this.data = res.json(); + + } + +} + + +/* Placeholder data */ +const data: Entry[] = [{ + name: "John Doe", + eid: "john.doe", + asset: "monitor", + complete: false, + photo: "./assets/monitor.jfif" +}] diff --git a/src/app/sign.component.ts b/src/app/sign.component.ts index 2ae87c8..87d9a87 100644 --- a/src/app/sign.component.ts +++ b/src/app/sign.component.ts @@ -19,7 +19,7 @@ export class SignComponent implements OnInit { pad: HTMLCanvasElement; - ngOnInit() { console.log("Sign your name!"); } + ngOnInit() { console.log("Sign", this.field.id); } ngAfterViewInit() { diff --git a/src/app/step.component.ts b/src/app/step.component.ts index 8e16b4a..813709c 100644 --- a/src/app/step.component.ts +++ b/src/app/step.component.ts @@ -46,13 +46,10 @@ export class StepComponent implements OnInit { @Input() step: Step; - ngOnInit() { console.log("Step", this.step); } + ngOnInit() { console.log("Step", this.step.prompt); } update() { - console.log(this.step.fields); - - /* Check for completeness */ for (let field of this.step.fields) { if (!field.ok) { this.step.ok = false; diff --git a/src/assets/monitor.jfif b/src/assets/monitor.jfif new file mode 100644 index 0000000..2ed1cca Binary files /dev/null and b/src/assets/monitor.jfif differ diff --git a/src/types.d.ts b/src/types.d.ts index 7f8c2c5..35b221c 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,11 +1,3 @@ -declare interface TextOptions { - modifier: string; -} - -declare interface RadioOptions { - choices: string[]; -} - declare interface Field { type: string; id: string; @@ -26,4 +18,12 @@ declare interface Form { goto: string; step: number; steps: Step[]; -} +} + +declare interface Entry { + name: string; + eid: string; + asset: string; + complete: boolean; + photo: string; +}