Compare commits

...
Sign in to create a new pull request.
Author SHA1 Message Date
Gundersen
6382544457 bux fixes 2022-03-01 14:30:09 -06:00
Gundersen
a46a5b4012 bux fixes with template 2022-03-01 13:58:54 -06:00
Gundersen
8d9a49c337 boilerplate report page 2022-03-01 11:31:11 -06:00
Gundersen
5f0f80a7cd testing initialized 2022-03-01 10:57:15 -06:00
14 changed files with 128 additions and 39 deletions

16
package-lock.json generated
View file

@ -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",

View file

@ -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"
}
}

13
spec/support/jasmine.json Normal file
View file

@ -0,0 +1,13 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.?(m)js"
],
"helpers": [
"helpers/**/*.?(m)js"
],
"env": {
"stopSpecOnExpectationFailure": false,
"random": true
}
}

View file

@ -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({

View file

@ -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,

View file

@ -21,7 +21,7 @@ export class CameraComponent implements OnInit {
video: HTMLVideoElement;
ngOnInit() { console.log("Smile!"); }
ngOnInit() { console.log("Camera", this.field.id); }
ngAfterViewInit() {

View file

@ -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;
};

View file

@ -16,6 +16,8 @@ import { checkin, checkout } from "src/assets/forms";
<app-form *ngIf="action=='checkout'" [template]="checkout"></app-form>
<a routerLink="/report">Go To Report Page</a>
<footer>Accenture | 2022</footer>
`
})

View file

@ -25,7 +25,7 @@ export class RadioComponent implements OnInit {
@Input() field: Field;
@Output() update: EventEmitter<null> = new EventEmitter();
ngOnInit() { console.log("Text", this.field.id); }
ngOnInit() { console.log("Radio", this.field.id); }
check() {

View file

@ -0,0 +1,53 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-report',
template: `
<div class="report">
<span *ngFor="let entry of data">
<img [src]="entry.photo"/>
<div class="info">
{{ entry.name }}
</div>
</span>
</div>
`,
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"
}]

View file

@ -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() {

View file

@ -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;

BIN
src/assets/monitor.jfif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

18
src/types.d.ts vendored
View file

@ -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;
}