Skip to content

Commit fb8c2e1

Browse files
committed
Use toast notifications when creating and editing config maps
1 parent cdf2198 commit fb8c2e1

File tree

6 files changed

+98
-52
lines changed

6 files changed

+98
-52
lines changed

app/scripts/controllers/createConfigMap.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ angular.module('openshiftConsole')
1616
AuthorizationService,
1717
DataService,
1818
Navigate,
19+
NotificationsService,
1920
ProjectsService) {
20-
$scope.alerts = {};
2121
$scope.projectName = $routeParams.project;
2222

2323
// TODO: Update BreadcrumbsService to handle create pages.
@@ -35,6 +35,19 @@ angular.module('openshiftConsole')
3535
}
3636
];
3737

38+
var hideErrorNotifications = function() {
39+
NotificationsService.hideNotification("create-config-map-error");
40+
};
41+
42+
var navigateBack = function() {
43+
$window.history.back();
44+
};
45+
46+
$scope.cancel = function() {
47+
hideErrorNotifications();
48+
navigateBack();
49+
};
50+
3851
ProjectsService
3952
.get($routeParams.project)
4053
.then(_.spread(function(project, context) {
@@ -58,19 +71,24 @@ angular.module('openshiftConsole')
5871

5972
$scope.createConfigMap = function() {
6073
if ($scope.createConfigMapForm.$valid) {
74+
hideErrorNotifications();
6175
$scope.disableInputs = true;
62-
6376
DataService.create('configmaps', null, $scope.configMap, context)
6477
.then(function() { // Success
78+
NotificationsService.addNotification({
79+
type: "success",
80+
message: "Config map " + $scope.configMap.metadata.name + " successfully created."
81+
});
6582
// Return to the previous page.
66-
$window.history.back();
83+
navigateBack();
6784
}, function(result) { // Failure
6885
$scope.disableInputs = false;
69-
$scope.alerts['create-config-map'] = {
86+
NotificationsService.addNotification({
87+
id: "create-config-map-error",
7088
type: "error",
7189
message: "An error occurred creating the config map.",
7290
details: $filter('getErrorDetails')(result)
73-
};
91+
});
7492
});
7593
}
7694
};

app/scripts/controllers/edit/configMap.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ angular.module('openshiftConsole')
1616
DataService,
1717
BreadcrumbsService,
1818
Navigate,
19+
NotificationsService,
1920
ProjectsService) {
2021
var watches = [];
21-
$scope.alerts = {};
2222
$scope.forms = {};
2323
$scope.projectName = $routeParams.project;
2424

@@ -34,6 +34,19 @@ angular.module('openshiftConsole')
3434
return _.get(resource, 'metadata.resourceVersion');
3535
};
3636

37+
var hideErrorNotifications = function() {
38+
NotificationsService.hideNotification("edit-config-map-error");
39+
};
40+
41+
var navigateBack = function() {
42+
$window.history.back();
43+
};
44+
45+
$scope.cancel = function() {
46+
hideErrorNotifications();
47+
navigateBack();
48+
};
49+
3750
ProjectsService
3851
.get($routeParams.project)
3952
.then(_.spread(function(project, context) {
@@ -54,29 +67,30 @@ angular.module('openshiftConsole')
5467
$scope.resourceDeleted = action === "DELETED";
5568
}));
5669
}, function(e) {
57-
$scope.loaded = true;
58-
$scope.alerts["load"] = {
59-
type: "error",
60-
message: "The config map details could not be loaded.",
61-
details: $filter('getErrorDetails')(e)
62-
};
70+
Navigate.toErrorPage("Could not load config map " + $routeParams.configMap + ". " +
71+
$filter('getErrorDetails')(e));
6372
});
6473

6574
$scope.updateConfigMap = function() {
6675
if ($scope.forms.editConfigMapForm.$valid) {
76+
hideErrorNotifications();
6777
$scope.disableInputs = true;
6878

6979
DataService.update('configmaps', $scope.configMap.metadata.name, $scope.configMap, context)
7080
.then(function() { // Success
71-
// Return to the previous page
72-
$window.history.back();
81+
NotificationsService.addNotification({
82+
type: "success",
83+
message: "Config map " + $scope.configMap.metadata.name + " successfully updated."
84+
});
85+
navigateBack();
7386
}, function(result) { // Failure
7487
$scope.disableInputs = false;
75-
$scope.alerts['create-config-map'] = {
88+
NotificationsService.addNotification({
89+
id: "edit-config-map-error",
7690
type: "error",
7791
message: "An error occurred updating the config map.",
7892
details: $filter('getErrorDetails')(result)
79-
};
93+
});
8094
});
8195
}
8296
};

