Browse Source

trying to get this PR working. a lot has changed and is broken

Torkel Ödegaard 11 years ago
parent
commit
3e24a87ead
3 changed files with 115 additions and 113 deletions
  1. 6 4
      src/app/controllers/dash.js
  2. 12 13
      src/app/panels/filtering/module.js
  3. 97 96
      src/app/services/filterSrv.js

+ 6 - 4
src/app/controllers/dash.js

@@ -52,21 +52,23 @@ function (angular, $, config, _) {
 
 
     $scope.init = function() {
     $scope.init = function() {
       $scope.config = config;
       $scope.config = config;
+
       // Make stuff, including underscore.js available to views
       // Make stuff, including underscore.js available to views
       $scope._ = _;
       $scope._ = _;
       $scope.dashboard = dashboard;
       $scope.dashboard = dashboard;
       $scope.dashAlerts = alertSrv;
       $scope.dashAlerts = alertSrv;
 
 
       $scope.filter = filterSrv;
       $scope.filter = filterSrv;
-      $scope.filter.init( dashboard.current );
+      $scope.filter.init(dashboard.current);
 
 
       $scope.$watch('dashboard.current', function(newValue) {
       $scope.$watch('dashboard.current', function(newValue) {
-          $scope.filter.init( newValue );
+        $scope.filter.init(newValue);
       });
       });
 
 
       $scope.$watch('filter.time', function() {
       $scope.$watch('filter.time', function() {
-          $scope.dashboard.refresh();
+        $scope.dashboard.refresh();
       }, true);
       }, true);
+
       // Clear existing alerts
       // Clear existing alerts
       alertSrv.clearAll();
       alertSrv.clearAll();
 
 
@@ -87,7 +89,7 @@ function (angular, $, config, _) {
       }
       }
     };
     };
 
 
-    $scope.add_row = function(dash,row) {
+    $scope.add_row = function(dash, row) {
       dash.rows.push(row);
       dash.rows.push(row);
     };
     };
 
 

+ 12 - 13
src/app/panels/filtering/module.js

@@ -30,25 +30,25 @@ function (angular, app, _) {
         // empty. Don't know if I need the function then.
         // empty. Don't know if I need the function then.
     };
     };
 
 
-    $scope.remove = function( templateParameter ) {
-        this.filter.removeTemplateParameter( templateParameter );
-        
+    $scope.remove = function(templateParameter) {
+        $scope.filter.removeTemplateParameter(templateParameter);
+
         // TODO hkraemer: check if this makes sense like this
         // TODO hkraemer: check if this makes sense like this
         if(!$rootScope.$$phase) {
         if(!$rootScope.$$phase) {
             $rootScope.$apply();
             $rootScope.$apply();
         }
         }
         $timeout(function(){
         $timeout(function(){
-            this.dashboard.refresh();
+            $scope.dashboard.refresh();
         },0);
         },0);
     };
     };
 
 
