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

refactor(core): change EntityConfig to flattened structure with EntitySchemaField including .id #2102

Merged
merged 11 commits into from
Nov 30, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class EventAttendance {
private _status: AttendanceStatusType;
@DatabaseField({
dataType: "configurable-enum",
innerDataType: ATTENDANCE_STATUS_CONFIG_ID,
additional: ATTENDANCE_STATUS_CONFIG_ID,
})
get status(): AttendanceStatusType {
return this._status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class RecurringActivity extends Entity {
@DatabaseField({
label: $localize`:Label for the interaction type of a recurring activity:Type`,
dataType: "configurable-enum",
innerDataType: INTERACTION_TYPE_CONFIG_ID,
additional: INTERACTION_TYPE_CONFIG_ID,
})
type: InteractionType;

Expand Down
8 changes: 4 additions & 4 deletions src/app/child-dev-project/children/aser/model/aser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ export class Aser extends Entity {
@DatabaseField({
label: $localize`:Label of the Hindi ASER result:Hindi`,
dataType: "configurable-enum",
innerDataType: "reading-levels",
additional: "reading-levels",
})
hindi: SkillLevel;
@DatabaseField({
label: $localize`:Label of the Bengali ASER result:Bengali`,
dataType: "configurable-enum",
innerDataType: "reading-levels",
additional: "reading-levels",
})
bengali: SkillLevel;
@DatabaseField({
label: $localize`:Label of the English ASER result:English`,
dataType: "configurable-enum",
innerDataType: "reading-levels",
additional: "reading-levels",
})
english: SkillLevel;
@DatabaseField({
label: $localize`:Label of the Math ASER result:Math`,
dataType: "configurable-enum",
innerDataType: "math-levels",
additional: "math-levels",
})
math: SkillLevel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class EducationalMaterial extends Entity {
@DatabaseField({
label: $localize`:The material which has been borrowed:Material`,
dataType: "configurable-enum",
innerDataType: "materials",
additional: "materials",
validators: {
required: true,
},
Expand Down
4 changes: 2 additions & 2 deletions src/app/child-dev-project/children/model/child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ export class Child extends Entity {
@DatabaseField({
dataType: "configurable-enum",
label: $localize`:Label for the gender of a child:Gender`,
innerDataType: "genders",
additional: "genders",
anonymize: "retain",
})
gender: ConfigurableEnumValue;

@DatabaseField({
dataType: "configurable-enum",
innerDataType: "center",
additional: "center",
label: $localize`:Label for the center of a child:Center`,
anonymize: "retain",
})
Expand Down
4 changes: 2 additions & 2 deletions src/app/child-dev-project/notes/model/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class Note extends Entity {
@DatabaseField({
label: $localize`:Label for the category of a note:Category`,
dataType: "configurable-enum",
innerDataType: INTERACTION_TYPE_CONFIG_ID,
additional: INTERACTION_TYPE_CONFIG_ID,
anonymize: "retain",
})
category: InteractionType;
Expand Down Expand Up @@ -175,7 +175,7 @@ export class Note extends Entity {
@DatabaseField({
label: $localize`:Status of a note:Status`,
dataType: "configurable-enum",
innerDataType: "warning-levels",
additional: "warning-levels",
anonymize: "retain",
})
warningLevel: Ordering.EnumValue;
Expand Down
1 change: 1 addition & 0 deletions src/app/core/basic-datatypes/array/array.datatype.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ConfigurableEnumService } from "../configurable-enum/configurable-enum.

describe("Schema data type: array", () => {
const schema: EntitySchemaField = {
id: null,
dataType: "array",
innerDataType: "configurable-enum",
additional: "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ describe("Schema data type: configurable-enum", () => {
const actualMapped = dataType.importMapFunction(
input,
{
id: null,
dataType: "configurable-enum",
additional: "genders",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ describe("EditConfigurableEnumComponent", () => {
expect(component.multi).toBeTrue();
});

function initWithSchema(schema: EntitySchemaField) {
function initWithSchema(schema: Omit<EntitySchemaField, "id">) {
const fromGroup = new FormGroup({ test: new FormControl() });
component.formControl = fromGroup.get("test") as FormControl;
component.formFieldConfig = { id: "test" };
component.propertySchema = schema;
component.propertySchema = { id: "test", ...schema };
component.entity = new Entity();
component.ngOnInit();
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/core/basic-datatypes/entity/entity.datatype.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ describe("Schema data type: entity", () => {
const dataType = new EntityDatatype(entityMapper, mockRemoveService);

const testValue = referencedEntity.getId();
const testSchemaField = { additional: "Child", dataType: "entity" };
const testSchemaField = {
id: null,
additional: "Child",
dataType: "entity",
};

const anonymizedValue = await dataType.anonymize(
testValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe("EntityFormService", () => {
});

it("should assign default values", () => {
const schema: EntitySchemaField = { defaultValue: 1 };
const schema: EntitySchemaField = { id: "test", defaultValue: 1 };
Entity.schema.set("test", schema);

let form = service.createFormGroup([{ id: "test" }], new Entity());
Expand All @@ -191,7 +191,7 @@ describe("EntityFormService", () => {
});

it("should not assign default values to existing entities", () => {
Entity.schema.set("test", { defaultValue: 1 });
Entity.schema.set("test", { id: "test", defaultValue: 1 });

const entity = new Entity();
entity._rev = "1-existing_entity";
Expand All @@ -202,7 +202,7 @@ describe("EntityFormService", () => {
});

it("should not overwrite existing values with default value", () => {
Entity.schema.set("test", { defaultValue: 1 });
Entity.schema.set("test", { id: "test", defaultValue: 1 });

const entity = new Entity();
entity["test"] = 2;
Expand Down
174 changes: 68 additions & 106 deletions src/app/core/config/config-fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,160 +946,122 @@ export const defaultJsonConfig = {
"labelPlural": $localize`:Plural label for child:Children`,
"attributes": [
{
"name": "address",
"schema": {
"dataType": "location",
"label": $localize`:Label for the address of a child:Address`
}
"id": "address",
"dataType": "location",
"label": $localize`:Label for the address of a child:Address`
},
{
"name": "health_bloodGroup",
"schema": {
"dataType": "string",
"label": $localize`:Label for a child attribute:Blood Group`
}
"id": "health_bloodGroup",
"dataType": "string",
"label": $localize`:Label for a child attribute:Blood Group`
},
{
"name": "religion",
"schema": {
"dataType": "string",
"label": $localize`:Label for the religion of a child:Religion`
}
"id": "religion",
"dataType": "string",
"label": $localize`:Label for the religion of a child:Religion`
},
{
"name": "motherTongue",
"schema": {
"dataType": "string",
"label": $localize`:Label for the mother tongue of a child:Mother Tongue`,
description: $localize`:Tooltip description for the mother tongue of a child:The primary language spoken at home`,
}
"id": "motherTongue",
"dataType": "string",
"label": $localize`:Label for the mother tongue of a child:Mother Tongue`,
description: $localize`:Tooltip description for the mother tongue of a child:The primary language spoken at home`,
},
{
"name": "health_lastDentalCheckup",
"schema": {
"dataType": "date",
"label": $localize`:Label for a child attribute:Last Dental Check-Up`
}
"id": "health_lastDentalCheckup",
"dataType": "date",
"label": $localize`:Label for a child attribute:Last Dental Check-Up`
},
{
"name": "birth_certificate",
"schema": {
"dataType": "file",
"label": $localize`:Label for a child attribute:Birth certificate`
}
"id": "birth_certificate",
"dataType": "file",
"label": $localize`:Label for a child attribute:Birth certificate`
}
]
},
"entity:School": {
"attributes": [
{
"name": "name",
"schema": {
"dataType": "string",
"label": $localize`:Label for the name of a school:Name`
}
"id": "name",
"dataType": "string",
"label": $localize`:Label for the name of a school:Name`
},
{
"name": "privateSchool",
"schema": {
"dataType": "boolean",
"label": $localize`:Label for if a school is a private school:Private School`
}
"id": "privateSchool",
"dataType": "boolean",
"label": $localize`:Label for if a school is a private school:Private School`
},
{
"name": "language",
"schema": {
"dataType": "string",
"label": $localize`:Label for the language of a school:Language`
}
"id": "language",
"dataType": "string",
"label": $localize`:Label for the language of a school:Language`
},
{
"name": "address",
"schema": {
"dataType": "location",
"label": $localize`:Label for the address of a school:Address`
}
"id": "address",
"dataType": "location",
"label": $localize`:Label for the address of a school:Address`
},
{
"name": "phone",
"schema": {
"dataType": "string",
"label": $localize`:Label for the phone number of a school:Phone Number`
}
"id": "phone",
"dataType": "string",
"label": $localize`:Label for the phone number of a school:Phone Number`
},
{
"name": "timing",
"schema": {
"dataType": "string",
"label": $localize`:Label for the timing of a school:School Timing`
}
"id": "timing",
"dataType": "string",
"label": $localize`:Label for the timing of a school:School Timing`
},
{
"name": "remarks",
"schema": {
"dataType": "string",
"label": $localize`:Label for the remarks for a school:Remarks`
}
"id": "remarks",
"dataType": "string",
"label": $localize`:Label for the remarks for a school:Remarks`
}
]
},
"entity:HistoricalEntityData": {
"attributes": [
{
"name": "isMotivatedDuringClass",
"schema": {
"dataType": "configurable-enum",
"innerDataType": "rating-answer",
"label": $localize`:Label for a child attribute:Motivated`,
description: $localize`:Description for a child attribute:The child is motivated during the class.`
}
"id": "isMotivatedDuringClass",
"dataType": "configurable-enum",
"additional": "rating-answer",
"label": $localize`:Label for a child attribute:Motivated`,
description: $localize`:Description for a child attribute:The child is motivated during the class.`
},
{
"name": "isParticipatingInClass",
"schema": {
"dataType": "configurable-enum",
"innerDataType": "rating-answer",
"label": $localize`:Label for a child attribute:Participating`,
description: $localize`:Description for a child attribute:The child is actively participating in the class.`
}
"id": "isParticipatingInClass",
"dataType": "configurable-enum",
"additional": "rating-answer",
"label": $localize`:Label for a child attribute:Participating`,
description: $localize`:Description for a child attribute:The child is actively participating in the class.`
},
{
"name": "isInteractingWithOthers",
"schema": {
"dataType": "configurable-enum",
"innerDataType": "rating-answer",
"label": $localize`:Label for a child attribute:Interacting`,
description: $localize`:Description for a child attribute:The child interacts with other students during the class.`
}
"id": "isInteractingWithOthers",
"dataType": "configurable-enum",
"additional": "rating-answer",
"label": $localize`:Label for a child attribute:Interacting`,
description: $localize`:Description for a child attribute:The child interacts with other students during the class.`
},
{
"name": "doesHomework",
"schema": {
"dataType": "configurable-enum",
"innerDataType": "rating-answer",
"label": $localize`:Label for a child attribute:Homework`,
description: $localize`:Description for a child attribute:The child does its homework.`
}
"id": "doesHomework",
"dataType": "configurable-enum",
"additional": "rating-answer",
"label": $localize`:Label for a child attribute:Homework`,
description: $localize`:Description for a child attribute:The child does its homework.`
},
{
"name": "asksQuestions",
"schema": {
"dataType": "configurable-enum",
"innerDataType": "rating-answer",
"label": $localize`:Label for a child attribute:Asking Questions`,
description: $localize`:Description for a child attribute:The child is asking questions during the class.`
}
"id": "asksQuestions",
"dataType": "configurable-enum",
"additional": "rating-answer",
"label": $localize`:Label for a child attribute:Asking Questions`,
description: $localize`:Description for a child attribute:The child is asking questions during the class.`
},
]
},
"entity:User": {
"attributes": [
{
"name": "phone",
"schema": {
"dataType": "string",
"label": $localize`:Label of user phone:Contact`
}
"id": "phone",
"dataType": "string",
"label": $localize`:Label of user phone:Contact`
},
]
},
Expand Down
Loading