Skip to content

Routes - convert form alerts to toast notifications for creating, editing and deleting #1567

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 2 commits into from
Jun 5, 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
21 changes: 18 additions & 3 deletions app/scripts/controllers/createRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ angular.module('openshiftConsole')
AuthorizationService,
DataService,
Navigate,
NotificationsService,
ProjectsService,
keyValueEditorUtils) {
$scope.alerts = {};
$scope.renderOptions = {
hideFilterWidget: true
};
Expand All @@ -46,6 +46,15 @@ angular.module('openshiftConsole')
}
];

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

$scope.cancel = function() {
hideErrorNotifications();
$window.history.back();
};

ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
Expand Down Expand Up @@ -83,6 +92,7 @@ angular.module('openshiftConsole')

$scope.createRoute = function() {
if ($scope.createRouteForm.$valid) {
hideErrorNotifications();
$scope.disableInputs = true;
var serviceName = $scope.routing.to.name;
var labels = keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.labels));
Expand All @@ -102,15 +112,20 @@ angular.module('openshiftConsole')

DataService.create('routes', null, route, context)
.then(function() { // Success
NotificationsService.addNotification({
type: "success",
message: "Route " + route.metadata.name + " was successfully created."
});
// Return to the previous page
$window.history.back();
}, function(result) { // Failure
$scope.disableInputs = false;
$scope.alerts['create-route'] = {
NotificationsService.addNotification({
type: "error",
id: "create-route-error",
message: "An error occurred creating the route.",
details: $filter('getErrorDetails')(result)
};
});
});
}
};
Expand Down
21 changes: 12 additions & 9 deletions app/scripts/controllers/edit/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ angular.module('openshiftConsole')
AuthorizationService,
DataService,
Navigate,
NotificationsService,
ProjectsService,
RoutesService) {
$scope.alerts = {};
$scope.renderOptions = {
hideFilterWidget: true
};
Expand All @@ -41,6 +41,10 @@ angular.module('openshiftConsole')
title: "Edit"
}];

$scope.hideErrorNotifications = function() {
NotificationsService.hideNotification("edit-route-error");
};

ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
Expand Down Expand Up @@ -161,25 +165,24 @@ angular.module('openshiftConsole')

