From c6046510924433e0ba9f2c0d5be8779eb22bd13c Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Thu, 5 Jul 2018 10:19:22 +0200 Subject: [PATCH] fix group by ui --- .../postgres/partials/query.editor.html | 2 +- .../datasource/postgres/postgres_query.ts | 25 ++++++------------- .../plugins/datasource/postgres/query_ctrl.ts | 20 +++++++++------ 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/public/app/plugins/datasource/postgres/partials/query.editor.html b/public/app/plugins/datasource/postgres/partials/query.editor.html index 4f7bed3e2c4..28f8af52930 100644 --- a/public/app/plugins/datasource/postgres/partials/query.editor.html +++ b/public/app/plugins/datasource/postgres/partials/query.editor.html @@ -86,7 +86,7 @@
- +
diff --git a/public/app/plugins/datasource/postgres/postgres_query.ts b/public/app/plugins/datasource/postgres/postgres_query.ts index 78429739c97..aad36cee569 100644 --- a/public/app/plugins/datasource/postgres/postgres_query.ts +++ b/public/app/plugins/datasource/postgres/postgres_query.ts @@ -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); diff --git a/public/app/plugins/datasource/postgres/query_ctrl.ts b/public/app/plugins/datasource/postgres/query_ctrl.ts index d2b7631dfdc..37e5aa13bd0 100644 --- a/public/app/plugins/datasource/postgres/query_ctrl.ts +++ b/public/app/plugins/datasource/postgres/query_ctrl.ts @@ -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(); }