You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by on...@apache.org on 2015/04/22 12:53:34 UTC
ambari git commit: AMBARI-10651. 'hbase_regionserver_heapsize' widget
has confusing minimum tick and value (onechiporenko)
Repository: ambari
Updated Branches:
refs/heads/trunk 1ff5182ee -> 1da29560d
AMBARI-10651. 'hbase_regionserver_heapsize' widget has confusing minimum tick and value (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1da29560
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1da29560
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1da29560
Branch: refs/heads/trunk
Commit: 1da29560de193d3189edb4d4200f7c0a8eb98928
Parents: 1ff5182
Author: Oleg Nechiporenko <on...@apache.org>
Authored: Wed Apr 22 13:35:59 2015 +0300
Committer: Oleg Nechiporenko <on...@apache.org>
Committed: Wed Apr 22 13:53:21 2015 +0300
----------------------------------------------------------------------
.../widgets/slider_config_widget_view.js | 11 ++-
.../widgets/slider_config_widget_view_test.js | 88 +++++++++++++++++++-
2 files changed, 93 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/1da29560/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js b/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js
index d4b95b4..ba8a6fb 100644
--- a/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js
+++ b/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js
@@ -237,13 +237,13 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
parseFunction = this.get('parseFunction'),
ticks = [this.get('minMirrorValue')],
ticksLabels = [],
- defaultValue = this.widgetValueByConfigAttributes(this.valueForTick(+config.get('defaultValue'))),
+ defaultValue = this.valueForTick(+this.get('widgetDefaultValue')),
defaultValueMirroredId,
defaultValueId;
// ticks and labels
for (var i = 1; i <= 3; i++) {
- var val = (this.get('maxMirrorValue') + this.get('minMirrorValue')) / 4 * i;
+ var val = this.get('minMirrorValue') + (this.get('maxMirrorValue') - this.get('minMirrorValue')) * (i / 4);
// if value's type is float, ticks may be float too
ticks.push(this.valueForTick(val));
}
@@ -265,13 +265,17 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
defaultValueId = ticks.indexOf(defaultValue);
// to save nice tick labels layout we should add new tick value which is mirrored by index to default value
defaultValueMirroredId = ticks.length - defaultValueId;
+ // push mirrored default value behind default
+ if (defaultValueId == defaultValueMirroredId) {
+ defaultValueMirroredId--;
+ }
// push empty label for default value tick
ticksLabels.insertAt(defaultValueId, '');
// push empty to mirrored position
ticksLabels.insertAt(defaultValueMirroredId, '');
// for saving correct sliding need to add value to mirrored position which is average between previous
// and next value
- ticks.insertAt(defaultValueMirroredId, (ticks[defaultValueMirroredId] + ticks[defaultValueMirroredId - 1]) / 2);
+ ticks.insertAt(defaultValueMirroredId, this.valueForTick((ticks[defaultValueMirroredId] + ticks[defaultValueMirroredId - 1]) / 2));
// get new index for default value
defaultValueId = ticks.indexOf(defaultValue);
} else {
@@ -288,7 +292,6 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
return val + self.get('unitLabel');
}
});
-
slider.on('change', function (obj) {
var val = self.get('mirrorValueParseFunction')(obj.newValue);
self.set('config.value', '' + self.configValueByWidget(val));
http://git-wip-us.apache.org/repos/asf/ambari/blob/1da29560/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js b/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
index ebf2d10..b894a1d 100644
--- a/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
+++ b/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
@@ -70,7 +70,7 @@ describe('App.SliderConfigWidgetView', function () {
valueAttributes: Em.Object.create({
type: 'float',
minimum: '0',
- maximum: '100',
+ maximum: '100'
}),
widget: Em.Object.create({
type: 'slider',
@@ -99,7 +99,7 @@ describe('App.SliderConfigWidgetView', function () {
valueAttributes: Em.Object.create({
type: 'float',
minimum: '0',
- maximum: '0.8',
+ maximum: '0.8'
}),
widget: Em.Object.create({
type: 'slider',
@@ -172,4 +172,88 @@ describe('App.SliderConfigWidgetView', function () {
});
});
+ describe('#initSlider', function() {
+ beforeEach(function() {
+ this.view = App.SliderConfigWidgetView;
+ });
+
+ afterEach(function() {
+ this.view.destroy();
+ this.view = null;
+ });
+
+ var tests = [
+ {
+ viewSetup: {
+ minMirrorValue: 20,
+ maxMirrorValue: 100,
+ widgetDefaultValue: 30,
+ config: Em.Object.create({
+ stackConfigProperty: Em.Object.create({
+ valueAttributes: { type: 'float' },
+ widget: { units: [ { 'unit-name': "percent"}]}
+ })
+ })
+ },
+ e: {
+ ticks: [20,30,40,60,80,90,100],
+ ticksLabels: ['20 %', '', '', '60 %', '', '', '100 %']
+ }
+ },
+ {
+ viewSetup: {
+ minMirrorValue: 5,
+ maxMirrorValue: 50,
+ widgetDefaultValue: 35,
+ config: Em.Object.create({
+ stackConfigProperty: Em.Object.create({
+ valueAttributes: { type: 'int' },
+ widget: { units: [ { 'unit-name': "int"}]}
+ })
+ })
+ },
+ e: {
+ ticks: [5, 16, 22, 28, 35, 39, 50],
+ ticksLabels: ['5 ','', '', '28 ', '', '', '50 ']
+ }
+ }
+ ];
+
+ tests.forEach(function(test) {
+ it('should generate ticks: {0} - tick labels: {1}'.format(test.e.ticks, test.e.ticksLabels), function() {
+ var ticks, ticksLabels;
+ this.view = this.view.create(test.viewSetup);
+ var sliderCopy= window.Slider.prototype;
+ window.Slider = function(a, b) {
+ ticks = b.ticks;
+ ticksLabels = b.ticks_labels;
+ return {
+ on: function() {
+ return this;
+ }
+ };
+ };
+ sinon.stub(this.view, '$')
+ .withArgs('input.slider-input').returns([])
+ .withArgs('.ui-slider-wrapper:eq(0) .slider-tick').returns({
+ eq: function() {return this;},
+ addClass: function() {return this;},
+ on: function() {return this;},
+ append: function() {return this;},
+ find: function() {return this;},
+ css: function() {return this;},
+ width: function() {},
+ last: function() { return this;},
+ hide: function() { return this;}
+ });
+ this.view.willInsertElement();
+ this.view.initSlider();
+ window.Slider.prototype = sliderCopy;
+ this.view.$.restore();
+ expect(ticks.toArray()).to.be.eql(test.e.ticks);
+ expect(ticksLabels.toArray()).to.be.eql(test.e.ticksLabels);
+ });
+ });
+ });
+
});