mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
adding directieve, modifying point series options and greater_than directive
This commit is contained in:
parent
652eb42b4f
commit
738e16f197
5 changed files with 80 additions and 7 deletions
|
@ -9,9 +9,10 @@ define(function (require) {
|
|||
ngModel.$formatters.push(validator);
|
||||
|
||||
function validator(value) {
|
||||
var val = +$attr.greaterThan || 0;
|
||||
var val = $attr.greaterThan;
|
||||
var valid = false;
|
||||
if (!isNaN(value)) valid = +value > val;
|
||||
|
||||
if (!isNaN(value)) valid = +value > +val;
|
||||
ngModel.$setValidity('greaterThan', valid);
|
||||
return value;
|
||||
}
|
||||
|
|
51
src/kibana/directives/inequality.js
Normal file
51
src/kibana/directives/inequality.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
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);
|
||||
|
||||
inequalityMaps[$attr.name] = name;
|
||||
ngModel.$parsers.push(validator);
|
||||
ngModel.$formatters.push(validator);
|
||||
|
||||
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);
|
||||
|
||||
if (!isNaN(thisVal)) {
|
||||
switch (sign) {
|
||||
case ('<'):
|
||||
valid = +thisVal < otherVal;
|
||||
break;
|
||||
case ('>'):
|
||||
valid = +thisVal > otherVal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
};
|
||||
});
|
||||
});
|
|
@ -3,16 +3,29 @@ define(function (require) {
|
|||
.get('kibana')
|
||||
.directive('lessThan', function () {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function ($scope, $el, $attr, ngModel) {
|
||||
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 val = +$attr.lessThan || 0;
|
||||
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,7 +17,7 @@
|
|||
class="form-control"
|
||||
type="number"
|
||||
step="0.1"
|
||||
greater-than="{{vis.params.yAxis.min}}"
|
||||
inequality=">yMin"
|
||||
ng-model="vis.params.yAxis.max"
|
||||
ng-required="vis.params.setYExtents">
|
||||
</label>
|
||||
|
@ -30,10 +30,17 @@
|
|||
class="form-control"
|
||||
type="number"
|
||||
step="0.1"
|
||||
less-than="{{vis.params.yAxis.max}}"
|
||||
inequality="<yMax"
|
||||
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">
|
||||
<span class="text-danger">Min must exceed 0 when a log scale is selected</span>
|
||||
</div>
|
||||
<div class="vis-option-item">
|
||||
<label>
|
||||
|
|
|
@ -4,6 +4,7 @@ define(function (require) {
|
|||
var module = require('modules').get('kibana');
|
||||
require('directives/greater_than');
|
||||
require('directives/less_than');
|
||||
require('directives/inequality');
|
||||
|
||||
module.directive('pointSeriesOptions', function ($parse, $compile) {
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue