[filterBar] abstract watch logic, and split into update/fetch
This commit is contained in:
parent
405d516605
commit
96aef8f02e
25
src/kibana/components/filter_bar/lib/watchFilters.js
Normal file
25
src/kibana/components/filter_bar/lib/watchFilters.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
define(function (require) {
|
||||
return function watchFiltersProvider(Promise) {
|
||||
var _ = require('lodash');
|
||||
var onlyDisabled = require('components/filter_bar/lib/onlyDisabled');
|
||||
|
||||
return function ($scope, handlers) {
|
||||
if (!handlers || !handlers.update || !handlers.fetch) {
|
||||
throw new TypeError('handlers for update and fetch are required');
|
||||
}
|
||||
|
||||
$scope.$watch('state.filters', function (newFilters, oldFilters) {
|
||||
if (newFilters === oldFilters) return;
|
||||
|
||||
Promise.resolve()
|
||||
.then(handlers.update)
|
||||
.then(function () {
|
||||
if (!onlyDisabled(newFilters, oldFilters)) {
|
||||
return handlers.fetch();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
};
|
||||
});
|
|
@ -3,7 +3,6 @@ define(function (require) {
|
|||
var $ = require('jquery');
|
||||
var angular = require('angular');
|
||||
var ConfigTemplate = require('utils/config_template');
|
||||
var onlyDisabled = require('components/filter_bar/lib/onlyDisabled');
|
||||
|
||||
require('directives/config');
|
||||
require('components/courier/courier');
|
||||
|
@ -51,6 +50,8 @@ define(function (require) {
|
|||
app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, kbnUrl) {
|
||||
return {
|
||||
controller: function ($scope, $route, $routeParams, $location, configFile, Private) {
|
||||
var filterBarWatchFilters = Private(require('components/filter_bar/lib/watchFilters'));
|
||||
|
||||
var notify = new Notifier({
|
||||
location: 'Dashboard'
|
||||
});
|
||||
|
@ -113,12 +114,12 @@ define(function (require) {
|
|||
}
|
||||
}
|
||||
|
||||
$scope.$watch('state.filters', function (newFilters, oldFilters) {
|
||||
if (onlyDisabled(newFilters, oldFilters)) {
|
||||
filterBarWatchFilters($scope, {
|
||||
update: function () {
|
||||
updateQueryOnRootSource();
|
||||
$state.save();
|
||||
return;
|
||||
}
|
||||
$scope.filterResults();
|
||||
},
|
||||
fetch: $scope.refresh
|
||||
});
|
||||
|
||||
$scope.newDashboard = function () {
|
||||
|
|
|
@ -3,7 +3,6 @@ define(function (require) {
|
|||
var angular = require('angular');
|
||||
var moment = require('moment');
|
||||
var ConfigTemplate = require('utils/config_template');
|
||||
var onlyDisabled = require('components/filter_bar/lib/onlyDisabled');
|
||||
var filterManager = require('components/filter_manager/filter_manager');
|
||||
var getSort = require('components/doc_table/lib/get_sort');
|
||||
var rison = require('utils/rison');
|
||||
|
@ -70,6 +69,7 @@ define(function (require) {
|
|||
var docTitle = Private(require('components/doc_title/doc_title'));
|
||||
var brushEvent = Private(require('utils/brush_event'));
|
||||
var HitSortFn = Private(require('plugins/discover/_hit_sort_fn'));
|
||||
var filterBarWatchFilters = Private(require('components/filter_bar/lib/watchFilters'));
|
||||
|
||||
var notify = new Notifier({
|
||||
location: 'Discover'
|
||||
|
@ -188,15 +188,13 @@ define(function (require) {
|
|||
if (!angular.equals(sort, currentSort)) $scope.fetch();
|
||||
});
|
||||
|
||||
$scope.$watch('state.filters', function (newFilters, oldFilters) {
|
||||
if (newFilters === oldFilters) return;
|
||||
|
||||
if (onlyDisabled(newFilters, oldFilters)) {
|
||||
$state.save();
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.fetch();
|
||||
filterBarWatchFilters($scope, {
|
||||
update: function () {
|
||||
return $scope.updateDataSource().then(function () {
|
||||
$state.save();
|
||||
});
|
||||
},
|
||||
fetch: $scope.fetch
|
||||
});
|
||||
|
||||
$scope.$watch('opts.timefield', function (timefield) {
|
||||
|
|
|
@ -52,12 +52,12 @@ define(function (require) {
|
|||
.controller('VisEditor', function ($scope, $route, timefilter, AppState, $location, kbnUrl, $timeout, courier, Private, Promise) {
|
||||
|
||||
var _ = require('lodash');
|
||||
var onlyDisabled = require('components/filter_bar/lib/onlyDisabled');
|
||||
var angular = require('angular');
|
||||
var ConfigTemplate = require('utils/config_template');
|
||||
var Notifier = require('components/notify/_notifier');
|
||||
var docTitle = Private(require('components/doc_title/doc_title'));
|
||||
var brushEvent = Private(require('utils/brush_event'));
|
||||
var filterBarWatchFilters = Private(require('components/filter_bar/lib/watchFilters'));
|
||||
var filterBarClickHandler = Private(require('components/filter_bar/filter_bar_click_handler'));
|
||||
|
||||
var notify = new Notifier({
|
||||
|
@ -151,12 +151,9 @@ define(function (require) {
|
|||
timefilter.enabled = !!timeField;
|
||||
});
|
||||
|
||||
$scope.$watch('state.filters', function (newFilters, oldFilters) {
|
||||
if (onlyDisabled(newFilters, oldFilters)) {
|
||||
$state.save();
|
||||
return;
|
||||
}
|
||||
if (newFilters !== oldFilters) $scope.fetch();
|
||||
filterBarWatchFilters($scope, {
|
||||
update: $state.save,
|
||||
fetch: $scope.fetch
|
||||
});
|
||||
|
||||
$scope.$listen($state, 'fetch_with_changes', function (keys) {
|
||||
|
|
Loading…
Reference in a new issue