mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
fixed a couple places that were trying to get an indexPattern for an indexPattern, and enabled us to optionally collect history from searchSources for display in a spy-like panel
This commit is contained in:
parent
bd108790ff
commit
85ab3f208c
4 changed files with 84 additions and 54 deletions
|
@ -13,39 +13,28 @@ define(function (require) {
|
|||
|
||||
var visConfigCategories = require('../saved_visualizations/_config_categories');
|
||||
|
||||
var visAndIndexPattern = function (savedVisualizations, courier, Notifier, $location, $route) {
|
||||
return function (using) {
|
||||
return savedVisualizations.get(using)
|
||||
.then(function (vis) {
|
||||
var index = vis.searchSource.get('index');
|
||||
if (!index) throw new courier.errors.SavedObjectNotFound('index-pattern');
|
||||
|
||||
return courier.indexPatterns.get(index)
|
||||
.then(function (indexPattern) {
|
||||
return [vis, indexPattern];
|
||||
});
|
||||
})
|
||||
.catch(courier.redirectWhenMissing({
|
||||
'index-pattern': '/settings',
|
||||
'*': '/visualize'
|
||||
}));
|
||||
};
|
||||
};
|
||||
|
||||
require('routes')
|
||||
.when('/visualize/create', {
|
||||
template: require('text!../editor.html'),
|
||||
resolve: {
|
||||
visAndIndexPattern: function ($injector, $route) {
|
||||
return $injector.invoke(visAndIndexPattern)($route.current.params);
|
||||
vis: function (savedVisualizations, courier, $route) {
|
||||
return savedVisualizations.get($route.current.params)
|
||||
.catch(courier.redirectWhenMissing({
|
||||
'index-pattern': '/settings',
|
||||
'*': '/visualize'
|
||||
}));
|
||||
}
|
||||
}
|
||||
})
|
||||
.when('/visualize/edit/:id', {
|
||||
template: require('text!../editor.html'),
|
||||
resolve: {
|
||||
visAndIndexPattern: function ($injector, $route) {
|
||||
return $injector.invoke(visAndIndexPattern)($route.current.params.id);
|
||||
vis: function (savedVisualizations, courier, $route) {
|
||||
return savedVisualizations.get($route.current.params.id)
|
||||
.catch(courier.redirectWhenMissing({
|
||||
'index-pattern': '/settings',
|
||||
'*': '/visualize'
|
||||
}));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -58,9 +47,10 @@ define(function (require) {
|
|||
});
|
||||
|
||||
// get the vis loaded in from the routes
|
||||
var vis = $route.current.locals.visAndIndexPattern[0];
|
||||
var vis = $route.current.locals.vis;
|
||||
// vis.destroy called by visualize directive
|
||||
var indexPattern = $route.current.locals.visAndIndexPattern[1];
|
||||
|
||||
var indexPattern = vis.searchSource.get('index');
|
||||
|
||||
$scope.fields = _.sortBy(indexPattern.fields, 'name');
|
||||
$scope.fields.byName = indexPattern.fieldsByName;
|
||||
|
|
|
@ -57,12 +57,9 @@ define(function (require) {
|
|||
});
|
||||
|
||||
vis.searchSource.onResults(function onResults(resp) {
|
||||
indexPatterns.get(vis.searchSource.get('index'))
|
||||
.then(function (indexPattern) {
|
||||
var chartData = vis.buildChartDataFromResponse(indexPattern, resp);
|
||||
chart.render(chartData);
|
||||
})
|
||||
.catch(notify.fatal);
|
||||
var indexPattern = vis.searchSource.get('index');
|
||||
var chartData = vis.buildChartDataFromResponse(indexPattern, resp);
|
||||
chart.render(chartData);
|
||||
}).catch(notify.fatal);
|
||||
|
||||
vis.searchSource.onError(notify.error);
|
||||
|
|
|
@ -38,6 +38,9 @@ define(function (require) {
|
|||
return this;
|
||||
};
|
||||
}, this);
|
||||
|
||||
// this.history = [];
|
||||
this._fetchStrategy = fetch.strategies[this._getType()];
|
||||
}
|
||||
|
||||
/*****
|
||||
|
@ -104,10 +107,7 @@ define(function (require) {
|
|||
SourceAbstract.prototype.onResults = function (handler) {
|
||||
var source = this;
|
||||
return new Promise.emitter(function (resolve, reject, defer) {
|
||||
pendingRequests.push({
|
||||
source: source,
|
||||
defer: defer
|
||||
});
|
||||
source._createRequest(defer);
|
||||
}, handler);
|
||||
};
|
||||
|
||||
|
@ -132,17 +132,20 @@ define(function (require) {
|
|||
*/
|
||||
SourceAbstract.prototype.fetch = function () {
|
||||
var source = this;
|
||||
return fetch[this._getType()](this)
|
||||
.then(function (res) {
|
||||
pendingRequests.splice(0).forEach(function (req) {
|
||||
if (req.source === source) {
|
||||
req.defer.resolve(_.cloneDeep(res));
|
||||
} else {
|
||||
pendingRequests.push(req);
|
||||
}
|
||||
});
|
||||
return res;
|
||||
});
|
||||
|
||||
var req = source._createRequest();
|
||||
|
||||
// fetch just the requests for this source
|
||||
fetch.these(source._getType(), pendingRequests.splice(0).filter(function (req) {
|
||||
if (req.source !== source) {
|
||||
pendingRequests.push(req);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}));
|
||||
|
||||
return req.defer.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -166,6 +169,23 @@ define(function (require) {
|
|||
* PRIVATE API
|
||||
*****/
|
||||
|
||||
SourceAbstract.prototype._createRequest = function (defer) {
|
||||
var req = {
|
||||
source: this,
|
||||
defer: defer || Promise.defer()
|
||||
};
|
||||
|
||||
if (this.history) {
|
||||
// latest history at the top
|
||||
this.history.unshift(req);
|
||||
// trim all entries beyond 19/20
|
||||
this.history.splice(20);
|
||||
}
|
||||
|
||||
pendingRequests.push(req);
|
||||
return req;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walk the inheritance chain of a source and return it's
|
||||
* flat representaion (taking into account merging rules)
|
||||
|
@ -239,6 +259,5 @@ define(function (require) {
|
|||
};
|
||||
|
||||
return SourceAbstract;
|
||||
|
||||
};
|
||||
});
|
|
@ -5,6 +5,10 @@ define(function (require) {
|
|||
|
||||
var docStrategy = Private(require('./strategy/doc'));
|
||||
var searchStrategy = Private(require('./strategy/search'));
|
||||
var strategies = this.strategies = {
|
||||
doc: docStrategy,
|
||||
search: searchStrategy
|
||||
};
|
||||
|
||||
var RequestErrorHandler = Private(require('./_request_error_handler'));
|
||||
var pendingRequests = Private(require('../_pending_requests'));
|
||||
|
@ -30,10 +34,10 @@ define(function (require) {
|
|||
// the source was requested at least twice
|
||||
var uniq = uniqs[iid];
|
||||
if (uniq._merged) {
|
||||
// already setup the multi-responder
|
||||
// already setup the merged list
|
||||
uniq._merged.push(req);
|
||||
} else {
|
||||
// put all requests into this array and itterate them all
|
||||
// put all requests into this array and itterate them on response
|
||||
uniq._merged = [uniq, req];
|
||||
}
|
||||
});
|
||||
|
@ -41,26 +45,33 @@ define(function (require) {
|
|||
return Promise.map(all, function (req) {
|
||||
return req.source._flatten();
|
||||
})
|
||||
.then(function (reqs) {
|
||||
.then(function (states) {
|
||||
// all requests must have been disabled
|
||||
if (!reqs.length) return Promise.resolve();
|
||||
if (!states.length) return Promise.resolve();
|
||||
|
||||
body = strategy.requestStatesToBody(reqs);
|
||||
body = strategy.requestStatesToBody(states);
|
||||
|
||||
return es[strategy.clientMethod]({
|
||||
body: body
|
||||
})
|
||||
.then(function (resp) {
|
||||
var sendResponse = function (req, resp) {
|
||||
req.complete = true;
|
||||
req.resp = resp;
|
||||
|
||||
if (resp.error) return reqErrHandler.handle(req, new errors.FetchFailure(resp));
|
||||
else strategy.resolveRequest(req, resp);
|
||||
};
|
||||
|
||||
strategy.getResponses(resp).forEach(function (resp) {
|
||||
var req = all.shift();
|
||||
if (!req._merged) sendResponse(req, resp);
|
||||
else {
|
||||
var state = states.shift();
|
||||
if (!req._merged) {
|
||||
req.state = state;
|
||||
sendResponse(req, resp);
|
||||
} else {
|
||||
req._merged.forEach(function (mergedReq) {
|
||||
mergedReq.state = state;
|
||||
sendResponse(mergedReq, _.cloneDeep(resp));
|
||||
});
|
||||
}
|
||||
|
@ -129,5 +140,18 @@ define(function (require) {
|
|||
* @async
|
||||
*/
|
||||
this.search = _.partial(fetchASource, searchStrategy);
|
||||
|
||||
/**
|
||||
* Fetch a list of pendingRequests, which is already filtered
|
||||
* @param {string} type - the type name for the sources in the requests
|
||||
* @param {array} reqs - the requests to fetch
|
||||
*/
|
||||
this.these = function (type, reqs) {
|
||||
return fetchThese(
|
||||
strategies[type],
|
||||
reqs,
|
||||
new RequestErrorHandler()
|
||||
);
|
||||
};
|
||||
};
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue