Skip to content

Commit

Permalink
fix: reports are own entities (#2106)
Browse files Browse the repository at this point in the history
closes #2104 

MIGRATION REQUIRED

Co-authored-by: Sebastian <sebastian@aam-digital.com>
  • Loading branch information
TheSlimvReal and sleidig authored Dec 5, 2023
1 parent 9d906f2 commit d742e69
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 185 deletions.
130 changes: 0 additions & 130 deletions src/app/core/config/config-fix.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Child } from "../../child-dev-project/children/model/child";
import { School } from "../../child-dev-project/schools/model/school";
import { ChildSchoolRelation } from "../../child-dev-project/children/model/childSchoolRelation";
import { EventNote } from "../../child-dev-project/attendance/model/event-note";
import { defaultDateFilters } from "../basic-datatypes/date/date-range-filter/date-range-filter-panel/date-range-filter-panel.component";
import { EducationalMaterial } from "../../child-dev-project/children/educational-material/model/educational-material";

Expand Down Expand Up @@ -784,135 +783,6 @@ export const defaultJsonConfig = {
},
"view:report": {
"component": "Reporting",
"config": {
"reports": [
{
"title": $localize`:Name of a report:Basic Report`,
"aggregationDefinitions": [
{
"query": `${Child.ENTITY_TYPE}:toArray[*isActive=true]`,
"label": $localize`:Label of report query:All children`,
"groupBy": ["gender"],
},
{
"query": `${School.ENTITY_TYPE}:toArray`,
"label": $localize`:Label for report query:All schools`,
"aggregations": [
{
"label": $localize`:Label for report query:Children attending a school`,
"query": `:getRelated(${ChildSchoolRelation.ENTITY_TYPE}, schoolId)[*isActive=true].childId:unique`
},
{
"label": $localize`:Label for report query:Governmental schools`,
"query": `[*privateSchool!=true]`
},
{
"query": `[*privateSchool!=true]:getRelated(${ChildSchoolRelation.ENTITY_TYPE}, schoolId)[*isActive=true].childId:addPrefix(${Child.ENTITY_TYPE}):unique:toEntities`,
"label": $localize`:Label for report query:Children attending a governmental school`,
"groupBy": ["gender"],
},
{
"label": $localize`:Label for report query:Private schools`,
"query": `[*privateSchool=true]`
},
{
"query": `[*privateSchool=true]:getRelated(${ChildSchoolRelation.ENTITY_TYPE}, schoolId)[*isActive=true].childId:addPrefix(${Child.ENTITY_TYPE}):unique:toEntities`,
"label": $localize`:Label for report query:Children attending a private school`,
"groupBy": ["gender"],
},
]
}
],
},
{
"title": $localize`:Name of a report:Event Report`,
"aggregationDefinitions": [
{
"query": `${EventNote.ENTITY_TYPE}:toArray[*date >= ? & date <= ?]`,
"groupBy": ["category"],
"label": $localize`:Label for a report query:Events`,
"aggregations": [
{
"query": `:getParticipantsWithAttendance(PRESENT):unique:addPrefix(${Child.ENTITY_TYPE}):toEntities`,
"groupBy": ["gender"],
"label": $localize`:Label for a report query:Participants`
}
]
}
],
},
{
"title": $localize`:Name of a report:Attendance Report`,
"mode": "exporting",
"aggregationDefinitions": [
{
"query": `${EventNote.ENTITY_TYPE}:toArray[* date >= ? & date <= ?]`,
"groupBy": { "label": "Type", "property": "category" },
"subQueries": [
{
"query": ":getAttendanceArray:getAttendanceReport",
"subQueries": [
{
"label": $localize`:Name of a column of a report:Name`,
"query": `.participant:toEntities(Child).name`
},
{
"query": ".participant:toEntities(Child):getRelated(ChildSchoolRelation, childId)[*isActive=true]",
"subQueries": [
{
"label": "Class",
"query": ".schoolClass"
},
{
"label": "School",
"query": ".schoolId:toEntities(School).name"
},
]
},
{
"label": $localize`:Name of a column of a report:Total`,
"query": `total`
},
{
"label": $localize`:Name of a column of a report:Present`,
"query": `present`
},
{
"label": $localize`:Name of a column of a report:Rate`,
"query": `percentage`
},
{
"label": $localize`:Name of a column of a report:Late`,
"query": `detailedStatus.LATE`
}
]
}
]
},
],
},
{
"title": $localize`:Name of a report:Materials Distributed`,
"mode": "exporting",
"aggregationDefinitions": [
{
"query": `${EducationalMaterial.ENTITY_TYPE}:toArray[*date >= ? & date <= ?]`,
"groupBy": { "label": "Type", "property": "materialType" },
"subQueries": [
{
"label": "Number of events of handing out",
"query": `.materialAmount:count`
},
{
"label": "Total Items",
"query": `.materialAmount:sum`
},
]
},
]
}
]
}
},

