Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: Notification Setting Page #2712

Merged
merged 168 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
168 commits
Select commit Hold shift + click to select a range
832f23a
feat(*): firebase integration for push notification
Ayush8923 Nov 27, 2024
04b6672
feat(*): create the wrapper function for the firebase messaging
Ayush8923 Nov 29, 2024
c29861f
feat(*): create the push notification UI
Ayush8923 Nov 29, 2024
6e7ed4b
fix(*): update the notification UI alignment
Ayush8923 Nov 29, 2024
5293440
fix(*): update the notification UI styling
Ayush8923 Nov 29, 2024
afac897
fix(*): update the notification list UI
Ayush8923 Dec 2, 2024
4f60d7c
fix
Ayush8923 Dec 2, 2024
4199026
fix(*): update the aam digital firebase credintals
Ayush8923 Dec 2, 2024
91b6a2e
fix(*): refactore the push notification service and create the new No…
Ayush8923 Dec 3, 2024
30132b1
feat(*): integrate the firebase send api to send the notification to …
Ayush8923 Dec 3, 2024
3e3562c
fix(*): remove the hardcoded project ID
Ayush8923 Dec 3, 2024
0dae24c
fix(*): update the notification entity fields
Ayush8923 Dec 3, 2024
c13bfe6
fix(*): implement the get the notification list and cleanups
Ayush8923 Dec 4, 2024
c277454
fix(*): linting checks
Ayush8923 Dec 10, 2024
6e30e7a
fix(*): added the padding in the notification item class
Ayush8923 Dec 10, 2024
3896fcf
Merge branch 'master' into feat/push-notification-firebase-integration
Ayush8923 Dec 10, 2024
9d20b82
fix(*): update the firebaseConfig import
Ayush8923 Dec 10, 2024
c384ebd
Merge branch 'feat/push-notification-firebase-integration' of https:/…
Ayush8923 Dec 10, 2024
7af4344
fix(*): added the firebase config in the environment prod and spec file
Ayush8923 Dec 10, 2024
71ed3b4
fix(*): linting checks fixes
Ayush8923 Dec 10, 2024
7da91d3
feat(*): update the notification list UI
Ayush8923 Dec 11, 2024
e0961ee
fix*(*): fix the indentation
Ayush8923 Dec 11, 2024
da0a887
fix(*): update the notification list UI
Ayush8923 Dec 11, 2024
d3eaa1a
fix(*): cleanups and refactoring
Ayush8923 Dec 11, 2024
457e7d6
fix(*): update the code description
Ayush8923 Dec 11, 2024
ef93d0d
fix(*): added the logging
Ayush8923 Dec 11, 2024
5c37352
fix(*): cleanups
Ayush8923 Dec 11, 2024
1d05768
fix(*): remove the unwanted styles
Ayush8923 Dec 11, 2024
c7f38e0
fix(*): minor updates on the markAsRead Logic and cleanups
Ayush8923 Dec 11, 2024
73329b0
fix(*): update the notification setting item
Ayush8923 Dec 11, 2024
66e074a
fix(*): added the inline css
Ayush8923 Dec 11, 2024
cb769b4
fix(*): fix the prettier checks
Ayush8923 Dec 12, 2024
5c3ca42
feat(*): initiate the notification setting page
Ayush8923 Dec 12, 2024
fc34c93
feat(*): create the own component for the user notification setting
Ayush8923 Dec 12, 2024
d389271
fix(*): UI updates
Ayush8923 Dec 12, 2024
4e4f600
fix(*): added the enable and disable the notification type and cleanups
Ayush8923 Dec 12, 2024
ada0d4f
fix(*): redirect the user to notification setting page via notificati…
Ayush8923 Dec 12, 2024
09f19c9
fix(*): added the comment in the event types
Ayush8923 Dec 12, 2024
c309525
fix(*): implement for the add new notification rule functionality and…
Ayush8923 Dec 13, 2024
7ae4240
fix(*): code cleanups and unwanted code
Ayush8923 Dec 13, 2024
94fc5ef
Merge branch 'feat/notification-final-integration' into feat/notifica…
Ayush8923 Dec 13, 2024
5383470
fix(*): create the own component for the entity type selector
Ayush8923 Dec 13, 2024
1c7daa9
Merge branch 'feat/notification-setting-page' of https://github.com/A…
Ayush8923 Dec 13, 2024
783c4b6
fix(*): add the place holder
Ayush8923 Dec 13, 2024
e16be28
fix(gst)
Ayush8923 Dec 13, 2024
8547364
fix(*): remove the comments
Ayush8923 Dec 13, 2024
1c917a3
fix(*): create the entity type dropdown component
Ayush8923 Dec 13, 2024
f657512
fix(*): fix the linting checks
Ayush8923 Dec 13, 2024
d4ddae3
fix(*): remove the unused imports
Ayush8923 Dec 13, 2024
3548a97
fix(*): update the test cases and indentation
Ayush8923 Dec 13, 2024
f03a8d6
fix(*): update the changes in the notification setting page
Ayush8923 Dec 13, 2024
7ad1167
fix(*): add the placeholder in the entity type selector
Ayush8923 Dec 13, 2024
943f4a9
fix(i18n): add and improve translations
sleidig Dec 13, 2024
ec72442
fix(*): remove the duplicate code and refactor the edit entity type d…
Ayush8923 Dec 13, 2024
07deddd
fix(*): update the spec file describe name
Ayush8923 Dec 13, 2024
59c6b87
Merge branch 'master' into feat/entity-type-dropdown-component
Ayush8923 Dec 13, 2024
49bbeaa
fix(*): revert the languages files
Ayush8923 Dec 13, 2024
f1c6af5
Merge branch 'master' into feat/entity-type-dropdown-component
Ayush8923 Dec 13, 2024
5d31b5a
Update src/app/core/entity/entity-type-selector/entity-type-selector.…
sleidig Dec 13, 2024
75e4b23
fix(*): code cleanups and change the file name of entity dropdown
Ayush8923 Dec 16, 2024
af475c7
fix(*): update the entity type select component name
Ayush8923 Dec 16, 2024
fda4326
Merge branch 'master' into feat/entity-type-dropdown-component
Ayush8923 Dec 16, 2024
8a305a4
Merge branch 'feat/1055_notifications-final' into feat/notification-f…
Ayush8923 Dec 16, 2024
610241f
fix(*): revert the firebase implementation changes
Ayush8923 Dec 16, 2024
99174b4
fix(*): add the app component html file
Ayush8923 Dec 16, 2024
05a0fa7
fix(*): suggestion implemented
Ayush8923 Dec 16, 2024
057b73f
fix(*): update the indentation in the notification component
Ayush8923 Dec 16, 2024
14c8d0d
fix(*): add the notfication list UI mocked data
Ayush8923 Dec 16, 2024
2ee5dc2
fix(*): remove the mocked notification data fcm token
Ayush8923 Dec 16, 2024
64b9fc0
fix(*): few condition updates
Ayush8923 Dec 16, 2024
862d9c4
fix(*): revert the firebase implementation changes in the notfication…
Ayush8923 Dec 16, 2024
fe2db79
fix(*): remove the unused code
Ayush8923 Dec 16, 2024
513e0d2
Merge branch 'feat/notification-final-integration' into feat/notifica…
Ayush8923 Dec 16, 2024
603c9db
fix(*): codecleans & remove unwanted imports
Ayush8923 Dec 16, 2024
b8b2d95
Merge branch 'feat/notification-setting-page' of https://github.com/A…
Ayush8923 Dec 16, 2024
a0af2ab
fix(*): import the public form module
Ayush8923 Dec 16, 2024
b613fd1
Merge branch 'feat/entity-type-dropdown-component' of https://github.…
Ayush8923 Dec 16, 2024
d31ebe0
fix(*): update the naming convention and few cleanups
Ayush8923 Dec 16, 2024
8478abf
fix(*): remove the unused styling
Ayush8923 Dec 16, 2024
ff1f2ec
fix(*): cleanups and update the styling
Ayush8923 Dec 16, 2024
33a64e4
fix(*): fix the indentation of user notification spec file
Ayush8923 Dec 16, 2024
d02d46e
fix(*): add the i18n for translation
Ayush8923 Dec 16, 2024
797ddc7
fix(*): remove the unused imports
Ayush8923 Dec 16, 2024
4624539
fix(*): add the i18n for translation
Ayush8923 Dec 16, 2024
ddaf431
Merge branch 'feat/notification-final-integration' into feat/notifica…
Ayush8923 Dec 16, 2024
1442987
fix(*): implement if the only one notification rule then not show the…
Ayush8923 Dec 16, 2024
7960fe7
fix(*): added the i18n-label
Ayush8923 Dec 16, 2024
9145c85
fix(*): cleanups in the entity type select component
Ayush8923 Dec 16, 2024
2988840
fix(*): add the i18n
Ayush8923 Dec 16, 2024
71153a3
fix(*): update the notification event file name
Ayush8923 Dec 16, 2024
23313d8
fix(*): update the indentation and add the comment
Ayush8923 Dec 17, 2024
3acb0e7
Merge branch 'feat/notification-final-integration' into feat/notifica…
Ayush8923 Dec 17, 2024
63d49be
fix(*): cleanups
Ayush8923 Dec 17, 2024
24e4156
Merge branch 'feat/notification-final-integration' into feat/notifica…
Ayush8923 Dec 17, 2024
96dc68e
fix(*): updaet the test cases for the notification setting page
Ayush8923 Dec 17, 2024
fbe2907
fix(*): update the code and ui as per the suggestion
Ayush8923 Dec 17, 2024
7201c20
fix(*): added the date and time in the tooltip
Ayush8923 Dec 17, 2024
6475489
fix(*): use the new syntax for if and for
Ayush8923 Dec 17, 2024
07d2c7c
fix(*): add the comment in the notification time pipe file
Ayush8923 Dec 17, 2024
ebc9f39
fix(*): remove the unused imports
Ayush8923 Dec 17, 2024
ed517f6
Merge branch 'feat/notification-final-integration' of https://github.…
Ayush8923 Dec 17, 2024
2c009db
fix(*): update the test cases of entity type select component
Ayush8923 Dec 17, 2024
5c3160b
fix(*): update the notification file name
Ayush8923 Dec 18, 2024
fc0332b
fix(*): update the notfication html file name
Ayush8923 Dec 18, 2024
cab30c7
fix(*): update the file notification file name
Ayush8923 Dec 18, 2024
b6da287
Merge branch 'feat/notification-final-integration' of https://github.…
Ayush8923 Dec 18, 2024
f94ab94
fix(*): update the notification component spec name
Ayush8923 Dec 18, 2024
46afdc4
Merge branch 'feat/notification-final-integration' into feat/notifica…
Ayush8923 Dec 18, 2024
656630a
feat(*): update in the notification list ui
Ayush8923 Dec 19, 2024
c71f389
fix(*): update the notification time pipe and date on the tooltip
Ayush8923 Dec 19, 2024
a842f5b
fix(*): create the own function for the stop propogation
Ayush8923 Dec 19, 2024
f6ea242
fix(*): update the name of the enabled notification
Ayush8923 Dec 19, 2024
25b4b31
fix(*gst)
Ayush8923 Dec 19, 2024
7249bb4
fix(*): update the jsDoc in the notification component
Ayush8923 Dec 19, 2024
fdd50cc
Merge branch 'feat/notification-final-integration' into feat/notifica…
Ayush8923 Dec 19, 2024
1244000
fix(*): update the few changes in the notifcation list ui
Ayush8923 Dec 19, 2024
7adaadc
prevent submenu actions to close notifications panel
sleidig Dec 19, 2024
8807f1c
fix(*): update the notification setting UI
Ayush8923 Dec 20, 2024
82263ac
Merge branch 'feat/notification-final-integration' of https://github.…
Ayush8923 Dec 20, 2024
92247dc
fix(*): update the time of mock notification
Ayush8923 Dec 20, 2024
4a0766c
feat(*): update the notification setting UI
Ayush8923 Dec 23, 2024
81b59e9
Merge branch 'feat/notification-final-integration' into feat/notifica…
Ayush8923 Dec 23, 2024
6755afc
fix
Ayush8923 Dec 23, 2024
60e519d
fix(*): update the jsDoc in notification setting page
Ayush8923 Dec 23, 2024
c9e9b12
translated time periods + more mock events
sleidig Dec 23, 2024
d2e25f4
UI tuning
sleidig Dec 23, 2024
03ddd6e
fix outputs
sleidig Dec 23, 2024
0566b50
fix outputs and tests
sleidig Dec 23, 2024
6534650
fix(*): added the position sticky
Ayush8923 Dec 23, 2024
01d7f97
fix(*): update the notification list header styling
Ayush8923 Dec 23, 2024
64e2d0f
fix(*): update the notification setting page UI
Ayush8923 Dec 24, 2024
fd6a6c7
fix(*): update the style class name
Ayush8923 Dec 24, 2024
82b7d9b
fix(*): update the notification setting page test cases
Ayush8923 Dec 24, 2024
82194ca
fix(*): update the test cases and cleanups
Ayush8923 Dec 24, 2024
a5d827b
fix(*): add the comment and remove unused imports
Ayush8923 Dec 24, 2024
3b07b28
fix(*): refactore the code of notification setting page
Ayush8923 Dec 24, 2024
81b1c1b
fix(*): revert the notification event file changes + added the jsDoc
Ayush8923 Dec 24, 2024
d28d8a6
fix(*): remove the unwanted imports
Ayush8923 Dec 24, 2024
fc9c183
fix(*): added ngonit in the entity type select component
Ayush8923 Dec 24, 2024
1d6ff42
i18n label clarifications
sleidig Dec 27, 2024
604e218
tuning texts
sleidig Dec 27, 2024
8f72c07
fix(*): Merge branch 'feat/1055_notifications-final' of https://githu…
Ayush8923 Jan 2, 2025
47371cd
Merge branch 'feat/notification-setting-page' of https://github.com/A…
Ayush8923 Jan 2, 2025
0cb9c22
fix(*): cleanups
Ayush8923 Jan 2, 2025
bc7dc53
fix(*): cleanups and update the code according the suggestion
Ayush8923 Jan 2, 2025
5e3fcd7
fix(*): added the warning icon in the where you receive notification …
Ayush8923 Jan 2, 2025
c2ca65f
fix(*): added the badge text if the notification is enabled and disabled
Ayush8923 Jan 2, 2025
4e68945
fix(*): update the ordering and tooltip text
Ayush8923 Jan 2, 2025
a3bef65
fix(*): cleanups and refactoring
Ayush8923 Jan 2, 2025
4a11ca0
fix(*): update the file name for the notification method
Ayush8923 Jan 2, 2025
228df71
fix(*): update the css for the notification method select
Ayush8923 Jan 2, 2025
023cf5e
fix(*): remove the unused code
Ayush8923 Jan 2, 2025
95196d7
fix(*): the notification setting pop up auto close after redirect
Ayush8923 Jan 2, 2025
54e06fc
fix(*): update the notification setting component
Ayush8923 Jan 3, 2025
0a62d5d
fix(*): update the notification method select component
Ayush8923 Jan 3, 2025
91d64d6
Merge branch 'feat/1055_notifications-final' into feat/notification-s…
sleidig Jan 3, 2025
4cc3643
rename setting - settings
sleidig Jan 3, 2025
959443f
refine notification method select
sleidig Jan 3, 2025
aa0f95f
fix(Admin UI): field group titles are saved again (#2765)
Abhinegi2 Jan 3, 2025
ba89478
fix(Admin UI): correctly save changes to fields from Public Forms Edi…
Abhinegi2 Jan 3, 2025
70519f3
fix(*): update the code as per the suggestions
Ayush8923 Jan 3, 2025
6cc76e8
fix(*): update the notification pannel wrapper styling
Ayush8923 Jan 3, 2025
92e1146
refactor: turn entity-type-select into a form-control
sleidig Jan 3, 2025
16e3f21
change to new entity-type-select
sleidig Jan 3, 2025
c504723
refactor(core): add option to entities-table to open full details vie…
sleidig Jan 3, 2025
8537d86
fix(Admin UI): manage related public forms directly from Admin Entity…
Abhinegi2 Jan 3, 2025
c8f9351
refactor: turn entity-type-select into a form-control
sleidig Jan 3, 2025
661e7b2
Merge branch 'refactor/entity-type-select2' into feat/notification-se…
sleidig Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</div>

<app-view-actions>
<app-dialog-buttons [form]="form.formGroup" [entity]="entity">
<app-dialog-buttons [form]="form" [entity]="entity">
<button
mat-menu-item
[appExportData]="[entity]"
Expand Down
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 @@ -12,7 +12,8 @@
>
<!-- GROUP HEADER -->
<app-admin-section-header
[(title)]="group.header"
[title]="group.header"
(titleChange)="group.header = $event; emitUpdatedConfig()"
(remove)="removeGroup(i)"
></app-admin-section-header>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ export class AdminEntityFormComponent implements OnChanges {

this._config = value;
}

get config(): FormConfig {
return this._config;
}

private _config: FormConfig;

@Output() configChange = new EventEmitter<FormConfig>();
Expand Down Expand Up @@ -163,7 +165,7 @@ export class AdminEntityFormComponent implements OnChanges {
];
}

