Commit 3e24a87e by Torkel Ödegaard

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

parent 992bccce
...@@ -52,21 +52,23 @@ function (angular, $, config, _) { ...@@ -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, _) { ...@@ -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);
}; };
......
...@@ -30,25 +30,25 @@ function (angular, app, _) { ...@@ -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 ) { $scope.remove = function(templateParameter) {
this.filter.removeTemplateParameter( 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 ) { $scope.filterOptionSelected = function(templateParameter, option) {
this.filter.templateOptionSelected(option); $scope.filter.templateOptionSelected(templateParameter, option);
this.applyFilterToOtherFilters(templateParameter); $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, _) { ...@@ -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, _) { ...@@ -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, _) { ...@@ -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() {
......
...@@ -16,7 +16,7 @@ define([ ...@@ -16,7 +16,7 @@ define([
}; };
var result = { var result = {
_updateTemplateData : function(initial) { _updateTemplateData: function(initial) {
var _templateData = {}; var _templateData = {};
_.each(this.templateParameters, function( templateParameter ) { _.each(this.templateParameters, function( templateParameter ) {
if (initial) { if (initial) {
...@@ -34,17 +34,18 @@ define([ ...@@ -34,17 +34,18 @@ define([
this._templateData = _templateData; this._templateData = _templateData;
}, },
templateOptionSelected : function(templateParameter, option) { templateOptionSelected: function(templateParameter, option) {
templateParameter.current = option; templateParameter.current = option;
this._updateTemplateData(); this._updateTemplateData();
dashboard.refresh();
}, },
addTemplateParameter : function( templateParameter ) { addTemplateParameter: function( templateParameter ) {
this.templateParameters.push( templateParameter ); this.templateParameters.push( templateParameter );
this._updateTemplateData(); this._updateTemplateData();
}, },
applyTemplateToTarget : function(target) { applyTemplateToTarget: function(target) {
if (target.indexOf('[[') === -1) { if (target.indexOf('[[') === -1) {
return target; return target;
} }
...@@ -52,7 +53,7 @@ define([ ...@@ -52,7 +53,7 @@ define([
return _.template(target, this._templateData, this.templateSettings); return _.template(target, this._templateData, this.templateSettings);
}, },
setTime : function(time) { setTime: function(time) {
_.extend(this.time, time); _.extend(this.time, time);
// disable refresh if we have an absolute time // disable refresh if we have an absolute time
if (time.to !== 'now') { if (time.to !== 'now') {
...@@ -67,7 +68,7 @@ define([ ...@@ -67,7 +68,7 @@ define([
} }
}, },
timeRange : function(parse) { timeRange: function(parse) {
var _t = this.time; var _t = this.time;
if(_.isUndefined(_t) || _.isUndefined(_t.from)) { if(_.isUndefined(_t) || _.isUndefined(_t.from)) {
return false; return false;
...@@ -88,7 +89,7 @@ define([ ...@@ -88,7 +89,7 @@ define([
} }
}, },
removeTemplateParameter : function( templateParameter ) { removeTemplateParameter: function(templateParameter) {
this.templateParameters = _.without( this.templateParameters, templateParameter ); this.templateParameters = _.without( this.templateParameters, templateParameter );
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment