Skip to content

Commit

Permalink
Use toast notifications when creating and editing config maps
Browse files Browse the repository at this point in the history
  • Loading branch information
spadgett committed Jun 12, 2017
1 parent cdf2198 commit fb8c2e1
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 52 deletions.
28 changes: 23 additions & 5 deletions app/scripts/controllers/createConfigMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ angular.module('openshiftConsole')
AuthorizationService,
DataService,
Navigate,
NotificationsService,
ProjectsService) {
$scope.alerts = {};
$scope.projectName = $routeParams.project;

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

var hideErrorNotifications = function() {
NotificationsService.hideNotification("create-config-map-error");
};

var navigateBack = function() {
$window.history.back();
};

$scope.cancel = function() {
hideErrorNotifications();
navigateBack();
};

ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
Expand All @@ -58,19 +71,24 @@ angular.module('openshiftConsole')

$scope.createConfigMap = function() {
if ($scope.createConfigMapForm.$valid) {
hideErrorNotifications();
$scope.disableInputs = true;

DataService.create('configmaps', null, $scope.configMap, context)
.then(function() { // Success
NotificationsService.addNotification({
type: "success",
message: "Config map " + $scope.configMap.metadata.name + " successfully created."
});
// Return to the previous page.
$window.history.back();
navigateBack();
}, function(result) { // Failure
$scope.disableInputs = false;
$scope.alerts['create-config-map'] = {
NotificationsService.addNotification({
id: "create-config-map-error",
type: "error",
message: "An error occurred creating the config map.",
details: $filter('getErrorDetails')(result)
};
});
});
}
};
Expand Down
36 changes: 25 additions & 11 deletions app/scripts/controllers/edit/configMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ angular.module('openshiftConsole')
DataService,
BreadcrumbsService,
Navigate,
NotificationsService,
ProjectsService) {
var watches = [];
$scope.alerts = {};
$scope.forms = {};
$scope.projectName = $routeParams.project;

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

var hideErrorNotifications = function() {
NotificationsService.hideNotification("edit-config-map-error");
};

var navigateBack = function() {
$window.history.back();
};

$scope.cancel = function() {
hideErrorNotifications();
navigateBack();
};

ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
Expand All @@ -54,29 +67,30 @@ angular.module('openshiftConsole')
$scope.resourceDeleted = action === "DELETED";
}));
}, function(e) {
$scope.loaded = true;
$scope.alerts["load"] = {
type: "error",
message: "The config map details could not be loaded.",
details: $filter('getErrorDetails')(e)
};
Navigate.toErrorPage("Could not load config map " + $routeParams.configMap + ". " +
$filter('getErrorDetails')(e));
});

