mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
fixes renderComplete in angular vis type (#16150)
This commit is contained in:
parent
7b3a2f182c
commit
cb7b38bb69
11 changed files with 47 additions and 39 deletions
|
@ -5,9 +5,17 @@ import $ from 'jquery';
|
||||||
describe('markdown vis controller', function () {
|
describe('markdown vis controller', function () {
|
||||||
let $scope;
|
let $scope;
|
||||||
|
|
||||||
|
const applyChanges = () => {
|
||||||
|
$scope.updateStatus.params = true;
|
||||||
|
$scope.renderComplete = () => {};
|
||||||
|
$scope.$digest();
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(ngMock.module('kibana/markdown_vis'));
|
beforeEach(ngMock.module('kibana/markdown_vis'));
|
||||||
beforeEach(ngMock.inject(function ($rootScope, $controller) {
|
beforeEach(ngMock.inject(function ($rootScope, $controller) {
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
|
$scope.updateStatus = {};
|
||||||
|
$scope.vis = { params: {} };
|
||||||
$scope.renderComplete = () => {};
|
$scope.renderComplete = () => {};
|
||||||
const $element = $('<div>');
|
const $element = $('<div>');
|
||||||
$controller('KbnMarkdownVisController', { $scope, $element });
|
$controller('KbnMarkdownVisController', { $scope, $element });
|
||||||
|
@ -16,12 +24,8 @@ describe('markdown vis controller', function () {
|
||||||
|
|
||||||
it('should set html from markdown params', function () {
|
it('should set html from markdown params', function () {
|
||||||
expect($scope).to.not.have.property('html');
|
expect($scope).to.not.have.property('html');
|
||||||
$scope.vis = {
|
$scope.vis.params.markdown = 'This is a test of the [markdown](http://daringfireball.net/projects/markdown) vis.';
|
||||||
params: {
|
applyChanges();
|
||||||
markdown: 'This is a test of the [markdown](http://daringfireball.net/projects/markdown) vis.'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
$scope.$digest();
|
|
||||||
|
|
||||||
expect($scope).to.have.property('html');
|
expect($scope).to.have.property('html');
|
||||||
expect($scope.html.toString().indexOf('<a href')).to.be.greaterThan(-1);
|
expect($scope.html.toString().indexOf('<a href')).to.be.greaterThan(-1);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import _ from 'lodash';
|
||||||
import MarkdownIt from 'markdown-it';
|
import MarkdownIt from 'markdown-it';
|
||||||
import { uiModules } from 'ui/modules';
|
import { uiModules } from 'ui/modules';
|
||||||
import 'angular-sanitize';
|
import 'angular-sanitize';
|
||||||
|
@ -9,9 +10,9 @@ const markdownIt = new MarkdownIt({
|
||||||
|
|
||||||
const module = uiModules.get('kibana/markdown_vis', ['kibana', 'ngSanitize']);
|
const module = uiModules.get('kibana/markdown_vis', ['kibana', 'ngSanitize']);
|
||||||
module.controller('KbnMarkdownVisController', function ($scope) {
|
module.controller('KbnMarkdownVisController', function ($scope) {
|
||||||
$scope.$watch('vis.params.markdown', function (html) {
|
$scope.$watch('renderComplete', function () {
|
||||||
if (html) {
|
if ($scope.updateStatus.params && _.get($scope, 'vis.params.markdown', null)) {
|
||||||
$scope.html = markdownIt.render(html);
|
$scope.html = markdownIt.render($scope.vis.params.markdown);
|
||||||
}
|
}
|
||||||
$scope.renderComplete();
|
$scope.renderComplete();
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,6 +19,7 @@ describe('metric vis', function () {
|
||||||
beforeEach(ngMock.module('kibana/metric_vis'));
|
beforeEach(ngMock.module('kibana/metric_vis'));
|
||||||
beforeEach(ngMock.inject(function ($rootScope, $controller) {
|
beforeEach(ngMock.inject(function ($rootScope, $controller) {
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
|
$scope.renderComplete = () => {};
|
||||||
$scope.vis = {
|
$scope.vis = {
|
||||||
params: {
|
params: {
|
||||||
metric: {
|
metric: {
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
<div class="metric-container" ng-repeat="metric in metrics" ng-style="{'background-color': metric.bgColor}">
|
<div class="metric-container" ng-repeat="metric in metrics" ng-style="{'background-color': metric.bgColor}">
|
||||||
<div class="metric-value"
|
<div class="metric-value"
|
||||||
ng-bind-html="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>
|
||||||
<div ng-if="vis.params.metric.labels.show">{{metric.label}}</div>
|
<div ng-if="visState.params.metric.labels.show">{{metric.label}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { uiModules } from 'ui/modules';
|
import { uiModules } from 'ui/modules';
|
||||||
import { getHeatmapColors } from 'ui/vislib/components/color/heatmap_color';
|
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
|
// get the kibana/metric_vis module, and make sure that it requires the "kibana" module if it
|
||||||
// didn't already
|
// didn't already
|
||||||
const module = uiModules.get('kibana/metric_vis', ['kibana']);
|
const module = uiModules.get('kibana/metric_vis', ['kibana']);
|
||||||
|
|
||||||
module.controller('KbnMetricVisController', function ($scope, $element) {
|
module.controller('KbnMetricVisController', function ($scope) {
|
||||||
|
|
||||||
const metrics = $scope.metrics = [];
|
const metrics = $scope.metrics = [];
|
||||||
let labels = [];
|
let labels = [];
|
||||||
|
@ -113,15 +112,15 @@ module.controller('KbnMetricVisController', function ($scope, $element) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.$watch('esResponse', function (resp) {
|
$scope.$watch('renderComplete', function () {
|
||||||
if (resp) {
|
if ($scope.esResponse) {
|
||||||
metrics.length = 0;
|
metrics.length = 0;
|
||||||
labels.length = 0;
|
labels.length = 0;
|
||||||
colors.length = 0;
|
colors.length = 0;
|
||||||
colors = getColors();
|
colors = getColors();
|
||||||
labels = getLabels();
|
labels = getLabels();
|
||||||
$scope.processTableGroups(resp);
|
$scope.processTableGroups($scope.esResponse);
|
||||||
dispatchRenderComplete($element[0]);
|
|
||||||
}
|
}
|
||||||
|
$scope.renderComplete();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -79,6 +79,7 @@ describe('Controller', function () {
|
||||||
// remove the response from the controller
|
// remove the response from the controller
|
||||||
function removeEsResponseFromScope() {
|
function removeEsResponseFromScope() {
|
||||||
delete $rootScope.esResponse;
|
delete $rootScope.esResponse;
|
||||||
|
$rootScope.renderComplete = () => {};
|
||||||
$rootScope.$apply();
|
$rootScope.$apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
<div ng-if="tableGroups" class="table-vis-container">
|
<div ng-if="tableGroups" class="table-vis-container">
|
||||||
<kbn-agg-table-group
|
<kbn-agg-table-group
|
||||||
group="tableGroups"
|
group="tableGroups"
|
||||||
export-title="vis.title"
|
export-title="visState.title"
|
||||||
per-page="vis.params.perPage"
|
per-page="visState.params.perPage"
|
||||||
sort="sort"
|
sort="sort"
|
||||||
show-total="vis.params.showTotal"
|
show-total="visState.params.showTotal"
|
||||||
total-func="vis.params.totalFunc">
|
total-func="visState.params.totalFunc">
|
||||||
</kbn-agg-table-group>
|
</kbn-agg-table-group>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -21,26 +21,25 @@ module.controller('KbnTableVisController', function ($scope) {
|
||||||
* - the underlying data changes (esResponse)
|
* - the underlying data changes (esResponse)
|
||||||
* - one of the view options changes (vis.params)
|
* - one of the view options changes (vis.params)
|
||||||
*/
|
*/
|
||||||
$scope.$watch('esResponse', function (resp) {
|
$scope.$watch('renderComplete', function () {
|
||||||
|
|
||||||
let tableGroups = $scope.tableGroups = null;
|
let tableGroups = $scope.tableGroups = null;
|
||||||
let hasSomeRows = $scope.hasSomeRows = null;
|
let hasSomeRows = $scope.hasSomeRows = null;
|
||||||
|
|
||||||
if (resp) {
|
if ($scope.esResponse) {
|
||||||
tableGroups = resp;
|
tableGroups = $scope.esResponse;
|
||||||
|
|
||||||
hasSomeRows = tableGroups.tables.some(function haveRows(table) {
|
hasSomeRows = tableGroups.tables.some(function haveRows(table) {
|
||||||
if (table.tables) return table.tables.some(haveRows);
|
if (table.tables) return table.tables.some(haveRows);
|
||||||
return table.rows.length > 0;
|
return table.rows.length > 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.renderComplete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.hasSomeRows = hasSomeRows;
|
$scope.hasSomeRows = hasSomeRows;
|
||||||
if (hasSomeRows) {
|
if (hasSomeRows) {
|
||||||
$scope.tableGroups = tableGroups;
|
$scope.tableGroups = tableGroups;
|
||||||
}
|
}
|
||||||
|
$scope.renderComplete();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ module.controller('KbnTagCloudController', function ($scope, $element) {
|
||||||
if (!$scope.vis.aggs[0] || !$scope.vis.aggs[1]) {
|
if (!$scope.vis.aggs[0] || !$scope.vis.aggs[1]) {
|
||||||
incompleteMessage.style.display = 'none';
|
incompleteMessage.style.display = 'none';
|
||||||
truncatedMessage.style.display = 'none';
|
truncatedMessage.style.display = 'none';
|
||||||
|
$scope.renderComplete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,18 +39,25 @@ module.controller('KbnTagCloudController', function ($scope, $element) {
|
||||||
incompleteMessage.style.display = 'block';
|
incompleteMessage.style.display = 'block';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$scope.renderComplete();
|
$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([]);
|
tagCloud.setData([]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = response.tables[0];
|
const data = $scope.esResponse.tables[0];
|
||||||
bucketAgg = data.columns[0].aggConfig;
|
bucketAgg = data.columns[0].aggConfig;
|
||||||
|
|
||||||
const tags = data.rows.map(row => {
|
const tags = data.rows.map(row => {
|
||||||
|
@ -72,11 +80,4 @@ module.controller('KbnTagCloudController', function ($scope, $element) {
|
||||||
tagCloud.setData(tags);
|
tagCloud.setData(tags);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$scope.$watch('vis.params', (options) => tagCloud.setOptions(options));
|
|
||||||
|
|
||||||
$scope.$watch('resize', () => {
|
|
||||||
tagCloud.resize();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
<div ng-controller="TimelionVisController" class="timelion-vis">
|
<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>
|
</div>
|
||||||
|
|
|
@ -11,15 +11,17 @@ export function AngularVisTypeProvider(Private, $compile, $rootScope) {
|
||||||
this.vis = vis;
|
this.vis = vis;
|
||||||
}
|
}
|
||||||
|
|
||||||
render(esResponse) {
|
render(esResponse, status) {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const updateScope = () => {
|
const updateScope = () => {
|
||||||
this.$scope.vis = this.vis;
|
this.$scope.vis = this.vis;
|
||||||
|
this.$scope.visState = this.vis.getState();
|
||||||
this.$scope.esResponse = esResponse;
|
this.$scope.esResponse = esResponse;
|
||||||
this.$scope.renderComplete = resolve;
|
this.$scope.renderComplete = resolve;
|
||||||
this.$scope.renderFailed = reject;
|
this.$scope.renderFailed = reject;
|
||||||
this.$scope.resize = Date.now();
|
this.$scope.resize = Date.now();
|
||||||
|
this.$scope.updateStatus = status;
|
||||||
this.$scope.$apply();
|
this.$scope.$apply();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue