mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(elasticsearch): fields are fetch from mapping instead of docs, you can enter custom value in field options, other fixes, #1034
This commit is contained in:
@@ -20,7 +20,6 @@ function (angular, app, _, $) {
|
||||
return {
|
||||
scope: {
|
||||
segment: "=",
|
||||
noCustom: "=",
|
||||
getOptions: "&",
|
||||
onChange: "&",
|
||||
},
|
||||
@@ -48,7 +47,7 @@ function (angular, app, _, $) {
|
||||
segment.fake = false;
|
||||
segment.expandable = selected.expandable;
|
||||
}
|
||||
else if ($scope.noCustom === false) {
|
||||
else if (segment.custom !== 'false') {
|
||||
segment.value = value;
|
||||
segment.html = $sce.trustAsHtml(value);
|
||||
segment.expandable = true;
|
||||
@@ -83,7 +82,7 @@ function (angular, app, _, $) {
|
||||
options = _.map($scope.altSegments, function(alt) { return alt.value; });
|
||||
|
||||
// add custom values
|
||||
if ($scope.noCustom === false) {
|
||||
if (segment.custom !== 'false') {
|
||||
if (!segment.fake && _.indexOf(options, segment.value) === -1) {
|
||||
options.unshift(segment.value);
|
||||
}
|
||||
@@ -161,7 +160,7 @@ function (angular, app, _, $) {
|
||||
.module('grafana.directives')
|
||||
.directive('metricSegmentModel', function(uiSegmentSrv, $q) {
|
||||
return {
|
||||
template: '<metric-segment segment="segment" get-options="getOptionsInternal()" on-change="onSegmentChange()" no-custom="true"></metric-segment>',
|
||||
template: '<metric-segment segment="segment" get-options="getOptionsInternal()" on-change="onSegmentChange()"></metric-segment>',
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
property: "=",
|
||||
@@ -175,9 +174,9 @@ function (angular, app, _, $) {
|
||||
$scope.valueToSegment = function(value) {
|
||||
var option = _.findWhere($scope.options, {value: value});
|
||||
if (option) {
|
||||
return uiSegmentSrv.newSegment({value: option.text, cssClass: attrs.cssClass});
|
||||
return uiSegmentSrv.newSegment({value: option.text, cssClass: attrs.cssClass, custom: attrs.custom});
|
||||
} else {
|
||||
return uiSegmentSrv.newSegment({value: value, cssClass: attrs.cssClass});
|
||||
return uiSegmentSrv.newSegment({value: value, cssClass: attrs.cssClass, custom: attrs.custom});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -257,43 +257,19 @@ function (angular, _, config, kbn, moment, ElasticQueryBuilder) {
|
||||
var timeFrom = this.translateTime(timeSrv.time.from);
|
||||
var timeTo = this.translateTime(timeSrv.time.to);
|
||||
|
||||
var query = {
|
||||
size: 10,
|
||||
"query": {
|
||||
"filtered": {
|
||||
"filter": {
|
||||
"bool": {
|
||||
"must": [
|
||||
{
|
||||
"range": {
|
||||
"@timestamp": {
|
||||
"gte": timeFrom,
|
||||
"lte": timeTo
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return this._post('/_search?', query).then(function(res) {
|
||||
return this._get('/_mapping').then(function(res) {
|
||||
var fields = {};
|
||||
|
||||
for (var i = 0; i < res.hits.hits.length; i++) {
|
||||
var hit = res.hits.hits[i];
|
||||
for (var field in hit) {
|
||||
if (hit.hasOwnProperty(field) && field[0] !== '_') {
|
||||
fields[field] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (hit._source) {
|
||||
for (var fieldProp in hit._source) {
|
||||
if (hit._source.hasOwnProperty(fieldProp)) {
|
||||
fields[fieldProp] = 1;
|
||||
for (var indexName in res) {
|
||||
var index = res[indexName];
|
||||
var mappings = index.mappings;
|
||||
if (!mappings) { continue; }
|
||||
for (var typeName in mappings) {
|
||||
var properties = mappings[typeName].properties;
|
||||
for (var field in properties) {
|
||||
var prop = properties[field];
|
||||
if (prop.type && field[0] !== '_') {
|
||||
fields[field] = prop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ function (angular, _, queryDef) {
|
||||
});
|
||||
|
||||
$scope.validateModel = function() {
|
||||
$scope.settingsLinkText = '';
|
||||
|
||||
if (!$scope.agg.field) {
|
||||
$scope.agg.field = 'select field';
|
||||
}
|
||||
@@ -43,6 +45,7 @@ function (angular, _, queryDef) {
|
||||
|
||||
$scope.onTypeChange = function() {
|
||||
$scope.agg.settings = {};
|
||||
$scope.validateModel();
|
||||
$scope.onChange();
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<span ng-hide="isFirst">Then by</span>
|
||||
</li>
|
||||
<li>
|
||||
<metric-segment-model property="agg.type" options="bucketAggTypes" on-change="onChangeInternal()"></metric-segment-model>
|
||||
<metric-segment-model property="agg.type" options="bucketAggTypes" on-change="onChangeInternal()" custom="false"></metric-segment-model>
|
||||
<metric-segment-model property="agg.field" get-options="getFields()" on-change="onChangeInternal()"></metric-segment>
|
||||
</li>
|
||||
<li class="tight-form-item tight-form-align" ng-if="settingsLinkText">
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
Metric
|
||||
</li>
|
||||
<li>
|
||||
<metric-segment-model property="agg.type" options="metricAggTypes" on-change="onTypeChange()"></metric-segment-model>
|
||||
<metric-segment-model property="agg.type" options="metricAggTypes" on-change="onTypeChange()" custom="false"></metric-segment-model>
|
||||
</li>
|
||||
<li ng-if="agg.type !== 'count'">
|
||||
<metric-segment-model property="agg.field" get-options="getFields()" on-change="onChange()"></metric-segment>
|
||||
|
||||
@@ -24,6 +24,7 @@ function (angular, _) {
|
||||
}
|
||||
|
||||
this.cssClass = options.cssClass;
|
||||
this.custom = options.custom;
|
||||
this.type = options.type;
|
||||
this.fake = options.fake;
|
||||
this.value = options.value;
|
||||
|
||||
Reference in New Issue
Block a user