Skip to content

Commit

Permalink
fix(Admin UI): manage related public forms directly from Admin Entity…
Browse files Browse the repository at this point in the history
… view (#2740)

closes #2708

---------

Co-authored-by: Sebastian Leidig <[email protected]>
  • Loading branch information
Abhinegi2 and sleidig authored Jan 3, 2025
1 parent c504723 commit 8537d86
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { NgForOf, NgIf } from "@angular/common";
import { MatTabsModule } from "@angular/material/tabs";
import { FaIconComponent } from "@fortawesome/angular-fontawesome";
import { MatButtonModule } from "@angular/material/button";
import { EntityTypeLabelPipe } from "../../../common-components/entity-type-label/entity-type-label.pipe";
import { ViewTitleComponent } from "../../../common-components/view-title/view-title.component";
import { AdminSectionHeaderComponent } from "../../building-blocks/admin-section-header/admin-section-header.component";
import { AdminEntityFormComponent } from "../admin-entity-form/admin-entity-form.component";
Expand All @@ -31,7 +30,6 @@ import { AdminTabTemplateDirective } from "../../building-blocks/admin-tabs/admi
MatTabsModule,
FaIconComponent,
MatButtonModule,
EntityTypeLabelPipe,
ViewTitleComponent,
AdminSectionHeaderComponent,
AdminEntityFormComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import {
ViewChild,
} from "@angular/core";
import { CommonModule } from "@angular/common";
import { FilterComponent } from "../../filter/filter/filter.component";
import { MatTab, MatTabGroup } from "@angular/material/tabs";
import { EntitiesTableComponent } from "../../common-components/entities-table/entities-table.component";
import { EntityConstructor } from "../../entity/model/entity";
import {
EntityListConfig,
Expand All @@ -29,7 +26,6 @@ import {
moveItemInArray,
} from "@angular/cdk/drag-drop";
import { FaIconComponent } from "@fortawesome/angular-fontawesome";
import { MatIconButton } from "@angular/material/button";
import { MatFormField, MatLabel } from "@angular/material/form-field";
import { MatSelect } from "@angular/material/select";
import { AdminTabsComponent } from "../building-blocks/admin-tabs/admin-tabs.component";
Expand All @@ -41,16 +37,11 @@ import { ViewTitleComponent } from "../../common-components/view-title/view-titl
standalone: true,
imports: [
CommonModule,
FilterComponent,
MatTabGroup,
EntitiesTableComponent,
MatTab,
EntityFieldsMenuComponent,
MatTableModule,
EntityFieldLabelComponent,
CdkDrag,
FaIconComponent,
MatIconButton,
CdkDropList,
MatFormField,
MatLabel,
Expand Down Expand Up @@ -92,11 +83,13 @@ export class AdminEntityListComponent implements OnChanges, AfterViewInit {
this.initAvailableFields();
}
}

ngAfterViewInit() {
const placeholderElement = this.placeholder.element.nativeElement;
placeholderElement.style.display = "none";
placeholderElement.parentNode.removeChild(placeholderElement);
}

/**
* Config allows to not have columnGroups and by default then display all `columns`,
* create an initial columnGroup in this case to allow full editing.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="hint-banner" i18n>
You can share the link to a "Public Form" with people who do not have an
account or embed it in your website. People can submit new records through
this form without logging in. For example, you can let participants
self-register this way and then review their data later.
</div>

<app-view-title [disableBackButton]="true" [displayInPlace]="true" i18n>
Public Forms
</app-view-title>

<div>
<app-related-entities
entityType="PublicFormConfig"
property="entity"
[columns]="['title', 'route', 'description']"
[entity]="dummyEntity"
clickMode="popup-details"
></app-related-entities>
</div>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { AdminEntityPublicFormsComponent } from "./admin-entity-public-forms-component";
import { MockedTestingModule } from "../../../utils/mocked-testing.module";
import { TestEntity } from "../../../utils/test-utils/TestEntity";

describe("AdminEntityPublicFormsComponent", () => {
let component: AdminEntityPublicFormsComponent;
let fixture: ComponentFixture<AdminEntityPublicFormsComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
AdminEntityPublicFormsComponent,
MockedTestingModule.withState(),
],
}).compileComponents();

fixture = TestBed.createComponent(AdminEntityPublicFormsComponent);
component = fixture.componentInstance;
component.entityConstructor = TestEntity;
});

it("should create the component", () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Component, Input } from "@angular/core";
import { EntityConstructor } from "app/core/entity/model/entity";
import { ViewTitleComponent } from "../../common-components/view-title/view-title.component";
import { RelatedEntitiesComponent } from "../../entity-details/related-entities/related-entities.component";

@Component({
selector: "app-admin-entity-public-forms-component",
standalone: true,
templateUrl: "./admin-entity-public-forms-component.html",
styleUrls: [
"./admin-entity-public-forms-component.scss",
"../admin-entity/admin-entity-styles.scss",
],
imports: [ViewTitleComponent, RelatedEntitiesComponent],
})
export class AdminEntityPublicFormsComponent {
/**
* The entity type for which to display public forms for.
*/
@Input() entityConstructor: EntityConstructor;

/**
* Fake entity instance to correctly filter/link related PublicFormConfigs
* using the standard related-entities component.
*/
protected dummyEntity: any = {
getId: () => this.entityConstructor.ENTITY_TYPE,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import { EntitySchemaField } from "app/core/entity/schema/entity-schema-field";
import { AdminEntityService } from "../../admin-entity.service";
import { StringDatatype } from "../../../basic-datatypes/string/string.datatype";
import { HelpButtonComponent } from "../../../common-components/help-button/help-button.component";
import { MatSort } from "@angular/material/sort";
import { EntityFieldLabelComponent } from "../../../common-components/entity-field-label/entity-field-label.component";
import { AnonymizeOptionsComponent } from "../../admin-entity-details/admin-entity-field/anonymize-options/anonymize-options.component";
import { FaIconComponent } from "@fortawesome/angular-fontawesome";

Expand Down Expand Up @@ -54,8 +52,6 @@ import { FaIconComponent } from "@fortawesome/angular-fontawesome";
CommonModule,
MatTooltipModule,
HelpButtonComponent,
MatSort,
EntityFieldLabelComponent,
AnonymizeOptionsComponent,
FaIconComponent,
],
Expand Down Expand Up @@ -162,6 +158,7 @@ export class AdminEntityGeneralSettingsComponent implements OnInit {
...unselectedOptions,
];
}

objectToLabel = (v: SimpleDropdownValue) => v?.label;
objectToValue = (v: SimpleDropdownValue) => v?.key;
}
Expand Down
13 changes: 12 additions & 1 deletion src/app/core/admin/admin-entity/admin-entity.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@
>
General Settings
</mat-list-item>

