fixes renderComplete in angular vis type (#16150)

This commit is contained in:
Peter Pisljar 2018-01-23 15:16:36 +01:00 committed by GitHub
parent 7b3a2f182c
commit cb7b38bb69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 47 additions and 39 deletions

View file

@ -5,9 +5,17 @@ import $ from 'jquery';
describe('markdown vis controller', function () {
let $scope;
const applyChanges = () => {
$scope.updateStatus.params = true;
$scope.renderComplete = () => {};
$scope.$digest();
};
beforeEach(ngMock.module('kibana/markdown_vis'));
beforeEach(ngMock.inject(function ($rootScope, $controller) {
$scope = $rootScope.$new();
$scope.updateStatus = {};
$scope.vis = { params: {} };
$scope.renderComplete = () => {};
const $element = $('<div>');
$controller('KbnMarkdownVisController', { $scope, $element });
@ -16,12 +24,8 @@ describe('markdown vis controller', function () {
it('should set html from markdown params', function () {
expect($scope).to.not.have.property('html');
$scope.vis = {
params: {
markdown: 'This is a test of the [markdown](http://daringfireball.net/projects/markdown) vis.'
}
};
$scope.$digest();
$scope.vis.params.markdown = 'This is a test of the [markdown](http://daringfireball.net/projects/markdown) vis.';
applyChanges();
expect($scope).to.have.property('html');
expect($scope.html.toString().indexOf('<a href')).to.be.greaterThan(-1);

View file

@ -1,3 +1,4 @@
import _ from 'lodash';
import MarkdownIt from 'markdown-it';
import { uiModules } from 'ui/modules';
import 'angular-sanitize';
@ -9,9 +10,9 @@ const markdownIt = new MarkdownIt({
const module = uiModules.get('kibana/markdown_vis', ['kibana', 'ngSanitize']);
module.controller('KbnMarkdownVisController', function ($scope) {
$scope.$watch('vis.params.markdown', function (html) {
if (html) {
$scope.html = markdownIt.render(html);
$scope.$watch('renderComplete', function () {
if ($scope.updateStatus.params && _.get($scope, 'vis.params.markdown', null)) {
$scope.html = markdownIt.render($scope.vis.params.markdown);
}
$scope.renderComplete();
});

View file

@ -19,6 +19,7 @@ describe('metric vis', function () {
beforeEach(ngMock.module('kibana/metric_vis'));
beforeEach(ngMock.inject(function ($rootScope, $controller) {
$scope = $rootScope.$new();
$scope.renderComplete = () => {};
$scope.vis = {
params: {
metric: {

View file

@ -2,8 +2,8 @@
<div class="metric-container" ng-repeat="metric in metrics" ng-style="{'background-color': metric.bgColor}">
<div class="metric-value"
ng-bind-html="metric.value"
ng-style="{'font-size': vis.params.metric.style.fontSize+'pt', 'color': metric.color}"
ng-style="{'font-size': visState.params.metric.style.fontSize+'pt', 'color': metric.color}"
></div>
<div ng-if="vis.params.metric.labels.show">{{metric.label}}</div>
<div ng-if="visState.params.metric.labels.show">{{metric.label}}</div>
</div>
</div>

View file

@ -1,12 +1,11 @@
import _ from 'lodash';
import { uiModules } from 'ui/modules';
import { getHeatmapColors } from 'ui/vislib/components/color/heatmap_color';
import { dispatchRenderComplete } from 'ui/render_complete';
// get the kibana/metric_vis module, and make sure that it requires the "kibana" module if it
// didn't already
const module = uiModules.get('kibana/metric_vis', ['kibana']);
module.controller('KbnMetricVisController', function ($scope, $element) {
module.controller('KbnMetricVisController', function ($scope) {
const metrics = $scope.metrics = [];
let labels = [];
@ -113,15 +112,15 @@ module.controller('KbnMetricVisController', function ($scope, $element) {
});
};
$scope.$watch('esResponse', function (resp) {
if (resp) {
$scope.$watch('renderComplete', function () {
if ($scope.esResponse) {
metrics.length = 0;
labels.length = 0;
colors.length = 0;
colors = getColors();
labels = getLabels();
$scope.processTableGroups(resp);
dispatchRenderComplete($element[0]);
$scope.processTableGroups($scope.esResponse);
}
$scope.renderComplete();
});
});

View file

@ -79,6 +79,7 @@ describe('Controller', function () {
// remove the response from the controller
function removeEsResponseFromScope() {
delete $rootScope.esResponse;
$rootScope.renderComplete = () => {};
$rootScope.$apply();
}

View file

@ -7,11 +7,11 @@
<div ng-if="tableGroups" class="table-vis-container">
<kbn-agg-table-group
group="tableGroups"
export-title="vis.title"
per-page="vis.params.perPage"
export-title="visState.title"
per-page="visState.params.perPage"
sort="sort"
show-total="vis.params.showTotal"
total-func="vis.params.totalFunc">
show-total="visState.params.showTotal"
total-func="visState.params.totalFunc">
</kbn-agg-table-group>
</div>
</div>

View file

@ -21,26 +21,25 @@ module.controller('KbnTableVisController', function ($scope) {
* - the underlying data changes (esResponse)
* - one of the view options changes (vis.params)
*/
$scope.$watch('esResponse', function (resp) {
$scope.$watch('renderComplete', function () {
let tableGroups = $scope.tableGroups = null;
let hasSomeRows = $scope.hasSomeRows = null;
if (resp) {
tableGroups = resp;
if ($scope.esResponse) {
tableGroups = $scope.esResponse;
hasSomeRows = tableGroups.tables.some(function haveRows(table) {
if (table.tables) return table.tables.some(haveRows);
return table.rows.length > 0;
});
$scope.renderComplete();
}
$scope.hasSomeRows = hasSomeRows;
if (hasSomeRows) {
$scope.tableGroups = tableGroups;
}
$scope.renderComplete();
});
});

View file

@ -24,6 +24,7 @@ module.controller('KbnTagCloudController', function ($scope, $element) {
if (!$scope.vis.aggs[0] || !$scope.vis.aggs[1]) {
incompleteMessage.style.display = 'none';
truncatedMessage.style.display = 'none';
$scope.renderComplete();
return;
}
@ -38,18 +39,25 @@ module.controller('KbnTagCloudController', function ($scope, $element) {
incompleteMessage.style.display = 'block';
}
$scope.renderComplete();
});
$scope.$watch('esResponse', async function (response) {
$scope.$watch('renderComplete', async function () {
if (!response || !response.tables.length) {
if ($scope.updateStatus.resize) {
tagCloud.resize();
}
if ($scope.updateStatus.params) {
tagCloud.setOptions($scope.vis.params);
}
if (!$scope.esResponse || !$scope.esResponse.tables.length) {
tagCloud.setData([]);
return;
}
const data = response.tables[0];
const data = $scope.esResponse.tables[0];
bucketAgg = data.columns[0].aggConfig;
const tags = data.rows.map(row => {
@ -72,11 +80,4 @@ module.controller('KbnTagCloudController', function ($scope, $element) {
tagCloud.setData(tags);
});
$scope.$watch('vis.params', (options) => tagCloud.setOptions(options));
$scope.$watch('resize', () => {
tagCloud.resize();
});
});

View file

@ -1,3 +1,3 @@
<div ng-controller="TimelionVisController" class="timelion-vis">
<div chart="esResponse.sheet[0]" interval="vis.params.interval"></div>
<div chart="esResponse.sheet[0]" interval="visState.params.interval"></div>
</div>

View file

@ -11,15 +11,17 @@ export function AngularVisTypeProvider(Private, $compile, $rootScope) {
this.vis = vis;
}
render(esResponse) {
render(esResponse, status) {
return new Promise((resolve, reject) => {
const updateScope = () => {
this.$scope.vis = this.vis;
this.$scope.visState = this.vis.getState();
this.$scope.esResponse = esResponse;
this.$scope.renderComplete = resolve;
this.$scope.renderFailed = reject;
this.$scope.resize = Date.now();
this.$scope.updateStatus = status;
this.$scope.$apply();
};