From 6b3b9a4fbfb6f3689ed0867b64458e89ae16b750 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Fri, 18 Sep 2015 15:29:59 -0700 Subject: [PATCH] Enable auto refresh functionality, closes #1 --- public/app.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/public/app.js b/public/app.js index 106d9cc596f3dd..5890f188650444 100644 --- a/public/app.js +++ b/public/app.js @@ -40,13 +40,13 @@ require('ui/routes') } }); -app.controller('timelion', function ($scope, $http, timefilter, AppState, courier, $route, $routeParams, kbnUrl, Notifier, config) { +app.controller('timelion', function ( + $scope, $http, timefilter, AppState, courier, $route, $routeParams, kbnUrl, Notifier, config, $timeout) { timefilter.enabled = true; var notify = new Notifier({ location: 'Timelion' }); - var defaultExpression = '.es(*)'; var savedSheet = $route.current.locals.savedSheet; var blankSheet = [defaultExpression]; @@ -92,6 +92,20 @@ app.controller('timelion', function ($scope, $http, timefilter, AppState, courie }; }; + var refresher; + $scope.$watchCollection('timefilter.refreshInterval', function (interval) { + if (refresher) $timeout.cancel(refresher); + if (interval.value > 0 && !interval.pause) { + function startRefresh() { + refresher = $timeout(function () { + if (!$scope.running) $scope.search(); + startRefresh(); + }, interval.value); + }; + startRefresh(); + } + }); + $scope.toggle = function (property) { console.log(property); $scope[property] = !$scope[property]; @@ -151,7 +165,6 @@ app.controller('timelion', function ($scope, $http, timefilter, AppState, courie $scope.safeSearch = _.debounce($scope.search, 500); - function save() { savedSheet.id = savedSheet.title; savedSheet.timelion_sheet = $scope.state.sheet;