import { Component } from '@angular/core' ; import { History } from '../../models/history' ; import { HistoryDAO } from '../../dao/history' ; import { Analytics } from '../../core/analytics' ; import strings from '../../strings' ; class @ Component ( { templateUrl : 'template.html' , } ) export class HistoryPage { private items : any = { } ; public get Text ( ) : any { return strings ; } public constructor ( private dao ) { Analytics . trackView ( 'HistoryPage' ) ; } return { void } public ionViewWillEnter ( ) { document . getElementById ( 'history-view' ) . style . display = 'initial' ; this . loadHistories ( ) ; } return { void } public ionViewWillLeave ( ) { document . getElementById ( 'history-view' ) . style . display = 'none' ; } return { string [ ] } public get Days ( ) : string [ ] { return Object . keys ( this . items ) ; } param { string } day return { History [ ] } public getByDay ( day ) { return this . items [ day ] ; } private return { void } private loadHistories ( ) { this . dao . getAll ( ) . then ( histories => { histories . forEach ( history => { let day = `${ history . Timestamp . getDate ( ) }/${ history . Timestamp . getMonth ( ) }/${ history . Timestamp . getFullYear ( ) }` ; if ( ! this . items [ day ] ) this . items [ day ] = [ ] ; this . items [ day ] . push ( history ) ; } ) ; } ) ; } }