From 424de1f01f6624098076fc46746032a75b6ef8e9 Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Sun, 17 Nov 2024 18:00:27 +0530 Subject: [PATCH 1/5] initial commit --- src/app/app.module.ts | 2 + .../admin-overview/admin-overview.service.ts | 4 + .../public-form/public-form.entity.ts | 89 ++++++++++++ .../public-form/public-form.module.ts | 131 ++++++++++++++++++ .../template-export/template-export.entity.ts | 2 +- .../template-export/template-export.module.ts | 2 +- 6 files changed, 228 insertions(+), 2 deletions(-) create mode 100644 src/app/features/public-form/public-form.entity.ts create mode 100644 src/app/features/public-form/public-form.module.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index b544dec3b2..68ff9e9eec 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -88,6 +88,7 @@ import { AdminModule } from "./core/admin/admin.module"; import { Logging } from "./core/logging/logging.service"; import { APP_INITIALIZER_DEMO_DATA } from "./core/demo-data/demo-data.app-initializer"; import { TemplateExportModule } from "./features/template-export/template-export.module"; +import { PubliFormModule } from "./features/public-form/public-form.module"; /** * Main entry point of the application. @@ -132,6 +133,7 @@ import { TemplateExportModule } from "./features/template-export/template-export TodosModule, AdminModule, TemplateExportModule, + PubliFormModule, // top level component UiComponent, // Global Angular Material modules diff --git a/src/app/core/admin/admin-overview/admin-overview.service.ts b/src/app/core/admin/admin-overview/admin-overview.service.ts index 1788c0468b..4c60c690c1 100644 --- a/src/app/core/admin/admin-overview/admin-overview.service.ts +++ b/src/app/core/admin/admin-overview/admin-overview.service.ts @@ -27,5 +27,9 @@ export class AdminOverviewService { label: $localize`:admin menu item:Setup Wizard`, link: "/admin/setup-wizard", }, + { + label: $localize`:admin menu item:Manage Public Forms`, + link: "/admin/publicform", + }, ]; } diff --git a/src/app/features/public-form/public-form.entity.ts b/src/app/features/public-form/public-form.entity.ts new file mode 100644 index 0000000000..bc540adcb7 --- /dev/null +++ b/src/app/features/public-form/public-form.entity.ts @@ -0,0 +1,89 @@ +import { Entity } from "../../core/entity/model/entity"; +import { DatabaseEntity } from "../../core/entity/database-entity.decorator"; +import { DatabaseField } from "../../core/entity/database-field.decorator"; +import { LongTextDatatype } from "../../core/basic-datatypes/string/long-text.datatype"; +import { FileFieldConfig } from "../file/file.datatype"; +import { EntityBlockConfig } from "../../core/basic-datatypes/entity/entity-block/entity-block-config"; +import { TemplateExportFileDatatype } from "../template-export/template-export-file-datatype/template-export-file.datatype"; + +/** + * Represents a PublicForm that can be used to generate PDFs via API, + * replacing placeholders in the file with data from an entity. + * + * A PublicForm entity represents the meta-data of a template and can be added and manage by admin users. + */ +@DatabaseEntity("PublicForm") +export class PublicForm extends Entity { + static override label = $localize`:PublicForm:Public Forms`; + static override labelPlural = $localize`:PublicForm:Public Forms`; + static override toStringAttributes = ["title"]; + static override toBlockDetailsAttributes: EntityBlockConfig = { + title: "title", + fields: ["description"], + }; + static override route = "admin/public-form"; + + /** + * human-readable label + */ + @DatabaseField({ + label: $localize`:PublicForm:Title`, + validators: { required: true }, + }) + title: string; + + /** + * Additional description to guide users + */ + @DatabaseField({ + label: $localize`:PublicForm:Description`, + dataType: LongTextDatatype.dataType, + }) + description: string; + + /** + * The entity type(s) this template can be used with (i.e. placeholders matching the entity type) + */ + @DatabaseField({ + label: $localize`:PublicForm:Applicable Entity Types`, + labelShort: $localize`:PublicForm:Entity Types`, + editComponent: "EditEntityTypeDropdown", + isArray: true, + }) + applicableForEntityTypes: string[]; + + /** + * File (storing the file name) of the template uploaded to the server. + */ + @DatabaseField({ + label: $localize`:PublicForm:Template File`, + description: $localize`:PublicForm:Upload a specially prepared document that contains placeholders, which will be replace with actual data from a specific entity when generating a PDF.`, + validators: { required: true }, + dataType: TemplateExportFileDatatype.dataType, + additional: { + acceptedFileTypes: + ".docx, .doc, .odt, .xlsx, .xls, .ods, .pptx, .ppt, .odp", + } as FileFieldConfig, + }) + templateFile: string; + + /** + * ID of the template file in the server-side managed API. + * + * This is not displayed to users - they interact with the templateFile property instead + * while this templateId is automatically set when the file is uploaded. + */ + @DatabaseField() + templateId: string; + + /** + * A string with the pattern including placeholders for the file name of the generated files. + */ + @DatabaseField({ + label: $localize`:PublicForm:File name pattern for generated file`, + labelShort: $localize`:PublicForm:File name pattern`, + description: $localize`:PublicForm:The filename for the resulting file when using this template. You can use the same placeholders here as in the template file itself (e.g. "my-report_{d.name}.pdf").`, + validators: { required: true }, + }) + targetFileName: string; +} diff --git a/src/app/features/public-form/public-form.module.ts b/src/app/features/public-form/public-form.module.ts new file mode 100644 index 0000000000..1bf9a6cbd5 --- /dev/null +++ b/src/app/features/public-form/public-form.module.ts @@ -0,0 +1,131 @@ +import { NgModule } from "@angular/core"; +import { CommonModule } from "@angular/common"; +import { AsyncComponent, ComponentRegistry } from "../../dynamic-components"; +import { RouterService } from "../../core/config/dynamic-routing/router.service"; +import { ViewConfig } from "../../core/config/dynamic-routing/view-config.interface"; +import { EntityDetailsConfig } from "../../core/entity-details/EntityDetailsConfig"; +import { EntityListConfig } from "../../core/entity-list/EntityListConfig"; +import { AdminOverviewService } from "../../core/admin/admin-overview/admin-overview.service"; +import { EntityActionsMenuService } from "../../core/entity-details/entity-actions-menu/entity-actions-menu.service"; +import { DefaultDatatype } from "../../core/entity/default-datatype/default.datatype"; +import { Entity } from "../../core/entity/model/entity"; +import { TemplateExportFileDatatype } from "../template-export/template-export-file-datatype/template-export-file.datatype"; +import { TemplateExport } from "../template-export/template-export.entity"; +import { TemplateExportService } from "../template-export/template-export-service/template-export.service"; +import { PublicForm } from "./public-form.entity"; + +/** + * Manage template files with placeholders that can be used to render files for export of entities. + */ +@NgModule({ + declarations: [], + imports: [CommonModule], + providers: [ + { + provide: DefaultDatatype, + useClass: TemplateExportFileDatatype, + multi: true, + }, + ], +}) +export class PubliFormModule { + static databaseEntities = [PublicForm]; + + constructor( + components: ComponentRegistry, + routerService: RouterService, + adminOverviewService: AdminOverviewService, + entityActionsMenuService: EntityActionsMenuService, + templateExportService: TemplateExportService, + ) { + // components.addAll(dynamicComponents); + routerService.addRoutes(viewConfigs); + + entityActionsMenuService.registerActions([ + { + action: "template-export", + label: $localize`:entity context menu:Generate File`, + icon: "print", + tooltip: $localize`:entity context menu tooltip:Create a file based on a selected template.`, + permission: "read", + execute: async (e: Entity) => templateExportService.generateFile(e), + }, + ]); + + adminOverviewService.menuItems.push({ + label: $localize`:admin menu item:Manage Public forms`, + link: PublicForm.route, + }); + } +} + +// const dynamicComponents: [string, AsyncComponent][] = [ +// [ +// "EditTemplateExportFile", +// () => +// import( +// "../template-export/template-export-file-datatype/edit-template-export-file.component" +// ).then((c) => c.EditTemplateExportFileComponent), +// ], +// ]; + +const viewConfigs: ViewConfig[] = [ + // List View + { + _id: "view:" + PublicForm.route, + component: "EntityList", + config: { + entityType: PublicForm.ENTITY_TYPE, + columns: ["title", "description", "applicableForEntityTypes"], + filters: [{ id: "applicableForEntityTypes" }], + } as EntityListConfig, + }, + + // Details View + { + _id: "view:" + PublicForm.route + "/:id", + component: "EntityDetails", + config: { + entityType: PublicForm.ENTITY_TYPE, + panels: [ + { + components: [ + { + component: "Form", + config: { + fieldGroups: [ + { + fields: [ + "title", + "description", + "applicableForEntityTypes", + ], + }, + { + fields: [ + { + id: "template_explanation", + editComponent: "EditDescriptionOnly", + label: $localize`:PublicForm:Upload a specially prepared template file here. +The file can contain placeholders that will be replaced with actual data when a file is generated for a selected record. +For example {d.name} will be replaced with the value in the "name" field of the given entity. +See the documentation of the [carbone system](https://carbone.io/documentation.html#substitutions) for more information. + +The placeholder keys must match the field "Field ID" of the record data structure in Aam Digital. +You can find this in the Admin UI form builder (Edit Data Structure -> Details View) and edit a specific field to view its details. + +Template files can be in most office document formats (odt, docx, ods, xlsx, odp, pptx) or PDF.`, + }, + "templateFile", + "targetFileName", + ], + }, + ], + }, + }, + ], + }, + ], + } as EntityDetailsConfig, + }, +]; diff --git a/src/app/features/template-export/template-export.entity.ts b/src/app/features/template-export/template-export.entity.ts index 58e1111b7b..4b2c2f1bc0 100644 --- a/src/app/features/template-export/template-export.entity.ts +++ b/src/app/features/template-export/template-export.entity.ts @@ -21,7 +21,7 @@ export class TemplateExport extends Entity { title: "title", fields: ["description"], }; - static override route = "admin/template-export"; + static override route = "admin/template-exports"; /** * human-readable label diff --git a/src/app/features/template-export/template-export.module.ts b/src/app/features/template-export/template-export.module.ts index 29389d7a64..1495a81787 100644 --- a/src/app/features/template-export/template-export.module.ts +++ b/src/app/features/template-export/template-export.module.ts @@ -52,7 +52,7 @@ export class TemplateExportModule { ]); adminOverviewService.menuItems.push({ - label: $localize`:admin menu item:Manage Export Templates`, + label: $localize`:admin menu item:Manage Export Templatess`, link: TemplateExport.route, }); } From 6bc739c799ea6cfa3a815f6a59c623ceeaa6230b Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Mon, 25 Nov 2024 15:56:20 +0530 Subject: [PATCH 2/5] updated code for public form listing --- .../admin-overview/admin-overview.service.ts | 4 -- .../public-form/public-form.module.ts | 68 ++++--------------- 2 files changed, 14 insertions(+), 58 deletions(-) diff --git a/src/app/core/admin/admin-overview/admin-overview.service.ts b/src/app/core/admin/admin-overview/admin-overview.service.ts index 4c60c690c1..1788c0468b 100644 --- a/src/app/core/admin/admin-overview/admin-overview.service.ts +++ b/src/app/core/admin/admin-overview/admin-overview.service.ts @@ -27,9 +27,5 @@ export class AdminOverviewService { label: $localize`:admin menu item:Setup Wizard`, link: "/admin/setup-wizard", }, - { - label: $localize`:admin menu item:Manage Public Forms`, - link: "/admin/publicform", - }, ]; } diff --git a/src/app/features/public-form/public-form.module.ts b/src/app/features/public-form/public-form.module.ts index 1bf9a6cbd5..1d1296def7 100644 --- a/src/app/features/public-form/public-form.module.ts +++ b/src/app/features/public-form/public-form.module.ts @@ -8,11 +8,8 @@ import { EntityListConfig } from "../../core/entity-list/EntityListConfig"; import { AdminOverviewService } from "../../core/admin/admin-overview/admin-overview.service"; import { EntityActionsMenuService } from "../../core/entity-details/entity-actions-menu/entity-actions-menu.service"; import { DefaultDatatype } from "../../core/entity/default-datatype/default.datatype"; -import { Entity } from "../../core/entity/model/entity"; import { TemplateExportFileDatatype } from "../template-export/template-export-file-datatype/template-export-file.datatype"; -import { TemplateExport } from "../template-export/template-export.entity"; -import { TemplateExportService } from "../template-export/template-export-service/template-export.service"; -import { PublicForm } from "./public-form.entity"; +import { PublicFormConfig } from "./public-form-config"; /** * Manage template files with placeholders that can be used to render files for export of entities. @@ -29,64 +26,45 @@ import { PublicForm } from "./public-form.entity"; ], }) export class PubliFormModule { - static databaseEntities = [PublicForm]; + static databaseEntities = [PublicFormConfig]; constructor( components: ComponentRegistry, routerService: RouterService, adminOverviewService: AdminOverviewService, entityActionsMenuService: EntityActionsMenuService, - templateExportService: TemplateExportService, ) { - // components.addAll(dynamicComponents); routerService.addRoutes(viewConfigs); + console.log(PublicFormConfig.ENTITY_TYPE,"PublicFormConfig.ENTITY_TYPE") - entityActionsMenuService.registerActions([ - { - action: "template-export", - label: $localize`:entity context menu:Generate File`, - icon: "print", - tooltip: $localize`:entity context menu tooltip:Create a file based on a selected template.`, - permission: "read", - execute: async (e: Entity) => templateExportService.generateFile(e), - }, - ]); adminOverviewService.menuItems.push({ label: $localize`:admin menu item:Manage Public forms`, - link: PublicForm.route, + link: PublicFormConfig.route, }); } } -// const dynamicComponents: [string, AsyncComponent][] = [ -// [ -// "EditTemplateExportFile", -// () => -// import( -// "../template-export/template-export-file-datatype/edit-template-export-file.component" -// ).then((c) => c.EditTemplateExportFileComponent), -// ], -// ]; const viewConfigs: ViewConfig[] = [ // List View { - _id: "view:" + PublicForm.route, + + _id: "view:" + PublicFormConfig.route, component: "EntityList", config: { - entityType: PublicForm.ENTITY_TYPE, - columns: ["title", "description", "applicableForEntityTypes"], - filters: [{ id: "applicableForEntityTypes" }], + entityType: PublicFormConfig.ENTITY_TYPE, + columns: ["title", "description", "entity", "columns"], + filters: [{ id: "entity" }], } as EntityListConfig, }, // Details View { - _id: "view:" + PublicForm.route + "/:id", + _id: "view:" + PublicFormConfig.route + "/:id", component: "EntityDetails", config: { - entityType: PublicForm.ENTITY_TYPE, + entityType: PublicFormConfig.ENTITY_TYPE, panels: [ { components: [ @@ -98,28 +76,10 @@ const viewConfigs: ViewConfig[] = [ fields: [ "title", "description", - "applicableForEntityTypes", + "entity", + "columns" ], - }, - { - fields: [ - { - id: "template_explanation", - editComponent: "EditDescriptionOnly", - label: $localize`:PublicForm:Upload a specially prepared template file here. -The file can contain placeholders that will be replaced with actual data when a file is generated for a selected record. -For example {d.name} will be replaced with the value in the "name" field of the given entity. -See the documentation of the [carbone system](https://carbone.io/documentation.html#substitutions) for more information. - -The placeholder keys must match the field "Field ID" of the record data structure in Aam Digital. -You can find this in the Admin UI form builder (Edit Data Structure -> Details View) and edit a specific field to view its details. - -Template files can be in most office document formats (odt, docx, ods, xlsx, odp, pptx) or PDF.`, - }, - "templateFile", - "targetFileName", - ], - }, + } ], }, }, From b2bb4efb8a4a84ed7f105293c3c502f6221f4137 Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Mon, 25 Nov 2024 15:57:25 +0530 Subject: [PATCH 3/5] remove unused class --- .../public-form/public-form.entity.ts | 89 ------------------- 1 file changed, 89 deletions(-) delete mode 100644 src/app/features/public-form/public-form.entity.ts diff --git a/src/app/features/public-form/public-form.entity.ts b/src/app/features/public-form/public-form.entity.ts deleted file mode 100644 index bc540adcb7..0000000000 --- a/src/app/features/public-form/public-form.entity.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { Entity } from "../../core/entity/model/entity"; -import { DatabaseEntity } from "../../core/entity/database-entity.decorator"; -import { DatabaseField } from "../../core/entity/database-field.decorator"; -import { LongTextDatatype } from "../../core/basic-datatypes/string/long-text.datatype"; -import { FileFieldConfig } from "../file/file.datatype"; -import { EntityBlockConfig } from "../../core/basic-datatypes/entity/entity-block/entity-block-config"; -import { TemplateExportFileDatatype } from "../template-export/template-export-file-datatype/template-export-file.datatype"; - -/** - * Represents a PublicForm that can be used to generate PDFs via API, - * replacing placeholders in the file with data from an entity. - * - * A PublicForm entity represents the meta-data of a template and can be added and manage by admin users. - */ -@DatabaseEntity("PublicForm") -export class PublicForm extends Entity { - static override label = $localize`:PublicForm:Public Forms`; - static override labelPlural = $localize`:PublicForm:Public Forms`; - static override toStringAttributes = ["title"]; - static override toBlockDetailsAttributes: EntityBlockConfig = { - title: "title", - fields: ["description"], - }; - static override route = "admin/public-form"; - - /** - * human-readable label - */ - @DatabaseField({ - label: $localize`:PublicForm:Title`, - validators: { required: true }, - }) - title: string; - - /** - * Additional description to guide users - */ - @DatabaseField({ - label: $localize`:PublicForm:Description`, - dataType: LongTextDatatype.dataType, - }) - description: string; - - /** - * The entity type(s) this template can be used with (i.e. placeholders matching the entity type) - */ - @DatabaseField({ - label: $localize`:PublicForm:Applicable Entity Types`, - labelShort: $localize`:PublicForm:Entity Types`, - editComponent: "EditEntityTypeDropdown", - isArray: true, - }) - applicableForEntityTypes: string[]; - - /** - * File (storing the file name) of the template uploaded to the server. - */ - @DatabaseField({ - label: $localize`:PublicForm:Template File`, - description: $localize`:PublicForm:Upload a specially prepared document that contains placeholders, which will be replace with actual data from a specific entity when generating a PDF.`, - validators: { required: true }, - dataType: TemplateExportFileDatatype.dataType, - additional: { - acceptedFileTypes: - ".docx, .doc, .odt, .xlsx, .xls, .ods, .pptx, .ppt, .odp", - } as FileFieldConfig, - }) - templateFile: string; - - /** - * ID of the template file in the server-side managed API. - * - * This is not displayed to users - they interact with the templateFile property instead - * while this templateId is automatically set when the file is uploaded. - */ - @DatabaseField() - templateId: string; - - /** - * A string with the pattern including placeholders for the file name of the generated files. - */ - @DatabaseField({ - label: $localize`:PublicForm:File name pattern for generated file`, - labelShort: $localize`:PublicForm:File name pattern`, - description: $localize`:PublicForm:The filename for the resulting file when using this template. You can use the same placeholders here as in the template file itself (e.g. "my-report_{d.name}.pdf").`, - validators: { required: true }, - }) - targetFileName: string; -} From 582b47017a4b365abf489464ee90f91c1b37128f Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Mon, 25 Nov 2024 17:56:38 +0530 Subject: [PATCH 4/5] revert the code --- src/app/features/template-export/template-export.entity.ts | 2 +- src/app/features/template-export/template-export.module.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/features/template-export/template-export.entity.ts b/src/app/features/template-export/template-export.entity.ts index 4b2c2f1bc0..58e1111b7b 100644 --- a/src/app/features/template-export/template-export.entity.ts +++ b/src/app/features/template-export/template-export.entity.ts @@ -21,7 +21,7 @@ export class TemplateExport extends Entity { title: "title", fields: ["description"], }; - static override route = "admin/template-exports"; + static override route = "admin/template-export"; /** * human-readable label diff --git a/src/app/features/template-export/template-export.module.ts b/src/app/features/template-export/template-export.module.ts index 1495a81787..29389d7a64 100644 --- a/src/app/features/template-export/template-export.module.ts +++ b/src/app/features/template-export/template-export.module.ts @@ -52,7 +52,7 @@ export class TemplateExportModule { ]); adminOverviewService.menuItems.push({ - label: $localize`:admin menu item:Manage Export Templatess`, + label: $localize`:admin menu item:Manage Export Templates`, link: TemplateExport.route, }); } From 95fa7f127341f2cc2e7a49cbd3fe86e28c5472a8 Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Mon, 25 Nov 2024 19:30:27 +0530 Subject: [PATCH 5/5] update public config class --- .../public-form/public-form-config.ts | 23 +++++++++++++++---- .../public-form/public-form.component.ts | 1 + .../public-form/public-form.module.ts | 8 +------ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/app/features/public-form/public-form-config.ts b/src/app/features/public-form/public-form-config.ts index ffbfc5d866..7245950b88 100644 --- a/src/app/features/public-form/public-form-config.ts +++ b/src/app/features/public-form/public-form-config.ts @@ -1,12 +1,27 @@ import { Entity } from "../../core/entity/model/entity"; import { DatabaseEntity } from "../../core/entity/database-entity.decorator"; import { DatabaseField } from "../../core/entity/database-field.decorator"; +import { LongTextDatatype } from "app/core/basic-datatypes/string/long-text.datatype"; @DatabaseEntity("PublicFormConfig") export class PublicFormConfig extends Entity { - @DatabaseField() title: string; - @DatabaseField() description: string; - @DatabaseField() entity: string; - @DatabaseField() columns: string[][]; + static override label = $localize`:PublicFormConfig:Public Form`; + static override labelPlural = $localize`:PublicFormConfig:Public Forms`; + static override route = "admin/public-forms"; + + @DatabaseField({ + label: $localize`:PublicFormConfig:Title`, +}) title: string; + @DatabaseField({ + label: $localize`:PublicFormConfig:Description`, + dataType: LongTextDatatype.dataType +}) description: string; + @DatabaseField({ + label: $localize`:PublicFormConfig:Entity`, +}) entity: string; + @DatabaseField({ + label: $localize`:PublicFormConfig:Columns`, + isArray: true, +}) columns: string[][]; @DatabaseField() prefilled: { [key in string]: any }; } diff --git a/src/app/features/public-form/public-form.component.ts b/src/app/features/public-form/public-form.component.ts index 4695170de0..60562e51d2 100644 --- a/src/app/features/public-form/public-form.component.ts +++ b/src/app/features/public-form/public-form.component.ts @@ -83,6 +83,7 @@ export class PublicFormComponent implements OnInit { private async loadFormConfig() { const id = this.route.snapshot.paramMap.get("id"); this.formConfig = await this.entityMapper.load(PublicFormConfig, id); + console.log(await this.entityMapper.loadType(PublicFormConfig),"nanannanana") this.entityType = this.entities.get( this.formConfig.entity, ) as EntityConstructor; diff --git a/src/app/features/public-form/public-form.module.ts b/src/app/features/public-form/public-form.module.ts index 1d1296def7..03dba176c8 100644 --- a/src/app/features/public-form/public-form.module.ts +++ b/src/app/features/public-form/public-form.module.ts @@ -17,13 +17,7 @@ import { PublicFormConfig } from "./public-form-config"; @NgModule({ declarations: [], imports: [CommonModule], - providers: [ - { - provide: DefaultDatatype, - useClass: TemplateExportFileDatatype, - multi: true, - }, - ], + }) export class PubliFormModule { static databaseEntities = [PublicFormConfig];