Skip to content

Commit

Permalink
fix(demo): added public form in demo mode (#1673)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian <sebastian.leidig@gmail.com>
  • Loading branch information
TheSlimvReal and sleidig authored Jan 24, 2023
1 parent db457c4 commit 3be7ace
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/app/core/config/config-fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
]
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/demo-data/demo-data.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
25 changes: 25 additions & 0 deletions src/app/features/public-form/demo-public-form-generator.service.ts
Original file line number Diff line number Diff line change
@@ -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<PublicFormConfig> {
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];
}
}
12 changes: 8 additions & 4 deletions src/app/features/public-form/public-form.component.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -27,7 +27,7 @@ import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
imports: [EntityFormComponent, MatButtonModule, MatCardModule],
standalone: true,
})
export class PublicFormComponent<E extends Entity> {
export class PublicFormComponent<E extends Entity> implements OnInit {
private entityType: EntityConstructor<E>;
private prefilled: Partial<E> = {};
formConfig: PublicFormConfig;
Expand All @@ -44,8 +44,12 @@ export class PublicFormComponent<E extends Entity> {
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))
Expand Down

0 comments on commit 3be7ace

Please sign in to comment.