$scope.updateConfigMap = function() {
if ($scope.forms.editConfigMapForm.$valid) {
hideErrorNotifications();
$scope.disableInputs = true;

DataService.update('configmaps', $scope.configMap.metadata.name, $scope.configMap, context)
.then(function() { // Success
// Return to the previous page
$window.history.back();
NotificationsService.addNotification({
type: "success",
message: "Config map " + $scope.configMap.metadata.name + " successfully updated."
});
navigateBack();
}, function(result) { // Failure
$scope.disableInputs = false;
$scope.alerts['create-config-map'] = {
NotificationsService.addNotification({
id: "edit-config-map-error",
type: "error",
message: "An error occurred updating the config map.",
details: $filter('getErrorDetails')(result)
};
});
});
}
};
Expand Down
3 changes: 1 addition & 2 deletions app/views/create-config-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<div class="row">
<div class="col-md-10 col-md-offset-1">
<breadcrumbs breadcrumbs="breadcrumbs"></breadcrumbs>
<alerts alerts="alerts"></alerts>
<div class="mar-top-xl">
<h1>Create Config Map</h1>
<div class="help-block">
Expand All @@ -28,7 +27,7 @@ <h1>Create Config Map</h1>
ng-click="createConfigMap()"
ng-disabled="createConfigMapForm.$invalid || disableInputs"
value="">Create</button>
<a class="btn btn-default btn-lg" href="#" back>Cancel</a>
<a class="btn btn-default btn-lg" href="" ng-click="cancel()" role="button">Cancel</a>
</div>
</fieldset>
</form>
Expand Down
3 changes: 1 addition & 2 deletions app/views/edit/config-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<div class="row">
<div class="col-md-10 col-md-offset-1">
<breadcrumbs breadcrumbs="breadcrumbs"></breadcrumbs>
<alerts alerts="alerts"></alerts>
<div class="mar-top-xl">
<h1>Edit Config Map {{configMap.metadata.name}}</h1>
<div class="help-block">
Expand Down Expand Up @@ -41,7 +40,7 @@ <h1>Edit Config Map {{configMap.metadata.name}}</h1>
ng-click="updateConfigMap()"
ng-disabled="forms.editConfigMapForm.$invalid || forms.editConfigMapForm.$pristine || disableInputs || resourceChanged || resourceDeleted"
value="">Save</button>
<a class="btn btn-default btn-lg" href="#" back>Cancel</a>
<a class="btn btn-default btn-lg" href="" ng-click="cancel()" role="button">Cancel</a>
</div>
</fieldset>
</form>
Expand Down
74 changes: 46 additions & 28 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6270,32 +6270,44 @@ a.loaded = !0, a.error = b;
e.unwatchAll(g);
});
}));
} ]), angular.module("openshiftConsole").controller("CreateConfigMapController", [ "$filter", "$routeParams", "$scope", "$window", "AuthorizationService", "DataService", "Navigate", "ProjectsService", function(a, b, c, d, e, f, g, h) {
c.alerts = {}, c.projectName = b.project, c.breadcrumbs = [ {
} ]), angular.module("openshiftConsole").controller("CreateConfigMapController", [ "$filter", "$routeParams", "$scope", "$window", "AuthorizationService", "DataService", "Navigate", "NotificationsService", "ProjectsService", function(a, b, c, d, e, f, g, h, i) {
c.projectName = b.project, c.breadcrumbs = [ {
title:c.projectName,
link:"project/" + c.projectName
}, {
title:"Config Maps",
link:"project/" + c.projectName + "/browse/config-maps"
}, {
title:"Create Config Map"
} ], h.get(b.project).then(_.spread(function(h, i) {
return c.project = h, c.breadcrumbs[0].title = a("displayName")(h), e.canI("configmaps", "create", b.project) ? (c.configMap = {
} ];
var j = function() {
h.hideNotification("create-config-map-error");
}, k = function() {
d.history.back();
};
c.cancel = function() {
j(), k();
}, i.get(b.project).then(_.spread(function(d, i) {
return c.project = d, c.breadcrumbs[0].title = a("displayName")(d), e.canI("configmaps", "create", b.project) ? (c.configMap = {
apiVersion:"v1",
kind:"ConfigMap",
metadata:{
namespace:b.project
},
data:{}
}, void (c.createConfigMap = function() {
c.createConfigMapForm.$valid && (c.disableInputs = !0, f.create("configmaps", null, c.configMap, i).then(function() {
d.history.back();
c.createConfigMapForm.$valid && (j(), c.disableInputs = !0, f.create("configmaps", null, c.configMap, i).then(function() {
h.addNotification({
type:"success",
message:"Config map " + c.configMap.metadata.name + " successfully created."
}), k();
}, function(b) {
c.disableInputs = !1, c.alerts["create-config-map"] = {
c.disableInputs = !1, h.addNotification({
id:"create-config-map-error",
type:"error",
message:"An error occurred creating the config map.",
details:a("getErrorDetails")(b)
};
});
}));
})) :void g.toErrorPage("You do not have authority to create config maps in project " + b.project + ".", "access_denied");
}));
Expand Down Expand Up @@ -6940,47 +6952,53 @@ details:b("getErrorDetails")(c)
}, a.$on("$destroy", function() {
h.unwatchAll(q);
});
} ]), angular.module("openshiftConsole").controller("EditConfigMapController", [ "$filter", "$routeParams", "$scope", "$window", "DataService", "BreadcrumbsService", "Navigate", "ProjectsService", function(a, b, c, d, e, f, g, h) {
var i = [];
c.alerts = {}, c.forms = {}, c.projectName = b.project, c.breadcrumbs = f.getBreadcrumbs({
} ]), angular.module("openshiftConsole").controller("EditConfigMapController", [ "$filter", "$routeParams", "$scope", "$window", "DataService", "BreadcrumbsService", "Navigate", "NotificationsService", "ProjectsService", function(a, b, c, d, e, f, g, h, i) {
var j = [];
c.forms = {}, c.projectName = b.project, c.breadcrumbs = f.getBreadcrumbs({
name:b.configMap,
kind:"ConfigMap",
namespace:b.project,
includeProject:!0,
subpage:"Edit Config Map"
});
var j = function(a) {
var k = function(a) {
return _.get(a, "metadata.resourceVersion");
}, l = function() {
h.hideNotification("edit-config-map-error");
}, m = function() {
d.history.back();
};
h.get(b.project).then(_.spread(function(g, h) {
e.get("configmaps", b.configMap, h).then(function(a) {
c.cancel = function() {
l(), m();
}, i.get(b.project).then(_.spread(function(d, i) {
e.get("configmaps", b.configMap, i).then(function(a) {
c.loaded = !0, c.breadcrumbs = f.getBreadcrumbs({
name:b.configMap,
object:a,
includeProject:!0,
project:g,
project:d,
subpage:"Edit Config Map"
}), c.configMap = a, i.push(e.watchObject("configmaps", b.configMap, h, function(a, b) {
c.resourceChanged = j(a) !== j(c.configMap), c.resourceDeleted = "DELETED" === b;
}), c.configMap = a, j.push(e.watchObject("configmaps", b.configMap, i, function(a, b) {
c.resourceChanged = k(a) !== k(c.configMap), c.resourceDeleted = "DELETED" === b;
}));
}, function(b) {
c.loaded = !0, c.alerts.load = {
type:"error",
message:"The config map details could not be loaded.",
details:a("getErrorDetails")(b)
};
}, function(c) {
g.toErrorPage("Could not load config map " + b.configMap + ". " + a("getErrorDetails")(c));
}), c.updateConfigMap = function() {
c.forms.editConfigMapForm.$valid && (c.disableInputs = !0, e.update("configmaps", c.configMap.metadata.name, c.configMap, h).then(function() {
d.history.back();
c.forms.editConfigMapForm.$valid && (l(), c.disableInputs = !0, e.update("configmaps", c.configMap.metadata.name, c.configMap, i).then(function() {
h.addNotification({
type:"success",
message:"Config map " + c.configMap.metadata.name + " successfully updated."
}), m();
}, function(b) {
c.disableInputs = !1, c.alerts["create-config-map"] = {
c.disableInputs = !1, h.addNotification({
id:"edit-config-map-error",
type:"error",
message:"An error occurred updating the config map.",
details:a("getErrorDetails")(b)
};
});
}));
}, c.$on("$destroy", function() {
e.unwatchAll(i);
e.unwatchAll(j);
});
}));
} ]), 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) {
Expand Down
6 changes: 2 additions & 4 deletions dist/scripts/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -4516,7 +4516,6 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"<div class=\"row\">\n" +
"<div class=\"col-md-10 col-md-offset-1\">\n" +
"<breadcrumbs breadcrumbs=\"breadcrumbs\"></breadcrumbs>\n" +
"<alerts alerts=\"alerts\"></alerts>\n" +
"<div class=\"mar-top-xl\">\n" +
"<h1>Create Config Map</h1>\n" +
"<div class=\"help-block\">\n" +
Expand All @@ -4527,7 +4526,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"<edit-config-map model=\"configMap\" show-name-input=\"true\"></edit-config-map>\n" +
"<div class=\"button-group gutter-top gutter-bottom\">\n" +
"<button type=\"submit\" class=\"btn btn-primary btn-lg\" ng-click=\"createConfigMap()\" ng-disabled=\"createConfigMapForm.$invalid || disableInputs\" value=\"\">Create</button>\n" +
"<a class=\"btn btn-default btn-lg\" href=\"#\" back>Cancel</a>\n" +
"<a class=\"btn btn-default btn-lg\" href=\"\" ng-click=\"cancel()\" role=\"button\">Cancel</a>\n" +
"</div>\n" +
"</fieldset>\n" +
"</form>\n" +
Expand Down Expand Up @@ -9294,7 +9293,6 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"<div class=\"row\">\n" +
"<div class=\"col-md-10 col-md-offset-1\">\n" +
"<breadcrumbs breadcrumbs=\"breadcrumbs\"></breadcrumbs>\n" +
"<alerts alerts=\"alerts\"></alerts>\n" +
"<div class=\"mar-top-xl\">\n" +
"<h1>Edit Config Map {{configMap.metadata.name}}</h1>\n" +
"<div class=\"help-block\">\n" +
Expand All @@ -9317,7 +9315,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"<edit-config-map model=\"configMap\"></edit-config-map>\n" +
"<div class=\"button-group gutter-top gutter-bottom\">\n" +
"<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" +
"<a class=\"btn btn-default btn-lg\" href=\"#\" back>Cancel</a>\n" +
"<a class=\"btn btn-default btn-lg\" href=\"\" ng-click=\"cancel()\" role=\"button\">Cancel</a>\n" +
"</div>\n" +
"</fieldset>\n" +
"</form>\n" +
Expand Down

0 comments on commit fb8c2e1

Please sign in to comment.