app/views/create-config-map.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<div class="row">
1313
<div class="col-md-10 col-md-offset-1">
1414
<breadcrumbs breadcrumbs="breadcrumbs"></breadcrumbs>
15-
<alerts alerts="alerts"></alerts>
1615
<div class="mar-top-xl">
1716
<h1>Create Config Map</h1>
1817
<div class="help-block">
@@ -28,7 +27,7 @@ <h1>Create Config Map</h1>
2827
ng-click="createConfigMap()"
2928
ng-disabled="createConfigMapForm.$invalid || disableInputs"
3029
value="">Create</button>
31-
<a class="btn btn-default btn-lg" href="#" back>Cancel</a>
30+
<a class="btn btn-default btn-lg" href="" ng-click="cancel()" role="button">Cancel</a>
3231
</div>
3332
</fieldset>
3433
</form>

app/views/edit/config-map.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<div class="row">
1313
<div class="col-md-10 col-md-offset-1">
1414
<breadcrumbs breadcrumbs="breadcrumbs"></breadcrumbs>
15-
<alerts alerts="alerts"></alerts>
1615
<div class="mar-top-xl">
1716
<h1>Edit Config Map {{configMap.metadata.name}}</h1>
1817
<div class="help-block">
@@ -41,7 +40,7 @@ <h1>Edit Config Map {{configMap.metadata.name}}</h1>
4140
ng-click="updateConfigMap()"
4241
ng-disabled="forms.editConfigMapForm.$invalid || forms.editConfigMapForm.$pristine || disableInputs || resourceChanged || resourceDeleted"
4342
value="">Save</button>
44-
<a class="btn btn-default btn-lg" href="#" back>Cancel</a>
43+
<a class="btn btn-default btn-lg" href="" ng-click="cancel()" role="button">Cancel</a>
4544
</div>
4645
</fieldset>
4746
</form>

