Skip to content

Improve quota table sorting #1123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions app/scripts/controllers/quota.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,72 @@ angular.module('openshiftConsole')
return used >= hard;
};

// Order the table rows first in the order of the donuts above the table,
// then alphabetically by humanized label.
var humanizeQuotaResource = $filter('humanizeQuotaResource');
var compareResourceType = function(left, right) {
// CPU Request
if (left === 'cpu' || left === 'requests.cpu') {
return right === 'cpu' || right === 'requests.cpu' ? 0 : -1;
}
if (right === 'cpu' || right === 'requests.cpu') {
return 1;
}

// Memory Request
if (left === 'memory' || left === 'requests.memory') {
return right === 'memory' || right === 'requests.memory' ? 0 : -1;
}
if (right === 'memory' || right === 'requests.memory') {
return 1;
}

// CPU Limit
if (left === 'limits.cpu') {
return right === 'limits.cpu' ? 0 : -1;
}
if (right === 'limits.cpu') {
return 1;
}

// Memory Limit
if (left === 'limits.memory') {
return right === 'limits.memory' ? 0 : -1;
}
if (right === 'limits.memory') {
return 1;
}

left = humanizeQuotaResource(left);
right = humanizeQuotaResource(right);
return left.localeCompare(right);
};

var orderTypes = function(quotas) {
var orderedTypesByQuota = {};
_.each(quotas, function(quota) {
var specHard = _.get(quota, 'spec.quota.hard') || _.get(quota, 'spec.hard');
var orderedTypes = _.keys(specHard).sort(compareResourceType);
orderedTypesByQuota[quota.metadata.name] = orderedTypes;
});

return orderedTypesByQuota;
};

ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;

DataService.list("resourcequotas", context, function(quotas) {
$scope.quotas = quotas.by("metadata.name");
$scope.orderedTypesByQuota = orderTypes($scope.quotas);
Logger.log("quotas", $scope.quotas);
});

