Skip to content

Commit

Permalink
Merge branch 'master' into feat/translation-poeditor-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush8923 authored Nov 25, 2024
2 parents 0975b47 + c02ed26 commit 1b24909
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 182 deletions.
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
8 changes: 6 additions & 2 deletions src/app/core/config/config-fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const defaultJsonConfig = {
label: $localize`:Label for the actual notes of a note:Notes`
},
authors: {
label: $localize`:Label for the social worker(s) who created the note:SW`,
label: $localize`:Label for the social worker(s) who created the note:Team involved`,
dataType: "entity",
isArray: true,
additional: "User",
Expand Down Expand Up @@ -1162,9 +1162,13 @@ export const defaultJsonConfig = {
hasPII: true,

attributes: {
name: {
dataType: "string",
label: $localize`:Label of user field:Name`
},
phone: {
dataType: "string",
label: $localize`:Label of user phone:Contact`
label: $localize`:Label of user field:Contact`
}
}
},
Expand Down
11 changes: 6 additions & 5 deletions src/app/core/default-values/default-value-strategy.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { EntitySchemaField } from "../entity/schema/entity-schema-field";
import { EntityForm } from "../common-components/entity-form/entity-form.service";
import { DefaultValueConfig } from "../entity/schema/default-value-config";
import { Entity } from "../entity/model/entity";
import { FormFieldConfig } from "../common-components/entity-form/FormConfig";

/**
* A special strategy to define and set default values, which can be used by the DefaultValueService,
Expand Down Expand Up @@ -30,18 +31,18 @@ export abstract class DefaultValueStrategy {

/**
* Get the default value configs filtered for the given mode.
* @param defaultValueConfigs
* @param fieldConfigs
* @param mode
*/
export function getConfigsByMode(
defaultValueConfigs: Map<string, DefaultValueConfig>,
fieldConfigs: FormFieldConfig[],
mode: ("inherited" | "static" | "dynamic")[],
): Map<string, DefaultValueConfig> {
let configs: Map<string, DefaultValueConfig> = new Map();

for (const [key, defaultValueConfig] of defaultValueConfigs) {
if (mode.indexOf(defaultValueConfig.mode) !== -1) {
configs.set(key, defaultValueConfig);
for (const field of fieldConfigs) {
if (mode.includes(field.defaultValue?.mode)) {
configs.set(field.id, field.defaultValue);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/app/core/default-values/default-value.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export function getDefaultInheritedForm(

return {
entity: entity,
defaultValueConfigs: DefaultValueService.getDefaultValueConfigs(entity),
fieldConfigs: Array.from(entity.getSchema().entries()).map(
([key, fieldConfig]) => ({ id: key, ...fieldConfig }),
),
inheritedParentValues: new Map(),
watcher: new Map(),
formGroup: new FormBuilder().group<any>({
Expand All @@ -38,6 +40,7 @@ export function getDefaultInheritedForm(
}),
};
}

/**
* Helper function to remove custom schema fields from Entity
* that have been created using getDefaultInheritedForm().
Expand Down
Loading

0 comments on commit 1b24909

Please sign in to comment.