$scope.updateRoute = function() {
if ($scope.form.$valid) {
$scope.hideErrorNotifications();
$scope.disableInputs = true;
var updated = updateRouteFields();
DataService.update('routes', $scope.routeName, updated, context)
.then(function() { // Success
AlertMessageService.addAlert({
name: $scope.routeName,
data: {
type: "success",
message: "Route " + $scope.routeName + " was successfully updated."
}
NotificationsService.addNotification({
type: "success",
message: "Route " + $scope.routeName + " was successfully updated."
});
$location.path($scope.routeURL);
}, function(response) { // Failure
$scope.disableInputs = false;
$scope.alerts['update-route'] = {
NotificationsService.addNotification({
type: "error",
id: "edit-route-error",
message: "An error occurred updating route " + $scope.routeName + ".",
details: $filter('getErrorDetails')(response)
};
});
});
}
};
Expand Down
3 changes: 1 addition & 2 deletions app/views/create-route.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 Route</h1>
<div class="help-block">
Expand Down Expand Up @@ -40,7 +39,7 @@ <h1>Create Route</h1>
ng-click="createRoute()"
ng-disabled="createRouteForm.$invalid || disableInputs || !createRoute"
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()">Cancel</a>
</div>
</fieldset>
</div>
Expand Down
4 changes: 3 additions & 1 deletion app/views/edit/route.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ <h1>Edit Route {{routeName}}</h1>
ng-click="updateRoute()"
ng-disabled="form.$invalid || disableInputs"
value="">Save</button>
<a class="btn btn-default btn-lg" ng-href="{{routeURL}}">Cancel</a>
<a class="btn btn-default btn-lg"
ng-click="hideErrorNotifications()"
ng-href="{{routeURL}}">Cancel</a>
</div>
</fieldset>
</form>
Expand Down
70 changes: 40 additions & 30 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7923,8 +7923,8 @@ d.disableInputs = !1, n(o + " could not be updated.", m(a));
n(o + " could not be loaded.", m(a));
}) :void j.toErrorPage("You do not have authority to update " + o + ".", "access_denied");
}));
} ]), angular.module("openshiftConsole").controller("EditRouteController", [ "$filter", "$location", "$routeParams", "$scope", "AlertMessageService", "AuthorizationService", "DataService", "Navigate", "ProjectsService", "RoutesService", function(a, b, c, d, e, f, g, h, i, j) {
d.alerts = {}, d.renderOptions = {
} ]), angular.module("openshiftConsole").controller("EditRouteController", [ "$filter", "$location", "$routeParams", "$scope", "AlertMessageService", "AuthorizationService", "DataService", "Navigate", "NotificationsService", "ProjectsService", "RoutesService", function(a, b, c, d, e, f, g, h, i, j, k) {
d.renderOptions = {
hideFilterWidget:!0
}, d.projectName = c.project, d.routeName = c.route, d.loading = !0, d.routeURL = h.resourceURL(d.routeName, "Route", d.projectName), d.breadcrumbs = [ {
title:d.projectName,
Expand All @@ -7937,22 +7937,24 @@ title:d.routeName,
link:d.routeURL
}, {
title:"Edit"
} ], i.get(c.project).then(_.spread(function(i, k) {
if (d.project = i, d.breadcrumbs[0].title = a("displayName")(i), !f.canI("routes", "update", c.project)) return void h.toErrorPage("You do not have authority to update route " + c.routeName + ".", "access_denied");
} ], d.hideErrorNotifications = function() {
i.hideNotification("edit-route-error");
}, j.get(c.project).then(_.spread(function(e, j) {
if (d.project = e, d.breadcrumbs[0].title = a("displayName")(e), !f.canI("routes", "update", c.project)) return void h.toErrorPage("You do not have authority to update route " + c.routeName + ".", "access_denied");
var l, m = a("orderByDisplayName"), n = function() {
h.toErrorPage('Editing routes with non-service targets is unsupported. You can edit the route with the "Edit YAML" action instead.');
};
g.get("routes", d.routeName, k).then(function(a) {
g.get("routes", d.routeName, j).then(function(a) {
if ("Service" !== a.spec.to.kind) return void n();
l = angular.copy(a);
var b = _.get(l, "spec.host"), c = "Subdomain" === _.get(l, "spec.wildcardPolicy");
c && (b = "*." + j.getSubdomain(l)), d.routing = {
c && (b = "*." + k.getSubdomain(l)), d.routing = {
host:b,
wildcardPolicy:_.get(l, "spec.wildcardPolicy"),
path:_.get(l, "spec.path"),
targetPort:_.get(l, "spec.port.targetPort"),
tls:angular.copy(_.get(l, "spec.tls"))
}, g.list("services", k).then(function(a) {
}, g.list("services", j).then(function(a) {
d.loading = !1;
var b = a.by("metadata.name");
d.routing.to = l.spec.to, d.routing.alternateServices = [], _.each(_.get(l, "spec.alternateBackends"), function(a) {
Expand Down Expand Up @@ -7980,22 +7982,20 @@ weight:a.weight
};
d.updateRoute = function() {
if (d.form.$valid) {
d.disableInputs = !0;
d.hideErrorNotifications(), d.disableInputs = !0;
var c = o();
g.update("routes", d.routeName, c, k).then(function() {
e.addAlert({
name:d.routeName,
data:{
g.update("routes", d.routeName, c, j).then(function() {
i.addNotification({
type:"success",
message:"Route " + d.routeName + " was successfully updated."
}
}), b.path(d.routeURL);
}, function(b) {
d.disableInputs = !1, d.alerts["update-route"] = {
d.disableInputs = !1, i.addNotification({
type:"error",
id:"edit-route-error",
message:"An error occurred updating route " + d.routeName + ".",
details:a("getErrorDetails")(b)
};
});
});
}
};
Expand Down Expand Up @@ -8746,8 +8746,8 @@ details:c("getErrorDetails")(b)
}
});
}));
} ]), angular.module("openshiftConsole").controller("CreateRouteController", [ "$filter", "$routeParams", "$scope", "$window", "ApplicationGenerator", "AuthorizationService", "DataService", "Navigate", "ProjectsService", "keyValueEditorUtils", function(a, b, c, d, e, f, g, h, i, j) {
c.alerts = {}, c.renderOptions = {
} ]), angular.module("openshiftConsole").controller("CreateRouteController", [ "$filter", "$routeParams", "$scope", "$window", "ApplicationGenerator", "AuthorizationService", "DataService", "Navigate", "NotificationsService", "ProjectsService", "keyValueEditorUtils", function(a, b, c, d, e, f, g, h, i, j, k) {
c.renderOptions = {
hideFilterWidget:!0
}, c.projectName = b.project, c.serviceName = b.service, c.labels = [], c.routing = {
name:c.serviceName || ""
Expand All @@ -8759,17 +8759,23 @@ title:"Routes",
link:"project/" + c.projectName + "/browse/routes"
}, {
title:"Create Route"
} ], i.get(b.project).then(_.spread(function(i, k) {
if (c.project = i, c.breadcrumbs[0].title = a("displayName")(i), !f.canI("routes", "create", b.project)) return void h.toErrorPage("You do not have authority to create routes in project " + b.project + ".", "access_denied");
var l = a("orderByDisplayName");
} ];
var l = function() {
i.hideNotification("create-route-error");
};
c.cancel = function() {
l(), d.history.back();
}, j.get(b.project).then(_.spread(function(j, m) {
if (c.project = j, c.breadcrumbs[0].title = a("displayName")(j), !f.canI("routes", "create", b.project)) return void h.toErrorPage("You do not have authority to create routes in project " + b.project + ".", "access_denied");
var n = a("orderByDisplayName");
c.routing.to = {
kind:"Service",
name:c.serviceName,
weight:1
}, g.list("services", k).then(function(a) {
c.services = l(a.by("metadata.name"));
}, g.list("services", m).then(function(a) {
c.services = n(a.by("metadata.name"));
}), c.copyServiceLabels = function() {
var a = _.get(c, "routing.to.service.metadata.labels", {}), b = j.mapEntries(j.compactEntries(c.labels)), d = _.assign(b, a);
var a = _.get(c, "routing.to.service.metadata.labels", {}), b = k.mapEntries(k.compactEntries(c.labels)), d = _.assign(b, a);
c.labels = _.map(d, function(a, b) {
return {
name:b,
Expand All @@ -8778,22 +8784,26 @@ value:a
});
}, c.createRoute = function() {
if (c.createRouteForm.$valid) {
c.disableInputs = !0;
var b = c.routing.to.name, f = j.mapEntries(j.compactEntries(c.labels)), h = e.createRoute(c.routing, b, f), i = _.get(c, "routing.alternateServices", []);
_.isEmpty(i) || (h.spec.to.weight = _.get(c, "routing.to.weight"), h.spec.alternateBackends = _.map(i, function(a) {
l(), c.disableInputs = !0;
var b = c.routing.to.name, f = k.mapEntries(k.compactEntries(c.labels)), h = e.createRoute(c.routing, b, f), j = _.get(c, "routing.alternateServices", []);
_.isEmpty(j) || (h.spec.to.weight = _.get(c, "routing.to.weight"), h.spec.alternateBackends = _.map(j, function(a) {
return {
kind:"Service",
name:a.name,
weight:a.weight
};
})), g.create("routes", null, h, k).then(function() {
d.history.back();
})), g.create("routes", null, h, m).then(function() {
i.addNotification({
type:"success",
message:"Route " + h.metadata.name + " was successfully created."
}), d.history.back();
}, function(b) {
c.disableInputs = !1, c.alerts["create-route"] = {
c.disableInputs = !1, i.addNotification({
type:"error",
id:"create-route-error",
message:"An error occurred creating the route.",
details:a("getErrorDetails")(b)
};
});
});
}
};
Expand Down
5 changes: 2 additions & 3 deletions dist/scripts/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -4695,7 +4695,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 Route</h1>\n" +
"<div class=\"help-block\">\n" +
Expand All @@ -4712,7 +4711,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"<a href=\"\" ng-click=\"copyServiceLabels()\">Copy Service Labels</a>\n" +
"<div class=\"button-group gutter-top gutter-bottom\">\n" +
"<button type=\"submit\" class=\"btn btn-primary btn-lg\" ng-click=\"createRoute()\" ng-disabled=\"createRouteForm.$invalid || disableInputs || !createRoute\" 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()\">Cancel</a>\n" +
"</div>\n" +
"</fieldset>\n" +
"</div>\n" +
Expand Down Expand Up @@ -9793,7 +9792,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"</osc-routing>\n" +
"<div class=\"button-group gutter-top gutter-bottom\">\n" +
"<button type=\"submit\" class=\"btn btn-primary btn-lg\" ng-click=\"updateRoute()\" ng-disabled=\"form.$invalid || disableInputs\" value=\"\">Save</button>\n" +
"<a class=\"btn btn-default btn-lg\" ng-href=\"{{routeURL}}\">Cancel</a>\n" +
"<a class=\"btn btn-default btn-lg\" ng-click=\"hideErrorNotifications()\" ng-href=\"{{routeURL}}\">Cancel</a>\n" +
"</div>\n" +
"</fieldset>\n" +
"</form>\n" +
Expand Down