From 637c720de5bf7a59263abd3d5b7ea820af313260 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Wed, 30 Apr 2014 09:40:06 +0200 Subject: [PATCH 01/20] Modified metricKeys to handle multiple graphite sources. This wasn't all too hard to change, I mostly changed the single http get to multiple http gets, one for each data source of type graphite. It's still not a good idea to call this on the web frontend, since the whole thing was working for about 20 - 30 minutes when I clicked it, so I'm not committing my changes to settings.js or the view itself. --- src/app/controllers/metricKeys.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/app/controllers/metricKeys.js b/src/app/controllers/metricKeys.js index e39d2b43c18..333be68baef 100644 --- a/src/app/controllers/metricKeys.js +++ b/src/app/controllers/metricKeys.js @@ -52,14 +52,16 @@ function (angular, _, config) { $scope.loadAll = function() { $scope.infoText = "Fetching all metrics from graphite..."; - return $http.get(config.graphiteUrl + "/metrics/index.json") - .then(saveMetricsArray) - .then(function () { + return $q.all( _.map( config.datasources, function( datasource ) { + if ( datasource.type = 'graphite' ) { + return $http.get( datasource.url + "/metrics/index.json" ) + .then( saveMetricsArray ); + } + } ) ).then( function() { $scope.infoText = "Indexing complete!"; - }) - .then(null, function(err) { + }).then(null, function(err) { $scope.errorText = err; - }); + }); }; function saveMetricsArray(data, currentIndex) @@ -155,6 +157,7 @@ function (angular, _, config) { function saveMetricKey(metricId) { // Create request with id as title. Rethink this. + console.log( config.grafana_metrics_index, metricId ); var request = $scope.ejs.Document(config.grafana_metrics_index, 'metricKey', metricId).source({ metricPath: metricId }); @@ -177,4 +180,4 @@ function (angular, _, config) { }); -}); \ No newline at end of file +}); From 52e1f5273ceef5b4fee262e90763606eb9c79c64 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Wed, 30 Apr 2014 13:13:51 +0200 Subject: [PATCH 02/20] Extracted multi-graphite query function, fixed loadRecursive The new function in metricKeys generalizes what my loadAll from the previous commit did, it takes a request and a callback. The request is executed on each graphite installation and the callback is executed for each result. This makes implementing loadAll and loadRecursive almost as simple as it was. --- src/app/controllers/metricKeys.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/app/controllers/metricKeys.js b/src/app/controllers/metricKeys.js index 333be68baef..fa39bfd4ad3 100644 --- a/src/app/controllers/metricKeys.js +++ b/src/app/controllers/metricKeys.js @@ -52,18 +52,23 @@ function (angular, _, config) { $scope.loadAll = function() { $scope.infoText = "Fetching all metrics from graphite..."; - return $q.all( _.map( config.datasources, function( datasource ) { - if ( datasource.type = 'graphite' ) { - return $http.get( datasource.url + "/metrics/index.json" ) - .then( saveMetricsArray ); - } - } ) ).then( function() { + getFromEachGraphite( '/metrics/index.json', saveMetricsArray ) + .then( function() { $scope.infoText = "Indexing complete!"; - }).then(null, function(err) { + }).then(null, function(err) { $scope.errorText = err; - }); + }); }; + function getFromEachGraphite( request, data_callback, error_callback ) { + return $q.all( _.map( config.datasources, function( datasource ) { + if ( datasource.type = 'graphite' ) { + return $http.get( datasource.url + request ) + .then( data_callback, error_callback ); + } + } ) ); + } + function saveMetricsArray(data, currentIndex) { if (!data && !data.data && data.data.length === 0) { @@ -82,6 +87,7 @@ function (angular, _, config) { }); } + function deleteIndex() { var deferred = $q.defer(); @@ -157,7 +163,6 @@ function (angular, _, config) { function saveMetricKey(metricId) { // Create request with id as title. Rethink this. - console.log( config.grafana_metrics_index, metricId ); var request = $scope.ejs.Document(config.grafana_metrics_index, 'metricKey', metricId).source({ metricPath: metricId }); @@ -175,7 +180,7 @@ function (angular, _, config) { function loadMetricsRecursive(metricPath) { - return $http.get(config.graphiteUrl + '/metrics/find/?query=' + metricPath).then(receiveMetric); + return getFromEachGraphite( '/metrics/find/?query=' + metricPath, receiveMetric ); } }); From 4a362704fd7386ea4d8b74625fd9699e01c6976c Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Thu, 15 May 2014 15:04:23 +0200 Subject: [PATCH 03/20] Moved dashboard keybinding setup to own service. The goal is to split up the situation between the dashboard controller and the current dashboard service. I want to be able to use the routing in order to select various dashboard controllers, so I can extend the current scripting mechanism by implementing new dashboard controllers. However, to do this in a non-insane way, I need to move as much functionality as possible into services, so the individual controllers just need to throw the right set of services together and add a bit of loading logic. --- src/app/app.js | 2 +- src/app/controllers/dash.js | 70 ++----------------- src/app/services/dashboard/all.js | 4 ++ .../dashboard/dashboardKeyBindings.js | 59 ++++++++++++++++ 4 files changed, 69 insertions(+), 66 deletions(-) create mode 100644 src/app/services/dashboard/all.js create mode 100644 src/app/services/dashboard/dashboardKeyBindings.js diff --git a/src/app/app.js b/src/app/app.js index c3c46dbdde0..1508f16e013 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -98,7 +98,7 @@ function (angular, $, _, appLevelRequire) { 'pasvaz.bindonce' ]; - _.each('controllers directives factories services filters'.split(' '), + _.each('controllers directives factories services services.dashboard filters'.split(' '), function (type) { var module_name = 'kibana.'+type; // create the module diff --git a/src/app/controllers/dash.js b/src/app/controllers/dash.js index 98f5df2983e..1038378b1b3 100644 --- a/src/app/controllers/dash.js +++ b/src/app/controllers/dash.js @@ -22,7 +22,8 @@ define([ 'jquery', 'config', 'underscore', - 'services/all' + 'services/all', + 'services/dashboard/all' ], function (angular, $, config, _) { "use strict"; @@ -30,7 +31,7 @@ function (angular, $, config, _) { var module = angular.module('kibana.controllers'); module.controller('DashCtrl', function( - $scope, $rootScope, ejsResource, dashboard, + $scope, $rootScope, ejsResource, dashboard, dashboardKeybindings, alertSrv, panelMove, keyboardManager, grafanaVersion) { $scope.requiredElasticSearchVersion = ">=0.90.3"; @@ -66,68 +67,7 @@ function (angular, $, config, _) { $scope.bindKeyboardShortcuts(); }; - $scope.bindKeyboardShortcuts = function() { - $rootScope.$on('panel-fullscreen-enter', function() { - $rootScope.fullscreen = true; - }); - - $rootScope.$on('panel-fullscreen-exit', function() { - $rootScope.fullscreen = false; - }); - - $rootScope.$on('dashboard-saved', function() { - if ($rootScope.fullscreen) { - $rootScope.$emit('panel-fullscreen-exit'); - } - }); - - keyboardManager.bind('ctrl+f', function(evt) { - $rootScope.$emit('open-search', evt); - }, { inputDisabled: true }); - - keyboardManager.bind('ctrl+h', function() { - var current = dashboard.current.hideControls; - dashboard.current.hideControls = !current; - dashboard.current.panel_hints = current; - }, { inputDisabled: true }); - - keyboardManager.bind('ctrl+s', function(evt) { - $rootScope.$emit('save-dashboard', evt); - }, { inputDisabled: true }); - - keyboardManager.bind('ctrl+r', function() { - dashboard.refresh(); - }, { inputDisabled: true }); - - keyboardManager.bind('ctrl+z', function(evt) { - $rootScope.$emit('zoom-out', evt); - }, { inputDisabled: true }); - - keyboardManager.bind('esc', function() { - var popups = $('.popover.in'); - if (popups.length > 0) { - return; - } - $rootScope.$emit('panel-fullscreen-exit'); - }, { inputDisabled: true }); - }; - - $scope.countWatchers = function (scopeStart) { - var q = [scopeStart || $rootScope], watchers = 0, scope; - while (q.length > 0) { - scope = q.pop(); - if (scope.$$watchers) { - watchers += scope.$$watchers.length; - } - if (scope.$$childHead) { - q.push(scope.$$childHead); - } - if (scope.$$nextSibling) { - q.push(scope.$$nextSibling); - } - } - window.console.log(watchers); - }; + $scope.bindKeyboardShortcuts = dashboardKeybindings.shortcuts $scope.isPanel = function(obj) { if(!_.isNull(obj) && !_.isUndefined(obj) && !_.isUndefined(obj.type)) { @@ -196,4 +136,4 @@ function (angular, $, config, _) { $scope.init(); }); -}); \ No newline at end of file +}); diff --git a/src/app/services/dashboard/all.js b/src/app/services/dashboard/all.js new file mode 100644 index 00000000000..f861edb5a8d --- /dev/null +++ b/src/app/services/dashboard/all.js @@ -0,0 +1,4 @@ +define([ + './dashboardKeyBindings', +], +function () {}); diff --git a/src/app/services/dashboard/dashboardKeyBindings.js b/src/app/services/dashboard/dashboardKeyBindings.js new file mode 100644 index 00000000000..d3127a10420 --- /dev/null +++ b/src/app/services/dashboard/dashboardKeyBindings.js @@ -0,0 +1,59 @@ +define([ + 'angular', + 'jquery', + 'underscore', + 'services/all' +], +function( angular, $, _ ) { + "use strict"; + + var module = angular.module('kibana.services.dashboard'); + + module.service( 'dashboardKeybindings', function($rootScope, keyboardManager, dashboard) { + this.shortcuts = function() { + $rootScope.$on('panel-fullscreen-enter', function() { + $rootScope.fullscreen = true; + }); + + $rootScope.$on('panel-fullscreen-exit', function() { + $rootScope.fullscreen = false; + }); + + $rootScope.$on('dashboard-saved', function() { + if ($rootScope.fullscreen) { + $rootScope.$emit('panel-fullscreen-exit'); + } + }); + + keyboardManager.bind('ctrl+f', function(evt) { + $rootScope.$emit('open-search', evt); + }, { inputDisabled: true }); + + keyboardManager.bind('ctrl+h', function() { + var current = dashboard.current.hideControls; + dashboard.current.hideControls = !current; + dashboard.current.panel_hints = current; + }, { inputDisabled: true }); + + keyboardManager.bind('ctrl+s', function(evt) { + $rootScope.$emit('save-dashboard', evt); + }, { inputDisabled: true }); + + keyboardManager.bind('ctrl+r', function() { + dashboard.refresh(); + }, { inputDisabled: true }); + + keyboardManager.bind('ctrl+z', function(evt) { + $rootScope.$emit('zoom-out', evt); + }, { inputDisabled: true }); + + keyboardManager.bind('esc', function() { + var popups = $('.popover.in'); + if (popups.length > 0) { + return; + } + $rootScope.$emit('panel-fullscreen-exit'); + }, { inputDisabled: true }); + }; + }); +}); From f70bf61ff6ed24006c4272c16db6a91f37d8a552 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Thu, 15 May 2014 15:07:03 +0200 Subject: [PATCH 04/20] Added vim swp files to gitignore --- .gitignore | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 701b6bbbc11..5ecb68eb64e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,11 @@ node_modules .aws-config.json dist + +# locally required config files web.config config.js -*.sublime-workspace \ No newline at end of file + +# Editor junk +*.sublime-workspace +*.swp From 03095dfa7493340876cb05bfa5819f4c78869bfa Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Mon, 19 May 2014 15:31:30 +0200 Subject: [PATCH 05/20] Changed filterSrv singleton into object in scope. This rework isn't entirely complete here, I haven't checked the tests yet and I didn't really test anything furthermore yet, so bear with this commit breaking things. Besides that, the goal of this commit was to rework the filterSrv singleton into a factory, so we move the filterSrv instance around via the scope. This should be a better solution than the current situation, because services shouldn't contain model data - the scope should. This will eventually straighten out control flow between dashboard, filters and so on, and allow us to leverage angularJS mechanics more. The latter has already started, since I could rework a bit of the existing event infrastructure to watches on times. --- src/app/controllers/dash.js | 15 +- src/app/controllers/dashLoader.js | 6 +- src/app/controllers/graphiteTarget.js | 8 +- src/app/directives/grafanaGraph.js | 11 +- src/app/panels/filtering/module.html | 4 +- src/app/panels/filtering/module.js | 32 +-- src/app/panels/graphite/module.js | 11 +- src/app/panels/timepicker/module.html | 4 +- src/app/panels/timepicker/module.js | 12 +- src/app/services/annotationsSrv.js | 10 +- src/app/services/dashboard.js | 7 - src/app/services/datasourceSrv.js | 4 +- src/app/services/filterSrv.js | 186 ++++++++---------- .../services/graphite/graphiteDatasource.js | 10 +- src/app/services/unsavedChangesSrv.js | 3 +- 15 files changed, 156 insertions(+), 167 deletions(-) diff --git a/src/app/controllers/dash.js b/src/app/controllers/dash.js index 1038378b1b3..e4d6af888da 100644 --- a/src/app/controllers/dash.js +++ b/src/app/controllers/dash.js @@ -31,7 +31,7 @@ function (angular, $, config, _) { var module = angular.module('kibana.controllers'); module.controller('DashCtrl', function( - $scope, $rootScope, ejsResource, dashboard, dashboardKeybindings, + $scope, $rootScope, $timeout, ejsResource, dashboard, filterSrv, dashboardKeybindings, alertSrv, panelMove, keyboardManager, grafanaVersion) { $scope.requiredElasticSearchVersion = ">=0.90.3"; @@ -57,6 +57,19 @@ function (angular, $, config, _) { $scope.dashboard = dashboard; $scope.dashAlerts = alertSrv; + $scope.filter = filterSrv; + console.log( "dash controller -> init -> current dashboard", dashboard.current ); + $scope.filter.init( dashboard.current ); + + $scope.$watch('dashboard.current', function(newValue, oldValue) { + $scope.filter.init( newValue ); + }); + + console.log( "Scope I watch on", $scope ); + $scope.$watch('filter.time', function(newValue, oldValue) { + console.log( "Hai" ); + $scope.dashboard.refresh(); + }, true); // Clear existing alerts alertSrv.clearAll(); diff --git a/src/app/controllers/dashLoader.js b/src/app/controllers/dashLoader.js index 7f9dc9232dd..fe5ed2a9c66 100644 --- a/src/app/controllers/dashLoader.js +++ b/src/app/controllers/dashLoader.js @@ -8,7 +8,7 @@ function (angular, _, moment) { var module = angular.module('kibana.controllers'); - module.controller('dashLoader', function($scope, $rootScope, $http, dashboard, alertSrv, $location, filterSrv, playlistSrv) { + module.controller('dashLoader', function($scope, $rootScope, $http, dashboard, alertSrv, $location, playlistSrv) { $scope.loader = dashboard.current.loader; $scope.init = function() { @@ -131,7 +131,7 @@ function (angular, _, moment) { // function $scope.zoom // factor :: Zoom factor, so 0.5 = cuts timespan in half, 2 doubles timespan $scope.zoom = function(factor) { - var _range = filterSrv.timeRange(); + var _range = this.filter.timeRange(); var _timespan = (_range.to.valueOf() - _range.from.valueOf()); var _center = _range.to.valueOf() - _timespan/2; @@ -145,7 +145,7 @@ function (angular, _, moment) { _to = Date.now(); } - filterSrv.setTime({ + this.filter.setTime({ from:moment.utc(_from).toDate(), to:moment.utc(_to).toDate(), }); diff --git a/src/app/controllers/graphiteTarget.js b/src/app/controllers/graphiteTarget.js index a7224b2ced6..5608df6d178 100644 --- a/src/app/controllers/graphiteTarget.js +++ b/src/app/controllers/graphiteTarget.js @@ -10,7 +10,7 @@ function (angular, _, config, gfunc, Parser) { var module = angular.module('kibana.controllers'); - module.controller('GraphiteTargetCtrl', function($scope, $http, filterSrv) { + module.controller('GraphiteTargetCtrl', function($scope, $http) { $scope.init = function() { parseTarget(); @@ -120,7 +120,7 @@ function (angular, _, config, gfunc, Parser) { } var path = getSegmentPathUpTo(fromIndex + 1); - return $scope.datasource.metricFindQuery(path) + return $scope.datasource.metricFindQuery($scope.filterSrv, path) .then(function(segments) { if (segments.length === 0) { $scope.segments = $scope.segments.splice(0, fromIndex); @@ -157,13 +157,13 @@ function (angular, _, config, gfunc, Parser) { var query = index === 0 ? '*' : getSegmentPathUpTo(index) + '.*'; - return $scope.datasource.metricFindQuery(query) + return $scope.datasource.metricFindQuery($scope.filterSrv, query) .then(function(segments) { _.each(segments, function(segment) { segment.html = segment.val = segment.text; }); - _.each(filterSrv.list, function(filter) { + _.each($scope.filter.list, function(filter) { segments.unshift({ type: 'template', html: '[[' + filter.name + ']]', diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index d5a44598ad0..883b8ab7655 100644 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -10,7 +10,7 @@ function (angular, $, kbn, moment, _) { var module = angular.module('kibana.directives'); - module.directive('grafanaGraph', function(filterSrv, $rootScope, dashboard) { + module.directive('grafanaGraph', function($rootScope, dashboard) { return { restrict: 'A', template: '
', @@ -387,9 +387,12 @@ function (angular, $, kbn, moment, _) { } elem.bind("plotselected", function (event, ranges) { - filterSrv.setTime({ - from : moment.utc(ranges.xaxis.from).toDate(), - to : moment.utc(ranges.xaxis.to).toDate(), + scope.$apply( function() { + console.log( "Scope I call filter.setTime on", scope ); + scope.filter.setTime({ + from : moment.utc(ranges.xaxis.from).toDate(), + to : moment.utc(ranges.xaxis.to).toDate(), + }); }); }); } diff --git a/src/app/panels/filtering/module.html b/src/app/panels/filtering/module.html index a360161aa83..950390b8107 100644 --- a/src/app/panels/filtering/module.html +++ b/src/app/panels/filtering/module.html @@ -2,7 +2,7 @@
-
+
@@ -47,4 +47,4 @@
-
\ No newline at end of file +
diff --git a/src/app/panels/filtering/module.js b/src/app/panels/filtering/module.js index c7c475fbd60..c4353202d17 100644 --- a/src/app/panels/filtering/module.js +++ b/src/app/panels/filtering/module.js @@ -14,7 +14,7 @@ function (angular, app, _) { var module = angular.module('kibana.panels.filtering', []); app.useModule(module); - module.controller('filtering', function($scope, filterSrv, datasourceSrv, $rootScope, dashboard) { + module.controller('filtering', function($scope, datasourceSrv, $rootScope, $timeout, dashboard) { $scope.panelMeta = { status : "Stable", @@ -28,19 +28,29 @@ function (angular, app, _) { $scope.init = function() { $scope.filterSrv = filterSrv; + console.log( "Filtering panel " + $scope.dashboard ); + $scope.filterSrv.init( $scope.dashboard ); }; $scope.remove = function(filter) { - filterSrv.remove(filter); + this.filter.removeFilter(filter); + + // TODO hkraemer: check if this makes sense like this + if(!$rootScope.$$phase) { + $rootScope.$apply(); + } + $timeout(function(){ + this.dashboard.refresh(); + },0); }; $scope.filterOptionSelected = function(filter, option) { - filterSrv.filterOptionSelected(filter, option); - $scope.applyFilterToOtherFilters(filter); + this.filter.filterOptionSelected(option); + this.applyFilterToOtherFilters(filter); }; $scope.applyFilterToOtherFilters = function(updatedFilter) { - _.each(filterSrv.list, function(filter) { + _.each(this.filter.list, function(filter) { if (filter === updatedFilter) { return; } @@ -51,9 +61,9 @@ function (angular, app, _) { }; $scope.applyFilter = function(filter) { - var query = filterSrv.applyFilterToTarget(filter.query); + var query = this.filter.applyFilterToTarget(filter.query); - datasourceSrv.default.metricFindQuery(query) + datasourceSrv.default.metricFindQuery($scope, query) .then(function (results) { filter.editing=undefined; filter.options = _.map(results, function(node) { @@ -69,12 +79,12 @@ function (angular, app, _) { filter.options.unshift({text: 'All', value: allExpr}); } - filterSrv.filterOptionSelected(filter, filter.options[0]); + this.filterSrv.filterOptionSelected(filter, filter.options[0]); }); }; $scope.add = function() { - filterSrv.add({ + this.filter.add({ type : 'filter', name : 'filter name', editing : true, @@ -83,7 +93,7 @@ function (angular, app, _) { }; $scope.refresh = function() { - dashboard.refresh(); + this.dashboard.refresh(); }; $scope.render = function() { @@ -91,4 +101,4 @@ function (angular, app, _) { }; }); -}); \ No newline at end of file +}); diff --git a/src/app/panels/graphite/module.js b/src/app/panels/graphite/module.js index 270be72e2b6..3a35fe9be69 100644 --- a/src/app/panels/graphite/module.js +++ b/src/app/panels/graphite/module.js @@ -19,7 +19,6 @@ define([ 'kbn', 'moment', './timeSeries', - 'services/filterSrv', 'services/annotationsSrv', 'services/datasourceSrv', 'jquery.flot', @@ -37,7 +36,7 @@ function (angular, app, $, _, kbn, moment, timeSeries) { var module = angular.module('kibana.panels.graphite', []); app.useModule(module); - module.controller('graphite', function($scope, $rootScope, filterSrv, datasourceSrv, $timeout, annotationsSrv) { + module.controller('graphite', function($scope, $rootScope, datasourceSrv, $timeout, annotationsSrv) { $scope.panelMeta = { modals : [], @@ -231,8 +230,8 @@ function (angular, app, $, _, kbn, moment, timeSeries) { }; $scope.updateTimeRange = function () { - $scope.range = filterSrv.timeRange(); - $scope.rangeUnparsed = filterSrv.timeRange(false); + $scope.range = this.filter.timeRange(); + $scope.rangeUnparsed = this.filter.timeRange(false); $scope.resolution = Math.ceil($(window).width() * ($scope.panel.span / 12)); $scope.interval = '10m'; @@ -259,9 +258,9 @@ function (angular, app, $, _, kbn, moment, timeSeries) { datasource: $scope.panel.datasource }; - $scope.annotationsPromise = annotationsSrv.getAnnotations($scope.rangeUnparsed); + $scope.annotationsPromise = annotationsSrv.getAnnotations($scope.filterSrv, $scope.rangeUnparsed); - return $scope.datasource.query(graphiteQuery) + return $scope.datasource.query($scope.filter, graphiteQuery) .then($scope.dataHandler) .then(null, function(err) { $scope.panelMeta.loading = false; diff --git a/src/app/panels/timepicker/module.html b/src/app/panels/timepicker/module.html index f0975d371ae..ea1759d2141 100644 --- a/src/app/panels/timepicker/module.html +++ b/src/app/panels/timepicker/module.html @@ -17,14 +17,14 @@ - + {{time.from.date | date:'MMM d, y HH:mm:ss'}} {{time.from.date | moment:'ago'}} to {{time.to.date | date:'MMM d, y HH:mm:ss'}} {{time.to.date | moment:'ago'}} - Time filter + Time filter refreshed every {{dashboard.current.refresh}} diff --git a/src/app/panels/timepicker/module.js b/src/app/panels/timepicker/module.js index 198239f6a0d..a16ebc132d5 100644 --- a/src/app/panels/timepicker/module.js +++ b/src/app/panels/timepicker/module.js @@ -25,7 +25,7 @@ function (angular, app, _, moment, kbn) { var module = angular.module('kibana.panels.timepicker', []); app.useModule(module); - module.controller('timepicker', function($scope, $modal, $q, filterSrv) { + module.controller('timepicker', function($scope, $modal, $q) { $scope.panelMeta = { status : "Stable", description : "A panel for controlling the time range filters. If you have time based data, "+ @@ -44,8 +44,6 @@ function (angular, app, _, moment, kbn) { _.defaults($scope.panel,_d); - $scope.filterSrv = filterSrv; - // ng-pattern regexs $scope.patterns = { date: /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/, @@ -58,9 +56,9 @@ function (angular, app, _, moment, kbn) { $scope.$on('refresh', function(){$scope.init();}); $scope.init = function() { - var time = filterSrv.timeRange(); + var time = this.filter.timeRange( true ); if(time) { - $scope.panel.now = filterSrv.timeRange(false).to === "now" ? true : false; + $scope.panel.now = this.filter.timeRange(false).to === "now" ? true : false; $scope.time = getScopeTimeObj(time.from,time.to); } }; @@ -135,7 +133,7 @@ function (angular, app, _, moment, kbn) { } // Set the filter - $scope.panel.filter_id = filterSrv.setTime(_filter); + $scope.panel.filter_id = $scope.filter.setTime(_filter); // Update our representation $scope.time = getScopeTimeObj(time.from,time.to); @@ -149,7 +147,7 @@ function (angular, app, _, moment, kbn) { to: "now" }; - filterSrv.setTime(_filter); + this.filter.setTime(_filter); $scope.time = getScopeTimeObj(kbn.parseDate(_filter.from),new Date()); }; diff --git a/src/app/services/annotationsSrv.js b/src/app/services/annotationsSrv.js index dceb28eea10..459b5ff2816 100644 --- a/src/app/services/annotationsSrv.js +++ b/src/app/services/annotationsSrv.js @@ -28,7 +28,7 @@ define([ list = []; }; - this.getAnnotations = function(rangeUnparsed) { + this.getAnnotations = function(filterSrv, rangeUnparsed) { if (!annotationPanel.enable) { return $q.when(null); } @@ -37,7 +37,7 @@ define([ return promiseCached; } - var graphiteMetrics = this.getGraphiteMetrics(rangeUnparsed); + var graphiteMetrics = this.getGraphiteMetrics(filterSrv, rangeUnparsed); var graphiteEvents = this.getGraphiteEvents(rangeUnparsed); promiseCached = $q.all(graphiteMetrics.concat(graphiteEvents)) @@ -81,7 +81,7 @@ define([ }); }; - this.getGraphiteMetrics = function(rangeUnparsed) { + this.getGraphiteMetrics = function(filterSrv, rangeUnparsed) { var annotations = this.getAnnotationsByType('graphite metric'); if (annotations.length === 0) { return []; @@ -97,7 +97,7 @@ define([ var receiveFunc = _.partial(receiveGraphiteMetrics, annotation); - return datasourceSrv.default.query(graphiteQuery) + return datasourceSrv.default.query(filterSrv, graphiteQuery) .then(receiveFunc) .then(null, errorHandler); }); @@ -154,4 +154,4 @@ define([ this.init(); }); -}); \ No newline at end of file +}); diff --git a/src/app/services/dashboard.js b/src/app/services/dashboard.js index 6c4cfd67e34..4f0ca8cee7c 100644 --- a/src/app/services/dashboard.js +++ b/src/app/services/dashboard.js @@ -54,7 +54,6 @@ function (angular, $, kbn, _, config, moment, Modernizr) { // Store a reference to this var self = this; - var filterSrv; this.current = _.clone(_dash); this.last = {}; @@ -157,10 +156,6 @@ function (angular, $, kbn, _, config, moment, Modernizr) { // Set the current dashboard self.current = angular.copy(dashboard); - - filterSrv = $injector.get('filterSrv'); - filterSrv.init(); - if(dashboard.refresh) { self.set_interval(dashboard.refresh); } @@ -467,8 +462,6 @@ function (angular, $, kbn, _, config, moment, Modernizr) { timer.cancel(self.refresh_timer); } }; - - }); }); diff --git a/src/app/services/datasourceSrv.js b/src/app/services/datasourceSrv.js index 77f0f9f1142..1f6f882ff5a 100644 --- a/src/app/services/datasourceSrv.js +++ b/src/app/services/datasourceSrv.js @@ -10,7 +10,7 @@ function (angular, _, config) { var module = angular.module('kibana.services'); - module.service('datasourceSrv', function($q, filterSrv, $http, GraphiteDatasource, InfluxDatasource) { + module.service('datasourceSrv', function($q, $http, GraphiteDatasource, InfluxDatasource) { this.init = function() { var defaultDatasource = _.findWhere(_.values(config.datasources), { default: true } ); @@ -48,4 +48,4 @@ function (angular, _, config) { this.init(); }); -}); \ No newline at end of file +}); diff --git a/src/app/services/filterSrv.js b/src/app/services/filterSrv.js index 7126a14d5e6..2efd54c4e52 100644 --- a/src/app/services/filterSrv.js +++ b/src/app/services/filterSrv.js @@ -8,125 +8,99 @@ define([ var module = angular.module('kibana.services'); - module.service('filterSrv', function(dashboard, $rootScope, $timeout, $routeParams) { + module.factory('filterSrv', function(dashboard, $rootScope, $timeout, $routeParams) { // defaults var _d = { list: [], time: {} }; - // Save a reference to this - var self = this; + var result = { + _updateTemplateData : function( initial ) { + this._filterTemplateData = {}; + _.each(this.list, function(filter) { + if (initial) { + var urlValue = $routeParams[filter.name]; + if (urlValue) { + filter.current = { text: urlValue, value: urlValue }; + } + } + if (!filter.current || !filter.current.value) { + return; + } - // Call this whenever we need to reload the important stuff - this.init = function() { - dashboard.current.services.filter = dashboard.current.services.filter || {}; + this._filterTemplateData[filter.name] = filter.current.value; + }); + }, - _.defaults(dashboard.current.services.filter, _d); + filterOptionSelected : function(option) { + this.current = option; + this._updateTemplateData(); + }, - self.list = dashboard.current.services.filter.list; - self.time = dashboard.current.services.filter.time; + add : function(filter) { + this.list.push(filter); + }, - self.templateSettings = { - interpolate : /\[\[([\s\S]+?)\]\]/g, - }; + applyFilterToTarget : function(target) { + if (target.indexOf('[[') === -1) { + return target; + } - if (self.list.length) { - this._updateTemplateData(true); - } - }; + return _.template(target, this._filterTemplateData, this.templateSettings); + }, - this._updateTemplateData = function(initial) { - self._filterTemplateData = {}; + 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) + }; + } + }, + + removeFilter : function( filter, dashboard ) { + this.list = _.without(this.list, filter); + }, + init : function( dashboard ) { + _.defaults(this, _d); + this.dashboard = dashboard; + this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g }; + if( dashboard && dashboard.services && dashboard.services.filter ) { + // compatiblity hack + this.time = dashboard.services.filter.time; + } - _.each(self.list, function(filter) { - if (initial) { - var urlValue = $routeParams[filter.name]; - if (urlValue) { - filter.current = { text: urlValue, value: urlValue }; - } } - if (!filter.current || !filter.current.value) { - return; - } - - self._filterTemplateData[filter.name] = filter.current.value; - }); - }; - - this.filterOptionSelected = function(filter, option) { - filter.current = option; - this._updateTemplateData(); - dashboard.refresh(); - }; - - this.add = function(filter) { - self.list.push(filter); - }; - - this.applyFilterToTarget = function(target) { - if (target.indexOf('[[') === -1) { - return target; - } - - return _.template(target, self._filterTemplateData, self.templateSettings); - }; - - this.remove = function(filter) { - self.list = dashboard.current.services.filter.list = _.without(self.list, filter); - - if(!$rootScope.$$phase) { - $rootScope.$apply(); - } - - $timeout(function(){ - dashboard.refresh(); - },0); - }; - - this.setTime = function(time) { - _.extend(self.time, time); - - // disable refresh if we have an absolute time - if (time.to !== 'now') { - self.old_refresh = dashboard.current.refresh; - dashboard.set_interval(false); - } - else if (self.old_refresh && self.old_refresh !== dashboard.current.refresh) { - dashboard.set_interval(self.old_refresh); - self.old_refresh = null; - } - - $timeout(function(){ - dashboard.refresh(); - },0); - }; - - this.timeRange = function(parse) { - var _t = self.time; - - if(_.isUndefined(_t)) { - return false; - } - if(parse === false) { - return { - from: _t.from, - to: _t.to - }; - } else { - var - _from = _t.from, - _to = _t.to || new Date(); - - return { - from : kbn.parseDate(_from), - to : kbn.parseDate(_to) - }; - } - }; - - // Now init - self.init(); + }; + return result; }); -}); \ No newline at end of file +}); diff --git a/src/app/services/graphite/graphiteDatasource.js b/src/app/services/graphite/graphiteDatasource.js index d48fdf7dd12..46f90909f08 100644 --- a/src/app/services/graphite/graphiteDatasource.js +++ b/src/app/services/graphite/graphiteDatasource.js @@ -11,7 +11,7 @@ function (angular, _, $, config, kbn, moment) { var module = angular.module('kibana.services'); - module.factory('GraphiteDatasource', function(dashboard, $q, filterSrv, $http) { + module.factory('GraphiteDatasource', function(dashboard, $q, $http) { function GraphiteDatasource(datasource) { this.type = 'graphite'; @@ -22,7 +22,7 @@ function (angular, _, $, config, kbn, moment) { this.render_method = datasource.render_method || 'POST'; } - GraphiteDatasource.prototype.query = function(options) { + GraphiteDatasource.prototype.query = function(filterSrv, options) { try { var graphOptions = { from: this.translateTime(options.range.from, 'round-down'), @@ -32,7 +32,7 @@ function (angular, _, $, config, kbn, moment) { maxDataPoints: options.maxDataPoints, }; - var params = this.buildGraphiteParams(graphOptions); + var params = this.buildGraphiteParams(filterSrv, graphOptions); if (options.format === 'png') { return $q.when(this.url + '/render' + '?' + params.join('&')); @@ -115,7 +115,7 @@ function (angular, _, $, config, kbn, moment) { return date.format('HH:mm_YYYYMMDD'); }; - GraphiteDatasource.prototype.metricFindQuery = function(query) { + GraphiteDatasource.prototype.metricFindQuery = function(filterSrv, query) { var interpolated; try { interpolated = filterSrv.applyFilterToTarget(query); @@ -158,7 +158,7 @@ function (angular, _, $, config, kbn, moment) { return $http(options); }; - GraphiteDatasource.prototype.buildGraphiteParams = function(options) { + GraphiteDatasource.prototype.buildGraphiteParams = function(filterSrv, options) { var clean_options = []; var graphite_options = ['target', 'targets', 'from', 'until', 'rawData', 'format', 'maxDataPoints']; diff --git a/src/app/services/unsavedChangesSrv.js b/src/app/services/unsavedChangesSrv.js index a0d2a079d34..5d90052b322 100644 --- a/src/app/services/unsavedChangesSrv.js +++ b/src/app/services/unsavedChangesSrv.js @@ -55,7 +55,6 @@ function (angular, _, config) { var original = dashboard.original; // ignore timespan changes - current.services.filter.time = original.services.filter.time = {}; current.refresh = original.refresh; var currentTimepicker = _.findWhere(current.nav, { type: 'timepicker' }); @@ -99,4 +98,4 @@ function (angular, _, config) { }).run(function(unsavedChangesSrv) { unsavedChangesSrv.init(); }); -}); \ No newline at end of file +}); From 63c75f714f043d98e8a8ce7b0bd39f68cfc8a103 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Mon, 19 May 2014 17:00:23 +0200 Subject: [PATCH 06/20] Warnings in dash.js --- src/app/controllers/dash.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/app/controllers/dash.js b/src/app/controllers/dash.js index e4d6af888da..09761d4c53d 100644 --- a/src/app/controllers/dash.js +++ b/src/app/controllers/dash.js @@ -61,13 +61,12 @@ function (angular, $, config, _) { console.log( "dash controller -> init -> current dashboard", dashboard.current ); $scope.filter.init( dashboard.current ); - $scope.$watch('dashboard.current', function(newValue, oldValue) { + $scope.$watch('dashboard.current', function(newValue) { $scope.filter.init( newValue ); }); console.log( "Scope I watch on", $scope ); - $scope.$watch('filter.time', function(newValue, oldValue) { - console.log( "Hai" ); + $scope.$watch('filter.time', function() { $scope.dashboard.refresh(); }, true); // Clear existing alerts @@ -80,7 +79,7 @@ function (angular, $, config, _) { $scope.bindKeyboardShortcuts(); }; - $scope.bindKeyboardShortcuts = dashboardKeybindings.shortcuts + $scope.bindKeyboardShortcuts = dashboardKeybindings.shortcuts; $scope.isPanel = function(obj) { if(!_.isNull(obj) && !_.isUndefined(obj) && !_.isUndefined(obj.type)) { From 2e26130d96a2b42256eaec6aa1c3bb804c74f2c1 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Mon, 19 May 2014 17:02:06 +0200 Subject: [PATCH 07/20] Warnings in graphiteTarget.js --- src/app/controllers/graphiteTarget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/controllers/graphiteTarget.js b/src/app/controllers/graphiteTarget.js index 5608df6d178..e9dc9f3867b 100644 --- a/src/app/controllers/graphiteTarget.js +++ b/src/app/controllers/graphiteTarget.js @@ -10,7 +10,7 @@ function (angular, _, config, gfunc, Parser) { var module = angular.module('kibana.controllers'); - module.controller('GraphiteTargetCtrl', function($scope, $http) { + module.controller('GraphiteTargetCtrl', function($scope) { $scope.init = function() { parseTarget(); From 4b8b961705987b4744111e4379d9f01276c5ef4c Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Mon, 19 May 2014 17:04:59 +0200 Subject: [PATCH 08/20] Warnings in dashboardKeybindings.js --- src/app/services/dashboard/dashboardKeyBindings.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/app/services/dashboard/dashboardKeyBindings.js b/src/app/services/dashboard/dashboardKeyBindings.js index d3127a10420..b399ca5bc5e 100644 --- a/src/app/services/dashboard/dashboardKeyBindings.js +++ b/src/app/services/dashboard/dashboardKeyBindings.js @@ -1,10 +1,9 @@ define([ 'angular', 'jquery', - 'underscore', 'services/all' ], -function( angular, $, _ ) { +function( angular, $ ) { "use strict"; var module = angular.module('kibana.services.dashboard'); From b1c9d5fd4aac0da9040c80c49b5257b7197e0ccf Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Mon, 19 May 2014 17:05:53 +0200 Subject: [PATCH 09/20] Warnings in filterSrv --- src/app/services/filterSrv.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/services/filterSrv.js b/src/app/services/filterSrv.js index 2efd54c4e52..157ca6eadc9 100644 --- a/src/app/services/filterSrv.js +++ b/src/app/services/filterSrv.js @@ -86,7 +86,7 @@ define([ } }, - removeFilter : function( filter, dashboard ) { + removeFilter : function( filter ) { this.list = _.without(this.list, filter); }, init : function( dashboard ) { From d04f2d5e2b36153ecaf5839668eca9e82e9f1243 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Tue, 20 May 2014 09:27:54 +0200 Subject: [PATCH 10/20] Renamed most filter-related things in filterSrv to template. After all, we are using the function "template" to apply some data we pull from the URL or other situations in order to call a function called template. Hence, filtering doesn't make sense as a term here. --- src/app/controllers/graphiteTarget.js | 10 +++---- src/app/panels/filtering/module.js | 30 ++++++++++----------- src/app/panels/graphite/module.js | 2 +- src/app/services/filterSrv.js | 39 ++++++++++++++------------- 4 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/app/controllers/graphiteTarget.js b/src/app/controllers/graphiteTarget.js index e9dc9f3867b..8e9f9799c94 100644 --- a/src/app/controllers/graphiteTarget.js +++ b/src/app/controllers/graphiteTarget.js @@ -120,7 +120,7 @@ function (angular, _, config, gfunc, Parser) { } var path = getSegmentPathUpTo(fromIndex + 1); - return $scope.datasource.metricFindQuery($scope.filterSrv, path) + return $scope.datasource.metricFindQuery($scope.filter, path) .then(function(segments) { if (segments.length === 0) { $scope.segments = $scope.segments.splice(0, fromIndex); @@ -157,17 +157,17 @@ function (angular, _, config, gfunc, Parser) { var query = index === 0 ? '*' : getSegmentPathUpTo(index) + '.*'; - return $scope.datasource.metricFindQuery($scope.filterSrv, query) + return $scope.datasource.metricFindQuery($scope.filter, query) .then(function(segments) { _.each(segments, function(segment) { segment.html = segment.val = segment.text; }); - _.each($scope.filter.list, function(filter) { + _.each($scope.filter.templateParameters, function( templateParameter ) { segments.unshift({ type: 'template', - html: '[[' + filter.name + ']]', - val: '[[' + filter.name + ']]', + html: '[[' + templateParameter.name + ']]', + val: '[[' + templateParameter.name + ']]', expandable: true, }); }); diff --git a/src/app/panels/filtering/module.js b/src/app/panels/filtering/module.js index c4353202d17..5a8c49e0cff 100644 --- a/src/app/panels/filtering/module.js +++ b/src/app/panels/filtering/module.js @@ -14,7 +14,7 @@ function (angular, app, _) { var module = angular.module('kibana.panels.filtering', []); app.useModule(module); - module.controller('filtering', function($scope, datasourceSrv, $rootScope, $timeout, dashboard) { + module.controller('filtering', function($scope, datasourceSrv, $rootScope, $timeout) { $scope.panelMeta = { status : "Stable", @@ -27,13 +27,11 @@ function (angular, app, _) { _.defaults($scope.panel,_d); $scope.init = function() { - $scope.filterSrv = filterSrv; - console.log( "Filtering panel " + $scope.dashboard ); - $scope.filterSrv.init( $scope.dashboard ); + // empty. Don't know if I need the function then. }; - $scope.remove = function(filter) { - this.filter.removeFilter(filter); + $scope.remove = function( templateParameter ) { + this.filter.removeTemplateParameter( templateParameter ); // TODO hkraemer: check if this makes sense like this if(!$rootScope.$$phase) { @@ -44,24 +42,24 @@ function (angular, app, _) { },0); }; - $scope.filterOptionSelected = function(filter, option) { - this.filter.filterOptionSelected(option); - this.applyFilterToOtherFilters(filter); + $scope.filterOptionSelected = function( templateParameter, option ) { + this.filter.templateOptionSelected(option); + this.applyFilterToOtherFilters(templateParameter); }; $scope.applyFilterToOtherFilters = function(updatedFilter) { - _.each(this.filter.list, function(filter) { - if (filter === updatedFilter) { + _.each(this.filter.templateParameters, function( templateParameter ) { + if (templateParameter === updatedFilter) { return; } - if (filter.query.indexOf(updatedFilter.name) !== -1) { - $scope.applyFilter(filter); + if (templateParameter.query.indexOf(updatedFilter.name) !== -1) { + $scope.applyFilter(templateParameter); } }); }; $scope.applyFilter = function(filter) { - var query = this.filter.applyFilterToTarget(filter.query); + var query = this.filter.applyTemplateToTarget(filter.query); datasourceSrv.default.metricFindQuery($scope, query) .then(function (results) { @@ -79,12 +77,12 @@ function (angular, app, _) { filter.options.unshift({text: 'All', value: allExpr}); } - this.filterSrv.filterOptionSelected(filter, filter.options[0]); + this.filter.templateOptionSelected(filter, filter.options[0]); }); }; $scope.add = function() { - this.filter.add({ + this.filter.addTemplateParameter({ type : 'filter', name : 'filter name', editing : true, diff --git a/src/app/panels/graphite/module.js b/src/app/panels/graphite/module.js index 3a35fe9be69..02f1abb43b4 100644 --- a/src/app/panels/graphite/module.js +++ b/src/app/panels/graphite/module.js @@ -258,7 +258,7 @@ function (angular, app, $, _, kbn, moment, timeSeries) { datasource: $scope.panel.datasource }; - $scope.annotationsPromise = annotationsSrv.getAnnotations($scope.filterSrv, $scope.rangeUnparsed); + $scope.annotationsPromise = annotationsSrv.getAnnotations($scope.filter, $scope.rangeUnparsed); return $scope.datasource.query($scope.filter, graphiteQuery) .then($scope.dataHandler) diff --git a/src/app/services/filterSrv.js b/src/app/services/filterSrv.js index 157ca6eadc9..dd1957f9ce7 100644 --- a/src/app/services/filterSrv.js +++ b/src/app/services/filterSrv.js @@ -11,43 +11,43 @@ define([ module.factory('filterSrv', function(dashboard, $rootScope, $timeout, $routeParams) { // defaults var _d = { - list: [], + templateParameters: [], time: {} }; var result = { _updateTemplateData : function( initial ) { - this._filterTemplateData = {}; - _.each(this.list, function(filter) { - if (initial) { - var urlValue = $routeParams[filter.name]; - if (urlValue) { - filter.current = { text: urlValue, value: urlValue }; + this._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; } - } - if (!filter.current || !filter.current.value) { - return; - } - this._filterTemplateData[filter.name] = filter.current.value; + this._templateData[ templateParameter.name ] = templateParameter.current.value; }); }, - filterOptionSelected : function(option) { + templateOptionSelected : function(option) { this.current = option; this._updateTemplateData(); }, - add : function(filter) { - this.list.push(filter); + addTemplateParameter : function( templateParameter ) { + this.templateParameters.push( templateParameter ); }, - applyFilterToTarget : function(target) { + applyTemplateToTarget : function(target) { if (target.indexOf('[[') === -1) { return target; } - return _.template(target, this._filterTemplateData, this.templateSettings); + return _.template(target, this._templateData, this.templateSettings); }, setTime : function(time) { @@ -86,9 +86,10 @@ define([ } }, - removeFilter : function( filter ) { - this.list = _.without(this.list, filter); + removeTemplateParameter : function( templateParameter ) { + this.templateParameters = _.without( this.templateParameters, templateParameter ); }, + init : function( dashboard ) { _.defaults(this, _d); this.dashboard = dashboard; From 51b70a7884982253b8a087e5016466e7e04e6759 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Tue, 20 May 2014 09:43:57 +0200 Subject: [PATCH 11/20] Fixed init-test. Mostly renames, new init semantic and I forgot to call updateTemplateParams in addTemplateParameter --- src/app/services/filterSrv.js | 6 ++++-- src/test/specs/filterSrv-specs.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/app/services/filterSrv.js b/src/app/services/filterSrv.js index dd1957f9ce7..c9707fec36e 100644 --- a/src/app/services/filterSrv.js +++ b/src/app/services/filterSrv.js @@ -17,7 +17,7 @@ define([ var result = { _updateTemplateData : function( initial ) { - this._templateData = {}; + var _templateData = {}; _.each(this.templateParameters, function( templateParameter ) { if (initial) { var urlValue = $routeParams[ templateParameter.name ]; @@ -29,8 +29,9 @@ define([ return; } - this._templateData[ templateParameter.name ] = templateParameter.current.value; + _templateData[ templateParameter.name ] = templateParameter.current.value; }); + this._templateData = _templateData; }, templateOptionSelected : function(option) { @@ -40,6 +41,7 @@ define([ addTemplateParameter : function( templateParameter ) { this.templateParameters.push( templateParameter ); + this._updateTemplateData(); }, applyTemplateToTarget : function(target) { diff --git a/src/test/specs/filterSrv-specs.js b/src/test/specs/filterSrv-specs.js index 1719827077f..e1d6467ea8c 100644 --- a/src/test/specs/filterSrv-specs.js +++ b/src/test/specs/filterSrv-specs.js @@ -21,12 +21,12 @@ define([ describe('init', function() { beforeEach(function() { - _filterSrv.add({ name: 'test', current: { value: 'oogle' } }); _filterSrv.init(); + _filterSrv.addTemplateParameter({ name: 'test', current: { value: 'oogle' } }); }); it('should initialize template data', function() { - var target = _filterSrv.applyFilterToTarget('this.[[test]].filters'); + var target = _filterSrv.applyTemplateToTarget('this.[[test]].filters'); expect(target).to.be('this.oogle.filters'); }); }); From 1cbc352c6c6f052faf99ccd44a7689dc10ab9667 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Tue, 20 May 2014 09:48:36 +0200 Subject: [PATCH 12/20] Fixed (filter->template)OptionSelected test - small misunderstanding on my part, fixed the API in the filterSrv back - renames to match my renames - init script has to be called or fundefined things happen --- src/app/services/filterSrv.js | 4 ++-- src/test/specs/filterSrv-specs.js | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/services/filterSrv.js b/src/app/services/filterSrv.js index c9707fec36e..3d882354cbd 100644 --- a/src/app/services/filterSrv.js +++ b/src/app/services/filterSrv.js @@ -34,8 +34,8 @@ define([ this._templateData = _templateData; }, - templateOptionSelected : function(option) { - this.current = option; + templateOptionSelected : function(templateParameter, option) { + templateParameter.current = option; this._updateTemplateData(); }, diff --git a/src/test/specs/filterSrv-specs.js b/src/test/specs/filterSrv-specs.js index e1d6467ea8c..1ab34aa0023 100644 --- a/src/test/specs/filterSrv-specs.js +++ b/src/test/specs/filterSrv-specs.js @@ -31,13 +31,14 @@ define([ }); }); - describe('filterOptionSelected', function() { + describe('templateOptionSelected', function() { beforeEach(function() { - _filterSrv.add({ name: 'test' }); - _filterSrv.filterOptionSelected(_filterSrv.list[0], { value: 'muuuu' }); + _filterSrv.init(); + _filterSrv.addTemplateParameter({ name: 'test' }); + _filterSrv.templateOptionSelected(_filterSrv.templateParameters[0], { value: 'muuuu' }); }); it('should set current value and update template data', function() { - var target = _filterSrv.applyFilterToTarget('this.[[test]].filters'); + var target = _filterSrv.applyTemplateToTarget('this.[[test]].filters'); expect(target).to.be('this.muuuu.filters'); }); }); From f2b9ea103431238811f820ed519252d1df45d462 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Tue, 20 May 2014 09:52:55 +0200 Subject: [PATCH 13/20] Fixed timerange unparsed - had to call init with the dashboard mock, since this checks dashboard.refresh (need to look at that sometime) --- src/test/specs/filterSrv-specs.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/specs/filterSrv-specs.js b/src/test/specs/filterSrv-specs.js index 1ab34aa0023..920277c63c3 100644 --- a/src/test/specs/filterSrv-specs.js +++ b/src/test/specs/filterSrv-specs.js @@ -21,7 +21,7 @@ define([ describe('init', function() { beforeEach(function() { - _filterSrv.init(); + _filterSrv.init( _dashboard ); _filterSrv.addTemplateParameter({ name: 'test', current: { value: 'oogle' } }); }); @@ -33,7 +33,7 @@ define([ describe('templateOptionSelected', function() { beforeEach(function() { - _filterSrv.init(); + _filterSrv.init( _dashboard ); _filterSrv.addTemplateParameter({ name: 'test' }); _filterSrv.templateOptionSelected(_filterSrv.templateParameters[0], { value: 'muuuu' }); }); @@ -45,6 +45,7 @@ define([ describe('timeRange', function() { it('should return unparsed when parse is false', function() { + _filterSrv.init( _dashboard ); _filterSrv.setTime({from: 'now', to: 'now-1h' }); var time = _filterSrv.timeRange(false); expect(time.from).to.be('now'); From 00e1a1c4425eb40be74791ed670f5932a8e7067c Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Tue, 20 May 2014 09:54:07 +0200 Subject: [PATCH 14/20] Fixed timerange parsed = true test - had to call init with dashboard mock --- src/test/specs/filterSrv-specs.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/specs/filterSrv-specs.js b/src/test/specs/filterSrv-specs.js index 920277c63c3..e540c95929e 100644 --- a/src/test/specs/filterSrv-specs.js +++ b/src/test/specs/filterSrv-specs.js @@ -53,6 +53,7 @@ define([ }); it('should return parsed when parse is true', function() { + _filterSrv.init( _dashboard ); _filterSrv.setTime({from: 'now', to: 'now-1h' }); var time = _filterSrv.timeRange(true); expect(_.isDate(time.from)).to.be(true); From ed76d718cd2a020dd69914f84a647db5c77729f4 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Tue, 20 May 2014 09:56:50 +0200 Subject: [PATCH 15/20] Fixed setTime should disable refresh test - init with dashboard mock --- src/test/specs/filterSrv-specs.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/specs/filterSrv-specs.js b/src/test/specs/filterSrv-specs.js index e540c95929e..beb9edf94b3 100644 --- a/src/test/specs/filterSrv-specs.js +++ b/src/test/specs/filterSrv-specs.js @@ -63,6 +63,7 @@ define([ describe('setTime', function() { it('should return disable refresh for absolute times', function() { + _filterSrv.init( _dashboard ); _dashboard.current.refresh = true; _filterSrv.setTime({from: '2011-01-01', to: '2015-01-01' }); From dcea2c5f4e51a3877ea2a6494856f8e1344263e2 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Tue, 20 May 2014 10:00:15 +0200 Subject: [PATCH 16/20] Fixed last test + a mistake in other tests setup - filterSrv expects the parameter to init to be the actual dashboard object (I'll depend on that later on), so I had to pass dashboard.current in there, instead of dashboard - in the last test, the problem was exactly that again. --- src/test/specs/filterSrv-specs.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/specs/filterSrv-specs.js b/src/test/specs/filterSrv-specs.js index beb9edf94b3..a6742bbed87 100644 --- a/src/test/specs/filterSrv-specs.js +++ b/src/test/specs/filterSrv-specs.js @@ -21,7 +21,7 @@ define([ describe('init', function() { beforeEach(function() { - _filterSrv.init( _dashboard ); + _filterSrv.init( _dashboard.current ); _filterSrv.addTemplateParameter({ name: 'test', current: { value: 'oogle' } }); }); @@ -33,7 +33,7 @@ define([ describe('templateOptionSelected', function() { beforeEach(function() { - _filterSrv.init( _dashboard ); + _filterSrv.init( _dashboard.current ); _filterSrv.addTemplateParameter({ name: 'test' }); _filterSrv.templateOptionSelected(_filterSrv.templateParameters[0], { value: 'muuuu' }); }); @@ -45,7 +45,7 @@ define([ describe('timeRange', function() { it('should return unparsed when parse is false', function() { - _filterSrv.init( _dashboard ); + _filterSrv.init( _dashboard.current ); _filterSrv.setTime({from: 'now', to: 'now-1h' }); var time = _filterSrv.timeRange(false); expect(time.from).to.be('now'); @@ -53,7 +53,7 @@ define([ }); it('should return parsed when parse is true', function() { - _filterSrv.init( _dashboard ); + _filterSrv.init( _dashboard.current ); _filterSrv.setTime({from: 'now', to: 'now-1h' }); var time = _filterSrv.timeRange(true); expect(_.isDate(time.from)).to.be(true); @@ -63,7 +63,7 @@ define([ describe('setTime', function() { it('should return disable refresh for absolute times', function() { - _filterSrv.init( _dashboard ); + _filterSrv.init( _dashboard.current ); _dashboard.current.refresh = true; _filterSrv.setTime({from: '2011-01-01', to: '2015-01-01' }); @@ -71,6 +71,7 @@ define([ }); it('should restore refresh after relative time range is set', function() { + _filterSrv.init( _dashboard.current ); _dashboard.current.refresh = true; _filterSrv.setTime({from: '2011-01-01', to: '2015-01-01' }); expect(_dashboard.current.refresh).to.be(false); From 36b44d697169a234ef2de91495e504a8b65e32a1 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Tue, 20 May 2014 10:23:36 +0200 Subject: [PATCH 17/20] Moved init calls to setup method --- src/test/specs/filterSrv-specs.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/test/specs/filterSrv-specs.js b/src/test/specs/filterSrv-specs.js index a6742bbed87..cd5d8434aad 100644 --- a/src/test/specs/filterSrv-specs.js +++ b/src/test/specs/filterSrv-specs.js @@ -19,9 +19,12 @@ define([ _filterSrv = filterSrv; })); + beforeEach(function() { + _filterSrv.init( _dashboard.current ); + }); + describe('init', function() { beforeEach(function() { - _filterSrv.init( _dashboard.current ); _filterSrv.addTemplateParameter({ name: 'test', current: { value: 'oogle' } }); }); @@ -33,7 +36,6 @@ define([ describe('templateOptionSelected', function() { beforeEach(function() { - _filterSrv.init( _dashboard.current ); _filterSrv.addTemplateParameter({ name: 'test' }); _filterSrv.templateOptionSelected(_filterSrv.templateParameters[0], { value: 'muuuu' }); }); @@ -45,7 +47,6 @@ define([ describe('timeRange', function() { it('should return unparsed when parse is false', function() { - _filterSrv.init( _dashboard.current ); _filterSrv.setTime({from: 'now', to: 'now-1h' }); var time = _filterSrv.timeRange(false); expect(time.from).to.be('now'); @@ -53,7 +54,6 @@ define([ }); it('should return parsed when parse is true', function() { - _filterSrv.init( _dashboard.current ); _filterSrv.setTime({from: 'now', to: 'now-1h' }); var time = _filterSrv.timeRange(true); expect(_.isDate(time.from)).to.be(true); @@ -63,7 +63,6 @@ define([ describe('setTime', function() { it('should return disable refresh for absolute times', function() { - _filterSrv.init( _dashboard.current ); _dashboard.current.refresh = true; _filterSrv.setTime({from: '2011-01-01', to: '2015-01-01' }); @@ -71,7 +70,6 @@ define([ }); it('should restore refresh after relative time range is set', function() { - _filterSrv.init( _dashboard.current ); _dashboard.current.refresh = true; _filterSrv.setTime({from: '2011-01-01', to: '2015-01-01' }); expect(_dashboard.current.refresh).to.be(false); From 6f2dd2e2a57e34a1eb8e03b384a4d72f8075dbbd Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Tue, 20 May 2014 10:23:49 +0200 Subject: [PATCH 18/20] Fixed an old method name --- src/app/services/graphite/graphiteDatasource.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/services/graphite/graphiteDatasource.js b/src/app/services/graphite/graphiteDatasource.js index 46f90909f08..78984a55cf7 100644 --- a/src/app/services/graphite/graphiteDatasource.js +++ b/src/app/services/graphite/graphiteDatasource.js @@ -118,7 +118,7 @@ function (angular, _, $, config, kbn, moment) { GraphiteDatasource.prototype.metricFindQuery = function(filterSrv, query) { var interpolated; try { - interpolated = filterSrv.applyFilterToTarget(query); + interpolated = filterSrv.applyTemplateToTarget(query); } catch(err) { return $q.reject(err); @@ -174,7 +174,7 @@ function (angular, _, $, config, kbn, moment) { if (key === "targets") { _.each(value, function (value) { if (!value.hide) { - var targetValue = filterSrv.applyFilterToTarget(value.target); + var targetValue = filterSrv.applyTemplateToTarget(value.target); clean_options.push("target=" + encodeURIComponent(targetValue)); } }, this); From e737b51e9d5038f7c8befdc720f45d6d9696b225 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Tue, 20 May 2014 10:24:03 +0200 Subject: [PATCH 19/20] Removed 2 console.logs --- src/app/controllers/dash.js | 2 -- src/app/directives/grafanaGraph.js | 1 - 2 files changed, 3 deletions(-) diff --git a/src/app/controllers/dash.js b/src/app/controllers/dash.js index 09761d4c53d..71222c1b7c7 100644 --- a/src/app/controllers/dash.js +++ b/src/app/controllers/dash.js @@ -58,14 +58,12 @@ function (angular, $, config, _) { $scope.dashAlerts = alertSrv; $scope.filter = filterSrv; - console.log( "dash controller -> init -> current dashboard", dashboard.current ); $scope.filter.init( dashboard.current ); $scope.$watch('dashboard.current', function(newValue) { $scope.filter.init( newValue ); }); - console.log( "Scope I watch on", $scope ); $scope.$watch('filter.time', function() { $scope.dashboard.refresh(); }, true); diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 883b8ab7655..798584ca194 100644 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -388,7 +388,6 @@ function (angular, $, kbn, moment, _) { elem.bind("plotselected", function (event, ranges) { scope.$apply( function() { - console.log( "Scope I call filter.setTime on", scope ); scope.filter.setTime({ from : moment.utc(ranges.xaxis.from).toDate(), to : moment.utc(ranges.xaxis.to).toDate(), From 674390dfa273fbe28fb2a2c7693f20aa6e5afb31 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Tue, 20 May 2014 12:40:56 +0200 Subject: [PATCH 20/20] Fixed unsaved changes alerting about timechanges only. --- src/app/services/unsavedChangesSrv.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/services/unsavedChangesSrv.js b/src/app/services/unsavedChangesSrv.js index 5d90052b322..bdbd024b91d 100644 --- a/src/app/services/unsavedChangesSrv.js +++ b/src/app/services/unsavedChangesSrv.js @@ -55,6 +55,8 @@ function (angular, _, config) { var original = dashboard.original; // ignore timespan changes + current.services.filter.time = original.services.filter.time = {}; + current.refresh = original.refresh; var currentTimepicker = _.findWhere(current.nav, { type: 'timepicker' });