import { Component, Injector, OnInit, ViewChild, ViewEncapsulation, Input, OnChanges, Output,EventEmitter } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { AppConsts } from '@shared/AppConsts'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { RouteListDto, RouteServiceProxy } from '@shared/service-proxies/service-proxies'; import { TimerService } from '@app/sprintship/core-components/timer/timer.service'; import * as moment from 'moment'; import { HttpClient } from '@angular/common/http'; import { finalize } from 'rxjs/operators'; import { Subscription } from 'rxjs'; declare var $: any; declare var jquery:any; @Component({ selector: 'timer', templateUrl: './timer.component.html', styleUrls: ['./timer.component.css'], encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], }) export class TimerComponent extends AppComponentBase implements OnInit { hide : boolean; interval: any; ctr: number; result: any; subscription: Subscription; action: any; @Input('time_interval') time_interval: number; @Output() refresh = new EventEmitter(); @Output() change_interval = new EventEmitter(); constructor( injector: Injector, private _routeService: RouteServiceProxy, private _timerService: TimerService, ) { super(injector); this.subscription = _timerService.tmrMediator.subscribe(details => { }); } ngOnInit(): void { clearInterval(this.interval); this.startTimer(); console.log('TIMER STARTING'); } onShown(): void { } ngOnChanges(): void { } startTimer() { var that = this; if(localStorage.getItem('time_interval') == null) { that.time_interval = 60000; localStorage.setItem('time_interval', that.time_interval.toString()); } that.time_interval = parseInt(localStorage.getItem('time_interval')); this.ctr = 1; this.interval = setInterval( ()=> { if(this._timerService.default === undefined) { that._timerService.default = {'action': 'CONTROLLER_REFRESH'}; that._timerService.messageTimer({'action': 'CONTROLLER_REFRESH'}); } that._timerService.messageTimer({'timer': this.time_interval, 'seconds': that.ctr}); this.refresh.emit(this._timerService.default); that.ctr++; }, that.time_interval); } changeInterval() { clearInterval(this.interval); localStorage.setItem('time_interval', $('#refreshInterval').val()); this.time_interval = $('#refreshInterval').val(); this.startTimer(); this.change_interval.emit($('#refreshInterval').val()); } }