dist/scripts/scripts.js

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6270,32 +6270,44 @@ a.loaded = !0, a.error = b;
62706270
e.unwatchAll(g);
62716271
});
62726272
}));
6273-
} ]), angular.module("openshiftConsole").controller("CreateConfigMapController", [ "$filter", "$routeParams", "$scope", "$window", "AuthorizationService", "DataService", "Navigate", "ProjectsService", function(a, b, c, d, e, f, g, h) {
6274-
c.alerts = {}, c.projectName = b.project, c.breadcrumbs = [ {
6273+
} ]), angular.module("openshiftConsole").controller("CreateConfigMapController", [ "$filter", "$routeParams", "$scope", "$window", "AuthorizationService", "DataService", "Navigate", "NotificationsService", "ProjectsService", function(a, b, c, d, e, f, g, h, i) {
6274+
c.projectName = b.project, c.breadcrumbs = [ {
62756275
title:c.projectName,
62766276
link:"project/" + c.projectName
62776277
}, {
62786278
title:"Config Maps",
62796279
link:"project/" + c.projectName + "/browse/config-maps"
62806280
}, {
62816281
title:"Create Config Map"
6282-
} ], h.get(b.project).then(_.spread(function(h, i) {
6283-
return c.project = h, c.breadcrumbs[0].title = a("displayName")(h), e.canI("configmaps", "create", b.project) ? (c.configMap = {
6282+
} ];
6283+
var j = function() {
6284+
h.hideNotification("create-config-map-error");
6285+
}, k = function() {
6286+
d.history.back();
6287+
};
6288+
c.cancel = function() {
6289+
j(), k();
6290+
}, i.get(b.project).then(_.spread(function(d, i) {
6291+
return c.project = d, c.breadcrumbs[0].title = a("displayName")(d), e.canI("configmaps", "create", b.project) ? (c.configMap = {
62846292
apiVersion:"v1",
62856293
kind:"ConfigMap",
62866294
metadata:{
62876295
namespace:b.project
62886296
},
62896297
data:{}
62906298
}, void (c.createConfigMap = function() {
6291-
c.createConfigMapForm.$valid && (c.disableInputs = !0, f.create("configmaps", null, c.configMap, i).then(function() {
6292-
d.history.back();
6299+
c.createConfigMapForm.$valid && (j(), c.disableInputs = !0, f.create("configmaps", null, c.configMap, i).then(function() {
6300+
h.addNotification({
6301+
type:"success",
6302+
message:"Config map " + c.configMap.metadata.name + " successfully created."
6303+
}), k();
62936304
}, function(b) {
6294-
c.disableInputs = !1, c.alerts["create-config-map"] = {
6305+
c.disableInputs = !1, h.addNotification({
6306+
id:"create-config-map-error",
62956307
type:"error",
62966308
message:"An error occurred creating the config map.",
62976309
details:a("getErrorDetails")(b)
6298-
};
6310+
});
62996311
}));
63006312
})) :void g.toErrorPage("You do not have authority to create config maps in project " + b.project + ".", "access_denied");
63016313
}));
@@ -6940,47 +6952,53 @@ details:b("getErrorDetails")(c)
69406952
}, a.$on("$destroy", function() {
69416953
h.unwatchAll(q);
69426954
});
6943-
} ]), angular.module("openshiftConsole").controller("EditConfigMapController", [ "$filter", "$routeParams", "$scope", "$window", "DataService", "BreadcrumbsService", "Navigate", "ProjectsService", function(a, b, c, d, e, f, g, h) {
6944-
var i = [];
6945-
c.alerts = {}, c.forms = {}, c.projectName = b.project, c.breadcrumbs = f.getBreadcrumbs({
6955+
} ]), angular.module("openshiftConsole").controller("EditConfigMapController", [ "$filter", "$routeParams", "$scope", "$window", "DataService", "BreadcrumbsService", "Navigate", "NotificationsService", "ProjectsService", function(a, b, c, d, e, f, g, h, i) {
6956+
var j = [];
6957+
c.forms = {}, c.projectName = b.project, c.breadcrumbs = f.getBreadcrumbs({
69466958
name:b.configMap,
69476959
kind:"ConfigMap",
69486960
namespace:b.project,
69496961
includeProject:!0,
69506962
subpage:"Edit Config Map"
69516963
});
6952-
var j = function(a) {
6964+
var k = function(a) {
69536965
return _.get(a, "metadata.resourceVersion");
6966+
}, l = function() {
6967+
h.hideNotification("edit-config-map-error");
6968+
}, m = function() {
6969+
d.history.back();
69546970
};
6955-
h.get(b.project).then(_.spread(function(g, h) {
6956-
e.get("configmaps", b.configMap, h).then(function(a) {
6971+
c.cancel = function() {
6972+
l(), m();
6973+
}, i.get(b.project).then(_.spread(function(d, i) {
6974+
e.get("configmaps", b.configMap, i).then(function(a) {
69576975
c.loaded = !0, c.breadcrumbs = f.getBreadcrumbs({
69586976
name:b.configMap,
69596977
object:a,
69606978
includeProject:!0,
6961-
project:g,
6979+
project:d,
69626980
subpage:"Edit Config Map"
6963-
}), c.configMap = a, i.push(e.watchObject("configmaps", b.configMap, h, function(a, b) {
6964-
c.resourceChanged = j(a) !== j(c.configMap), c.resourceDeleted = "DELETED" === b;
6981+
}), c.configMap = a, j.push(e.watchObject("configmaps", b.configMap, i, function(a, b) {
6982+
c.resourceChanged = k(a) !== k(c.configMap), c.resourceDeleted = "DELETED" === b;
69656983
}));
6966-
}, function(b) {
6967-
c.loaded = !0, c.alerts.load = {
6968-
type:"error",
6969-
message:"The config map details could not be loaded.",
6970-
details:a("getErrorDetails")(b)
6971-
};
6984+
}, function(c) {
6985+
g.toErrorPage("Could not load config map " + b.configMap + ". " + a("getErrorDetails")(c));
69726986
}), c.updateConfigMap = function() {
6973-
c.forms.editConfigMapForm.$valid && (c.disableInputs = !0, e.update("configmaps", c.configMap.metadata.name, c.configMap, h).then(function() {
6974-
d.history.back();
6987+
c.forms.editConfigMapForm.$valid && (l(), c.disableInputs = !0, e.update("configmaps", c.configMap.metadata.name, c.configMap, i).then(function() {
6988+
h.addNotification({
6989+
type:"success",
6990+
message:"Config map " + c.configMap.metadata.name + " successfully updated."
6991+
}), m();
69756992
}, function(b) {
6976-
c.disableInputs = !1, c.alerts["create-config-map"] = {
6993+
c.disableInputs = !1, h.addNotification({
6994+
id:"edit-config-map-error",
69776995
type:"error",
69786996
message:"An error occurred updating the config map.",
69796997
details:a("getErrorDetails")(b)
6980-
};
6998+
});
69816999
}));
69827000
}, c.$on("$destroy", function() {
6983-
e.unwatchAll(i);
7001+
e.unwatchAll(j);
69847002
});
69857003
}));
69867004
} ]), angular.module("openshiftConsole").controller("EditDeploymentConfigController", [ "$scope", "$filter", "$location", "$routeParams", "$uibModal", "$window", "AuthorizationService", "BreadcrumbsService", "DataService", "EnvironmentService", "Navigate", "NotificationsService", "ProjectsService", "SecretsService", "keyValueEditorUtils", function(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) {

dist/scripts/templates.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4516,7 +4516,6 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
45164516
"<div class=\"row\">\n" +
45174517
"<div class=\"col-md-10 col-md-offset-1\">\n" +
45184518
"<breadcrumbs breadcrumbs=\"breadcrumbs\"></breadcrumbs>\n" +
4519-
"<alerts alerts=\"alerts\"></alerts>\n" +
45204519
"<div class=\"mar-top-xl\">\n" +
45214520
"<h1>Create Config Map</h1>\n" +
45224521
"<div class=\"help-block\">\n" +
@@ -4527,7 +4526,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
45274526
"<edit-config-map model=\"configMap\" show-name-input=\"true\"></edit-config-map>\n" +
45284527
"<div class=\"button-group gutter-top gutter-bottom\">\n" +
45294528
"<button type=\"submit\" class=\"btn btn-primary btn-lg\" ng-click=\"createConfigMap()\" ng-disabled=\"createConfigMapForm.$invalid || disableInputs\" value=\"\">Create</button>\n" +
4530-
"<a class=\"btn btn-default btn-lg\" href=\"#\" back>Cancel</a>\n" +
4529+
"<a class=\"btn btn-default btn-lg\" href=\"\" ng-click=\"cancel()\" role=\"button\">Cancel</a>\n" +
45314530
"</div>\n" +
45324531
"</fieldset>\n" +
45334532
"</form>\n" +
@@ -9294,7 +9293,6 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
92949293
"<div class=\"row\">\n" +
92959294
"<div class=\"col-md-10 col-md-offset-1\">\n" +
92969295
"<breadcrumbs breadcrumbs=\"breadcrumbs\"></breadcrumbs>\n" +
9297-
"<alerts alerts=\"alerts\"></alerts>\n" +
92989296
"<div class=\"mar-top-xl\">\n" +
92999297
"<h1>Edit Config Map {{configMap.metadata.name}}</h1>\n" +
93009298
"<div class=\"help-block\">\n" +
@@ -9317,7 +9315,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
93179315
"<edit-config-map model=\"configMap\"></edit-config-map>\n" +
93189316
"<div class=\"button-group gutter-top gutter-bottom\">\n" +
93199317
"<button type=\"submit\" class=\"btn btn-primary btn-lg\" ng-click=\"updateConfigMap()\" ng-disabled=\"forms.editConfigMapForm.$invalid || forms.editConfigMapForm.$pristine || disableInputs || resourceChanged || resourceDeleted\" value=\"\">Save</button>\n" +
9320-
"<a class=\"btn btn-default btn-lg\" href=\"#\" back>Cancel</a>\n" +
9318+
"<a class=\"btn btn-default btn-lg\" href=\"\" ng-click=\"cancel()\" role=\"button\">Cancel</a>\n" +
93219319
"</div>\n" +
93229320
"</fieldset>\n" +
93239321
"</form>\n" +

0 commit comments

Comments
 (0)