From 3be7aceb645305e3bd309bd64fae5d290208bdec Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 24 Jan 2023 16:07:21 +0100 Subject: [PATCH] fix(demo): added public form in demo mode (#1673) Co-authored-by: Sebastian --- src/app/core/config/config-fix.ts | 5 ++++ src/app/core/demo-data/demo-data.module.ts | 2 ++ .../demo-public-form-generator.service.ts | 25 +++++++++++++++++++ .../public-form/public-form.component.ts | 12 ++++++--- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/app/features/public-form/demo-public-form-generator.service.ts diff --git a/src/app/core/config/config-fix.ts b/src/app/core/config/config-fix.ts index d58abeceee..5def0b94fd 100644 --- a/src/app/core/config/config-fix.ts +++ b/src/app/core/config/config-fix.ts @@ -168,6 +168,11 @@ export const defaultJsonConfig = { "label": $localize`:Dashboard shortcut widget|record attendance shortcut:Add Child`, "icon": "plus", "link": "/child/new", + }, + { + "label": $localize`:Dashboard shortcut widget|open public form:Public Registration Form`, + "icon": "file-circle-check", + "link": "/public-form/test", } ] } diff --git a/src/app/core/demo-data/demo-data.module.ts b/src/app/core/demo-data/demo-data.module.ts index 6c7ea84d05..808204dbd2 100644 --- a/src/app/core/demo-data/demo-data.module.ts +++ b/src/app/core/demo-data/demo-data.module.ts @@ -36,8 +36,10 @@ import { DemoUserGeneratorService } from "../user/demo-user-generator.service"; import { DemoHistoricalDataGenerator } from "../../features/historical-data/demo-historical-data-generator"; import { DemoPermissionGeneratorService } from "../permissions/demo-permission-generator.service"; import { DemoTodoGeneratorService } from "../../features/todos/model/demo-todo-generator.service"; +import { DemoPublicFormGeneratorService } from "../../features/public-form/demo-public-form-generator.service"; const demoDataGeneratorProviders = [ + ...DemoPublicFormGeneratorService.provider(), ...DemoConfigGeneratorService.provider(), ...DemoChildGenerator.provider({ count: 120 }), ...DemoSchoolGenerator.provider({ count: 8 }), diff --git a/src/app/features/public-form/demo-public-form-generator.service.ts b/src/app/features/public-form/demo-public-form-generator.service.ts new file mode 100644 index 0000000000..42e2ccead7 --- /dev/null +++ b/src/app/features/public-form/demo-public-form-generator.service.ts @@ -0,0 +1,25 @@ +import { Injectable } from "@angular/core"; +import { DemoDataGenerator } from "../../core/demo-data/demo-data-generator"; +import { PublicFormConfig } from "./public-form-config"; + +@Injectable() +export class DemoPublicFormGeneratorService extends DemoDataGenerator { + static provider() { + return [ + { + provide: DemoPublicFormGeneratorService, + useClass: DemoPublicFormGeneratorService, + }, + ]; + } + + protected generateEntities(): PublicFormConfig[] { + const form = new PublicFormConfig("test"); + form.title = $localize`Example form`; + form.description = $localize`This is a form that can be shared as a link or embedded in a website. It can be filled by users without having an account. For example you can let participants self-register their details and just review the records within Aam Digital.`; + form.entity = "Child"; + form.prefilled = { status: "new" }; + form.columns = [["name", "phone", "gender", "dateOfBirth", "center"]]; + return [form]; + } +} diff --git a/src/app/features/public-form/public-form.component.ts b/src/app/features/public-form/public-form.component.ts index 75b6124955..8c51e7dcd1 100644 --- a/src/app/features/public-form/public-form.component.ts +++ b/src/app/features/public-form/public-form.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { PouchDatabase } from "../../core/database/pouch-database"; import { ActivatedRoute } from "@angular/router"; import { EntityRegistry } from "../../core/entity/database-entity.decorator"; @@ -27,7 +27,7 @@ import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; imports: [EntityFormComponent, MatButtonModule, MatCardModule], standalone: true, }) -export class PublicFormComponent { +export class PublicFormComponent implements OnInit { private entityType: EntityConstructor; private prefilled: Partial = {}; formConfig: PublicFormConfig; @@ -44,8 +44,12 @@ export class PublicFormComponent { private configService: ConfigService, private entitySchemaService: EntitySchemaService, private snackbar: MatSnackBar - ) { - this.database.initRemoteDB(); + ) {} + + ngOnInit() { + if (!this.database["pouchDB"]) { + this.database.initRemoteDB(); + } // wait for config to be initialized this.configService.configUpdates .pipe(untilDestroyed(this))