"entity:Child": {
Expand Down
3 changes: 1 addition & 2 deletions src/app/core/config/demo-config-generator.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable } from "@angular/core";
import { DemoDataGenerator } from "../demo-data/demo-data-generator";
import { Config } from "./config";
import { DatabaseRules } from "../permissions/permission-types";
import { defaultJsonConfig } from "./config-fix";

@Injectable()
Expand All @@ -15,7 +14,7 @@ export class DemoConfigGeneratorService extends DemoDataGenerator<Config> {
];
}

protected generateEntities(): Config<DatabaseRules>[] {
protected generateEntities(): Config[] {
const defaultConfig = JSON.parse(JSON.stringify(defaultJsonConfig));
return [new Config(Config.CONFIG_KEY, defaultConfig)];
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/demo-data/demo-data.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { DemoTodoGeneratorService } from "../../features/todos/model/demo-todo-g
import { DemoConfigurableEnumGeneratorService } from "../basic-datatypes/configurable-enum/demo-configurable-enum-generator.service";
import { DemoPublicFormGeneratorService } from "../../features/public-form/demo-public-form-generator.service";
import { DemoSiteSettingsGeneratorService } from "../site-settings/demo-site-settings-generator.service";
import { DemoReportConfigGeneratorService } from "../../features/reporting/demo-report-config-generator.service";

const demoDataGeneratorProviders = [
...DemoConfigGeneratorService.provider(),
Expand Down Expand Up @@ -69,6 +70,7 @@ const demoDataGeneratorProviders = [
maxCountAttributes: 5,
}),
...DemoTodoGeneratorService.provider(),
...DemoReportConfigGeneratorService.provider(),
];

/**
Expand Down
153 changes: 153 additions & 0 deletions src/app/features/reporting/demo-report-config-generator.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { Injectable } from "@angular/core";
import { DemoDataGenerator } from "../../core/demo-data/demo-data-generator";
import { ReportConfig } from "./report-config";
import { Child } from "../../child-dev-project/children/model/child";
import { School } from "../../child-dev-project/schools/model/school";
import { ChildSchoolRelation } from "../../child-dev-project/children/model/childSchoolRelation";
import { EventNote } from "../../child-dev-project/attendance/model/event-note";
import { EducationalMaterial } from "../../child-dev-project/children/educational-material/model/educational-material";

@Injectable()
export class DemoReportConfigGeneratorService extends DemoDataGenerator<ReportConfig> {
static provider() {
return [
{
provide: DemoReportConfigGeneratorService,
useClass: DemoReportConfigGeneratorService,
},
];
}

protected generateEntities(): ReportConfig[] {
return demoReports.map((report) => ReportConfig.create(report));
}
}

const demoReports: Partial<ReportConfig>[] = [
{
title: $localize`:Name of a report:Basic Report`,
aggregationDefinitions: [
{
query: `${Child.ENTITY_TYPE}:toArray[*isActive=true]`,
label: $localize`:Label of report query:All children`,
groupBy: ["gender"],
},
{
query: `${School.ENTITY_TYPE}:toArray`,
label: $localize`:Label for report query:All schools`,
aggregations: [
{
label: $localize`:Label for report query:Children attending a school`,
query: `:getRelated(${ChildSchoolRelation.ENTITY_TYPE}, schoolId)[*isActive=true].childId:unique`,
},
{
label: $localize`:Label for report query:Governmental schools`,
query: `[*privateSchool!=true]`,
},
{
query: `[*privateSchool!=true]:getRelated(${ChildSchoolRelation.ENTITY_TYPE}, schoolId)[*isActive=true].childId:addPrefix(${Child.ENTITY_TYPE}):unique:toEntities`,
label: $localize`:Label for report query:Children attending a governmental school`,
groupBy: ["gender"],
},
{
label: $localize`:Label for report query:Private schools`,
query: `[*privateSchool=true]`,
},
{
query: `[*privateSchool=true]:getRelated(${ChildSchoolRelation.ENTITY_TYPE}, schoolId)[*isActive=true].childId:addPrefix(${Child.ENTITY_TYPE}):unique:toEntities`,
label: $localize`:Label for report query:Children attending a private school`,
groupBy: ["gender"],
},
],
},
],
},
{
title: $localize`:Name of a report:Event Report`,
aggregationDefinitions: [
{
query: `${EventNote.ENTITY_TYPE}:toArray[*date >= ? & date <= ?]`,
groupBy: ["category"],
label: $localize`:Label for a report query:Events`,
aggregations: [
{
query: `:getParticipantsWithAttendance(PRESENT):unique:addPrefix(${Child.ENTITY_TYPE}):toEntities`,
groupBy: ["gender"],
label: $localize`:Label for a report query:Participants`,
},
],
},
],
},
{
title: $localize`:Name of a report:Attendance Report`,
mode: "exporting",
aggregationDefinitions: [
{
query: `${EventNote.ENTITY_TYPE}:toArray[* date >= ? & date <= ?]`,
groupBy: { label: "Type", property: "category" },
subQueries: [
{
query: ":getAttendanceArray:getAttendanceReport",
subQueries: [
{
label: $localize`:Name of a column of a report:Name`,
query: `.participant:toEntities(Child).name`,
},
{
query:
".participant:toEntities(Child):getRelated(ChildSchoolRelation, childId)[*isActive=true]",
subQueries: [
{
label: "Class",
query: ".schoolClass",
},
{
label: "School",
query: ".schoolId:toEntities(School).name",
},
],
},
{
label: $localize`:Name of a column of a report:Total`,
query: `total`,
},
{
label: $localize`:Name of a column of a report:Present`,
query: `present`,
},
{
label: $localize`:Name of a column of a report:Rate`,
query: `percentage`,
},
{
label: $localize`:Name of a column of a report:Late`,
query: `detailedStatus.LATE`,
},
],
},
],
},
],
},
{
title: $localize`:Name of a report:Materials Distributed`,
mode: "exporting",
aggregationDefinitions: [
{
query: `${EducationalMaterial.ENTITY_TYPE}:toArray[*date >= ? & date <= ?]`,
groupBy: { label: "Type", property: "materialType" },
subQueries: [
{
label: "Number of events of handing out",
query: `.materialAmount:count`,
},
{
label: "Total Items",
query: `.materialAmount:sum`,
},
],
},
],
},
];
30 changes: 30 additions & 0 deletions src/app/features/reporting/report-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Entity } from "../../core/entity/model/entity";
import { DatabaseEntity } from "../../core/entity/database-entity.decorator";
import { Aggregation } from "./data-aggregation.service";
import { ExportColumnConfig } from "../../core/export/data-transformation-service/export-column-config";
import { DatabaseField } from "../../core/entity/database-field.decorator";

/**
* A report can be accessed by users to generate aggregated statistics or customized exports calculated from available data.
* "read" permission for a ReportConfig entity is also used to control which users can generate the report's results.
*/
@DatabaseEntity("ReportConfig")
export class ReportConfig extends Entity {
static create(data: Partial<ReportConfig>) {
return Object.assign(new ReportConfig(), data);
}

/** human-readable title of the report */
@DatabaseField() title: string;

/**
* (optional) mode whether the aggregation definitions are of type {@interface Aggregation} or {@interface ExportColumnConfig}
* Default is "reporting"
*/
@DatabaseField() mode?: "reporting" | "exporting";

/** the definitions to calculate the report's aggregations */
@DatabaseField() aggregationDefinitions?:
| Aggregation[]
| ExportColumnConfig[] = [];
}
28 changes: 0 additions & 28 deletions src/app/features/reporting/reporting/reporting-component-config.ts

This file was deleted.

Loading

0 comments on commit d742e69

Please sign in to comment.