Skip to content

Commit

Permalink
Backport PR elastic#8566
Browse files Browse the repository at this point in the history
---------

**Commit 1:**
Modifying the histograms interval to support decimals

* Original sha: 189c60d45010eb843dc573863aaf0fb85fbaefc6 [formerly da04e10]
* Authored by = <[email protected]> on 2016-10-05T20:46:52Z

**Commit 2:**
Removing the input-whole-number, no longer used.

* Original sha: 6217f3d8bf453f8431f90f5f5b3acc4defaf6ad6 [formerly cccb370]
* Authored by = <[email protected]> on 2016-10-06T17:29:03Z


Former-commit-id: 2172489
  • Loading branch information
elastic-jasper committed Oct 10, 2016
1 parent ef60553 commit d25851e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 31 deletions.
14 changes: 12 additions & 2 deletions src/ui/public/agg_types/__tests__/buckets/_histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,22 @@ describe('Histogram Agg', function () {
describe('interval', function () {
// reads aggConfig.params.interval, writes to dsl.interval

it('accepts a number', function () {
it('accepts a whole number', function () {
let output = paramWriter.write({ interval: 100 });
expect(output.params).to.have.property('interval', 100);
});

it('accepts a string', function () {
it('accepts a decimal number', function () {
let output = paramWriter.write({ interval: 0.1 });
expect(output.params).to.have.property('interval', 0.1);
});

it('accepts a decimal number string', function () {
let output = paramWriter.write({ interval: '0.1' });
expect(output.params).to.have.property('interval', 0.1);
});

it('accepts a whole number string', function () {
let output = paramWriter.write({ interval: '10' });
expect(output.params).to.have.property('interval', 10);
});
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/agg_types/buckets/_interval_options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from 'moment';
import 'ui/directives/input_whole_number';

export default function IntervalOptionsService(Private) {

// shorthand
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/agg_types/buckets/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function HistogramAggDefinition(Private) {
name: 'interval',
editor: intervalTemplate,
write: function (aggConfig, output) {
output.params.interval = parseInt(aggConfig.params.interval, 10);
output.params.interval = parseFloat(aggConfig.params.interval);
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/agg_types/controls/interval.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
class="form-control"
name="interval"
min="0"
input-whole-number
input-number
>
</div>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import angular from 'angular';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import 'ui/directives/input_whole_number';
import 'ui/directives/input_number';

describe('Whole number input directive', function () {
describe('Number input directive', function () {
let $compile;
let $rootScope;
let html = '<input type="text" ng-model="value" input-whole-number />';
let html = '<input type="text" ng-model="value" input-number />';

beforeEach(ngMock.module('kibana'));

Expand All @@ -22,16 +22,16 @@ describe('Whole number input directive', function () {
$rootScope.$digest();
expect(element.hasClass('ng-valid')).to.be.ok();

$rootScope.value = '1.0';
$rootScope.value = '1';
$rootScope.$digest();
expect(element.hasClass('ng-valid')).to.be.ok();

$rootScope.value = '-5.0';
$rootScope.value = '-5';
$rootScope.$digest();
expect(element.hasClass('ng-valid')).to.be.ok();
});

it('should disallow numbers with decimals', function () {
it('should allow numbers with decimals', function () {
let element = $compile(html)($rootScope);

$rootScope.value = '123.0';
Expand All @@ -40,10 +40,10 @@ describe('Whole number input directive', function () {

$rootScope.value = '1.2';
$rootScope.$digest();
expect(element.hasClass('ng-invalid')).to.be.ok();
expect(element.hasClass('ng-valid')).to.be.ok();

$rootScope.value = '-5.5';
$rootScope.$digest();
expect(element.hasClass('ng-invalid')).to.be.ok();
expect(element.hasClass('ng-valid')).to.be.ok();
});
});
18 changes: 18 additions & 0 deletions src/ui/public/directives/input_number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import uiModules from 'ui/modules';
let module = uiModules.get('kibana');

module.directive('inputNumber', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function ($scope, $elem, attrs, ngModel) {
ngModel.$parsers.push(checkNumber);
ngModel.$formatters.push(checkNumber);

function checkNumber(value) {
ngModel.$setValidity('number', !isNaN(parseFloat(value)));
return value;
}
}
};
});
18 changes: 0 additions & 18 deletions src/ui/public/directives/input_whole_number.js

This file was deleted.

0 comments on commit d25851e

Please sign in to comment.