import { Directive , HostListener } from '@angular/core' ; import { Alert , AlertController } from 'ionic-angular' ; import { HistoryDAO } from '../../dao/history' ; import { Analytics } from '../../core/analytics' ; import strings from '../../strings' ; export class @ Directive ( { selector : '[clear-history]' , } ) export class ClearHistory { public get Text ( ) : any { return strings ; } public constructor ( private ctrl , private dao ) { } return { void } @ HostListener ( 'click' , [ '$event.target' ] ) public onClick ( ) { Analytics . trackEvent ( 'Clear History' , 'click' , 'button' ) ; let confirm = this . ctrl . create ( { title : this . Text . COMPONENT_CLEAR_HISTORY_ALERT_TITLE , message : this . Text . COMPONENT_CLEAR_HISTORY_ALERT_MESSAGE , buttons : [ { text : this . Text . COMPONENT_CLEAR_HISTORY_ALERT_BUTTON_NO , handler : ( ) : void => console . log ( 'Clear canceled' ) , } , { text : this . Text . COMPONENT_CLEAR_HISTORY_ALERT_BUTTON_YES , handler : ( ) : void => this . clearHistory ( ) , } , ] , } ) ; confirm . present ( confirm ) ; } return { void } private clearHistory ( ) { this . dao . clear ( ) . then ( ( ) => console . log ( 'History cleared.' ) , error => console . log ( 'Failed to clear history.' ) ) ; } }