Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #161 from doitintl/issue-137
Browse files Browse the repository at this point in the history
Solves #137
  • Loading branch information
avivl authored Nov 4, 2019
2 parents 3bad7cc + 8eb95a1 commit 37b0d36
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 5 deletions.
26 changes: 24 additions & 2 deletions dist/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -58477,6 +58477,8 @@ function () {
this.groupBy = "";
this.tmpValue = "";
target.format = target.format || "time_series";
target.orderByCol = target.orderByCol || "1";
target.orderBySort = target.orderBySort || "1";
target.timeColumn = target.timeColumn || "-- time --";
target.timeColumnType = target.timeColumnType || "TIMESTAMP";
target.metricColumn = target.metricColumn || "none";
Expand Down Expand Up @@ -58938,10 +58940,16 @@ function () {
query += this.buildGroupClause();

if (!this.isWindow) {
query += "\nORDER BY 1";
var orderBy = "\nORDER BY 1";

if (this.hasMetricColumn()) {
query += ",2";
orderBy = this.target.orderByCol === "1" ? "\nORDER BY 1,2" : "\nORDER BY 2,1";
}

query += orderBy;

if (this.target.orderBySort === "2") {
query += " DESC";
}
} // query += '\nLIMIT 2';

Expand Down Expand Up @@ -60260,6 +60268,20 @@ function (_super) {
text: "Table",
value: "table"
}];
_this.orderByCols = [{
text: "Time",
value: "1"
}, {
text: "Metric",
value: "2"
}];
_this.orderBySorts = [{
text: "ASC",
value: "1"
}, {
text: "DESC",
value: "2"
}];

if (!_this.target.rawSql) {
// special handling when in table panel
Expand Down
2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions dist/partials/query.editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@
</div>
</div>

<!-- Start Order BY -->

<div class="gf-form">
<label class="gf-form-label query-keyword width-8">ORDER BY</label>
<div class="gf-form-select-wrapper">
<select class="gf-form-input gf-size-auto" ng-model="ctrl.target.orderByCol" ng-options="f.value as f.text for f in ctrl.orderByCols"
ng-change="ctrl.refresh()"></select>
</div>
<div class="gf-form-select-wrapper">
<select class="gf-form-input gf-size-auto" ng-model="ctrl.target.orderBySort" ng-options="f.value as f.text for f in ctrl.orderBySorts"
ng-change="ctrl.refresh()"></select>
</div>
<div class="gf-form gf-form--grow">
<div class="gf-form-label gf-form-label--grow"></div>
</div>
</div>
<!-- End Order BY. -->

<div class="gf-form-inline">
<div class="gf-form">
<label class="gf-form-label query-keyword">Format as</label>
Expand Down
11 changes: 9 additions & 2 deletions src/bigquery_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export default class BigQueryQuery {
this.tmpValue = "";

target.format = target.format || "time_series";
target.orderByCol = target.orderByCol || "1";
target.orderBySort = target.orderBySort || "1";
target.timeColumn = target.timeColumn || "-- time --";
target.timeColumnType = target.timeColumnType || "TIMESTAMP";
target.metricColumn = target.metricColumn || "none";
Expand Down Expand Up @@ -477,9 +479,14 @@ export default class BigQueryQuery {
query += this.buildWhereClause();
query += this.buildGroupClause();
if (!this.isWindow) {
query += "\nORDER BY 1";
let orderBy = "\nORDER BY 1";
if (this.hasMetricColumn()) {
query += ",2";
orderBy =
this.target.orderByCol === "1" ? "\nORDER BY 1,2" : "\nORDER BY 2,1";
}
query += orderBy;
if (this.target.orderBySort === "2") {
query += " DESC";
}
}
// query += '\nLIMIT 2';
Expand Down
18 changes: 18 additions & 0 deletions src/partials/query.editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@
</div>
</div>

<!-- Start Order BY -->

<div class="gf-form">
<label class="gf-form-label query-keyword width-8">ORDER BY</label>
<div class="gf-form-select-wrapper">
<select class="gf-form-input gf-size-auto" ng-model="ctrl.target.orderByCol" ng-options="f.value as f.text for f in ctrl.orderByCols"
ng-change="ctrl.refresh()"></select>
</div>
<div class="gf-form-select-wrapper">
<select class="gf-form-input gf-size-auto" ng-model="ctrl.target.orderBySort" ng-options="f.value as f.text for f in ctrl.orderBySorts"
ng-change="ctrl.refresh()"></select>
</div>
<div class="gf-form gf-form--grow">
<div class="gf-form-label gf-form-label--grow"></div>
</div>
</div>
<!-- End Order BY. -->

<div class="gf-form-inline">
<div class="gf-form">
<label class="gf-form-label query-keyword">Format as</label>
Expand Down
12 changes: 12 additions & 0 deletions src/query_ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ WHERE
export class BigQueryQueryCtrl extends QueryCtrl {
public static templateUrl = "partials/query.editor.html";
public formats: any[];
public orderByCols: any[];
public orderBySorts: any[];
public queryModel: BigQueryQuery;
public lastQueryMeta: QueryMeta;
public lastQueryError: string;
Expand All @@ -36,6 +38,7 @@ export class BigQueryQueryCtrl extends QueryCtrl {
public selectParts: SqlPart[][];
public groupParts: SqlPart[];
public whereParts: SqlPart[];
public orderParts: SqlPart[];
public groupAdd: any;

/** @ngInject */
Expand All @@ -57,6 +60,15 @@ export class BigQueryQueryCtrl extends QueryCtrl {
{ text: "Time series", value: "time_series" },
{ text: "Table", value: "table" }
];
this.orderByCols = [
{ text: "Time", value: "1" },
{ text: "Metric", value: "2" }
];
this.orderBySorts = [
{ text: "ASC", value: "1" },
{ text: "DESC", value: "2" }
];

if (!this.target.rawSql) {
// special handling when in table panel
if (this.panelCtrl.panel.type === "table") {
Expand Down

0 comments on commit 37b0d36

Please sign in to comment.