Remove ready:vis and application.load event (#14988)

* Remove ready:vis event

* Remove application.load event

* Remove commented code

* Fix comment

* Fix broken indentation
This commit is contained in:
Tim Roes 2017-11-17 10:46:02 +01:00 committed by GitHub
parent 5793410a35
commit be54f367e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 40 additions and 97 deletions

View file

@ -1,8 +1,8 @@
[[development-embedding-visualizations]]
=== Embedding Visualizations
There are two different angular directives you can use to insert a visualization in your page.
To display an already saved visualization, use the `<visualize>` directive.
There are two different angular directives you can use to insert a visualization in your page.
To display an already saved visualization, use the `<visualize>` directive.
To reuse an existing Visualization implementation for a more custom purpose, use the `<visualization>` directive instead.
==== VisualizeLoader
@ -23,11 +23,11 @@ two methods:
==== `<visualize>` directive
The `<visualize>` directive takes care of loading data, parsing data, rendering the editor
(if the Visualization is in edit mode) and rendering the visualization.
The directive takes a savedVis object for its configuration.
It is the easiest way to add visualization to your page under the assumption that
the visualization you are trying to display is saved in kibana.
The `<visualize>` directive takes care of loading data, parsing data, rendering the editor
(if the Visualization is in edit mode) and rendering the visualization.
The directive takes a savedVis object for its configuration.
It is the easiest way to add visualization to your page under the assumption that
the visualization you are trying to display is saved in kibana.
If that is not the case, take a look at using `<visualization>` directive.
The simplest way is to just pass `saved-id` to `<visualize>`:
@ -37,7 +37,7 @@ The simplest way is to just pass `saved-id` to `<visualize>`:
For the above to work with time based visualizations time picker must be present (enabled) on the page. For scenarios
where timepicker is not available time range can be passed in as additional parameter:
`<visualize saved-id="'447d2930-9eb2-11e7-a956-5558df96e706'"
`<visualize saved-id="'447d2930-9eb2-11e7-a956-5558df96e706'"
time-range="{ max: '2017-09-21T21:59:59.999Z', min: '2017-09-18T22:00:00.000Z' }"></visualize>`
Once <visualize> is done rendering the element will emit `renderComplete` event.
@ -57,7 +57,7 @@ which is explained later in this documentation.
If `appState` is not provided, `<visualize>` will not monitor the `AppState`.
`uiState` should be an instance of `PersistedState`. if not provided visualize will generate one,
`uiState` should be an instance of `PersistedState`. if not provided visualize will generate one,
but you will have no access to it. It is used to store viewer specific information like whether the legend is toggled on or off.
`editor-mode` defines if <visualize> should render in editor or in view mode.
@ -80,7 +80,6 @@ uiModules.get('kibana')
});
-----------
When <visualize> is ready it will emit `ready:vis` event on the root scope.
When <visualize> is done rendering it will emit `renderComplete` event on the element.
==== `<visualization>` directive
@ -96,7 +95,7 @@ The `<visualization>` directive takes a visualization configuration and data.
`visData` is the data object. Each visualization defines a `responseHandler`, which defines the format of this object.
`uiState` is an instance of PersistedState. Visualizations use it to keep track of their current state. If not provided
`uiState` is an instance of PersistedState. Visualizations use it to keep track of their current state. If not provided
`<visualization>` will create its own (but you won't be able to check its values)
*code example: create single metric visualization*
@ -120,4 +119,4 @@ uiModules.get('kibana')
});
-----------
<visualization> will trigger `renderComplete` event on the element once it's done rendering.
<visualization> will trigger `renderComplete` event on the element once it's done rendering.

View file

@ -388,8 +388,6 @@ app.directive('dashboardApp', function ($injector) {
addSearch: $scope.addSearch,
timefilter: $scope.timefilter
};
$scope.$emit('application.load');
}
};
});

View file

@ -388,16 +388,13 @@ function discoverController(
};
}()));
function initForTime() {
return setupVisualization().then($scope.updateTime);
if ($scope.opts.timefield) {
setupVisualization();
$scope.updateTime();
}
return Promise.resolve($scope.opts.timefield && initForTime())
.then(function () {
init.complete = true;
$state.replace();
$scope.$emit('application.load');
});
init.complete = true;
$state.replace();
});
});
@ -637,11 +634,9 @@ function discoverController(
$scope.minimumVisibleRows = $scope.hits;
};
let loadingVis;
function setupVisualization() {
// If we're not setting anything up we need to return an empty promise
if (!$scope.opts.timefield) return Promise.resolve();
if (loadingVis) return loadingVis;
// If no timefield has been specified we don't create a histogram of messages
if (!$scope.opts.timefield) return;
const visStateAggs = [
{
@ -664,39 +659,25 @@ function discoverController(
visState.aggs = visStateAggs;
$scope.vis.setState(visState);
return Promise.resolve($scope.vis);
} else {
$scope.vis = new Vis($scope.indexPattern, {
title: savedSearch.title,
type: 'histogram',
params: {
addLegend: false,
addTimeMarker: true
},
aggs: visStateAggs
});
$scope.searchSource.onRequestStart((searchSource, searchRequest) => {
return $scope.vis.onSearchRequestStart(searchSource, searchRequest);
});
$scope.searchSource.aggs(function () {
return $scope.vis.getAggConfig().toDsl();
});
}
$scope.vis = new Vis($scope.indexPattern, {
title: savedSearch.title,
type: 'histogram',
params: {
addLegend: false,
addTimeMarker: true
},
aggs: visStateAggs
});
$scope.searchSource.onRequestStart((searchSource, searchRequest) => {
return $scope.vis.onSearchRequestStart(searchSource, searchRequest);
});
$scope.searchSource.aggs(function () {
return $scope.vis.getAggConfig().toDsl();
});
// stash this promise so that other calls to setupVisualization will have to wait
loadingVis = new Promise(function (resolve) {
$scope.$on('ready:vis', function () {
resolve($scope.vis);
});
})
.finally(function () {
// clear the loading flag
loadingVis = null;
});
return loadingVis;
}
function resolveIndexPatternLoading() {

View file

@ -75,9 +75,6 @@ export class SearchEmbeddableFactory extends EmbeddableFactory {
const rootNode = angular.element(domNode);
rootNode.append(searchInstance);
// TODO: There is probably a better way to do this.
searchScope.$on('ready:vis', () => this.courier.fetch());
this.addDestroyEmeddable(panel.panelIndex, () => {
searchInstance.remove();
searchScope.savedObj.destroy();

View file

@ -1,11 +1,6 @@
import moment from 'moment-timezone';
export function KibanaRootController($scope, courier, config) {
// wait for the application to finish loading
$scope.$on('application.load', function () {
courier.start();
});
config.watch('dateFormat:tz', setDefaultTimezone, $scope);
config.watch('dateFormat:dow', setStartDayOfWeek, $scope);

View file

@ -54,8 +54,6 @@ uiModules.get('apps/management')
};
});
});
$scope.$emit('application.load');
}
};
});

View file

@ -209,10 +209,6 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie
$scope.vis.forceReload();
};
$scope.$on('ready:vis', function () {
$scope.$emit('application.load');
});
$scope.$on('$destroy', function () {
savedVis.destroy();
stateMonitor.destroy();

View file

@ -11,7 +11,7 @@ import { uiModules } from 'ui/modules';
import { getLimitedSearchResultsMessage } from './doc_table_strings';
uiModules.get('kibana')
.directive('docTable', function (config, Notifier, getAppState, pagerFactory, $filter) {
.directive('docTable', function (config, Notifier, getAppState, pagerFactory, $filter, courier) {
return {
restrict: 'E',
template: html,
@ -42,24 +42,6 @@ uiModules.get('kibana')
columns: $scope.columns
};
const prereq = (function () {
const fns = [];
return function register(fn) {
fns.push(fn);
return function () {
fn.apply(this, arguments);
if (fns.length) {
_.pull(fns, fn);
if (!fns.length) {
$scope.$root.$broadcast('ready:vis');
}
}
};
};
}());
const limitTo = $filter('limitTo');
const calculateItemsOnPage = () => {
$scope.pager.setTotalItems($scope.hits.length);
@ -90,7 +72,7 @@ uiModules.get('kibana')
});
$scope.$watch('searchSource', prereq(function () {
$scope.$watch('searchSource', function () {
if (!$scope.searchSource) return;
$scope.indexPattern = $scope.searchSource.get('index');
@ -139,7 +121,8 @@ uiModules.get('kibana')
});
}
startSearching();
}));
courier.fetch();
});
$scope.pageOfItems = [];
$scope.onPageNext = () => {

View file

@ -11,9 +11,6 @@ const VisualizeLoaderProvider = ($compile, $rootScope, savedVisualizations) => {
scope.timeRange = params.timeRange;
scope.showSpyPanel = params.showSpyPanel;
scope.editorMode = params.editorMode;
scope.$on('ready:vis', $event => {
$event.stopPropagation();
});
const container = el instanceof $ ? el : $(el);

View file

@ -205,7 +205,6 @@ uiModules
$scope.$watch('vis.initialized', $scope.fetch);
$scope.fetch();
$scope.$root.$broadcast('ready:vis');
}
};
});