import { Component , OnInit , ViewChild , Input , ElementRef } from '@angular/core' ; import { AnalyticsDashboardService } from '../../dashboard.service' ; import { Session } from '../../../../../services/session' ; import { Filter , Option } from '../../../../../interfaces/dashboard' ; @ Component ( { selector : 'm-analytics__search' , templateUrl : './search.component.html' , } ) export class AnalyticsSearchComponent implements OnInit { active : boolean ; q : string ; id : string ; hasSearchContext : boolean = true ; searchContext : string | Promise < string > = '' ; @ ViewChild ( 'searchInput' , { static : true } ) searchInput : ElementRef ; constructor ( private analyticsService , private session ) { } ngOnInit ( ) { } search ( ) { } keyup ( e ) { if ( e . keyCode === 13 && this . session . isLoggedIn ( ) ) { this . search ( ) ; this . unsetFocus ( ) ; } } focus ( ) { this . active = true ; } blur ( ) { setTimeout ( ( ) => ( this . active = false ) , 100 ) ; } setFocus ( ) { if ( this . searchInput . nativeElement ) { this . searchInput . nativeElement . focus ( ) ; } } unsetFocus ( ) { if ( this . searchInput . nativeElement ) { this . searchInput . nativeElement . blur ( ) ; } } }