import { DemoChildGenerator } from "../../children/demo-data-generators/demo-child-generator.service" ; import { DemoDataGenerator } from "../../../core/demo-data/demo-data-generator" ; import { Injectable } from "@angular/core" ; import { Child } from "../../children/model/child" ; import { faker } from "../../../core/demo-data/faker" ; import { RecurringActivity } from "../model/recurring-activity" ; import { DemoUserGeneratorService } from "../../../core/user/demo-user-generator.service" ; import { User } from "../../../core/user/user" ; import { defaultInteractionTypes } from "../../../core/config/default-config/default-interaction-types" ; /**
 * Generate AttendanceMonth entities for the last 15 months
 * Builds upon the generated demo Child entities.
 */ @ Injectable ( ) export class DemoActivityGeneratorService extends DemoDataGenerator < RecurringActivity > { private static readonly ACTIVITY_TYPES = [ defaultInteractionTypes . find ( ( t ) => t . id === "SCHOOL_CLASS" ) , defaultInteractionTypes . find ( ( t ) => t . id === "COACHING_CLASS" ) , ] ; param children param assignedUser static generateActivityForChildren ( children , assignedUser ? ) { const activity = RecurringActivity . create ( ) ; const type = faker . random . arrayElement ( this . ACTIVITY_TYPES ) ; activity . title = type . label + " " + faker . datatype . number ( { min : 1 , max : 9 } ) + faker . random . alphaNumeric ( 1 ) . toUpperCase ( ) ; activity . type = type ; activity . participants = children . map ( ( c ) => c . getId ( ) ) ; activity . assignedTo = [ assignedUser ?. getId ( ) ] ; return activity ; } /**
     * This function returns a provider object to be used in an Angular Module configuration:
     *   `providers: [DemoAttendanceGenerator.provider()]`
     */ static provider ( ) { return [ { provide : DemoActivityGeneratorService , useClass : DemoActivityGeneratorService , } , ] ; } private readonly MIN_PARTICIPANTS = 3 ; private readonly MAX_PARTICIPANTS = 25 ; constructor ( private demoChildren , private demoUser ) { super ( ) ; } generateEntities ( ) { const data = [ ] ; const children = this . demoChildren . entities . filter ( ( c ) => c . isActive ) ; let i = 0 ; while ( i < children . length ) { const groupSize = faker . datatype . number ( { min : this . MIN_PARTICIPANTS , max : this . MAX_PARTICIPANTS , } ) ; const participatingChildren = children . slice ( i , i + groupSize ) ; data . push ( DemoActivityGeneratorService . generateActivityForChildren ( participatingChildren , faker . random . arrayElement ( this . demoUser . entities ) ) ) ; i += groupSize ; } return data ; } }