File

lib/core/src/items/reports/report.class.ts

Extends

Item

Index

Properties
Methods
Accessors

Constructor

constructor(config: ReportConfig)
Parameters :
Name Type Optional
config ReportConfig No

Properties

Static acceptsAsConfig
Default value : isReportConfig
Public date
Type : Date
Public entries
Type : Entry[]
Public label
Type : string
Private Optional _config
Type : C
Inherited from Item
Defined in Item:54
Public Optional id
Type : string
Inherited from Item
Defined in Item:50
Public Optional update$
Type : Observable<string>
Inherited from Item
Defined in Item:52
Protected Optional updateSubject
Type : Subject<string>
Inherited from Item
Defined in Item:51

Methods

Static from
from(entries: Entry[])
Parameters :
Name Type Optional
entries Entry[] No
Returns : Report
Static acceptsAsConfig
acceptsAsConfig(x)
Inherited from Item
Defined in Item:27
Parameters :
Name Optional
x No
Static assertData
assertData(data)
Inherited from Item
Defined in Item:40
Parameters :
Name Optional
data No
Returns : never
Static findConfigs
findConfigs(data)
Inherited from Item
Defined in Item:32
Type parameters :
  • U
Parameters :
Name Optional
data No
Returns : U[]
Public matches
matches(query)
Inherited from Item
Defined in Item:80

TODO: Is this useful or needed anywhere?

Parameters :
Name Optional
query No
Returns : boolean
Public toJSON
toJSON()
Inherited from Item
Defined in Item:75
Returns : string

Accessors

config
getconfig()
setconfig(config: ReportConfig)
Parameters :
Name Type Optional
config ReportConfig No
Returns : void
questionIds
getquestionIds()
import	{
			assert,
			isErrorFree
		}							from '../../utils'

import	{	Item				}	from '../item.class'
import	{	
			Entry,
			EntryConfig,
			assertEntryConfig
		}							from '../entries/entry.class'

export type ReportConfig = [string|null, string|null, EntryConfig[]] //label, date, entries



export function assertReportConfig(x: unknown ): asserts x is ReportConfig {

	assert( Array.isArray(x),								"isReportConfig() config must be an array.", x)

	assert(typeof x[0] == 'string' || x[0] == null, 		"isReportConfig() [0] must be a string or null.", x)
	assert(typeof x[1] == 'string' || x[1] == null, 		"isReportConfig() [1] must be a string or null.", x)
	assert(Array.isArray(x[2]), 							"isReportConfig() [2] must be an EntryConfig[].", x)

	x[2].every( (x:unknown) => assertEntryConfig(x) )

}


export function isReportConfig(x: unknown) : x is ReportConfig {
	return isErrorFree( () => assertReportConfig(x) )
}





export class Report extends Item<ReportConfig>{

	public entries 	: Entry[]
	public date		: Date
	public label	: string

	public static acceptsAsConfig = isReportConfig

	public static from(entries: Entry[]) : Report {
		return new Report( [null, new Date().toISOString(), entries.map( entry => entry.config)] )
	}


	constructor(config: ReportConfig){
		super(config)				
	}

	set config(config: ReportConfig){


		if(Array.isArray(config[0])){ 
			// legacy
			this.config = [null,null, config as any[] ]
		} else {

			assertReportConfig(config)

			this.label		= config[0]
			this.date 		= new Date(config[1])
			this.entries	= Array.from(config[2]).map( (config: EntryConfig) => new Entry(config) )

			console.log(config[1], this.date)
		}
	}

	get config(): ReportConfig{
		return [this.label, this.date.toISOString(), this.entries.map( (entry: Entry) => entry.config )]
	}

	get questionIds(): string[]{
		const ids 			= this.entries.map( entry => entry.questionId )
		const unique_ids	= Array.from(new Set(ids))
		return unique_ids
	}

	//todo add filter functions
}

results matching ""

    No results matching ""