-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathsettings.js
139 lines (127 loc) · 5.57 KB
/
settings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'use strict';
/* jshint unused: false */
/**
* @ngdoc function
* @name openshiftConsole.controller:SettingsController
* @description
* # ProjectController
* Controller of the openshiftConsole
*/
angular.module('openshiftConsole')
.controller('SettingsController', function ($routeParams, $scope, DataService, ProjectsService, AlertMessageService, $filter, $location, LabelFilter, $timeout, Logger, annotationFilter, annotationNameFilter) {
$scope.projectName = $routeParams.project;
$scope.limitRanges = {};
$scope.limitsByType = {};
$scope.labelSuggestions = {};
$scope.alerts = $scope.alerts || {};
$scope.quotaHelp = "Limits resource usage within this project.";
$scope.emptyMessageLimitRanges = "Loading...";
$scope.limitRangeHelp = "Defines minimum and maximum constraints for runtime resources such as memory and CPU.";
$scope.renderOptions = $scope.renderOptions || {};
$scope.renderOptions.hideFilterWidget = true;
var watches = [];
ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
var editableFields = function(resource) {
return {
description: annotationFilter(resource, 'description'),
displayName: annotationFilter(resource, 'displayName')
};
};
var mergeEditable = function(resource, editable) {
var toSubmit = angular.copy(resource);
toSubmit.metadata.annotations[annotationNameFilter('description')] = editable.description;
toSubmit.metadata.annotations[annotationNameFilter('displayName')] = editable.displayName;
return toSubmit;
};
angular.extend($scope, {
project: project,
editableFields: editableFields(project),
show: {
editing: false
},
actions: {
canSubmit: false
},
canSubmit: function(bool) {
$scope.actions.canSubmit = bool;
},
setEditing: function(bool) {
$scope.show.editing = bool;
},
cancel: function() {
$scope.setEditing(false);
$scope.editableFields = editableFields(project);
},
update: function() {
$scope.setEditing(false);
ProjectsService
.update($routeParams.project, mergeEditable(project, $scope.editableFields))
.then(function(updated) {
project = $scope.project = updated;
$scope.editableFields = editableFields(updated);
$scope.$emit('project.settings.update', updated);
}, function(result) {
$scope.editableFields = editableFields(project);
$scope.alerts["update"] = {
type: "error",
message: "An error occurred while updating the project",
details: $filter('getErrorDetails')(result)
};
});
}
});
DataService.list("resourcequotas", context, function(quotas) {
$scope.quotas = quotas.by("metadata.name");
Logger.log("quotas", $scope.quotas);
});
DataService.list("appliedclusterresourcequotas", context, function(quotas) {
$scope.clusterQuotas = quotas.by("metadata.name");
$scope.namespaceUsageByClusterQuota = {};
_.each($scope.clusterQuotas, function(quota, quotaName) {
if (quota.status) {
var namespaceUsage = _.find(quota.status.namespaces, { namespace: $routeParams.project });
$scope.namespaceUsageByClusterQuota[quotaName] = namespaceUsage.status;
}
});
Logger.log("cluster quotas", $scope.clusterQuotas);
});
DataService.list("limitranges", context, function(limitRanges) {
$scope.limitRanges = limitRanges.by("metadata.name");
$scope.emptyMessageLimitRanges = "There are no limit ranges set on this project.";
// Convert to a sane format for a view to a build a table with rows per resource type
angular.forEach($scope.limitRanges, function(limitRange, name){
$scope.limitsByType[name] = {};
angular.forEach(limitRange.spec.limits, function(limit) {
// We have nested types, top level type is something like "Container"
var typeLimits = $scope.limitsByType[name][limit.type] = {};
angular.forEach(limit.max, function(value, type) {
typeLimits[type] = typeLimits[type] || {};
typeLimits[type].max = value;
});
angular.forEach(limit.min, function(value, type) {
typeLimits[type] = typeLimits[type] || {};
typeLimits[type].min = value;
});
angular.forEach(limit["default"], function(value, type) {
typeLimits[type] = typeLimits[type] || {};
typeLimits[type]["default"] = value;
});
angular.forEach(limit.defaultRequest, function(value, type) {
typeLimits[type] = typeLimits[type] || {};
typeLimits[type].defaultRequest = value;
});
angular.forEach(limit.maxLimitRequestRatio, function(value, type) {
typeLimits[type] = typeLimits[type] || {};
typeLimits[type].maxLimitRequestRatio = value;
});
});
});
Logger.log("limitRanges", $scope.limitRanges);
});
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
}));
});