Commit 5e6485c2 by Torkel Ödegaard

feat(query editors): minor progress

parent 65b49455
......@@ -35,8 +35,8 @@
<i class="fa fa-bars"></i>
</a>
<ul class="dropdown-menu pull-right" role="menu">
<li role="menuitem">
<a tabindex="1" ng-click="ctrl.toggleEditorMode()">Toggle text editor</a>
<li role="menuitem" ng-if="ctrl.hasTextEditMode">
<a tabindex="1" ng-click="ctrl.toggleEditorMode()">Toggle Edit Mode</a>
</li>
<li role="menuitem">
<a tabindex="1" ng-click="ctrl.duplicateQuery()">Duplicate</a>
......
......@@ -20,16 +20,15 @@ export class QueryRowCtrl {
this.target = this.queryCtrl.target;
this.panel = this.panelCtrl.panel;
this.toggleCollapse(true);
if (!this.target.refId) {
this.target.refId = this.getNextQueryLetter();
}
this.toggleCollapse(true);
if (this.target.isNew) {
delete this.target.isNew;
this.toggleCollapse(false);
}
if (!this.target.refId) {
this.target.refId = this.getNextQueryLetter();
}
}
toggleHideQuery() {
......@@ -72,6 +71,10 @@ export class QueryRowCtrl {
}
toggleEditorMode() {
if (this.canCollapse && this.collapsed) {
this.collapsed = false;
}
this.queryCtrl.toggleEditorMode();
}
......@@ -104,6 +107,7 @@ function queryEditorRowDirective() {
scope: {
queryCtrl: "=",
canCollapse: "=",
hasTextEditMode: "=",
},
};
}
......
......@@ -59,7 +59,7 @@
</div>
<div ng-if="agg.type === 'extended_stats'">
<gf-form-switch ng-repeat="stat in extendedStats" class="gf-form offset-width-7" label="{{stat.text}}" label-class="width-10" checked="agg.meta[stat.value]" on-change="ctrl.render()"></gf-form-switch>
<gf-form-switch ng-repeat="stat in extendedStats" class="gf-form offset-width-7" label="{{stat.text}}" label-class="width-10" checked="agg.meta[stat.value]" on-change="onChangeInternal()"></gf-form-switch>
<div class="gf-form offset-width-7">
<label class="gf-form-label width-10">Sigma</label>
......
......@@ -5,6 +5,7 @@ import './metric_agg';
import angular from 'angular';
import _ from 'lodash';
import queryDef from './query_def';
import {QueryCtrl} from 'app/plugins/sdk';
export class ElasticQueryCtrl extends QueryCtrl {
......@@ -39,7 +40,44 @@ export class ElasticQueryCtrl extends QueryCtrl {
}
getCollapsedText() {
var text = 'Count(), Avg(@value), Group by(@timestamp, 1min) Query';
var metricAggs = this.target.metrics;
var bucketAggs = this.target.bucketAggs;
var metricAggTypes = queryDef.getMetricAggTypes(this.esVersion);
var bucketAggTypes = queryDef.bucketAggTypes;
var text = '';
if (this.target.query) {
text += 'Query: ' + this.target.query + ', ';
}
text += 'Metrics: ';
_.each(metricAggs, (metric, index) => {
var aggDef = _.findWhere(metricAggTypes, {value: metric.type});
text += aggDef.text + '(';
if (aggDef.requiresField) {
text += metric.field;
}
text += '), ';
});
_.each(bucketAggs, (bucketAgg, index) => {
if (index === 0) {
text += ' Group by: ';
}
var aggDef = _.findWhere(bucketAggTypes, {value: bucketAgg.type});
text += aggDef.text + '(';
if (aggDef.requiresField) {
text += bucketAgg.field;
}
text += '), ';
});
if (this.target.alias) {
text += 'Alias: ' + this.target.alias;
}
return text;
}
......
......@@ -20,9 +20,9 @@ function (_) {
],
bucketAggTypes: [
{text: "Terms", value: 'terms' },
{text: "Terms", value: 'terms', requiresField: true},
{text: "Filters", value: 'filters' },
{text: "Date Histogram", value: 'date_histogram' },
{text: "Date Histogram", value: 'date_histogram', requiresField: true},
],
orderByOptions: [
......
<query-editor-row query-ctrl="ctrl">
<query-editor-row query-ctrl="ctrl" has-text-edit-mode="true">
<div class="gf-form" ng-show="ctrl.target.textEditor">
<input type="text" class="gf-form-input" ng-model="ctrl.target.target" spellcheck="false" ng-blur="ctrl.refresh()"></input>
......
......@@ -164,7 +164,7 @@ export default class InfluxQuery {
getMeasurementAndPolicy(interpolate) {
var policy = this.target.policy;
var measurement = this.target.measurement;
var measurement = this.target.measurement || 'measurement';
if (!measurement.match('^/.*/')) {
measurement = '"' + measurement+ '"';
......@@ -192,10 +192,6 @@ export default class InfluxQuery {
}
}
if (!target.measurement) {
throw {message: "Metric measurement is missing"};
}
var query = 'SELECT ';
var i, y;
for (i = 0; i < this.selectModels.length; i++) {
......
<query-editor-row query-ctrl="ctrl" can-collapse="true">
<query-editor-row query-ctrl="ctrl" can-collapse="true" has-text-edit-mode="true">
<div class="gf-form" ng-if="ctrl.target.rawQuery">
<input type="text" class="gf-form-input" ng-model="ctrl.target.query" spellcheck="false" ng-blur="ctrl.refresh()"></input>
......@@ -25,7 +25,6 @@
<div class="gf-form gf-form--grow">
<div class="gf-form-label gf-form-label--grow"></div>
</div>
</div>
<div class="gf-form-inline" ng-repeat="selectParts in ctrl.queryModel.selectModels">
......
......@@ -155,7 +155,11 @@ export class InfluxQueryCtrl extends QueryCtrl {
}
toggleEditorMode() {
try {
this.target.query = this.queryModel.render(false);
} catch (err) {
console.log('query render error');
}
this.target.rawQuery = !this.target.rawQuery;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment