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, _) {
$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);
};
......
......@@ -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() {
......
......@@ -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 };
}
}
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;
});
});
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