Skip to content

Commit 4938784

Browse files
author
OpenShift Bot
authored
Merge pull request #1657 from spadgett/hpa-toasts
Merged by openshift-bot
2 parents 1f2c340 + f309227 commit 4938784

File tree

4 files changed

+97
-60
lines changed

4 files changed

+97
-60
lines changed

app/scripts/controllers/edit/autoscaler.js

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ angular.module('openshiftConsole')
2020
HPAService,
2121
MetricsService,
2222
Navigate,
23+
NotificationsService,
2324
ProjectsService,
2425
keyValueEditorUtils) {
2526
if (!$routeParams.kind || !$routeParams.name) {
@@ -62,16 +63,19 @@ angular.module('openshiftConsole')
6263
$scope.metricsWarning = !available;
6364
});
6465

65-
$scope.alerts = {};
66-
6766
var getErrorDetails = $filter('getErrorDetails');
6867

69-
var displayError = function(errorMessage, result) {
70-
$scope.alerts['autoscaling'] = {
71-
type: "error",
72-
message: errorMessage,
73-
details: getErrorDetails(result)
74-
};
68+
var navigateBack = function() {
69+
$window.history.back();
70+
};
71+
72+
var hideErrorNotifications = function() {
73+
NotificationsService.hideNotification('edit-hpa-error');
74+
};
75+
76+
$scope.cancel = function() {
77+
hideErrorNotifications();
78+
navigateBack();
7579
};
7680

7781
ProjectsService
@@ -88,6 +92,7 @@ angular.module('openshiftConsole')
8892

8993
var createHPA = function() {
9094
$scope.disableInputs = true;
95+
hideErrorNotifications();
9196
var hpa = {
9297
apiVersion: "autoscaling/v1",
9398
kind: "HorizontalPodAutoscaler",
@@ -112,12 +117,21 @@ angular.module('openshiftConsole')
112117
resource: 'horizontalpodautoscalers',
113118
group: 'autoscaling'
114119
}, null, hpa, context)
115-
.then(function() { // Success
116-
// Return to the previous page
117-
$window.history.back();
120+
.then(function(hpa) { // Success
121+
NotificationsService.addNotification({
122+
type: 'success',
123+
message: 'Horizontal pod autoscaler ' + hpa.metadata.name + ' successfully created.'
124+
});
125+
126+
navigateBack();
118127
}, function(result) { // Failure
119128
$scope.disableInputs = false;
120-
displayError('An error occurred creating the horizontal pod autoscaler.', result);
129+
NotificationsService.addNotification({
130+
id: 'edit-hpa-error',
131+
type: 'error',
132+
message: 'An error occurred creating the horizontal pod autoscaler.',
133+
details: getErrorDetails(result)
134+
});
121135
});
122136
};
123137

@@ -134,12 +148,21 @@ angular.module('openshiftConsole')
134148
resource: 'horizontalpodautoscalers',
135149
group: 'autoscaling'
136150
}, hpa.metadata.name, hpa, context)
137-
.then(function() { // Success
138-
// Return to the previous page
139-
$window.history.back();
151+
.then(function(hpa) { // Success
152+
NotificationsService.addNotification({
153+
type: 'success',
154+
message: 'Horizontal pod autoscaler ' + hpa.metadata.name + ' successfully updated.'
155+
});
156+
157+
navigateBack();
140158
}, function(result) { // Failure
141159
$scope.disableInputs = false;
142-
displayError('An error occurred updating horizontal pod autoscaler "' + hpa.metadata.name + '".', result);
160+
NotificationsService.addNotification({
161+
id: 'edit-hpa-error',
162+
type: 'error',
163+
message: 'An error occurred creating the horizontal pod autoscaler.',
164+
details: getErrorDetails(result)
165+
});
143166
});
144167
};
145168

app/views/edit/autoscaler.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<breadcrumbs breadcrumbs="breadcrumbs"></breadcrumbs>
1313
<div class="row">
1414
<div class="col-md-12">
15-
<alerts alerts="alerts"></alerts>
1615
<div ng-if="!targetKind || !targetName || !project" class="mar-top-md">
1716
Loading...
1817
</div>
@@ -67,7 +66,7 @@ <h1>
6766
ng-disabled="form.$invalid || form.$pristine">
6867
Save
6968
</button>
70-
<a href="" class="btn btn-default btn-lg" back>Cancel</a>
69+
<a href="" ng-click="cancel()" class="btn btn-default btn-lg" role="button">Cancel</a>
7170
</div>
7271
</fieldset>
7372
</form>

dist/scripts/scripts.js

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7213,37 +7213,37 @@ A(), f.history.back();
72137213
}, a.$on("$destroy", function() {
72147214
i.unwatchAll(s);
72157215
});
7216-
} ]), angular.module("openshiftConsole").controller("EditAutoscalerController", [ "$scope", "$filter", "$routeParams", "$window", "APIService", "AuthorizationService", "BreadcrumbsService", "DataService", "HPAService", "MetricsService", "Navigate", "ProjectsService", "keyValueEditorUtils", function(a, b, c, d, e, f, g, h, i, j, k, l, m) {
7216+
} ]), angular.module("openshiftConsole").controller("EditAutoscalerController", [ "$scope", "$filter", "$routeParams", "$window", "APIService", "AuthorizationService", "BreadcrumbsService", "DataService", "HPAService", "MetricsService", "Navigate", "NotificationsService", "ProjectsService", "keyValueEditorUtils", function(a, b, c, d, e, f, g, h, i, j, k, l, m, n) {
72177217
if (!c.kind || !c.name) return void k.toErrorPage("Kind or name parameter missing.");
7218-
var n = [ "Deployment", "DeploymentConfig", "HorizontalPodAutoscaler", "ReplicaSet", "ReplicationController" ];
7219-
if (!_.includes(n, c.kind)) return void k.toErrorPage("Autoscaling not supported for kind " + c.kind + ".");
7218+
var o = [ "Deployment", "DeploymentConfig", "HorizontalPodAutoscaler", "ReplicaSet", "ReplicationController" ];
7219+
if (!_.includes(o, c.kind)) return void k.toErrorPage("Autoscaling not supported for kind " + c.kind + ".");
72207220
a.kind = c.kind, a.name = c.name, "HorizontalPodAutoscaler" === c.kind ? a.disableInputs = !0 :(a.targetKind = c.kind, a.targetName = c.name), a.autoscaling = {
72217221
name:a.name
72227222
}, a.labels = [], j.isAvailable().then(function(b) {
72237223
a.metricsWarning = !b;
7224-
}), a.alerts = {};
7225-
var o = b("getErrorDetails"), p = function(b, c) {
7226-
a.alerts.autoscaling = {
7227-
type:"error",
7228-
message:b,
7229-
details:o(c)
7230-
};
7224+
});
7225+
var p = b("getErrorDetails"), q = function() {
7226+
d.history.back();
7227+
}, r = function() {
7228+
l.hideNotification("edit-hpa-error");
72317229
};
7232-
l.get(c.project).then(_.spread(function(b, j) {
7230+
a.cancel = function() {
7231+
r(), q();
7232+
}, m.get(c.project).then(_.spread(function(b, d) {
72337233
a.project = b;
7234-
var l = "HorizontalPodAutoscaler" === c.kind ? "update" :"create";
7234+
var j = "HorizontalPodAutoscaler" === c.kind ? "update" :"create";
72357235
if (!f.canI({
72367236
resource:"horizontalpodautoscalers",
72377237
group:"autoscaling"
7238-
}, l, c.project)) return void k.toErrorPage("You do not have authority to " + l + " horizontal pod autoscalers in project " + c.project + ".", "access_denied");
7239-
var n = function() {
7240-
a.disableInputs = !0;
7238+
}, j, c.project)) return void k.toErrorPage("You do not have authority to " + j + " horizontal pod autoscalers in project " + c.project + ".", "access_denied");
7239+
var m = function() {
7240+
a.disableInputs = !0, r();
72417241
var b = {
72427242
apiVersion:"autoscaling/v1",
72437243
kind:"HorizontalPodAutoscaler",
72447244
metadata:{
72457245
name:a.autoscaling.name,
7246-
labels:m.mapEntries(m.compactEntries(a.labels))
7246+
labels:n.mapEntries(n.compactEntries(a.labels))
72477247
},
72487248
spec:{
72497249
scaleTargetRef:{
@@ -7260,40 +7260,56 @@ targetCPUUtilizationPercentage:a.autoscaling.targetCPU || a.autoscaling.defaultT
72607260
h.create({
72617261
resource:"horizontalpodautoscalers",
72627262
group:"autoscaling"
7263-
}, null, b, j).then(function() {
7264-
d.history.back();
7263+
}, null, b, d).then(function(a) {
7264+
l.addNotification({
7265+
type:"success",
7266+
message:"Horizontal pod autoscaler " + a.metadata.name + " successfully created."
7267+
}), q();
72657268
}, function(b) {
7266-
a.disableInputs = !1, p("An error occurred creating the horizontal pod autoscaler.", b);
7269+
a.disableInputs = !1, l.addNotification({
7270+
id:"edit-hpa-error",
7271+
type:"error",
7272+
message:"An error occurred creating the horizontal pod autoscaler.",
7273+
details:p(b)
7274+
});
72677275
});
72687276
}, o = function(b) {
7269-
a.disableInputs = !0, b = angular.copy(b), b.metadata.labels = m.mapEntries(m.compactEntries(a.labels)), b.spec.minReplicas = a.autoscaling.minReplicas, b.spec.maxReplicas = a.autoscaling.maxReplicas, b.spec.targetCPUUtilizationPercentage = a.autoscaling.targetCPU || a.autoscaling.defaultTargetCPU || null, h.update({
7277+
a.disableInputs = !0, b = angular.copy(b), b.metadata.labels = n.mapEntries(n.compactEntries(a.labels)), b.spec.minReplicas = a.autoscaling.minReplicas, b.spec.maxReplicas = a.autoscaling.maxReplicas, b.spec.targetCPUUtilizationPercentage = a.autoscaling.targetCPU || a.autoscaling.defaultTargetCPU || null, h.update({
72707278
resource:"horizontalpodautoscalers",
72717279
group:"autoscaling"
7272-
}, b.metadata.name, b, j).then(function() {
7273-
d.history.back();
7274-
}, function(c) {
7275-
a.disableInputs = !1, p('An error occurred updating horizontal pod autoscaler "' + b.metadata.name + '".', c);
7280+
}, b.metadata.name, b, d).then(function(a) {
7281+
l.addNotification({
7282+
type:"success",
7283+
message:"Horizontal pod autoscaler " + a.metadata.name + " successfully updated."
7284+
}), q();
7285+
}, function(b) {
7286+
a.disableInputs = !1, l.addNotification({
7287+
id:"edit-hpa-error",
7288+
type:"error",
7289+
message:"An error occurred creating the horizontal pod autoscaler.",
7290+
details:p(b)
72767291
});
7277-
}, q = {};
7278-
q = "HorizontalPodAutoscaler" === c.kind ? {
7292+
});
7293+
}, s = {};
7294+
s = "HorizontalPodAutoscaler" === c.kind ? {
72797295
resource:"horizontalpodautoscalers",
72807296
group:"autoscaling",
72817297
version:"v1"
72827298
} :{
72837299
resource:e.kindToResource(c.kind),
72847300
group:c.group
7285-
}, h.get(q, c.name, j).then(function(d) {
7286-
if (a.labels = _.map(_.get(d, "metadata.labels", {}), function(a, b) {
7301+
}, h.get(s, c.name, d).then(function(e) {
7302+
if (a.labels = _.map(_.get(e, "metadata.labels", {}), function(a, b) {
72877303
return {
72887304
name:b,
72897305
value:a
72907306
};
7291-
}), "HorizontalPodAutoscaler" === c.kind) a.targetKind = _.get(d, "spec.scaleTargetRef.kind"), a.targetName = _.get(d, "spec.scaleTargetRef.name"), _.assign(a.autoscaling, {
7292-
minReplicas:_.get(d, "spec.minReplicas"),
7293-
maxReplicas:_.get(d, "spec.maxReplicas"),
7294-
targetCPU:_.get(d, "spec.targetCPUUtilizationPercentage")
7307+
}), "HorizontalPodAutoscaler" === c.kind) a.targetKind = _.get(e, "spec.scaleTargetRef.kind"), a.targetName = _.get(e, "spec.scaleTargetRef.name"), _.assign(a.autoscaling, {
7308+
minReplicas:_.get(e, "spec.minReplicas"),
7309+
maxReplicas:_.get(e, "spec.maxReplicas"),
7310+
targetCPU:_.get(e, "spec.targetCPUUtilizationPercentage")
72957311
}), a.disableInputs = !1, a.save = function() {
7296-
o(d);
7312+
o(e);
72977313
}, a.breadcrumbs = g.getBreadcrumbs({
72987314
name:a.targetName,
72997315
kind:a.targetKind,
@@ -7303,17 +7319,17 @@ subpage:"Autoscale",
73037319
includeProject:!0
73047320
}); else {
73057321
a.breadcrumbs = g.getBreadcrumbs({
7306-
object:d,
7322+
object:e,
73077323
project:b,
73087324
subpage:"Autoscale",
73097325
includeProject:!0
7310-
}), a.save = n;
7311-
var e = {}, f = function() {
7312-
var c = _.get(d, "spec.template.spec.containers", []);
7313-
a.showCPURequestWarning = !i.hasCPURequest(c, e, b);
7326+
}), a.save = m;
7327+
var f = {}, j = function() {
7328+
var c = _.get(e, "spec.template.spec.containers", []);
7329+
a.showCPURequestWarning = !i.hasCPURequest(c, f, b);
73147330
};
7315-
h.list("limitranges", j).then(function(a) {
7316-
e = a.by("metadata.name"), f();
7331+
h.list("limitranges", d).then(function(a) {
7332+
f = a.by("metadata.name"), j();
73177333
});
73187334
}
73197335
});

dist/scripts/templates.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8778,7 +8778,6 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
87788778
"<breadcrumbs breadcrumbs=\"breadcrumbs\"></breadcrumbs>\n" +
87798779
"<div class=\"row\">\n" +
87808780
"<div class=\"col-md-12\">\n" +
8781-
"<alerts alerts=\"alerts\"></alerts>\n" +
87828781
"<div ng-if=\"!targetKind || !targetName || !project\" class=\"mar-top-md\">\n" +
87838782
"Loading...\n" +
87848783
"</div>\n" +
@@ -8817,7 +8816,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
88178816
"<button type=\"submit\" class=\"btn btn-primary btn-lg\" ng-disabled=\"form.$invalid || form.$pristine\">\n" +
88188817
"Save\n" +
88198818
"</button>\n" +
8820-
"<a href=\"\" class=\"btn btn-default btn-lg\" back>Cancel</a>\n" +
8819+
"<a href=\"\" ng-click=\"cancel()\" class=\"btn btn-default btn-lg\" role=\"button\">Cancel</a>\n" +
88218820
"</div>\n" +
88228821
"</fieldset>\n" +
88238822
"</form>\n" +

0 commit comments

Comments
 (0)