-    $scope.filterOptionSelected = function( templateParameter, option ) {
-      this.filter.templateOptionSelected(option);
-      this.applyFilterToOtherFilters(templateParameter);
+    $scope.filterOptionSelected = function(templateParameter, option) {
+      $scope.filter.templateOptionSelected(templateParameter, option);
+      $scope.applyFilterToOtherFilters(templateParameter);
     };
     };
 
 
     $scope.applyFilterToOtherFilters = function(updatedFilter) {
     $scope.applyFilterToOtherFilters = function(updatedFilter) {
-      _.each(this.filter.templateParameters, function( templateParameter ) {
+      _.each($scope.filter.templateParameters, function(templateParameter) {
         if (templateParameter === updatedFilter) {
         if (templateParameter === updatedFilter) {
           return;
           return;
         }
         }
@@ -59,9 +59,8 @@ function (angular, app, _) {
     };
     };
 
 
     $scope.applyFilter = function(filter) {
     $scope.applyFilter = function(filter) {
-      var query = this.filter.applyTemplateToTarget(filter.query);
 
 
-      datasourceSrv.default.metricFindQuery($scope, query)
+      datasourceSrv.default.metricFindQuery($scope.filter, filter.query)
         .then(function (results) {
         .then(function (results) {
           filter.editing=undefined;
           filter.editing=undefined;
           filter.options = _.map(results, function(node) {
           filter.options = _.map(results, function(node) {
@@ -77,12 +76,12 @@ function (angular, app, _) {
             filter.options.unshift({text: 'All', value: allExpr});
             filter.options.unshift({text: 'All', value: allExpr});
           }
           }
 
 
-          this.filter.templateOptionSelected(filter, filter.options[0]);
+          $scope.filter.templateOptionSelected(filter, filter.options[0]);
         });
         });
     };
     };
 
 
     $scope.add = function() {
     $scope.add = function() {
-      this.filter.addTemplateParameter({
+      $scope.filter.addTemplateParameter({
         type      : 'filter',
         type      : 'filter',
         name      : 'filter name',
         name      : 'filter name',
         editing   : true,
         editing   : true,
@@ -91,7 +90,7 @@ function (angular, app, _) {
     };
     };
 
 
     $scope.refresh = function() {
     $scope.refresh = function() {
-      this.dashboard.refresh();
+      $scope.dashboard.refresh();
     };
     };
 
 
     $scope.render = function() {
     $scope.render = function() {

+ 97 - 96
src/app/services/filterSrv.js

@@ -9,103 +9,104 @@ define([
   var module = angular.module('kibana.services');
   var module = angular.module('kibana.services');
 
 
   module.factory('filterSrv', function(dashboard, $rootScope, $timeout, $routeParams) {
   module.factory('filterSrv', function(dashboard, $rootScope, $timeout, $routeParams) {
-    // defaults
-    var _d = {
-      templateParameters: [],
-      time: {}
-    };
-
-    var result = {
-        _updateTemplateData : function(initial) {
-            var _templateData = {};
-            _.each(this.templateParameters, function( templateParameter ) {
-                if (initial) {
-                    var urlValue = $routeParams[ templateParameter.name ];
-                    if (urlValue) {
-                        templateParameter.current = { text: urlValue, value: urlValue };
-                    }
-                }
-                if (!templateParameter.current || !templateParameter.current.value) {
-                    return;
-                }
-
-                _templateData[templateParameter.name] = templateParameter.current.value;
-            });
-            this._templateData = _templateData;
-        },
-
-        templateOptionSelected : function(templateParameter, option) {
-            templateParameter.current = option;
-            this._updateTemplateData();
-        },
-
-        addTemplateParameter : function( templateParameter ) {
-            this.templateParameters.push( templateParameter );
-            this._updateTemplateData();
-        },
-
-        applyTemplateToTarget : function(target) {
-            if (target.indexOf('[[') === -1) {
-                return target;
-            }
-
-            return _.template(target, this._templateData, this.templateSettings);
-        },
-
-        setTime : function(time) {
-            _.extend(this.time, time);
-            // disable refresh if we have an absolute time
-            if (time.to !== 'now') {
-                this.old_refresh = this.dashboard.refresh;
-                dashboard.set_interval(false);
-                return;
-            }
-
-            if (this.old_refresh && this.old_refresh !== this.dashboard.refresh) {
-                dashboard.set_interval(this.old_refresh);
-                this.old_refresh = null;
-            }
-        },
-
-        timeRange : function(parse) {
-            var _t = this.time;
-            if(_.isUndefined(_t) || _.isUndefined(_t.from)) {
-                return false;
-            }
-            if(parse === false) {
-                return {
-                    from: _t.from,
-                    to: _t.to
-                };
-            } else {
-                var _from = _t.from;
-                var _to = _t.to || new Date();
-
-                return {
-                    from : kbn.parseDate(_from),
-                    to : kbn.parseDate(_to)
-                };
-            }
-        },
-
-        removeTemplateParameter : function( templateParameter ) {
-            this.templateParameters = _.without( this.templateParameters, templateParameter );
-        },
-
-        init: function(dashboard) {
-            _.defaults(this, _d);
-            this.dashboard = dashboard;
-            this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g };
-
-            if(dashboard.services && dashboard.services.filter) {
-                this.time = dashboard.services.filter.time;
-                this.templateParameters = dashboard.services.filter.list || [];
-                this._updateTemplateData(true);
-            }
-
+  // defaults
+  var _d = {
+    templateParameters: [],
+    time: {}
+  };
+
+  var result = {
+    _updateTemplateData: function(initial) {
+      var _templateData = {};
+      _.each(this.templateParameters, function( templateParameter ) {
+        if (initial) {
+          var urlValue = $routeParams[ templateParameter.name ];
+          if (urlValue) {
+            templateParameter.current = { text: urlValue, value: urlValue };
+          }
+        }
+        if (!templateParameter.current || !templateParameter.current.value) {
+          return;
         }
         }
-    };
-    return result;
+
+        _templateData[templateParameter.name] = templateParameter.current.value;
+      });
+      this._templateData = _templateData;
+    },
+
+    templateOptionSelected: function(templateParameter, option) {
+      templateParameter.current = option;
+      this._updateTemplateData();
+      dashboard.refresh();
+    },
+
+    addTemplateParameter: function( templateParameter ) {
+      this.templateParameters.push( templateParameter );
+      this._updateTemplateData();
+    },
+
+    applyTemplateToTarget: function(target) {
+      if (target.indexOf('[[') === -1) {
+        return target;
+      }
+
+      return _.template(target, this._templateData, this.templateSettings);
+    },
+
+    setTime: function(time) {
+      _.extend(this.time, time);
+      // disable refresh if we have an absolute time
+      if (time.to !== 'now') {
+        this.old_refresh = this.dashboard.refresh;
+        dashboard.set_interval(false);
+        return;
+      }
+
+      if (this.old_refresh && this.old_refresh !== this.dashboard.refresh) {
+        dashboard.set_interval(this.old_refresh);
+        this.old_refresh = null;
+      }
+    },
+
+    timeRange: function(parse) {
+      var _t = this.time;
+      if(_.isUndefined(_t) || _.isUndefined(_t.from)) {
+        return false;
+      }
+      if(parse === false) {
+        return {
+          from: _t.from,
+          to: _t.to
+        };
+      } else {
+        var _from = _t.from;
+        var _to = _t.to || new Date();
+
+        return {
+          from : kbn.parseDate(_from),
+          to : kbn.parseDate(_to)
+        };
+      }
+    },
+
+    removeTemplateParameter: function(templateParameter) {
+      this.templateParameters = _.without( this.templateParameters, templateParameter );
+    },
+
+    init: function(dashboard) {
+      _.defaults(this, _d);
+      this.dashboard = dashboard;
+      this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g };
+
+      if(dashboard.services && dashboard.services.filter) {
+        this.time = dashboard.services.filter.time;
+        this.templateParameters = dashboard.services.filter.list || [];
+        this._updateTemplateData(true);
+      }
+
+    }
+  };
+  return result;
   });
   });
 
 
 });
 });