bux fixes with template
This commit is contained in:
parent
8d9a49c337
commit
a46a5b4012
7 changed files with 35 additions and 31 deletions
|
|
@ -21,7 +21,7 @@ export class CameraComponent implements OnInit {
|
|||
|
||||
video: HTMLVideoElement;
|
||||
|
||||
ngOnInit() { console.log("Smile!"); }
|
||||
ngOnInit() { console.log("Camera", this.field.id); }
|
||||
|
||||
ngAfterViewInit() {
|
||||
|
||||
|
|
|
|||
|
|
@ -36,15 +36,25 @@ 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() {
|
||||
|
||||
console.log("Form before:", this.form);
|
||||
|
||||
/* Make a deep copy of the template */
|
||||
this.form = JSON.parse(JSON.stringify(this.template));
|
||||
|
||||
console.log("Template:", this.template);
|
||||
console.log("Form after:", this.form);
|
||||
|
||||
}
|
||||
|
||||
next() {
|
||||
|
||||
|
|
@ -58,36 +68,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("Something went wrong");
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -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() {
|
||||
|
||||
|
|
|
|||
|
|
@ -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
BIN
src/assets/monitor.jfif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
Loading…
Reference in a new issue