mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
fixing issues with directives
This commit is contained in:
parent
738e16f197
commit
374205a729
5 changed files with 36 additions and 106 deletions
|
@ -1,22 +0,0 @@
|
|||
define(function (require) {
|
||||
require('modules')
|
||||
.get('kibana')
|
||||
.directive('greaterThan', function () {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function ($scope, $el, $attr, ngModel) {
|
||||
ngModel.$parsers.push(validator);
|
||||
ngModel.$formatters.push(validator);
|
||||
|
||||
function validator(value) {
|
||||
var val = $attr.greaterThan;
|
||||
var valid = false;
|
||||
|
||||
if (!isNaN(value)) valid = +value > +val;
|
||||
ngModel.$setValidity('greaterThan', valid);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
|
@ -1,51 +1,40 @@
|
|||
define(function (require) {
|
||||
var _ = require('lodash');
|
||||
var inequalityMaps = {};
|
||||
|
||||
function attachInequality() {
|
||||
return function ($scope, $el, $attr, controllers) {
|
||||
var ngModel = controllers[0];
|
||||
var ngForm = controllers[1];
|
||||
var name = $attr.inequality.slice(1);
|
||||
function makeDirectiveDef(id, compare) {
|
||||
return function ($parse) {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function ($scope, $el, $attr, ngModel) {
|
||||
var getBound = function () { return $parse($attr[id])(); };
|
||||
var defaultVal = {
|
||||
'greaterThan': -Infinity,
|
||||
'lessThan': Infinity
|
||||
}[id];
|
||||
|
||||
inequalityMaps[$attr.name] = name;
|
||||
ngModel.$parsers.push(validator);
|
||||
ngModel.$formatters.push(validator);
|
||||
ngModel.$parsers.push(validate);
|
||||
ngModel.$formatters.push(validate);
|
||||
|
||||
function validator(thisVal) {
|
||||
var sign = $attr.inequality.slice(0, 1);
|
||||
var valid = false;
|
||||
var otherElem = ngForm[name];
|
||||
var otherVal = +otherElem.$modelValue || 0;
|
||||
var hasCompliment = (inequalityMaps[name] === $attr.name);
|
||||
$scope.$watch(getBound, function () {
|
||||
validate(ngModel.$viewValue);
|
||||
});
|
||||
|
||||
if (!isNaN(thisVal)) {
|
||||
switch (sign) {
|
||||
case ('<'):
|
||||
valid = +thisVal < otherVal;
|
||||
break;
|
||||
case ('>'):
|
||||
valid = +thisVal > otherVal;
|
||||
break;
|
||||
function validate(val) {
|
||||
var bound = !isNaN(getBound()) ? +getBound() : defaultVal;
|
||||
var valid = !isNaN(bound) && !isNaN(val) && compare(val, bound);
|
||||
ngModel.$setValidity(id, valid);
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
ngModel.$setValidity('inequality', valid);
|
||||
if (hasCompliment) {
|
||||
otherElem.$setValidity('inequality', valid);
|
||||
}
|
||||
|
||||
return thisVal;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
require('modules')
|
||||
.get('kibana')
|
||||
.directive('inequality', function () {
|
||||
return {
|
||||
require: ['ngModel', '^form'],
|
||||
link: attachInequality()
|
||||
};
|
||||
});
|
||||
});
|
||||
.get('kibana')
|
||||
.directive('greaterThan', makeDirectiveDef('greaterThan', function (a, b) {
|
||||
return a > b;
|
||||
}))
|
||||
.directive('lessThan', makeDirectiveDef('lessThan', function (a, b) {
|
||||
return a < b;
|
||||
}));
|
||||
});
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
define(function (require) {
|
||||
require('modules')
|
||||
.get('kibana')
|
||||
.directive('lessThan', function () {
|
||||
return {
|
||||
require: ['ngModel', '^form'],
|
||||
link: function ($scope, $el, $attr, controllers) {
|
||||
var ngModel = controllers[0];
|
||||
var ngForm = controllers[1];
|
||||
|
||||
ngModel.$parsers.push(validator);
|
||||
ngModel.$formatters.push(validator);
|
||||
|
||||
function validator(value) {
|
||||
var otherElem = ngForm[$attr.lessThan];
|
||||
var val = +otherElem.$modelValue || 0;
|
||||
var valid = false;
|
||||
var hasCompliment = ngForm.$error.greaterThan && ngForm.$error.greaterThan
|
||||
.reduce(function (last, curr) {
|
||||
return last || (curr === otherElem ? otherElem : false);
|
||||
}, false);
|
||||
|
||||
if (!isNaN(value)) valid = +value < val;
|
||||
if (hasCompliment) {
|
||||
otherElem.$setValidity('greaterThan', valid); // Set Validity of other element
|
||||
}
|
||||
ngModel.$setValidity('lessThan', valid);
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
|
@ -17,11 +17,11 @@
|
|||
class="form-control"
|
||||
type="number"
|
||||
step="0.1"
|
||||
inequality=">yMin"
|
||||
greater-than="{{vis.params.yAxis.min}}"
|
||||
ng-model="vis.params.yAxis.max"
|
||||
ng-required="vis.params.setYExtents">
|
||||
</label>
|
||||
<div ng-if="vis.params.yAxis.min > vis.params.yAxis.max">
|
||||
<div ng-show="vis.params.yAxis.min > vis.params.yAxis.max">
|
||||
<span class="text-danger">Min must not exceed max</span>
|
||||
</div>
|
||||
<label>
|
||||
|
@ -30,16 +30,13 @@
|
|||
class="form-control"
|
||||
type="number"
|
||||
step="0.1"
|
||||
inequality="<yMax"
|
||||
less-than="{{vis.params.yAxis.max}}"
|
||||
greater-than="{{vis.params.scale === 'log' ? 0 : ''}}"
|
||||
ng-model="vis.params.yAxis.min"
|
||||
ng-required="vis.params.setYExtents">
|
||||
</label>
|
||||
<input type="number"
|
||||
style="display: none"
|
||||
name="scale-validator"
|
||||
ng-required="{{vis.params.scale === 'log' && vis.params.yAxis.min <= 0}}">
|
||||
</div>
|
||||
<div ng-if="vis.params.scale === 'log' && vis.params.yAxis.min <= 0">
|
||||
<div ng-show="vis.params.setYExtents && vis.params.scale === 'log' && vis.params.yAxis.min <= 0">
|
||||
<span class="text-danger">Min must exceed 0 when a log scale is selected</span>
|
||||
</div>
|
||||
<div class="vis-option-item">
|
||||
|
|
|
@ -2,8 +2,8 @@ define(function (require) {
|
|||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
var module = require('modules').get('kibana');
|
||||
require('directives/greater_than');
|
||||
require('directives/less_than');
|
||||
//require('directives/greater_than');
|
||||
//require('directives/less_than');
|
||||
require('directives/inequality');
|
||||
|
||||
module.directive('pointSeriesOptions', function ($parse, $compile) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue