Skip to content

Commit 05093f6

Browse files
author
OpenShift Bot
authored
Merge pull request #1125 from spadgett/limit-units
Merged by openshift-bot
2 parents 15e4baa + 4c2a622 commit 05093f6

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

app/scripts/directives/editRequestLimit.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ angular.module('openshiftConsole')
2525

2626
// Create a unique ID for `label for` and `aria-describedby` attributes.
2727
scope.id = _.uniqueId('compute-resource-');
28+
scope.input = {};
2829

2930
// If unit is not already in options, add it.
3031
var addUnitOption = function(unit) {
@@ -43,8 +44,8 @@ angular.module('openshiftConsole')
4344
scope.placeholder = defaultAmount;
4445
addUnitOption(defaultUnit);
4546
// Only change selected unit if no value is set.
46-
if (!scope.amount) {
47-
scope.unit = defaultUnit;
47+
if (!scope.input.amount) {
48+
scope.input.unit = defaultUnit;
4849
}
4950
});
5051
if (defaultValue) {
@@ -55,7 +56,7 @@ angular.module('openshiftConsole')
5556
// Set unit options and based on type.
5657
switch (scope.type) {
5758
case 'cpu':
58-
scope.unit = 'm';
59+
scope.input.unit = 'm';
5960
scope.units = [{
6061
value: "m",
6162
label: "millicores"
@@ -65,7 +66,7 @@ angular.module('openshiftConsole')
6566
}];
6667
break;
6768
case 'memory':
68-
scope.unit = 'Mi';
69+
scope.input.unit = 'Mi';
6970
scope.units = [{
7071
value: "M",
7172
label: "MB"
@@ -84,7 +85,7 @@ angular.module('openshiftConsole')
8485

8586
var validateLimitRange = function() {
8687
// Use usageValue filter to normalize units for comparison.
87-
var value = scope.amount && usageValue(scope.amount + scope.unit),
88+
var value = scope.input.amount && usageValue(scope.input.amount + scope.input.unit),
8889
min = scope.limitRangeMin && usageValue(scope.limitRangeMin),
8990
max = scope.limitRangeMax && usageValue(scope.limitRangeMax),
9091
minValid = true,
@@ -112,8 +113,8 @@ angular.module('openshiftConsole')
112113
limitWithinRatio = true;
113114

114115
// Limit is either the value set by the user or the default value if limit is unset.
115-
if (scope.amount) {
116-
limit = usageValue(scope.amount + scope.unit);
116+
if (scope.input.amount) {
117+
limit = usageValue(scope.input.amount + scope.input.unit);
117118
} else if (scope.defaultValue) {
118119
limit = usageValue(scope.defaultValue);
119120
}
@@ -140,25 +141,25 @@ angular.module('openshiftConsole')
140141
ngModel.$render = function() {
141142
var update = _.spread(function(amount, unit) {
142143
if (amount) {
143-
scope.amount = Number(amount);
144-
scope.unit = unit;
144+
scope.input.amount = Number(amount);
145+
scope.input.unit = unit;
145146
// If the unit already set in the resource isn't in the list, add it.
146147
addUnitOption(unit);
147148
} else {
148-
scope.amount = null;
149+
scope.input.amount = null;
149150
}
150151
});
151152
update(amountAndUnit(ngModel.$viewValue, scope.type));
152153
};
153154

154155
// Update model from view.
155-
scope.$watchGroup(['amount', 'unit'], function() {
156+
scope.$watchGroup(['input.amount', 'input.unit'], function() {
156157
validateLimitRange();
157158
validateLimitAgainstRequest();
158-
if (!scope.amount) {
159+
if (!scope.input.amount) {
159160
ngModel.$setViewValue(undefined);
160161
} else {
161-
ngModel.$setViewValue(scope.amount + scope.unit);
162+
ngModel.$setViewValue(scope.input.amount + scope.input.unit);
162163
}
163164
});
164165

app/views/_compute-resource.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
<input type="number"
88
name="amount"
99
ng-attr-id="{{id}}"
10-
ng-model="amount"
10+
ng-model="input.amount"
1111
min="0"
1212
ng-attr-placeholder="{{placeholder}}"
1313
class="form-control"
1414
ng-attr-aria-describedby="{{description ? id + '-help' : undefined}}">
1515
</div>
1616
<div class="resource-unit">
1717
<label class="sr-only" ng-attr-for="{{id}}-unit">Unit</label>
18-
<ui-select search-enabled="false" ng-model="unit" input-id="{{id}}-unit">
18+
<ui-select search-enabled="false" ng-model="input.unit" input-id="{{id}}-unit">
1919
<ui-select-match>{{$select.selected.label}}</ui-select-match>
2020
<ui-select-choices repeat="option.value as option in units">
2121
{{option.label}}
@@ -43,14 +43,14 @@
4343
Limit can't be less than request ({{request | usageWithUnits : type}}).
4444
</div>
4545
<div ng-if="form.amount.$error.limitWithinRatio" class="help-block">
46-
<span ng-if="!amount && !defaultValue">
46+
<span ng-if="!input.amount && !defaultValue">
4747
Limit is required if request is set. (Max Limit/Request Ratio: {{maxLimitRequestRatio}})
4848
</span>
49-
<span ng-if="amount || defaultValue">
49+
<span ng-if="input.amount || defaultValue">
5050
Limit cannot be more than {{maxLimitRequestRatio}} times request value.
5151
(Request: {{request | usageWithUnits : type}},
5252
<!-- Show default if amount is unset. -->
53-
Limit: {{(amount ? (amount + unit) : defaultValue) | usageWithUnits : type}})
53+
Limit: {{(input.amount ? (input.amount + input.unit) : defaultValue) | usageWithUnits : type}})
5454
</span>
5555
</div>
5656
</div>

dist/scripts/scripts.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -12390,7 +12390,7 @@ request:"="
1239012390
templateUrl:"views/_compute-resource.html",
1239112391
link:function(b, c, d, e) {
1239212392
var f = a("usageValue"), g = a("amountAndUnit"), h = a("humanizeUnit");
12393-
b.id = _.uniqueId("compute-resource-");
12393+
b.id = _.uniqueId("compute-resource-"), b.input = {};
1239412394
var i = function(a) {
1239512395
_.some(b.units, {
1239612396
value:a
@@ -12401,12 +12401,12 @@ label:h(a, b.type)
1240112401
};
1240212402
switch (b.$watch("defaultValue", function(a) {
1240312403
var c = _.spread(function(a, c) {
12404-
b.placeholder = a, i(c), b.amount || (b.unit = c);
12404+
b.placeholder = a, i(c), b.input.amount || (b.input.unit = c);
1240512405
});
1240612406
a && c(g(a, b.type));
1240712407
}), b.type) {
1240812408
case "cpu":
12409-
b.unit = "m", b.units = [ {
12409+
b.input.unit = "m", b.units = [ {
1241012410
value:"m",
1241112411
label:"millicores"
1241212412
}, {
@@ -12416,7 +12416,7 @@ label:"cores"
1241612416
break;
1241712417

1241812418
case "memory":
12419-
b.unit = "Mi", b.units = [ {
12419+
b.input.unit = "Mi", b.units = [ {
1242012420
value:"M",
1242112421
label:"MB"
1242212422
}, {
@@ -12431,19 +12431,19 @@ label:"GiB"
1243112431
} ];
1243212432
}
1243312433
var j = function() {
12434-
var a = b.amount && f(b.amount + b.unit), c = b.limitRangeMin && f(b.limitRangeMin), d = b.limitRangeMax && f(b.limitRangeMax), e = !0, g = !0;
12434+
var a = b.input.amount && f(b.input.amount + b.input.unit), c = b.limitRangeMin && f(b.limitRangeMin), d = b.limitRangeMax && f(b.limitRangeMax), e = !0, g = !0;
1243512435
a && c && (e = a >= c), a && d && (g = a <= d), b.form.amount.$setValidity("limitRangeMin", e), b.form.amount.$setValidity("limitRangeMax", g);
1243612436
}, k = function() {
1243712437
var a, c = b.request && f(b.request), d = !0, e = !0;
12438-
b.amount ? a = f(b.amount + b.unit) :b.defaultValue && (a = f(b.defaultValue)), c && a && (d = a >= c, b.maxLimitRequestRatio && (e = a / c <= b.maxLimitRequestRatio)), c && !a && b.maxLimitRequestRatio && (e = !1), b.form.amount.$setValidity("limitLargerThanRequest", d), b.form.amount.$setValidity("limitWithinRatio", e);
12438+
b.input.amount ? a = f(b.input.amount + b.input.unit) :b.defaultValue && (a = f(b.defaultValue)), c && a && (d = a >= c, b.maxLimitRequestRatio && (e = a / c <= b.maxLimitRequestRatio)), c && !a && b.maxLimitRequestRatio && (e = !1), b.form.amount.$setValidity("limitLargerThanRequest", d), b.form.amount.$setValidity("limitWithinRatio", e);
1243912439
};
1244012440
e.$render = function() {
1244112441
var a = _.spread(function(a, c) {
12442-
a ? (b.amount = Number(a), b.unit = c, i(c)) :b.amount = null;
12442+
a ? (b.input.amount = Number(a), b.input.unit = c, i(c)) :b.input.amount = null;
1244312443
});
1244412444
a(g(e.$viewValue, b.type));
12445-
}, b.$watchGroup([ "amount", "unit" ], function() {
12446-
j(), k(), b.amount ? e.$setViewValue(b.amount + b.unit) :e.$setViewValue(void 0);
12445+
}, b.$watchGroup([ "input.amount", "input.unit" ], function() {
12446+
j(), k(), b.input.amount ? e.$setViewValue(b.input.amount + b.input.unit) :e.$setViewValue(void 0);
1244712447
}), b.$watchGroup([ "limitRangeMin", "limitRangeMax" ], j), b.$watch("request", k);
1244812448
}
1244912449
};

dist/scripts/templates.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
7575
"<div class=\"resource-size\" ng-class=\"{ 'has-error': form.$invalid }\">\n" +
7676
"<div class=\"resource-amount\">\n" +
7777
"<label class=\"sr-only\" ng-attr-for=\"{{id}}\">Amount</label>\n" +
78-
"<input type=\"number\" name=\"amount\" ng-attr-id=\"{{id}}\" ng-model=\"amount\" min=\"0\" ng-attr-placeholder=\"{{placeholder}}\" class=\"form-control\" ng-attr-aria-describedby=\"{{description ? id + '-help' : undefined}}\">\n" +
78+
"<input type=\"number\" name=\"amount\" ng-attr-id=\"{{id}}\" ng-model=\"input.amount\" min=\"0\" ng-attr-placeholder=\"{{placeholder}}\" class=\"form-control\" ng-attr-aria-describedby=\"{{description ? id + '-help' : undefined}}\">\n" +
7979
"</div>\n" +
8080
"<div class=\"resource-unit\">\n" +
8181
"<label class=\"sr-only\" ng-attr-for=\"{{id}}-unit\">Unit</label>\n" +
82-
"<ui-select search-enabled=\"false\" ng-model=\"unit\" input-id=\"{{id}}-unit\">\n" +
82+
"<ui-select search-enabled=\"false\" ng-model=\"input.unit\" input-id=\"{{id}}-unit\">\n" +
8383
"<ui-select-match>{{$select.selected.label}}</ui-select-match>\n" +
8484
"<ui-select-choices repeat=\"option.value as option in units\">\n" +
8585
"{{option.label}}\n" +
@@ -107,13 +107,13 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
107107
"Limit can't be less than request ({{request | usageWithUnits : type}}).\n" +
108108
"</div>\n" +
109109
"<div ng-if=\"form.amount.$error.limitWithinRatio\" class=\"help-block\">\n" +
110-
"<span ng-if=\"!amount && !defaultValue\">\n" +
110+
"<span ng-if=\"!input.amount && !defaultValue\">\n" +
111111
"Limit is required if request is set. (Max Limit/Request Ratio: {{maxLimitRequestRatio}})\n" +
112112
"</span>\n" +
113-
"<span ng-if=\"amount || defaultValue\">\n" +
113+
"<span ng-if=\"input.amount || defaultValue\">\n" +
114114
"Limit cannot be more than {{maxLimitRequestRatio}} times request value. (Request: {{request | usageWithUnits : type}},\n" +
115115
"\n" +
116-
"Limit: {{(amount ? (amount + unit) : defaultValue) | usageWithUnits : type}})\n" +
116+
"Limit: {{(input.amount ? (input.amount + input.unit) : defaultValue) | usageWithUnits : type}})\n" +
117117
"</span>\n" +
118118
"</div>\n" +
119119
"</div>\n" +

0 commit comments

Comments
 (0)