Skip to content

Commit a3da0ef

Browse files
author
OpenShift Bot
authored
Merge pull request #1123 from spadgett/quota-page-sort
Merged by openshift-bot
2 parents e9ab6af + 7082229 commit a3da0ef

File tree

4 files changed

+87
-23
lines changed

4 files changed

+87
-23
lines changed

app/scripts/controllers/quota.js

+54
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,72 @@ angular.module('openshiftConsole')
4444
return used >= hard;
4545
};
4646

47+
// Order the table rows first in the order of the donuts above the table,
48+
// then alphabetically by humanized label.
49+
var humanizeQuotaResource = $filter('humanizeQuotaResource');
50+
var compareResourceType = function(left, right) {
51+
// CPU Request
52+
if (left === 'cpu' || left === 'requests.cpu') {
53+
return right === 'cpu' || right === 'requests.cpu' ? 0 : -1;
54+
}
55+
if (right === 'cpu' || right === 'requests.cpu') {
56+
return 1;
57+
}
58+
59+
// Memory Request
60+
if (left === 'memory' || left === 'requests.memory') {
61+
return right === 'memory' || right === 'requests.memory' ? 0 : -1;
62+
}
63+
if (right === 'memory' || right === 'requests.memory') {
64+
return 1;
65+
}
66+
67+
// CPU Limit
68+
if (left === 'limits.cpu') {
69+
return right === 'limits.cpu' ? 0 : -1;
70+
}
71+
if (right === 'limits.cpu') {
72+
return 1;
73+
}
74+
75+
// Memory Limit
76+
if (left === 'limits.memory') {
77+
return right === 'limits.memory' ? 0 : -1;
78+
}
79+
if (right === 'limits.memory') {
80+
return 1;
81+
}
82+
83+
left = humanizeQuotaResource(left);
84+
right = humanizeQuotaResource(right);
85+
return left.localeCompare(right);
86+
};
87+
88+
var orderTypes = function(quotas) {
89+
var orderedTypesByQuota = {};
90+
_.each(quotas, function(quota) {
91+
var specHard = _.get(quota, 'spec.quota.hard') || _.get(quota, 'spec.hard');
92+
var orderedTypes = _.keys(specHard).sort(compareResourceType);
93+
orderedTypesByQuota[quota.metadata.name] = orderedTypes;
94+
});
95+
96+
return orderedTypesByQuota;
97+
};
98+
4799
ProjectsService
48100
.get($routeParams.project)
49101
.then(_.spread(function(project, context) {
50102
$scope.project = project;
51103

52104
DataService.list("resourcequotas", context, function(quotas) {
53105
$scope.quotas = quotas.by("metadata.name");
106+
$scope.orderedTypesByQuota = orderTypes($scope.quotas);
54107
Logger.log("quotas", $scope.quotas);
55108
});
56109

57110
DataService.list("appliedclusterresourcequotas", context, function(quotas) {
58111
$scope.clusterQuotas = quotas.by("metadata.name");
112+
$scope.orderedTypesByClusterQuota = orderTypes($scope.clusterQuotas);
59113
$scope.namespaceUsageByClusterQuota = {};
60114
_.each($scope.clusterQuotas, function(quota, quotaName) {
61115
if (quota.status) {

app/views/quota.html

+10-10
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ <h3 class="text-center">Memory <small>Limit</small></h3>
6767
<table class="table">
6868
<thead>
6969
<th>Resource Type</th>
70-
<th>Used (this project)</th>
71-
<th>Used (all projects)</th>
70+
<th>Used (This Project)</th>
71+
<th>Used (All Projects)</th>
7272
<th>Max</th>
7373
</thead>
7474
<tbody>
@@ -81,16 +81,16 @@ <h3 class="text-center">Memory <small>Limit</small></h3>
8181
<!-- Don't show quotas for type `resourcequotas`. They are frequently at limit,
8282
which is not something to worry about, and only a cluster admin can create
8383
those resources anyway. -->
84-
<tr ng-repeat="(resourceType, specMax) in quota.spec.quota.hard"
84+
<tr ng-repeat="resourceType in orderedTypesByClusterQuota[quota.metadata.name]"
8585
ng-if="resourceType !== 'resourcequotas'"
8686
ng-class="{
8787
warning: isAtLimit(quota, resourceType),
88-
disabled: (quota.status.total.hard[resourceType] || specMax) === '0'
88+
disabled: (quota.status.total.hard[resourceType] || quota.spec.quota.hard[resourceType]) === '0'
8989
}">
9090
<td>
9191
{{resourceType | humanizeQuotaResource : true}}
9292
<span ng-if="isAtLimit(quota, resourceType)" data-toggle="tooltip" title="Quota limit reached." class="pficon pficon-warning-triangle-o warnings-popover"></span>
93-
<span ng-if="(quota.status.total.hard[resourceType] || specMax) === '0'"
93+
<span ng-if="(quota.status.total.hard[resourceType] || quota.spec.quota.hard[resourceType]) === '0'"
9494
data-toggle="tooltip"
9595
title="You are not allowed to create resources of this type."
9696
class="pficon pficon-info warnings-popover"></span>
@@ -104,7 +104,7 @@ <h3 class="text-center">Memory <small>Limit</small></h3>
104104
<span ng-if="quota.status.total.used">{{quota.status.total.used[resourceType] | usageWithUnits : resourceType}}</span>
105105
</td>
106106
<td>
107-
<span ng-if="!quota.status.total.hard">{{specMax | usageWithUnits : resourceType}}</span>
107+
<span ng-if="!quota.status.total.hard">{{quota.spec.quota.hard[resourceType] | usageWithUnits : resourceType}}</span>
108108
<span ng-if="quota.status.total.hard">{{quota.status.total.hard[resourceType] | usageWithUnits : resourceType}}</span>
109109
</td>
110110
</tr>
@@ -172,16 +172,16 @@ <h3 class="text-center">Memory <small>Limit</small></h3>
172172
<!-- Don't show quotas for type `resourcequotas`. They are frequently at limit,
173173
which is not something to worry about, and only a cluster admin can create
174174
those resources anyway. -->
175-
<tr ng-repeat="(resourceType, specMax) in quota.spec.hard"
175+
<tr ng-repeat="resourceType in orderedTypesByQuota[quota.metadata.name]"
176176
ng-if="resourceType !== 'resourcequotas'"
177177
ng-class="{
178178
warning: isAtLimit(quota, resourceType),
179-
disabled: (quota.status.hard[resourceType] || specMax) === '0'
179+
disabled: (quota.status.hard[resourceType] || quota.spec.hard[resourceType]) === '0'
180180
}">
181181
<td>
182182
{{resourceType | humanizeQuotaResource : true}}
183183
<span ng-if="isAtLimit(quota, resourceType)" data-toggle="tooltip" title="Quota limit reached." class="pficon pficon-warning-triangle-o warnings-popover"></span>
184-
<span ng-if="(quota.status.hard[resourceType] || specMax) === '0'"
184+
<span ng-if="(quota.status.hard[resourceType] || quota.spec.hard[resourceType]) === '0'"
185185
data-toggle="tooltip"
186186
title="You are not allowed to create resources of this type."
187187
class="pficon pficon-info warnings-popover"></span>
@@ -191,7 +191,7 @@ <h3 class="text-center">Memory <small>Limit</small></h3>
191191
<span ng-if="quota.status.used">{{quota.status.used[resourceType] | usageWithUnits : resourceType}}</span>
192192
</td>
193193
<td>
194-
<span ng-if="!quota.status.hard">{{specMax | usageWithUnits : resourceType}}</span>
194+
<span ng-if="!quota.status.hard">{{quota.spec.hard[resourceType] | usageWithUnits : resourceType}}</span>
195195
<span ng-if="quota.status.hard">{{quota.status.hard[resourceType] | usageWithUnits : resourceType}}</span>
196196
</td>
197197
</tr>

dist/scripts/scripts.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -4996,11 +4996,21 @@ var c = a.status.total || a.status, d = h(_.get(c, [ "hard", b ]));
49964996
if (!d) return !1;
49974997
var e = h(_.get(c, [ "used", b ]));
49984998
return !!e && e >= d;
4999-
}, e.get(b.project).then(_.spread(function(a, e) {
4999+
};
5000+
var i = a("humanizeQuotaResource"), j = function(a, b) {
5001+
return "cpu" === a || "requests.cpu" === a ? "cpu" === b || "requests.cpu" === b ? 0 :-1 :"cpu" === b || "requests.cpu" === b ? 1 :"memory" === a || "requests.memory" === a ? "memory" === b || "requests.memory" === b ? 0 :-1 :"memory" === b || "requests.memory" === b ? 1 :"limits.cpu" === a ? "limits.cpu" === b ? 0 :-1 :"limits.cpu" === b ? 1 :"limits.memory" === a ? "limits.memory" === b ? 0 :-1 :"limits.memory" === b ? 1 :(a = i(a), b = i(b), a.localeCompare(b));
5002+
}, k = function(a) {
5003+
var b = {};
5004+
return _.each(a, function(a) {
5005+
var c = _.get(a, "spec.quota.hard") || _.get(a, "spec.hard"), d = _.keys(c).sort(j);
5006+
b[a.metadata.name] = d;
5007+
}), b;
5008+
};
5009+
e.get(b.project).then(_.spread(function(a, e) {
50005010
c.project = a, d.list("resourcequotas", e, function(a) {
5001-
c.quotas = a.by("metadata.name"), f.log("quotas", c.quotas);
5011+
c.quotas = a.by("metadata.name"), c.orderedTypesByQuota = k(c.quotas), f.log("quotas", c.quotas);
50025012
}), d.list("appliedclusterresourcequotas", e, function(a) {
5003-
c.clusterQuotas = a.by("metadata.name"), c.namespaceUsageByClusterQuota = {}, _.each(c.clusterQuotas, function(a, d) {
5013+
c.clusterQuotas = a.by("metadata.name"), c.orderedTypesByClusterQuota = k(c.clusterQuotas), c.namespaceUsageByClusterQuota = {}, _.each(c.clusterQuotas, function(a, d) {
50045014
if (a.status) {
50055015
var e = _.find(a.status.namespaces, {
50065016
namespace:b.project

dist/scripts/templates.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -11684,8 +11684,8 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
1168411684
"<table class=\"table\">\n" +
1168511685
"<thead>\n" +
1168611686
"<th>Resource Type</th>\n" +
11687-
"<th>Used (this project)</th>\n" +
11688-
"<th>Used (all projects)</th>\n" +
11687+
"<th>Used (This Project)</th>\n" +
11688+
"<th>Used (All Projects)</th>\n" +
1168911689
"<th>Max</th>\n" +
1169011690
"</thead>\n" +
1169111691
"<tbody>\n" +
@@ -11696,14 +11696,14 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
1169611696
"</td>\n" +
1169711697
"</tr>\n" +
1169811698
"\n" +
11699-
"<tr ng-repeat=\"(resourceType, specMax) in quota.spec.quota.hard\" ng-if=\"resourceType !== 'resourcequotas'\" ng-class=\"{\n" +
11699+
"<tr ng-repeat=\"resourceType in orderedTypesByClusterQuota[quota.metadata.name]\" ng-if=\"resourceType !== 'resourcequotas'\" ng-class=\"{\n" +
1170011700
" warning: isAtLimit(quota, resourceType),\n" +
11701-
" disabled: (quota.status.total.hard[resourceType] || specMax) === '0'\n" +
11701+
" disabled: (quota.status.total.hard[resourceType] || quota.spec.quota.hard[resourceType]) === '0'\n" +
1170211702
" }\">\n" +
1170311703
"<td>\n" +
1170411704
"{{resourceType | humanizeQuotaResource : true}}\n" +
1170511705
"<span ng-if=\"isAtLimit(quota, resourceType)\" data-toggle=\"tooltip\" title=\"Quota limit reached.\" class=\"pficon pficon-warning-triangle-o warnings-popover\"></span>\n" +
11706-
"<span ng-if=\"(quota.status.total.hard[resourceType] || specMax) === '0'\" data-toggle=\"tooltip\" title=\"You are not allowed to create resources of this type.\" class=\"pficon pficon-info warnings-popover\"></span>\n" +
11706+
"<span ng-if=\"(quota.status.total.hard[resourceType] || quota.spec.quota.hard[resourceType]) === '0'\" data-toggle=\"tooltip\" title=\"You are not allowed to create resources of this type.\" class=\"pficon pficon-info warnings-popover\"></span>\n" +
1170711707
"</td>\n" +
1170811708
"<td>\n" +
1170911709
"<span ng-if=\"!namespaceUsageByClusterQuota[quota.metadata.name].used\">&mdash;</span>\n" +
@@ -11714,7 +11714,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
1171411714
"<span ng-if=\"quota.status.total.used\">{{quota.status.total.used[resourceType] | usageWithUnits : resourceType}}</span>\n" +
1171511715
"</td>\n" +
1171611716
"<td>\n" +
11717-
"<span ng-if=\"!quota.status.total.hard\">{{specMax | usageWithUnits : resourceType}}</span>\n" +
11717+
"<span ng-if=\"!quota.status.total.hard\">{{quota.spec.quota.hard[resourceType] | usageWithUnits : resourceType}}</span>\n" +
1171811718
"<span ng-if=\"quota.status.total.hard\">{{quota.status.total.hard[resourceType] | usageWithUnits : resourceType}}</span>\n" +
1171911719
"</td>\n" +
1172011720
"</tr>\n" +
@@ -11778,21 +11778,21 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
1177811778
"</td>\n" +
1177911779
"</tr>\n" +
1178011780
"\n" +
11781-
"<tr ng-repeat=\"(resourceType, specMax) in quota.spec.hard\" ng-if=\"resourceType !== 'resourcequotas'\" ng-class=\"{\n" +
11781+
"<tr ng-repeat=\"resourceType in orderedTypesByQuota[quota.metadata.name]\" ng-if=\"resourceType !== 'resourcequotas'\" ng-class=\"{\n" +
1178211782
" warning: isAtLimit(quota, resourceType),\n" +
11783-
" disabled: (quota.status.hard[resourceType] || specMax) === '0'\n" +
11783+
" disabled: (quota.status.hard[resourceType] || quota.spec.hard[resourceType]) === '0'\n" +
1178411784
" }\">\n" +
1178511785
"<td>\n" +
1178611786
"{{resourceType | humanizeQuotaResource : true}}\n" +
1178711787
"<span ng-if=\"isAtLimit(quota, resourceType)\" data-toggle=\"tooltip\" title=\"Quota limit reached.\" class=\"pficon pficon-warning-triangle-o warnings-popover\"></span>\n" +
11788-
"<span ng-if=\"(quota.status.hard[resourceType] || specMax) === '0'\" data-toggle=\"tooltip\" title=\"You are not allowed to create resources of this type.\" class=\"pficon pficon-info warnings-popover\"></span>\n" +
11788+
"<span ng-if=\"(quota.status.hard[resourceType] || quota.spec.hard[resourceType]) === '0'\" data-toggle=\"tooltip\" title=\"You are not allowed to create resources of this type.\" class=\"pficon pficon-info warnings-popover\"></span>\n" +
1178911789
"</td>\n" +
1179011790
"<td>\n" +
1179111791
"<span ng-if=\"!quota.status.used\">&mdash;</span>\n" +
1179211792
"<span ng-if=\"quota.status.used\">{{quota.status.used[resourceType] | usageWithUnits : resourceType}}</span>\n" +
1179311793
"</td>\n" +
1179411794
"<td>\n" +
11795-
"<span ng-if=\"!quota.status.hard\">{{specMax | usageWithUnits : resourceType}}</span>\n" +
11795+
"<span ng-if=\"!quota.status.hard\">{{quota.spec.hard[resourceType] | usageWithUnits : resourceType}}</span>\n" +
1179611796
"<span ng-if=\"quota.status.hard\">{{quota.status.hard[resourceType] | usageWithUnits : resourceType}}</span>\n" +
1179711797
"</td>\n" +
1179811798
"</tr>\n" +

0 commit comments

Comments
 (0)