<mat-list-item
(click)="mode = 'publicForm'"
[activated]="mode === 'publicForm'"
i18n="admin entity: nav item"
>
Public Forms
</mat-list-item>
<app-beta-feature></app-beta-feature>
</mat-nav-list>

Expand Down Expand Up @@ -74,6 +80,11 @@
[(generalSettings)]="configEntitySettings"
></app-admin-entity-general-settings>
}
@case ("publicForm") {
<app-admin-entity-public-forms-component
[entityConstructor]="entityConstructor"
></app-admin-entity-public-forms-component>
}
}
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/app/core/admin/admin-entity/admin-entity.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { AdminEntityGeneralSettingsComponent } from "./admin-entity-general-sett
import { BetaFeatureComponent } from "../../../features/coming-soon/beta-feature/beta-feature.component";
import { DynamicComponentConfig } from "../../config/dynamic-components/dynamic-component-config.interface";
import { AdminEntityService } from "../admin-entity.service";
import { AdminEntityPublicFormsComponent } from "../admin-entity-public-forms/admin-entity-public-forms-component";

@Component({
selector: "app-admin-entity",
Expand All @@ -41,6 +42,7 @@ import { AdminEntityService } from "../admin-entity.service";
AdminEntityDetailsComponent,
AdminEntityGeneralSettingsComponent,
BetaFeatureComponent,
AdminEntityPublicFormsComponent,
],
templateUrl: "./admin-entity.component.html",
styleUrl: "./admin-entity.component.scss",
Expand All @@ -53,7 +55,7 @@ export class AdminEntityComponent implements OnInit {
configDetailsView: DynamicComponentConfig<EntityDetailsConfig>;
configListView: DynamicComponentConfig<EntityListConfig>;
configEntitySettings: EntityConfig;
protected mode: "details" | "list" | "general" = "details";
protected mode: "details" | "list" | "general" | "publicForm" = "details";

@ContentChild(TemplateRef) templateRef: TemplateRef<any>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ export class DemoPublicFormGeneratorService extends DemoDataGenerator<PublicForm
}

protected generateEntities(): PublicFormConfig[] {
const form = new PublicFormConfig("test");
const form = new PublicFormConfig();
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.route = "test";
form.columns = [
{
fields: [
Expand Down

0 comments on commit 8537d86

Please sign in to comment.