Skip to content

Commit

Permalink
savedVis class now loads parent savedSearch objects properly, and use…
Browse files Browse the repository at this point in the history
…s the hits.total rather than global agg's bucket count
  • Loading branch information
Spencer Alger committed Apr 17, 2014
1 parent 7a587a4 commit 3e45998
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 54 deletions.
51 changes: 12 additions & 39 deletions src/kibana/apps/visualize/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,55 +68,27 @@ define(function (require) {
var updateDataSource = function () {
notify.event('update data source');

// get the config objects form the visualization
var config = vis.getConfig();

// group the segments by their categoryName, but merge the segments and groups
config = _.groupBy(config, function (config) {
switch (config.categoryName) {
case 'group':
case 'segment':
return 'dimension';
default:
return config.categoryName;
}
});

// use the global aggregation if we don't have any dimensions
if (!config.dimension) {
config.dimension = [{
agg: 'global',
aggParams: {}
}];
}

// stores the config objects in queryDsl
var dsl = {};
// counter to ensure unique agg names
var i = 0;
// start at the root, but the current will move
var current = dsl;

// continue to nest the aggs under each other
// writes to the dsl object
var nest = (function () {
var current = dsl;
return function (config) {
current.aggs = {};
var key = '_agg_' + (i++);

var aggDsl = {};
aggDsl[config.agg] = config.aggParams;
vis.getConfig().forEach(function (config) {
current.aggs = {};
var key = '_agg_' + (i++);

current = current.aggs[key] = aggDsl;
};
}());
var aggDsl = {};
aggDsl[config.agg] = config.aggParams;

// nest each config type in order
config.split && config.split.forEach(nest);
config.dimension && config.dimension.forEach(nest);
config.metric && config.metric.forEach(nest);
current = current.aggs[key] = aggDsl;
});

// set the dsl to the searchSource
vis.searchSource.aggs(dsl.aggs);
vis.searchSource.aggs(dsl.aggs || {});
notify.event('update data source', true);
};

Expand Down Expand Up @@ -146,7 +118,8 @@ define(function (require) {

vis.save()
.then(function () {
$location.url('/visualize/' + vis.typeName + '/' + vis.id);
$location.url('/visualize/edit/' + vis.id);
configTemplate.close('save');
}, notify.fatal);
};

Expand Down
6 changes: 3 additions & 3 deletions src/kibana/apps/visualize/controllers/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ define(function (require) {

app.controller('VisualizeWizardStep1', function ($route, $scope, courier, config, $location, indexPatterns) {
$scope.step2WithSearchUrl = function (hit) {
return '#/visualize/step/2?savedSearch=' + encodeURIComponent(hit.id);
return '#/visualize/step/2?savedSearchId=' + encodeURIComponent(hit.id);
};

$scope.indexPattern = {
selection: null,
list: $route.current.params.indexPatternIds
list: $route.current.locals.indexPatternIds
};

$scope.$watch('indexPattern.selection', function (pattern) {
Expand All @@ -52,7 +52,7 @@ define(function (require) {
});

app.controller('VisualizeWizardStep2', function ($scope, $route, $location) {
var existing = _.pick($route.current.params, 'indexPattern', 'savedSearch');
var existing = _.pick($route.current.params, 'indexPattern', 'savedSearchId');

$scope.visTypeDefs = typeDefs;
$scope.typeUrl = function (type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,17 @@ define(function (require) {
};

if (resp.aggregations) {
if (!configs.length) {
configs.push({
splitAndFlatten(chartData, resp.aggregations);
} else {
chartData.rows = [];
chartData.columns = [
{
categoryName: 'metric',
agg: aggs.byName.count.name,
label: aggs.byName.count.display
});
}
splitAndFlatten(chartData, resp.aggregations);
}
];
writeRow(chartData.rows, { value: resp.hits.total });
}

// flattening the chart does not always result in a split,
Expand Down
21 changes: 14 additions & 7 deletions src/kibana/apps/visualize/saved_visualizations/_saved_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ define(function (require) {

mapping: {
title: 'string',
description: 'string',
stateJSON: 'string',
savedSearchId: 'string',
typeName: 'string',
stateJSON: 'string',
description: 'string',
savedSearchId: 'string'
},

defaults: {
title: '',
description: '',
stateJSON: '{}',
typeName: opts.type,
stateJSON: '{}',
description: '',
savedSearchId: opts.savedSearchId,
},

searchSource: true,
Expand All @@ -54,8 +55,14 @@ define(function (require) {
// set the state on the vis
vis.setState(state);


// default parent is the rootSearch, mimic the
// searchSource prop from saved objects
var parent = {
searchSource: rootSearch
};

// set/get the parent savedSearch
var parent = rootSearch;
if (vis.savedSearchId) {
if (!vis.savedSearch || vis.savedSearch.id !== vis.savedSearchId) {
// returns a promise
Expand All @@ -69,7 +76,7 @@ define(function (require) {
vis.savedSearch = parent;

vis.searchSource
.inherits(vis.savedSearch)
.inherits(parent.searchSource)
.size(0);

vis._fillConfigsToMinimum();
Expand Down
7 changes: 7 additions & 0 deletions src/kibana/utils/config_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ define(function (require) {
}
};

this.close = function (name) {
var toClose = templates[name];
if (this.current === toClose) {
this.current = null;
}
};

this.toString = function () {
return this.current;
};
Expand Down

0 comments on commit 3e45998

Please sign in to comment.