mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(templating): good progress on new variable update code, #6048
This commit is contained in:
48
public/app/features/templating/interval_variable.ts
Normal file
48
public/app/features/templating/interval_variable.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
///<reference path="../../headers/common.d.ts" />
|
||||
|
||||
import _ from 'lodash';
|
||||
import kbn from 'app/core/utils/kbn';
|
||||
import {Variable} from './variable';
|
||||
import {VariableSrv, variableConstructorMap} from './variable_srv';
|
||||
|
||||
export class IntervalVariable implements Variable {
|
||||
auto_count: number;
|
||||
auto_min: number;
|
||||
options: any;
|
||||
auto: boolean;
|
||||
query: string;
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private model, private timeSrv, private templateSrv) {
|
||||
_.extend(this, model);
|
||||
}
|
||||
|
||||
setValue(option) {
|
||||
if (this.auto) {
|
||||
this.updateAutoValue();
|
||||
}
|
||||
}
|
||||
|
||||
updateAutoValue() {
|
||||
// add auto option if missing
|
||||
if (this.options.length && this.options[0].text !== 'auto') {
|
||||
this.options.unshift({ text: 'auto', value: '$__auto_interval' });
|
||||
}
|
||||
|
||||
var interval = kbn.calculateInterval(this.timeSrv.timeRange(), this.auto_count, (this.auto_min ? ">"+this.auto_min : null));
|
||||
this.templateSrv.setGrafanaVariable('$__auto_interval', interval);
|
||||
}
|
||||
|
||||
updateOptions() {
|
||||
// extract options in comma separated string
|
||||
this.options = _.map(this.query.split(/[,]+/), function(text) {
|
||||
return {text: text.trim(), value: text.trim()};
|
||||
});
|
||||
|
||||
if (this.auto) {
|
||||
this.updateAutoValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variableConstructorMap['interval'] = IntervalVariable;
|
||||
Reference in New Issue
Block a user