|
|
@@ -106,7 +106,7 @@ export class VariableSrv {
|
|
|
|
|
|
syncToDashboardModel() {
|
|
|
this.dashboard.templating.list = this.variables.map(variable => {
|
|
|
- return variable.model;
|
|
|
+ return variable.getModel();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -122,100 +122,100 @@ export class VariableSrv {
|
|
|
|
|
|
// cascade updates to variables that use this variable
|
|
|
var promises = _.map(this.variables, otherVariable => {
|
|
|
- if (otherVariable === variable) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (otherVariable === variable) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (otherVariable.dependsOn(variable)) {
|
|
|
- return this.updateOptions(otherVariable);
|
|
|
- }
|
|
|
- });
|
|
|
+ if (otherVariable.dependsOn(variable)) {
|
|
|
+ return this.updateOptions(otherVariable);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- return this.$q.all(promises);
|
|
|
- }
|
|
|
+ return this.$q.all(promises);
|
|
|
+ }
|
|
|
|
|
|
- selectOptionsForCurrentValue(variable) {
|
|
|
- var i, y, value, option;
|
|
|
- var selected: any = [];
|
|
|
-
|
|
|
- for (i = 0; i < variable.options.length; i++) {
|
|
|
- option = variable.options[i];
|
|
|
- option.selected = false;
|
|
|
- if (_.isArray(variable.current.value)) {
|
|
|
- for (y = 0; y < variable.current.value.length; y++) {
|
|
|
- value = variable.current.value[y];
|
|
|
- if (option.value === value) {
|
|
|
- option.selected = true;
|
|
|
- selected.push(option);
|
|
|
- }
|
|
|
+ selectOptionsForCurrentValue(variable) {
|
|
|
+ var i, y, value, option;
|
|
|
+ var selected: any = [];
|
|
|
+
|
|
|
+ for (i = 0; i < variable.options.length; i++) {
|
|
|
+ option = variable.options[i];
|
|
|
+ option.selected = false;
|
|
|
+ if (_.isArray(variable.current.value)) {
|
|
|
+ for (y = 0; y < variable.current.value.length; y++) {
|
|
|
+ value = variable.current.value[y];
|
|
|
+ if (option.value === value) {
|
|
|
+ option.selected = true;
|
|
|
+ selected.push(option);
|
|
|
}
|
|
|
- } else if (option.value === variable.current.value) {
|
|
|
- option.selected = true;
|
|
|
- selected.push(option);
|
|
|
}
|
|
|
+ } else if (option.value === variable.current.value) {
|
|
|
+ option.selected = true;
|
|
|
+ selected.push(option);
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ return selected;
|
|
|
+ }
|
|
|
|
|
|
- return selected;
|
|
|
+ validateVariableSelectionState(variable) {
|
|
|
+ if (!variable.current) {
|
|
|
+ if (!variable.options.length) { return this.$q.when(); }
|
|
|
+ return variable.setValue(variable.options[0]);
|
|
|
}
|
|
|
|
|
|
- validateVariableSelectionState(variable) {
|
|
|
- if (!variable.current) {
|
|
|
- if (!variable.options.length) { return this.$q.when(); }
|
|
|
- return variable.setValue(variable.options[0]);
|
|
|
- }
|
|
|
+ if (_.isArray(variable.current.value)) {
|
|
|
+ var selected = this.selectOptionsForCurrentValue(variable);
|
|
|
|
|
|
- if (_.isArray(variable.current.value)) {
|
|
|
- var selected = this.selectOptionsForCurrentValue(variable);
|
|
|
-
|
|
|
- // if none pick first
|
|
|
- if (selected.length === 0) {
|
|
|
- selected = variable.options[0];
|
|
|
- } else {
|
|
|
- selected = {
|
|
|
- value: _.map(selected, function(val) {return val.value;}),
|
|
|
- text: _.map(selected, function(val) {return val.text;}).join(' + '),
|
|
|
- };
|
|
|
- }
|
|
|
+ // if none pick first
|
|
|
+ if (selected.length === 0) {
|
|
|
+ selected = variable.options[0];
|
|
|
+ } else {
|
|
|
+ selected = {
|
|
|
+ value: _.map(selected, function(val) {return val.value;}),
|
|
|
+ text: _.map(selected, function(val) {return val.text;}).join(' + '),
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
- return variable.setValue(selected);
|
|
|
+ return variable.setValue(selected);
|
|
|
+ } else {
|
|
|
+ var currentOption = _.find(variable.options, {text: variable.current.text});
|
|
|
+ if (currentOption) {
|
|
|
+ return variable.setValue(currentOption);
|
|
|
} else {
|
|
|
- var currentOption = _.find(variable.options, {text: variable.current.text});
|
|
|
- if (currentOption) {
|
|
|
- return variable.setValue(currentOption);
|
|
|
- } else {
|
|
|
- if (!variable.options.length) { return Promise.resolve(); }
|
|
|
- return variable.setValue(variable.options[0]);
|
|
|
- }
|
|
|
+ if (!variable.options.length) { return Promise.resolve(); }
|
|
|
+ return variable.setValue(variable.options[0]);
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- setOptionFromUrl(variable, urlValue) {
|
|
|
- var promise = this.$q.when();
|
|
|
-
|
|
|
- if (variable.refresh) {
|
|
|
- promise = variable.updateOptions();
|
|
|
- }
|
|
|
+ setOptionFromUrl(variable, urlValue) {
|
|
|
+ var promise = this.$q.when();
|
|
|
|
|
|
- return promise.then(() => {
|
|
|
- var option = _.find(variable.options, op => {
|
|
|
- return op.text === urlValue || op.value === urlValue;
|
|
|
- });
|
|
|
+ if (variable.refresh) {
|
|
|
+ promise = variable.updateOptions();
|
|
|
+ }
|
|
|
|
|
|
- option = option || {text: urlValue, value: urlValue};
|
|
|
- return variable.setValue(option);
|
|
|
+ return promise.then(() => {
|
|
|
+ var option = _.find(variable.options, op => {
|
|
|
+ return op.text === urlValue || op.value === urlValue;
|
|
|
});
|
|
|
- }
|
|
|
|
|
|
- setOptionAsCurrent(variable, option) {
|
|
|
- variable.current = _.cloneDeep(option);
|
|
|
+ option = option || {text: urlValue, value: urlValue};
|
|
|
+ return variable.setValue(option);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- if (_.isArray(variable.current.text)) {
|
|
|
- variable.current.text = variable.current.text.join(' + ');
|
|
|
- }
|
|
|
+ setOptionAsCurrent(variable, option) {
|
|
|
+ variable.current = _.cloneDeep(option);
|
|
|
|
|
|
- this.selectOptionsForCurrentValue(variable);
|
|
|
- return this.variableUpdated(variable);
|
|
|
+ if (_.isArray(variable.current.text)) {
|
|
|
+ variable.current.text = variable.current.text.join(' + ');
|
|
|
}
|
|
|
+
|
|
|
+ this.selectOptionsForCurrentValue(variable);
|
|
|
+ return this.variableUpdated(variable);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
coreModule.service('variableSrv', VariableSrv);
|