{"version":3,"file":"8093.95f80f0f480e6c72.js","sources":["./src/app/core/entity/model/entity-update.ts","./src/app/features/dashboard-widgets/birthday-dashboard-widget/birthday-dashboard/birthday-dashboard.component.html","./src/app/features/dashboard-widgets/birthday-dashboard-widget/birthday-dashboard/birthday-dashboard.component.ts"],"sourceRoot":"webpack:///","sourcesContent":["import { Entity } from \"./entity\";\n\n/**\n * Interface that conveys an updated entity as well as information\n * on the update-type\n */\nexport interface UpdatedEntity {\n /**\n * The updated entity\n */\n entity: T;\n\n /**\n * The type of the update, either:\n * \"new\" - a new entity was created,\n * \"update\" - an existing entity was updated\n * \"remove\" - the entity was deleted\n */\n type: \"new\" | \"update\" | \"remove\";\n}\n\n/**\n * Updates a list of entities given an updated version of the entity. This updated version\n * can either be a new entity (that should be inserted into the list), or an existing entity\n * that should be updated or deleted.\n * The given array will not be mutated but will be returned when the given new entity\n * or type is illegal\n * @param next An entity that should be updated as well as the type of update. This, as well as the entity\n * may be undefined or null. In this event, the entities-array is returned as is.\n * @param entities The entities to update, must be defined\n * @param addIfMissing (Optional) whether to add an entity that comes through an update event but is not part of the array yet,\n * default is to add, disable this if you do special filtering or calculations on the data\n * @return An array of the given entities with the update applied\n */\nexport function applyUpdate(\n entities: T[],\n next: UpdatedEntity,\n addIfMissing: boolean = true,\n): T[] {\n if (!next || !next.entity || !entities) {\n return entities;\n }\n\n if (\n (next.type === \"new\" || (addIfMissing && next.type === \"update\")) &&\n !entities.find((e) => e.getId() === next.entity.getId())\n ) {\n return [next.entity].concat(entities);\n }\n\n if (next.type === \"update\") {\n return entities.map((e) =>\n e.getId() === next.entity.getId() ? next.entity : e,\n );\n }\n\n if (next.type === \"remove\") {\n return entities.filter((e) => e.getId() !== next.entity.getId());\n }\n\n return entities;\n}\n","\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n \n {{ entity.birthday | date: \"E dd.MM\" }}\n {{ entity.newAge }} yrs
\n
\n\n","import { Component, Input, OnInit } from \"@angular/core\";\nimport { EntityMapperService } from \"../../../../core/entity/entity-mapper/entity-mapper.service\";\nimport { DynamicComponent } from \"../../../../core/config/dynamic-components/dynamic-component.decorator\";\nimport { MatTableModule } from \"@angular/material/table\";\nimport { Entity } from \"../../../../core/entity/model/entity\";\nimport { DatePipe, NgIf } from \"@angular/common\";\nimport { EntityBlockComponent } from \"../../../../core/basic-datatypes/entity/entity-block/entity-block.component\";\n\nimport { DashboardWidget } from \"../../../../core/dashboard/dashboard-widget/dashboard-widget\";\nimport { DashboardListWidgetComponent } from \"../../../../core/dashboard/dashboard-list-widget/dashboard-list-widget.component\";\n\ninterface BirthdayDashboardConfig {\n entities: EntityPropertyMap;\n threshold: number;\n}\n\n@DynamicComponent(\"BirthdayDashboard\")\n@Component({\n selector: \"app-birthday-dashboard\",\n templateUrl: \"./birthday-dashboard.component.html\",\n styleUrls: [\"./birthday-dashboard.component.scss\"],\n standalone: true,\n imports: [\n NgIf,\n MatTableModule,\n EntityBlockComponent,\n DatePipe,\n DashboardListWidgetComponent,\n ],\n})\nexport class BirthdayDashboardComponent\n extends DashboardWidget\n implements BirthdayDashboardConfig, OnInit\n{\n static override getRequiredEntities(config: BirthdayDashboardConfig) {\n return config?.entities ? Object.keys(config.entities) : \"Child\";\n }\n\n private readonly today: Date;\n\n /**\n * An object holding the names of entities and properties where they have a `DateOfBirth` attribute.\n * E.g. (which is also the default)\n * ```json\n * \"entities\": { \"Child\": \"dateOfBirth\" }\n * ```\n */\n @Input() entities: EntityPropertyMap = { [\"Child\"]: \"dateOfBirth\" };\n\n /**\n * Birthdays that are less than \"threshold\" days away are shown.\n * Default 32\n */\n @Input() threshold = 32;\n\n entries: EntityWithBirthday[];\n\n @Input() subtitle: string =\n $localize`:dashboard widget subtitle:Upcoming Birthdays`;\n @Input() explanation: string;\n\n constructor(private entityMapper: EntityMapperService) {\n super();\n this.today = new Date();\n this.today.setHours(0, 0, 0, 0);\n }\n\n async ngOnInit() {\n const data: EntityWithBirthday[] = [];\n for (const [entityType, property] of Object.entries(this.entities)) {\n const entities = await this.entityMapper.loadType(entityType);\n data.push(\n ...entities\n .filter((entity) => entity.isActive && entity[property])\n .map((entity) => ({\n entity: entity,\n birthday: this.getNextBirthday(entity[property]),\n newAge: entity[property]?.age + 1,\n }))\n .filter((a) => this.daysUntil(a.birthday) < this.threshold),\n );\n }\n data.sort(\n (a, b) => this.daysUntil(a.birthday) - this.daysUntil(b.birthday),\n );\n this.entries = data;\n }\n\n private getNextBirthday(dateOfBirth: Date): Date {\n const birthday = new Date(\n this.today.getFullYear(),\n dateOfBirth.getMonth(),\n dateOfBirth.getDate(),\n );\n\n if (this.today.getTime() > birthday.getTime()) {\n birthday.setFullYear(birthday.getFullYear() + 1);\n }\n return birthday;\n }\n\n private daysUntil(date: Date): number {\n const diff = date.getTime() - this.today.getTime();\n return Math.floor(diff / (1000 * 60 * 60 * 24));\n }\n}\n\ninterface EntityPropertyMap {\n [key: string]: string;\n}\n\ninterface EntityWithBirthday {\n entity: Entity;\n birthday: Date;\n newAge: number;\n}\n"],"names":["applyUpdate","entities","next","addIfMissing","entity","type","find","e","getId","concat","map","filter","i0","entity_r1","entity_r2","birthday","entity_r3","newAge","BirthdayDashboardComponent","DashboardWidget","getRequiredEntities","config","Object","keys","constructor","entityMapper","super","this","Child","threshold","subtitle","$localize","today","Date","setHours","ngOnInit","_this","_asyncToGenerator","data","entityType","property","entries","loadType","push","isActive","getNextBirthday","age","a","daysUntil","sort","b","dateOfBirth","getFullYear","getMonth","getDate","getTime","setFullYear","date","diff","Math","floor","i1","selectors","inputs","explanation","standalone","features","decls","vars","consts","i18n_0","BirthdayDashboardComponent_td_11_Template","BirthdayDashboardComponent_td_13_Template","BirthdayDashboardComponent_td_15_Template","BirthdayDashboardComponent_tr_16_Template","ctx","_c0","MatTableModule","i2","EntityBlockComponent","DatePipe","DashboardListWidgetComponent","styles","__decorate","DynamicComponent","tslib__WEBPACK_IMPORTED_MODULE_8__","Sn","EntityMapperService"],"mappings":";;kGAkCM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