mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix group by ui
This commit is contained in:
parent
aacf555985
commit
c604651092
@ -86,7 +86,7 @@
|
||||
</div>
|
||||
|
||||
<div class="gf-form">
|
||||
<metric-segment segment="ctrl.groupBySegment" get-options="ctrl.getGroupByOptions()" on-change="ctrl.groupByAction(part, $index)"></metric-segment>
|
||||
<metric-segment segment="ctrl.groupByAdd" get-options="ctrl.getGroupByOptions()" on-change="ctrl.groupByAction(part, $index)"></metric-segment>
|
||||
</div>
|
||||
|
||||
<div class="gf-form gf-form--grow">
|
||||
|
@ -65,27 +65,23 @@ export default class PostgresQuery {
|
||||
return _.find(this.target.groupBy, (g: any) => g.type === 'time');
|
||||
}
|
||||
|
||||
addGroupBy(value) {
|
||||
var stringParts = value.match(/^(\w+)(\((.*)\))?$/);
|
||||
var typePart = stringParts[1];
|
||||
var args = stringParts[3].split(',');
|
||||
var partModel = sqlPart.create({ type: typePart, params: args });
|
||||
addGroupBy(partType, value) {
|
||||
var partModel = sqlPart.create({ type: partType, params: [value] });
|
||||
var partCount = this.target.groupBy.length;
|
||||
|
||||
if (partCount === 0) {
|
||||
this.target.groupBy.push(partModel.part);
|
||||
} else if (typePart === 'time') {
|
||||
} else if (partType === 'time') {
|
||||
// put timeGroup at start
|
||||
this.target.groupBy.splice(0, 0, partModel.part);
|
||||
} else if (typePart === 'column') {
|
||||
if (this.target.groupBy[partCount - 1].type === 'fill') {
|
||||
this.target.groupBy.splice(partCount - 1, 0, partModel.part);
|
||||
} else {
|
||||
this.target.groupBy.push(partModel.part);
|
||||
}
|
||||
} else {
|
||||
this.target.groupBy.push(partModel.part);
|
||||
}
|
||||
|
||||
if (partType === 'time') {
|
||||
partModel.part.params = ['1m', 'none'];
|
||||
}
|
||||
|
||||
this.updateProjection();
|
||||
}
|
||||
|
||||
@ -126,11 +122,6 @@ export default class PostgresQuery {
|
||||
this.updatePersistedParts();
|
||||
}
|
||||
|
||||
removeWherePart(whereParts, part) {
|
||||
var partIndex = _.indexOf(whereParts, part);
|
||||
whereParts.splice(partIndex, 1);
|
||||
}
|
||||
|
||||
addSelectPart(selectParts, type) {
|
||||
var partModel = sqlPart.create({ type: type });
|
||||
partModel.def.addStrategy(selectParts, partModel, this);
|
||||
|
@ -33,7 +33,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
timeColumnSegment: any;
|
||||
metricColumnSegment: any;
|
||||
selectMenu: any;
|
||||
groupBySegment: any;
|
||||
groupByAdd: any;
|
||||
|
||||
/** @ngInject **/
|
||||
constructor($scope, $injector, private templateSrv, private $q, private uiSegmentSrv) {
|
||||
@ -68,7 +68,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
this.buildSelectMenu();
|
||||
this.buildWhereSegments();
|
||||
this.whereAdd = this.uiSegmentSrv.newPlusButton();
|
||||
this.groupBySegment = this.uiSegmentSrv.newPlusButton();
|
||||
this.groupByAdd = this.uiSegmentSrv.newPlusButton();
|
||||
|
||||
this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
|
||||
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
|
||||
@ -273,7 +273,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
break;
|
||||
}
|
||||
case 'action': {
|
||||
this.queryModel.removeWherePart(part, index);
|
||||
whereParts.splice(index, 1);
|
||||
this.panelCtrl.refresh();
|
||||
break;
|
||||
}
|
||||
@ -302,7 +302,11 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
this.queryModel.whereParts.push(sqlPart.create({ type: 'expression', params: ['value', '=', 'value'] }));
|
||||
}
|
||||
}
|
||||
this.whereAdd = this.uiSegmentSrv.newPlusButton();
|
||||
|
||||
var plusButton = this.uiSegmentSrv.newPlusButton();
|
||||
this.whereAdd.html = plusButton.html;
|
||||
this.whereAdd.value = plusButton.value;
|
||||
|
||||
this.queryModel.updatePersistedParts();
|
||||
this.panelCtrl.refresh();
|
||||
}
|
||||
@ -324,15 +328,15 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
groupByAction() {
|
||||
switch (this.groupBySegment.value) {
|
||||
switch (this.groupByAdd.value) {
|
||||
default: {
|
||||
this.queryModel.addGroupBy(this.groupBySegment.value);
|
||||
this.queryModel.addGroupBy(this.groupByAdd.type, this.groupByAdd.value);
|
||||
}
|
||||
}
|
||||
|
||||
var plusButton = this.uiSegmentSrv.newPlusButton();
|
||||
this.groupBySegment.value = plusButton.value;
|
||||
this.groupBySegment.html = plusButton.html;
|
||||
this.groupByAdd.html = plusButton.html;
|
||||
this.groupByAdd.value = plusButton.value;
|
||||
this.panelCtrl.refresh();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user