DataService.list("appliedclusterresourcequotas", context, function(quotas) {
$scope.clusterQuotas = quotas.by("metadata.name");
$scope.orderedTypesByClusterQuota = orderTypes($scope.clusterQuotas);
$scope.namespaceUsageByClusterQuota = {};
_.each($scope.clusterQuotas, function(quota, quotaName) {
if (quota.status) {
Expand Down
20 changes: 10 additions & 10 deletions app/views/quota.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ <h3 class="text-center">Memory <small>Limit</small></h3>
<table class="table">
<thead>
<th>Resource Type</th>
<th>Used (this project)</th>
<th>Used (all projects)</th>
<th>Used (This Project)</th>
<th>Used (All Projects)</th>
<th>Max</th>
</thead>
<tbody>
Expand All @@ -81,16 +81,16 @@ <h3 class="text-center">Memory <small>Limit</small></h3>
<!-- Don't show quotas for type `resourcequotas`. They are frequently at limit,
which is not something to worry about, and only a cluster admin can create
those resources anyway. -->
<tr ng-repeat="(resourceType, specMax) in quota.spec.quota.hard"
<tr ng-repeat="resourceType in orderedTypesByClusterQuota[quota.metadata.name]"
ng-if="resourceType !== 'resourcequotas'"
ng-class="{
warning: isAtLimit(quota, resourceType),
disabled: (quota.status.total.hard[resourceType] || specMax) === '0'
disabled: (quota.status.total.hard[resourceType] || quota.spec.quota.hard[resourceType]) === '0'
}">
<td>
{{resourceType | humanizeQuotaResource : true}}
<span ng-if="isAtLimit(quota, resourceType)" data-toggle="tooltip" title="Quota limit reached." class="pficon pficon-warning-triangle-o warnings-popover"></span>
<span ng-if="(quota.status.total.hard[resourceType] || specMax) === '0'"
<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>
Expand All @@ -104,7 +104,7 @@ <h3 class="text-center">Memory <small>Limit</small></h3>
<span ng-if="quota.status.total.used">{{quota.status.total.used[resourceType] | usageWithUnits : resourceType}}</span>
</td>
<td>
<span ng-if="!quota.status.total.hard">{{specMax | usageWithUnits : resourceType}}</span>
<span ng-if="!quota.status.total.hard">{{quota.spec.quota.hard[resourceType] | usageWithUnits : resourceType}}</span>
<span ng-if="quota.status.total.hard">{{quota.status.total.hard[resourceType] | usageWithUnits : resourceType}}</span>
</td>
</tr>
Expand Down Expand Up @@ -172,16 +172,16 @@ <h3 class="text-center">Memory <small>Limit</small></h3>
<!-- Don't show quotas for type `resourcequotas`. They are frequently at limit,
which is not something to worry about, and only a cluster admin can create
those resources anyway. -->
<tr ng-repeat="(resourceType, specMax) in quota.spec.hard"
<tr ng-repeat="resourceType in orderedTypesByQuota[quota.metadata.name]"
ng-if="resourceType !== 'resourcequotas'"
ng-class="{
warning: isAtLimit(quota, resourceType),
disabled: (quota.status.hard[resourceType] || specMax) === '0'
disabled: (quota.status.hard[resourceType] || quota.spec.hard[resourceType]) === '0'
}">
<td>
{{resourceType | humanizeQuotaResource : true}}
<span ng-if="isAtLimit(quota, resourceType)" data-toggle="tooltip" title="Quota limit reached." class="pficon pficon-warning-triangle-o warnings-popover"></span>
<span ng-if="(quota.status.hard[resourceType] || specMax) === '0'"
<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>
Expand All @@ -191,7 +191,7 @@ <h3 class="text-center">Memory <small>Limit</small></h3>
<span ng-if="quota.status.used">{{quota.status.used[resourceType] | usageWithUnits : resourceType}}</span>
</td>
<td>
<span ng-if="!quota.status.hard">{{specMax | usageWithUnits : resourceType}}</span>
<span ng-if="!quota.status.hard">{{quota.spec.hard[resourceType] | usageWithUnits : resourceType}}</span>
<span ng-if="quota.status.hard">{{quota.status.hard[resourceType] | usageWithUnits : resourceType}}</span>
</td>
</tr>
Expand Down
16 changes: 13 additions & 3 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4994,11 +4994,21 @@ var c = a.status.total || a.status, d = h(_.get(c, [ "hard", b ]));
if (!d) return !1;
var e = h(_.get(c, [ "used", b ]));
return !!e && e >= d;
}, e.get(b.project).then(_.spread(function(a, e) {
};
var i = a("humanizeQuotaResource"), j = function(a, b) {
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));
}, k = function(a) {
var b = {};
return _.each(a, function(a) {
var c = _.get(a, "spec.quota.hard") || _.get(a, "spec.hard"), d = _.keys(c).sort(j);
b[a.metadata.name] = d;
}), b;
};
e.get(b.project).then(_.spread(function(a, e) {
c.project = a, d.list("resourcequotas", e, function(a) {
c.quotas = a.by("metadata.name"), f.log("quotas", c.quotas);
c.quotas = a.by("metadata.name"), c.orderedTypesByQuota = k(c.quotas), f.log("quotas", c.quotas);
}), d.list("appliedclusterresourcequotas", e, function(a) {
c.clusterQuotas = a.by("metadata.name"), c.namespaceUsageByClusterQuota = {}, _.each(c.clusterQuotas, function(a, d) {
c.clusterQuotas = a.by("metadata.name"), c.orderedTypesByClusterQuota = k(c.clusterQuotas), c.namespaceUsageByClusterQuota = {}, _.each(c.clusterQuotas, function(a, d) {
if (a.status) {
var e = _.find(a.status.namespaces, {
namespace:b.project
Expand Down
20 changes: 10 additions & 10 deletions dist/scripts/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -11684,8 +11684,8 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"<table class=\"table\">\n" +
"<thead>\n" +
"<th>Resource Type</th>\n" +
"<th>Used (this project)</th>\n" +
"<th>Used (all projects)</th>\n" +
"<th>Used (This Project)</th>\n" +
"<th>Used (All Projects)</th>\n" +
"<th>Max</th>\n" +
"</thead>\n" +
"<tbody>\n" +
Expand All @@ -11696,14 +11696,14 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"</td>\n" +
"</tr>\n" +
"\n" +
"<tr ng-repeat=\"(resourceType, specMax) in quota.spec.quota.hard\" ng-if=\"resourceType !== 'resourcequotas'\" ng-class=\"{\n" +
"<tr ng-repeat=\"resourceType in orderedTypesByClusterQuota[quota.metadata.name]\" ng-if=\"resourceType !== 'resourcequotas'\" ng-class=\"{\n" +
" warning: isAtLimit(quota, resourceType),\n" +
" disabled: (quota.status.total.hard[resourceType] || specMax) === '0'\n" +
" disabled: (quota.status.total.hard[resourceType] || quota.spec.quota.hard[resourceType]) === '0'\n" +
" }\">\n" +
"<td>\n" +
"{{resourceType | humanizeQuotaResource : true}}\n" +
"<span ng-if=\"isAtLimit(quota, resourceType)\" data-toggle=\"tooltip\" title=\"Quota limit reached.\" class=\"pficon pficon-warning-triangle-o warnings-popover\"></span>\n" +
"<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" +
"<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" +
"</td>\n" +
"<td>\n" +
"<span ng-if=\"!namespaceUsageByClusterQuota[quota.metadata.name].used\">&mdash;</span>\n" +
Expand All @@ -11714,7 +11714,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"<span ng-if=\"quota.status.total.used\">{{quota.status.total.used[resourceType] | usageWithUnits : resourceType}}</span>\n" +
"</td>\n" +
"<td>\n" +
"<span ng-if=\"!quota.status.total.hard\">{{specMax | usageWithUnits : resourceType}}</span>\n" +
"<span ng-if=\"!quota.status.total.hard\">{{quota.spec.quota.hard[resourceType] | usageWithUnits : resourceType}}</span>\n" +
"<span ng-if=\"quota.status.total.hard\">{{quota.status.total.hard[resourceType] | usageWithUnits : resourceType}}</span>\n" +
"</td>\n" +
"</tr>\n" +
Expand Down Expand Up @@ -11778,21 +11778,21 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"</td>\n" +
"</tr>\n" +
"\n" +
"<tr ng-repeat=\"(resourceType, specMax) in quota.spec.hard\" ng-if=\"resourceType !== 'resourcequotas'\" ng-class=\"{\n" +
"<tr ng-repeat=\"resourceType in orderedTypesByQuota[quota.metadata.name]\" ng-if=\"resourceType !== 'resourcequotas'\" ng-class=\"{\n" +
" warning: isAtLimit(quota, resourceType),\n" +
" disabled: (quota.status.hard[resourceType] || specMax) === '0'\n" +
" disabled: (quota.status.hard[resourceType] || quota.spec.hard[resourceType]) === '0'\n" +
" }\">\n" +
"<td>\n" +
"{{resourceType | humanizeQuotaResource : true}}\n" +
"<span ng-if=\"isAtLimit(quota, resourceType)\" data-toggle=\"tooltip\" title=\"Quota limit reached.\" class=\"pficon pficon-warning-triangle-o warnings-popover\"></span>\n" +
"<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" +
"<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" +
"</td>\n" +
"<td>\n" +
"<span ng-if=\"!quota.status.used\">&mdash;</span>\n" +
"<span ng-if=\"quota.status.used\">{{quota.status.used[resourceType] | usageWithUnits : resourceType}}</span>\n" +
"</td>\n" +
"<td>\n" +
"<span ng-if=\"!quota.status.hard\">{{specMax | usageWithUnits : resourceType}}</span>\n" +
"<span ng-if=\"!quota.status.hard\">{{quota.spec.hard[resourceType] | usageWithUnits : resourceType}}</span>\n" +
"<span ng-if=\"quota.status.hard\">{{quota.status.hard[resourceType] | usageWithUnits : resourceType}}</span>\n" +
"</td>\n" +
"</tr>\n" +
Expand Down