Commit 5e6485c2 by Torkel Ödegaard

feat(query editors): minor progress

parent 65b49455
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
<i class="fa fa-bars"></i> <i class="fa fa-bars"></i>
</a> </a>
<ul class="dropdown-menu pull-right" role="menu"> <ul class="dropdown-menu pull-right" role="menu">
<li role="menuitem"> <li role="menuitem" ng-if="ctrl.hasTextEditMode">
<a tabindex="1" ng-click="ctrl.toggleEditorMode()">Toggle text editor</a> <a tabindex="1" ng-click="ctrl.toggleEditorMode()">Toggle Edit Mode</a>
</li> </li>
<li role="menuitem"> <li role="menuitem">
<a tabindex="1" ng-click="ctrl.duplicateQuery()">Duplicate</a> <a tabindex="1" ng-click="ctrl.duplicateQuery()">Duplicate</a>
......
...@@ -20,16 +20,15 @@ export class QueryRowCtrl { ...@@ -20,16 +20,15 @@ export class QueryRowCtrl {
this.target = this.queryCtrl.target; this.target = this.queryCtrl.target;
this.panel = this.panelCtrl.panel; this.panel = this.panelCtrl.panel;
this.toggleCollapse(true); if (!this.target.refId) {
this.target.refId = this.getNextQueryLetter();
}
this.toggleCollapse(true);
if (this.target.isNew) { if (this.target.isNew) {
delete this.target.isNew; delete this.target.isNew;
this.toggleCollapse(false); this.toggleCollapse(false);
} }
if (!this.target.refId) {
this.target.refId = this.getNextQueryLetter();
}
} }
toggleHideQuery() { toggleHideQuery() {
...@@ -72,6 +71,10 @@ export class QueryRowCtrl { ...@@ -72,6 +71,10 @@ export class QueryRowCtrl {
} }
toggleEditorMode() { toggleEditorMode() {
if (this.canCollapse && this.collapsed) {
this.collapsed = false;
}
this.queryCtrl.toggleEditorMode(); this.queryCtrl.toggleEditorMode();
} }
...@@ -104,6 +107,7 @@ function queryEditorRowDirective() { ...@@ -104,6 +107,7 @@ function queryEditorRowDirective() {
scope: { scope: {
queryCtrl: "=", queryCtrl: "=",
canCollapse: "=", canCollapse: "=",
hasTextEditMode: "=",
}, },
}; };
} }
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
</div> </div>
<div ng-if="agg.type === 'extended_stats'"> <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"> <div class="gf-form offset-width-7">
<label class="gf-form-label width-10">Sigma</label> <label class="gf-form-label width-10">Sigma</label>
......
...@@ -5,6 +5,7 @@ import './metric_agg'; ...@@ -5,6 +5,7 @@ import './metric_agg';
import angular from 'angular'; import angular from 'angular';
import _ from 'lodash'; import _ from 'lodash';
import queryDef from './query_def';
import {QueryCtrl} from 'app/plugins/sdk'; import {QueryCtrl} from 'app/plugins/sdk';
export class ElasticQueryCtrl extends QueryCtrl { export class ElasticQueryCtrl extends QueryCtrl {
...@@ -39,7 +40,44 @@ export class ElasticQueryCtrl extends QueryCtrl { ...@@ -39,7 +40,44 @@ export class ElasticQueryCtrl extends QueryCtrl {
} }
getCollapsedText() { 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; return text;
} }
......
...@@ -20,9 +20,9 @@ function (_) { ...@@ -20,9 +20,9 @@ function (_) {
], ],
bucketAggTypes: [ bucketAggTypes: [
{text: "Terms", value: 'terms' }, {text: "Terms", value: 'terms', requiresField: true},
{text: "Filters", value: 'filters' }, {text: "Filters", value: 'filters' },
{text: "Date Histogram", value: 'date_histogram' }, {text: "Date Histogram", value: 'date_histogram', requiresField: true},
], ],
orderByOptions: [ 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"> <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> <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 { ...@@ -164,7 +164,7 @@ export default class InfluxQuery {
getMeasurementAndPolicy(interpolate) { getMeasurementAndPolicy(interpolate) {
var policy = this.target.policy; var policy = this.target.policy;
var measurement = this.target.measurement; var measurement = this.target.measurement || 'measurement';
if (!measurement.match('^/.*/')) { if (!measurement.match('^/.*/')) {
measurement = '"' + measurement+ '"'; measurement = '"' + measurement+ '"';
...@@ -192,10 +192,6 @@ export default class InfluxQuery { ...@@ -192,10 +192,6 @@ export default class InfluxQuery {
} }
} }
if (!target.measurement) {
throw {message: "Metric measurement is missing"};
}
var query = 'SELECT '; var query = 'SELECT ';
var i, y; var i, y;
for (i = 0; i < this.selectModels.length; i++) { 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"> <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> <input type="text" class="gf-form-input" ng-model="ctrl.target.query" spellcheck="false" ng-blur="ctrl.refresh()"></input>
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
<div class="gf-form gf-form--grow"> <div class="gf-form gf-form--grow">
<div class="gf-form-label gf-form-label--grow"></div> <div class="gf-form-label gf-form-label--grow"></div>
</div> </div>
</div> </div>
<div class="gf-form-inline" ng-repeat="selectParts in ctrl.queryModel.selectModels"> <div class="gf-form-inline" ng-repeat="selectParts in ctrl.queryModel.selectModels">
......
...@@ -155,7 +155,11 @@ export class InfluxQueryCtrl extends QueryCtrl { ...@@ -155,7 +155,11 @@ export class InfluxQueryCtrl extends QueryCtrl {
} }
toggleEditorMode() { toggleEditorMode() {
try {
this.target.query = this.queryModel.render(false); this.target.query = this.queryModel.render(false);
} catch (err) {
console.log('query render error');
}
this.target.rawQuery = !this.target.rawQuery; 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