private emitUpdatedConfig() {
protected emitUpdatedConfig() {
this.configChange.emit(this.config);
}

Expand Down Expand Up @@ -291,6 +293,7 @@ export class AdminEntityFormComponent implements OnChanges {

this.emitUpdatedConfig();
}

/**
* drop handler specifically for the "create new Text field" item
* @param event
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>
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,
};
}
13 changes: 12 additions & 1 deletion src/app/core/admin/admin-entity.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import { TestBed } from "@angular/core/testing";

import { AdminEntityService } from "./admin-entity.service";
import { EntityMapperService } from "../entity/entity-mapper/entity-mapper.service";
import { mockEntityMapper } from "../entity/entity-mapper/mock-entity-mapper-service";

describe("AdminEntityService", () => {
let service: AdminEntityService;

beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
providers: [
{
provide: EntityMapperService,
useValue: mockEntityMapper(),
},
],
});
service = TestBed.inject(AdminEntityService);
});

it("should be created", () => {
expect(service).toBeTruthy();
});

// saving tested via AdminEntityComponent (see admin-entity.component.spec.ts)
});
68 changes: 67 additions & 1 deletion src/app/core/admin/admin-entity.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { EventEmitter, Injectable } from "@angular/core";
import { EventEmitter, inject, Injectable } from "@angular/core";
import { EntityConstructor } from "../entity/model/entity";
import { Config } from "../config/config";
import { EntityConfig } from "../entity/entity-config";
import { EntityConfigService } from "../entity/entity-config.service";
import { EntityMapperService } from "../entity/entity-mapper/entity-mapper.service";
import { EntityListConfig } from "../entity-list/EntityListConfig";
import { EntityDetailsConfig } from "../entity-details/EntityDetailsConfig";
import { DynamicComponentConfig } from "../config/dynamic-components/dynamic-component-config.interface";

/**
* Simply service to centralize updates between various admin components in the form builder.
Expand All @@ -9,6 +16,7 @@ import { EntityConstructor } from "../entity/model/entity";
})
export class AdminEntityService {
public entitySchemaUpdated = new EventEmitter<void>();
private entityMapper = inject(EntityMapperService);

/**
* Set a new schema field to the given entity and trigger update event for related admin components.
Expand All @@ -24,4 +32,62 @@ export class AdminEntityService {
entityType.schema.set(fieldId, updatedEntitySchema);
this.entitySchemaUpdated.next();
}

/**
* Updates the EntityConfig in the database to take any in-memory changes
* of the EntityConstructor and persist them to the config doc.
*
* @param entityConstructor The entity type to be updated in the Config DB
* @param configEntitySettings (optional) general entity settings to also be applied
* @param configListView (optional) list view settings also to be applied
* @param configDetailsView (optional) details view settings also to be applied
*/
public async setAndSaveEntityConfig(
entityConstructor: EntityConstructor,
configEntitySettings?: EntityConfig,
configListView?: DynamicComponentConfig<EntityListConfig>,
configDetailsView?: DynamicComponentConfig<EntityDetailsConfig>,
): Promise<{ previous: Config; current: Config }> {
const originalConfig = await this.entityMapper.load(
Config,
Config.CONFIG_KEY,
);
const newConfig = originalConfig.copy();

let entitySchemaConfig: EntityConfig =
this.getEntitySchemaFromConfig(newConfig, entityConstructor) ?? {};
// Initialize config if not present
entitySchemaConfig.attributes = entitySchemaConfig.attributes ?? {};

for (const [fieldId, field] of entityConstructor.schema.entries()) {
entitySchemaConfig.attributes[fieldId] = field;
}

// Add additional general settings if available
if (configEntitySettings) {
Object.assign(entitySchemaConfig, configEntitySettings);
}

// Add additional view config if available
if (configListView) {
newConfig.data[EntityConfigService.getListViewId(entityConstructor)] =
configListView;
}
if (configDetailsView) {
newConfig.data[EntityConfigService.getDetailsViewId(entityConstructor)] =
configDetailsView;
}

const updatedConfig: Config = await this.entityMapper.save(newConfig);
return { previous: originalConfig, current: updatedConfig };
}

private getEntitySchemaFromConfig(
config: Config<unknown>,
entityConstructor: EntityConstructor,
): EntityConfig {
const entityConfigKey =
EntityConfigService.PREFIX_ENTITY_CONFIG + entityConstructor.ENTITY_TYPE;
return config.data[entityConfigKey];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { Entity, EntityConstructor } from "../../../entity/model/entity";
import { FaDynamicIconComponent } from "../../../common-components/fa-dynamic-icon/fa-dynamic-icon.component";
import { FontAwesomeTestingModule } from "@fortawesome/angular-fontawesome/testing";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { EntityMapperService } from "app/core/entity/entity-mapper/entity-mapper.service";
import { mockEntityMapper } from "app/core/entity/entity-mapper/mock-entity-mapper-service";

describe("AdminEntityGeneralSettingsComponent", () => {
let component: AdminEntityGeneralSettingsComponent;
Expand Down Expand Up @@ -41,6 +43,12 @@ describe("AdminEntityGeneralSettingsComponent", () => {
ReactiveFormsModule,
FormsModule,
],
providers: [
{
provide: EntityMapperService,
useValue: mockEntityMapper(),
},
],
}).compileComponents();
});

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ describe("AdminEntityComponent", () => {
config: expectedViewConfig,
});
expect(actual.data[entityConfigId]).toEqual(expectedEntityConfig);
// TODO: this expectation is not useful yet:
expect(component.configEntitySettings).toEqual(component.entityConstructor);

// cleanup:
AdminTestEntity.schema.delete("testSaveField");
Expand Down
Loading
Loading