import { Child } from "../model/child" ; import { religions } from "./fixtures/religions" ; import { languages } from "./fixtures/languages" ; import { dropoutTypes } from "./fixtures/dropout-types" ; import { Injectable } from "@angular/core" ; import { DemoDataGenerator } from "../../../core/demo-data/demo-data-generator" ; import { faker } from "../../../core/demo-data/faker" ; import { centersWithProbability } from "./fixtures/centers" ; import { addDefaultChildPhoto } from "../../../../../.storybook/utils/addDefaultChildPhoto" ; import { genders } from "../model/genders" ; export class DemoChildConfig { count : number ; } @ Injectable ( ) export class DemoChildGenerator extends DemoDataGenerator < Child > { static count : number ; param config static provider ( config ) { return [ { provide : DemoChildGenerator , useClass : DemoChildGenerator } , { provide : DemoChildConfig , useValue : config } , ] ; } static generateEntity ( id ) { const child = new Child ( id ) ; child . name = faker . name . firstName ( ) + " " + faker . name . lastName ( ) ; child . projectNumber = id ; child [ "religion" ] = faker . random . arrayElement ( religions ) ; child . gender = faker . random . arrayElement ( genders . slice ( 1 ) ) ; child . dateOfBirth = faker . dateOfBirth ( 5 , 20 ) ; child [ "motherTongue" ] = faker . random . arrayElement ( languages ) ; child . center = faker . random . arrayElement ( centersWithProbability ) ; child . phone = "+" + faker . datatype . number ( { min : 10 , max : 99 } ) + " " + faker . datatype . number ( { min : 10000000 , max : 99999999 } ) ; child . admissionDate = faker . date . past ( child . age - 4 ) ; if ( faker . datatype . number ( 100 ) > 90 ) { DemoChildGenerator . makeChildDropout ( child ) ; } addDefaultChildPhoto ( child ) ; return child ; } private static makeChildDropout ( child ) { child . dropoutDate = faker . date . between ( child . admissionDate , new Date ( ) ) ; child . dropoutRemarks = faker . lorem . sentence ( ) ; child . dropoutType = faker . random . arrayElement ( dropoutTypes ) ; child . status = $localize `:Child status:Dropout` ; } constructor ( public config ) { super ( ) ; } generateEntities ( ) { const data = [ ] ; for ( let i = 1 ; i <= this . config . count ; i ++ ) { data . push ( DemoChildGenerator . generateEntity ( String ( i ) ) ) ; } return data ; } }