Skip to content

Commit

Permalink
Merge branch 'feat/translation-poeditor-integration' of https://githu…
Browse files Browse the repository at this point in the history
…b.com/Aam-Digital/ndb-core into feat/translation-poeditor-integration
  • Loading branch information
Ayush8923 committed Nov 25, 2024
2 parents 2e8e192 + a0459d6 commit 732810c
Show file tree
Hide file tree
Showing 30 changed files with 4,321 additions and 3,663 deletions.
4,485 changes: 2,231 additions & 2,254 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion src/app/child-dev-project/attendance/model/recurring-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { asArray } from "../../../utils/utils";
@DatabaseEntity("RecurringActivity")
export class RecurringActivity extends Entity {
static override route = "attendance/recurring-activity";
static override toStringAttributes = ["title"];
static override label = $localize`:label for entity:Recurring Activity`;
static override labelPlural = $localize`:label (plural) for entity:Recurring Activities`;

static create(title: string = ""): RecurringActivity {
const instance = new RecurringActivity();
Expand All @@ -27,7 +30,12 @@ export class RecurringActivity extends Entity {
}

/** primary name to identify the activity */
@DatabaseField()
@DatabaseField({
label: $localize`:Label for the title of a recurring activity:Title`,
validators: {
required: true,
},
})
title: string = "";

/**
Expand All @@ -36,34 +44,39 @@ export class RecurringActivity extends Entity {
* This is also assigned to individual events' category generated for this activity.
*/
@DatabaseField({
label: $localize`:Label for the interaction type of a recurring activity:Type`,
dataType: "configurable-enum",
additional: INTERACTION_TYPE_CONFIG_ID,
})
type: InteractionType;

/** IDs of children linked to this activity */
@DatabaseField({
label: $localize`:Label for the participants of a recurring activity:Participants`,
dataType: "entity",
isArray: true,
})
participants: string[] = [];

/** IDs of groups (schools, teams) whose (active) members should be included in the activity*/
@DatabaseField({
label: $localize`:Label for the linked schools of a recurring activity:Groups`,
dataType: "entity",
isArray: true,
})
linkedGroups: string[] = [];

/** IDs of children that should be excluded from this activity despite being a group member */
@DatabaseField({
label: $localize`:Label for excluded participants of a recurring activity:Excluded Participants`,
dataType: "entity",
isArray: true,
})
excludedParticipants: string[] = [];

/** IDs of the users who are responsible for conducting this activity */
@DatabaseField({
label: $localize`:Label for the assigned user(s) of a recurring activity:Assigned user(s)`,
dataType: "entity",
isArray: true,
})
Expand Down
18 changes: 16 additions & 2 deletions src/app/child-dev-project/notes/model/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import { PLACEHOLDERS } from "../../../core/entity/schema/entity-schema-field";
@DatabaseEntity("Note")
export class Note extends Entity {
static override toStringAttributes = ["subject"];
static override label = $localize`:label for entity:Note`;
static override labelPlural = $localize`:label (plural) for entity:Notes`;
static override hasPII = true;

static create(
Expand Down Expand Up @@ -73,6 +75,7 @@ export class Note extends Entity {
// TODO: remove these special properties (children, schools) and use relatedEntities instead once the attendance system is generalized (#1364)
/** IDs of Child entities linked with this note */
@DatabaseField({
label: $localize`:Label for the participants field of a note:Participants`,
dataType: "entity",
isArray: true,
additional: "Child",
Expand All @@ -91,6 +94,7 @@ export class Note extends Entity {
private childrenAttendance: EventAttendanceMap = new EventAttendanceMap();

@DatabaseField({
label: $localize`:Label for the date of a note:Date`,
dataType: "date-only",
defaultValue: {
mode: "dynamic",
Expand All @@ -100,14 +104,20 @@ export class Note extends Entity {
})
date: Date;

@DatabaseField()
@DatabaseField({
label: $localize`:Label for the subject of a note:Subject`,
})
subject: string;

@DatabaseField({ dataType: "long-text" })
@DatabaseField({
label: $localize`:Label for the actual notes of a note:Notes`,
dataType: "long-text",
})
text: string;

/** IDs of users that authored this note */
@DatabaseField({
label: $localize`:Label for the social worker(s) who created the note:Team involved`,
dataType: "entity",
isArray: true,
additional: "User",
Expand All @@ -120,13 +130,15 @@ export class Note extends Entity {
authors: string[] = [];

@DatabaseField({
label: $localize`:Label for the category of a note:Category`,
dataType: "configurable-enum",
additional: INTERACTION_TYPE_CONFIG_ID,
anonymize: "retain",
})
category: InteractionType;

@DatabaseField({
label: $localize`Attachment`,
dataType: "file",
})
attachment: string;
Expand Down Expand Up @@ -158,6 +170,7 @@ export class Note extends Entity {
* related school ids (e.g. to infer participants for event roll calls)
*/
@DatabaseField({
label: $localize`:label for the linked schools:Groups`,
dataType: "entity",
isArray: true,
additional: "School",
Expand All @@ -167,6 +180,7 @@ export class Note extends Entity {
schools: string[] = [];

@DatabaseField({
label: $localize`:Status of a note:Status`,
dataType: "configurable-enum",
additional: "warning-levels",
anonymize: "retain",
Expand Down
50 changes: 26 additions & 24 deletions src/app/core/common-components/entity-form/entity-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Subscription } from "rxjs";
import { filter } from "rxjs/operators";
import { EntitySchemaField } from "../../entity/schema/entity-schema-field";
import { DefaultValueService } from "../../default-values/default-value.service";
import { DefaultValueConfig } from "../../entity/schema/default-value-config";

/**
* These are utility types that allow to define the type of `FormGroup` the way it is returned by `EntityFormService.create`
Expand All @@ -35,9 +34,9 @@ export interface EntityForm<T extends Entity> {
entity: T;

/**
* map of field ids to the default value configuration for that field
* (possible overridden) field configurations for that form
*/
defaultValueConfigs: Map<string, DefaultValueConfig>;
fieldConfigs: FormFieldConfig[];

/**
* map of field ids to the current value to be inherited from the referenced parent entities' field
Expand Down Expand Up @@ -87,6 +86,7 @@ export class EntityFormService {
forTable = false,
): FormFieldConfig {
const fullField = toFormFieldConfig(formField);

try {
return this.addSchemaToFormField(
fullField,
Expand All @@ -102,11 +102,15 @@ export class EntityFormService {

private addSchemaToFormField(
formField: FormFieldConfig,
propertySchema: EntitySchemaField,
propertySchema: EntitySchemaField | undefined,
forTable: boolean,
): FormFieldConfig {
// formField config has precedence over schema
const fullField = Object.assign({}, propertySchema, formField);
const fullField = Object.assign(
{},
JSON.parse(JSON.stringify(propertySchema ?? {})), // deep copy to avoid modifying the original schema
formField,
);

fullField.editComponent =
fullField.editComponent ||
Expand Down Expand Up @@ -143,20 +147,20 @@ export class EntityFormService {
forTable = false,
withPermissionCheck = true,
): Promise<EntityForm<T>> {
const fields = formFields.map((f) =>
this.extendFormFieldConfig(f, entity.getConstructor(), forTable),
);

const typedFormGroup: TypedFormGroup<Partial<T>> = this.createFormGroup(
formFields,
fields,
entity,
forTable,
withPermissionCheck,
);

const defaultValueConfigs =
DefaultValueService.getDefaultValueConfigs(entity);

const entityForm: EntityForm<T> = {
formGroup: typedFormGroup,
entity: entity,
defaultValueConfigs: defaultValueConfigs,
fieldConfigs: fields,
inheritedParentValues: new Map(),
watcher: new Map(),
};
Expand All @@ -166,10 +170,16 @@ export class EntityFormService {
return entityForm;
}

/**
*
* @param formFields The field configs in their final form (will not be extended by schema automatically)
* @param entity
* @param withPermissionCheck
* @private
*/
private createFormGroup<T extends Entity>(
formFields: ColumnConfig[],
formFields: FormFieldConfig[],
entity: T,
forTable = false,
withPermissionCheck = true,
): EntityFormGroup<T> {
const formConfig = {};
Expand All @@ -180,7 +190,7 @@ export class EntityFormService {
);

for (const f of formFields) {
this.addFormControlConfig(formConfig, f, copy, forTable);
this.addFormControlConfig(formConfig, f, copy);
}
const group = this.fb.group<Partial<T>>(formConfig);

Expand All @@ -204,23 +214,15 @@ export class EntityFormService {
/**
* Add a property with form control initialization config to the given formConfig object.
* @param formConfig
* @param fieldConfig
* @param field The final field config (will not be automatically extended by schema)
* @param entity
* @param forTable
* @private
*/
private addFormControlConfig(
formConfig: { [key: string]: FormControl },
fieldConfig: ColumnConfig,
field: FormFieldConfig,
entity: Entity,
forTable: boolean,
) {
const field = this.extendFormFieldConfig(
fieldConfig,
entity.getConstructor(),
forTable,
);

let value = entity[field.id];

const controlOptions: FormControlOptions = { nonNullable: true };
Expand Down
Loading

0 comments on commit 732810c

Please sign in to comment.