From 3e24a87eada4e35d9a9a196dc5452486cb8d8afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sun, 25 May 2014 21:03:53 +0200 Subject: [PATCH] trying to get this PR working. a lot has changed and is broken --- src/app/controllers/dash.js | 10 +- src/app/panels/filtering/module.js | 25 ++-- src/app/services/filterSrv.js | 191 +++++++++++++++-------------- 3 files changed, 114 insertions(+), 112 deletions(-) diff --git a/src/app/controllers/dash.js b/src/app/controllers/dash.js index 71222c1b7c7..4dd63be440b 100644 --- a/src/app/controllers/dash.js +++ b/src/app/controllers/dash.js @@ -52,21 +52,23 @@ function (angular, $, config, _) { $scope.init = function() { $scope.config = config; + // Make stuff, including underscore.js available to views $scope._ = _; $scope.dashboard = dashboard; $scope.dashAlerts = alertSrv; $scope.filter = filterSrv; - $scope.filter.init( dashboard.current ); + $scope.filter.init(dashboard.current); $scope.$watch('dashboard.current', function(newValue) { - $scope.filter.init( newValue ); + $scope.filter.init(newValue); }); $scope.$watch('filter.time', function() { - $scope.dashboard.refresh(); + $scope.dashboard.refresh(); }, true); + // Clear existing alerts 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); }; diff --git a/src/app/panels/filtering/module.js b/src/app/panels/filtering/module.js index 5a8c49e0cff..4630608d9af 100644 --- a/src/app/panels/filtering/module.js +++ b/src/app/panels/filtering/module.js @@ -30,25 +30,25 @@ function (angular, app, _) { // 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 if(!$rootScope.$$phase) { $rootScope.$apply(); } $timeout(function(){ - this.dashboard.refresh(); + $scope.dashboard.refresh(); },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) { - _.each(this.filter.templateParameters, function( templateParameter ) { + _.each($scope.filter.templateParameters, function(templateParameter) { if (templateParameter === updatedFilter) { return; } @@ -59,9 +59,8 @@ function (angular, app, _) { }; $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) { filter.editing=undefined; filter.options = _.map(results, function(node) { @@ -77,12 +76,12 @@ function (angular, app, _) { filter.options.unshift({text: 'All', value: allExpr}); } - this.filter.templateOptionSelected(filter, filter.options[0]); + $scope.filter.templateOptionSelected(filter, filter.options[0]); }); }; $scope.add = function() { - this.filter.addTemplateParameter({ + $scope.filter.addTemplateParameter({ type : 'filter', name : 'filter name', editing : true, @@ -91,7 +90,7 @@ function (angular, app, _) { }; $scope.refresh = function() { - this.dashboard.refresh(); + $scope.dashboard.refresh(); }; $scope.render = function() { diff --git a/src/app/services/filterSrv.js b/src/app/services/filterSrv.js index 4273535d9bd..1734578c012 100644 --- a/src/app/services/filterSrv.js +++ b/src/app/services/filterSrv.js @@ -9,103 +9,104 @@ define([ var module = angular.module('kibana.services'); 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 }; + } } - }; - return result; + 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(); + 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; }); });