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/06/12 14:32:57 UTC
ambari git commit: AMBARI-11877. Min/Max value for Sliders should be
proportional to the step_increment (onechiporenko)
Repository: ambari
Updated Branches:
refs/heads/trunk de59d01c3 -> 25322e999
AMBARI-11877. Min/Max value for Sliders should be proportional to the step_increment (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/25322e99
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/25322e99
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/25322e99
Branch: refs/heads/trunk
Commit: 25322e999eb2709901ea618e5db88027bc24e469
Parents: de59d01
Author: Oleg Nechiporenko <on...@apache.org>
Authored: Fri Jun 12 15:31:26 2015 +0300
Committer: Oleg Nechiporenko <on...@apache.org>
Committed: Fri Jun 12 15:31:26 2015 +0300
----------------------------------------------------------------------
.../widgets/slider_config_widget_view.js | 27 ++++++++++++----
.../widgets/slider_config_widget_view_test.js | 34 ++++++++++++++++++++
2 files changed, 55 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/25322e99/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 6f6b9e3..4eb6add 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
@@ -290,8 +290,11 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
parseFunction = this.get('parseFunction'),
ticks = [this.valueForTick(this.get('minMirrorValue'))],
ticksLabels = [],
+ maxMirrorValue = this.get('maxMirrorValue'),
+ minMirrorValue = this.get('minMirrorValue'),
+ mirrorStep = this.get('mirrorStep'),
recommendedValue = this.valueForTick(+this.get('widgetRecommendedValue')),
- range = this.get('maxMirrorValue') - this.get('minMirrorValue'),
+ range = Math.floor((maxMirrorValue - minMirrorValue) / mirrorStep) * mirrorStep,
// for little odd numbers in range 4..23 and widget type 'int' use always 4 ticks
isSmallInt = this.get('unitType') == 'int' && range > 4 && range < 23 && range % 2 == 1,
recommendedValueMirroredId,
@@ -299,12 +302,12 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
// ticks and labels
for (var i = 1; i <= 3; i++) {
- var val = this.get('minMirrorValue') + range * (i / (isSmallInt ? 3 : 4));
+ var val = minMirrorValue + this.valueForTickProportionalToStep(range * (i / (isSmallInt ? 3 : 4)));
// if value's type is float, ticks may be float too
- ticks.push(this.valueForTick(val));
+ ticks.push(val);
}
- ticks.push(this.valueForTick(this.get('maxMirrorValue')));
+ ticks.push(this.valueForTick(maxMirrorValue));
ticks = ticks.uniq();
ticks.forEach(function (tick, index, items) {
ticksLabels.push((items.length < 5 || index % 2 === 0 || items.length - 1 == index) ? tick + ' ' + self.get('unitLabel') : '');
@@ -313,7 +316,7 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
ticks = ticks.uniq();
// default marker should be added only if recommendedValue is in range [min, max]
- if (recommendedValue <= this.get('maxMirrorValue') && recommendedValue >= this.get('minMirrorValue') && recommendedValue != '') {
+ if (recommendedValue <= maxMirrorValue && recommendedValue >= minMirrorValue && recommendedValue != '') {
// process additional tick for default value if it not defined in previous computation
if (!ticks.contains(recommendedValue)) {
// push default value
@@ -357,7 +360,7 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
ticks: ticks,
tooltip: 'always',
ticks_labels: ticksLabels,
- step: this.get('mirrorStep'),
+ step: mirrorStep,
formatter: function(val) {
if (Em.isArray(val)) {
return val[0] + self.get('unitLabel');
@@ -429,6 +432,18 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
* @returns {Number}
*/
valueForTick: function(val) {
+ return this.get('unitType') === 'int' ? Math.round(val) : parseFloat(val.toFixed(3));
+ },
+
+ /**
+ * Convert value according to property attribute unit
+ * Also returned value is proportional to the <code>mirrorStep</code>
+ *
+ * @param {Number} val
+ * @private
+ * @returns {Number}
+ */
+ valueForTickProportionalToStep: function (val) {
if (this.get('unitType') === 'int') {
return Math.round(val);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25322e99/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 e4e8a7b..2d2b98e 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
@@ -330,6 +330,40 @@ describe('App.SliderConfigWidgetView', function () {
ticks: [0,2,6,12,17,20,23],
ticksLabels: ['0 ', '', '', '12 ', '', '', '23 ']
}
+ },
+ {
+ viewSetup: {
+ minMirrorValue: 1,
+ maxMirrorValue: 30,
+ widgetRecommendedValue: 1,
+ config: Em.Object.create({
+ stackConfigProperty: Em.Object.create({
+ valueAttributes: { unit: "B", type: "int", minimum: "1048576", maximum: "31457280", increment_step: "262144" },
+ widget: { units: [ { 'unit-name': "MB"}]}
+ })
+ })
+ },
+ e: {
+ ticks: [1, 8.25, 15.5, 22.75, 30],
+ ticksLabels: ["1 MB", "", "15.5 MB", "", "30 MB"]
+ }
+ },
+ {
+ viewSetup: {
+ minMirrorValue: 1,
+ maxMirrorValue: 100,
+ widgetRecommendedValue: 10,
+ config: Em.Object.create({
+ stackConfigProperty: Em.Object.create({
+ valueAttributes: {unit: "B", type: "int", minimum: "1073741824", maximum: "107374182400", increment_step: "1073741824"},
+ widget: { units: [ { 'unit-name': "GB"}]}
+ })
+ })
+ },
+ e: {
+ ticks: [1, 10, 26, 51, 75, 87.5, 100],
+ ticksLabels: ["1 GB", "", "", "51 GB", "", "", "100 GB"]
+ }
}
];