Browse Source

make suggested filter macro depend on type

Sven Klemm 7 years ago
parent
commit
9699d7a166

+ 5 - 1
public/app/plugins/datasource/postgres/postgres_query.ts

@@ -96,6 +96,10 @@ export default class PostgresQuery {
     }
     }
   }
   }
 
 
+  hasUnixEpochTimecolumn() {
+    return ['int4', 'int8', 'float4', 'float8', 'numeric'].indexOf(this.target.timeColumnType) > -1;
+  }
+
   buildTimeColumn(alias = true) {
   buildTimeColumn(alias = true) {
     let timeGroup = this.hasTimeGroup();
     let timeGroup = this.hasTimeGroup();
     let query;
     let query;
@@ -108,7 +112,7 @@ export default class PostgresQuery {
       } else {
       } else {
         args = timeGroup.params[0];
         args = timeGroup.params[0];
       }
       }
-      if (['int4', 'int8', 'float4', 'float8', 'numeric'].indexOf(this.target.timeColumnType) > -1) {
+      if (this.hasUnixEpochTimecolumn()) {
         macro = '$__unixEpochGroup';
         macro = '$__unixEpochGroup';
       }
       }
       if (alias) {
       if (alias) {

+ 5 - 2
public/app/plugins/datasource/postgres/query_ctrl.ts

@@ -523,8 +523,11 @@ export class PostgresQueryCtrl extends QueryCtrl {
 
 
   getWhereOptions() {
   getWhereOptions() {
     var options = [];
     var options = [];
-    options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__timeFilter' }));
-    // options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__unixEpochFilter' }));
+    if (this.queryModel.hasUnixEpochTimecolumn()) {
+      options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__unixEpochFilter' }));
+    } else {
+      options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__timeFilter' }));
+    }
     options.push(this.uiSegmentSrv.newSegment({ type: 'expression', value: 'Expression' }));
     options.push(this.uiSegmentSrv.newSegment({ type: 'expression', value: 'Expression' }));
     return this.$q.when(options);
     return this.$q.when(options);
   }
   }