Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Merge branch '6.x' of github.com:elastic/kibana into 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Roes committed Oct 2, 2017
2 parents 2f88558 + 46b5a3c commit d6b07ea
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ uiModules.get('apps/management')
const getData = function (filter) {
const services = savedObjectManagementRegistry.all().map(function (obj) {
const service = $injector.get(obj.service);
return service.find(filter).then(function (data) {
return service.findAll(filter).then(function (data) {
return {
service: service,
serviceName: obj.service,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ savedObjectManagementRegistry.register({
title: 'visualizations'
});

app.service('savedVisualizations', function (Promise, kbnIndex, SavedVis, Private, Notifier, kbnUrl, $http) {
app.service('savedVisualizations', function (Promise, kbnIndex, SavedVis, Private, kbnUrl, $http) {
const visTypes = Private(VisTypesRegistryProvider);
const notify = new Notifier({
location: 'Saved Visualization Service'
});

const saveVisualizationLoader = new SavedObjectLoader(SavedVis, kbnIndex, kbnUrl, $http);

Expand All @@ -32,9 +29,8 @@ app.service('savedVisualizations', function (Promise, kbnIndex, SavedVis, Privat
}

if (!typeName || !visTypes.byName[typeName]) {
if (!typeName) notify.error('Visualization type is missing. Please add a type to this visualization.', source);
else notify.error('Visualization type of "' + typeName + '" is invalid. Please change to a valid type.', source);
return kbnUrl.redirect('/management/kibana/objects/savedVisualizations/{{id}}', { id: source.id });
source.error = 'Unknown visualization type';
return source;
}

source.type = visTypes.byName[typeName];
Expand Down
25 changes: 24 additions & 1 deletion src/ui/public/agg_response/tabify/_buckets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash';

export function AggResponseBucketsProvider() {

function Buckets(aggResp) {
function Buckets(aggResp, aggParams) {
if (_.has(aggResp, 'buckets')) {
this.buckets = aggResp.buckets;
} else {
Expand All @@ -18,6 +18,8 @@ export function AggResponseBucketsProvider() {
} else {
this.length = this.buckets.length;
}

if (this.length && aggParams) this._orderBucketsAccordingToParams(aggParams);
}

Buckets.prototype.forEach = function (fn) {
Expand All @@ -34,5 +36,26 @@ export function AggResponseBucketsProvider() {
}
};

Buckets.prototype._orderBucketsAccordingToParams = function (params) {
if (params.filters && this.objectMode) {
this._keys = params.filters.map(filter => {
return filter.label || filter.input.query || '*';
});
} else if (params.ranges && this.objectMode) {
this._keys = params.ranges.map(range => {
return _.findKey(this.buckets, el => el.from === range.from && el.to === range.to);
});
} else if (params.ranges && params.field.type !== 'date') {
let ranges = params.ranges;
if (params.ipRangeType) {
ranges = params.ipRangeType === 'mask' ? ranges.mask : ranges.fromTo;
}
this.buckets = ranges.map(range => {
if (range.mask) return this.buckets.find(el => el.key === range.mask);
return this.buckets.find(el => el.from === range.from && el.to === range.to);
});
}
};

return Buckets;
}
2 changes: 1 addition & 1 deletion src/ui/public/agg_response/tabify/tabify.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function AggResponseTabifyProvider(Private, Notifier) {

switch (agg.schema.group) {
case 'buckets':
const buckets = new Buckets(bucket[agg.id]);
const buckets = new Buckets(bucket[agg.id], agg.params);
if (buckets.length) {
const splitting = write.canSplit && agg.schema.name === 'split';
if (splitting) {
Expand Down
5 changes: 4 additions & 1 deletion src/ui/public/courier/_redirect_when_missing.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export function RedirectWhenMissingProvider($location, kbnUrl, Notifier, Promise

return function (err) {
// if this error is not "404", rethrow
if (!(err instanceof SavedObjectNotFound)) throw err;
const savedObjectNotFound = err instanceof SavedObjectNotFound;
const unknownVisType = err.message.indexOf('Invalid type') === 0;
if (unknownVisType) err.savedObjectType = 'visualization';
else if (!savedObjectNotFound) throw err;

let url = mapping[err.savedObjectType] || mapping['*'];
if (!url) url = '/';
Expand Down
14 changes: 12 additions & 2 deletions src/ui/public/courier/saved_object/saved_object_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class SavedObjectLoader {
* @param size
* @returns {Promise}
*/
find(search = '', size = 100) {
findAll(search = '', size = 100) {
return this.savedObjectsClient.find(
{
type: this.lowercaseType,
Expand All @@ -99,8 +99,18 @@ export class SavedObjectLoader {
}).then((resp) => {
return {
total: resp.total,
hits: resp.savedObjects.map((savedObject) => this.mapSavedObjectApiHits(savedObject))
hits: resp.savedObjects
.map((savedObject) => this.mapSavedObjectApiHits(savedObject))
};
});
}

find(search = '', size = 100) {
return this.findAll(search, size).then(resp => {
return {
total: resp.total,
hits: resp.hits.filter(savedObject => !savedObject.error)
};
});
}
}

0 comments on commit d6b07ea

Please sign in to comment.