Skip to content

Commit

Permalink
Enable auto refresh functionality, closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed Sep 18, 2015
1 parent 693ce45 commit 6b3b9a4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6b3b9a4

Please sign in to comment.