Skip to content

Commit

Permalink
Make discover react to URL changes, only update URL on data refresh. C…
Browse files Browse the repository at this point in the history
…loses #58. Closes #61
  • Loading branch information
Rashid Khan committed Apr 17, 2014
1 parent ae1ec33 commit af87f13
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/kibana/apps/discover/controllers/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,26 @@ define(function (require) {
$scope.fetch();
}
});

// If the URL changes, we re-fetch, no matter what changes.
$scope.$on('$locationChangeSuccess', function () {
$scope.state = state.get();

// We have no state, don't try to refresh until we do
if (_.isEmpty($scope.state)) return;

updateDataSource();
// TODO: fetch just this savedSearch
courier.fetch();
});

// the index to use when they don't specify one
$scope.$watch('opts.index', function (val) {
if (!val) return;
updateDataSource();
$scope.fetch();
});

$scope.$watchCollection('state', state.set);

// Bind a result handler. Any time scope.fetch() is executed this gets called
// with the results
searchSource.onResults().then(function onResults(resp) {
Expand Down Expand Up @@ -240,9 +251,8 @@ define(function (require) {
}

$scope.fetch = function () {
updateDataSource();
// fetch just this savedSearch
courier.fetch();
// We only set the state on data refresh
state.set($scope.state);
};

// This is a hacky optimization for comparing the contents of a large array to a short one.
Expand Down

0 comments on commit af87f13

Please sign in to comment.