Skip to content

Show toast notifications when attaching / removing PVCs #1662

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 1 commit into from
Jun 7, 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
46 changes: 34 additions & 12 deletions app/scripts/controllers/attachPVC.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ angular.module('openshiftConsole')
DataService,
QuotaService,
Navigate,
NotificationsService,
ProjectsService,
StorageService,
RELATIVE_PATH_PATTERN) {
Expand All @@ -34,8 +35,9 @@ angular.module('openshiftConsole')
'ReplicationController'
];

var humanizeKind = $filter('humanizeKind');
if (!_.includes(supportedKinds, $routeParams.kind)) {
Navigate.toErrorPage("Storage is not supported for kind " + $routeParams.kind + ".");
Navigate.toErrorPage("Storage is not supported for kind " + humanizeKind($routeParams.kind) + ".");
return;
}

Expand All @@ -44,11 +46,6 @@ angular.module('openshiftConsole')
group: $routeParams.group
};

$scope.alerts = {};
$scope.renderOptions = {
hideFilterWidget: true
};

$scope.projectName = $routeParams.project;
$scope.kind = $routeParams.kind;
$scope.name = $routeParams.name;
Expand Down Expand Up @@ -81,7 +78,7 @@ angular.module('openshiftConsole')

if (!AuthorizationService.canI(resourceGroupVersion, 'update', $routeParams.project)) {
Navigate.toErrorPage('You do not have authority to update ' +
$filter('humanizeKind')($routeParams.kind) + ' ' + $routeParams.name + '.', 'access_denied');
humanizeKind($routeParams.kind) + ' ' + $routeParams.name + '.', 'access_denied');
return;
}

Expand All @@ -91,11 +88,21 @@ angular.module('openshiftConsole')

var displayError = function(errorMessage, errorDetails) {
$scope.disableInputs = true;
$scope.alerts['attach-persistent-volume-claim'] = {
NotificationsService.addNotification({
id: "attach-pvc-error",
type: "error",
message: errorMessage,
details: errorDetails
};
});
};

var hideErrorNotifications = function() {
NotificationsService.hideNotification("attach-pvc-error");
};

var navigateBack = function() {
_.set($scope, 'confirm.doneEditing', true);
$window.history.back();
};

var isContainerSelected = function(container) {
Expand Down Expand Up @@ -151,6 +158,7 @@ angular.module('openshiftConsole')

$scope.attachPVC = function() {
$scope.disableInputs = true;
hideErrorNotifications();

if ($scope.attachPVCForm.$valid) {
// generate a volume name if not provided
Expand Down Expand Up @@ -185,18 +193,32 @@ angular.module('openshiftConsole')
podTemplate.spec.volumes = [];
}
podTemplate.spec.volumes.push(newVolume);
$scope.alerts = {};

DataService.update(resourceGroupVersion, resource.metadata.name, $scope.attach.resource, context).then(
function() {
$window.history.back();
var details;
if (!mountPath) {
// FIXME: This seems like a bad experience since we don't give users a way to mount it later.
details = "No mount path was provided. The volume reference was added to the configuration, but it will not be mounted into running pods.";
}
NotificationsService.addNotification({
type: "success",
message: "Persistent volume claim " + persistentVolumeClaim.metadata.name + " added to " + humanizeKind($routeParams.kind) + " " + $routeParams.name + ".",
details: details
});
navigateBack();
},
function(result) {
displayError("An error occurred attaching the persistent volume claim to the " + $filter('humanizeKind')($routeParams.kind) + ".", getErrorDetails(result));
displayError("An error occurred attaching the persistent volume claim to the " + humanizeKind($routeParams.kind) + ".", getErrorDetails(result));
$scope.disableInputs = false;
}
);
}
};

$scope.cancel = function() {
hideErrorNotifications();
navigateBack();
};
}));
});
13 changes: 1 addition & 12 deletions app/scripts/controllers/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,8 @@ angular.module('openshiftConsole')
cancelButtonText: "Cancel"
});

var showError = function(e) {
$scope.alerts["remove-volume-error"] = {
type: "error",
message: "An error occurred removing the volume.",
details: $filter('getErrorDetails')(e)
};
};

var removeVolume = function() {
// No-op on success since the page updates.
StorageService
.removeVolume($scope.deployment, volume, context)
.then(_.noop, showError);
StorageService.removeVolume($scope.deployment, volume, context);
};

confirm.then(removeVolume);
Expand Down
13 changes: 1 addition & 12 deletions app/scripts/controllers/deploymentConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,19 +416,8 @@ angular.module('openshiftConsole')
cancelButtonText: "Cancel"
});

var showError = function(e) {
$scope.alerts["remove-volume-error"] = {
type: "error",
message: "An error occurred removing the volume.",
details: $filter('getErrorDetails')(e)
};
};

var removeVolume = function() {
// No-op on success since the page updates.
StorageService
.removeVolume($scope.deploymentConfig, volume, context)
.then(_.noop, showError);
StorageService.removeVolume($scope.deploymentConfig, volume, context);
};

confirm.then(removeVolume);
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/controllers/edit/deploymentConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ angular.module('openshiftConsole')

var doneEditing = function() {
_.set($scope, 'confirm.doneEditing', true);
}
};

var hideErrorNotifications = function() {
NotificationsService.hideNotification("edit-deployment-config-error");
Expand Down
13 changes: 1 addition & 12 deletions app/scripts/controllers/replicaSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,19 +618,8 @@ angular.module('openshiftConsole')
cancelButtonText: "Cancel"
});

var showError = function(e) {
$scope.alerts["remove-volume-error"] = {
type: "error",
message: "An error occurred removing the volume.",
details: $filter('getErrorDetails')(e)
};
};

var removeVolume = function() {
// No-op on success since the page updates.
StorageService
.removeVolume($scope.replicaSet, volume, context)
.then(_.noop, showError);
StorageService.removeVolume($scope.replicaSet, volume, context);
};

confirm.then(removeVolume);
Expand Down
23 changes: 21 additions & 2 deletions app/scripts/services/storage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
'use strict';

angular.module("openshiftConsole")
.factory("StorageService", function(APIService, DataService) {
.factory("StorageService",
function($filter,
APIService,
DataService,
NotificationsService) {
var getErrorDetails = $filter('getErrorDetails');
var humanizeKind = $filter('humanizeKind');

return {
createVolume: function(name, persistentVolumeClaim) {
return {
Expand Down Expand Up @@ -64,7 +71,19 @@ angular.module("openshiftConsole")
});

var resource = APIService.objectToResourceGroupVersion(copy);
return DataService.update(resource, copy.metadata.name, copy, context);
return DataService.update(resource, copy.metadata.name, copy, context)
.then(function() {
NotificationsService.addNotification({
type: "success",
message: "Volume " + volume.name + " removed from " + humanizeKind(object.kind) + " " + object.metadata.name + "."
});
}, function(e) {
NotificationsService.addNotification({
type: "error",
message: "An error occurred removing volume " + volume.name + " from " + humanizeKind(object.kind) + " " + object.metadata.name + ".",
details: getErrorDetails(e)
});
});
}
};
});
6 changes: 1 addition & 5 deletions app/views/attach-pvc.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<div class="row">
<div class="col-md-10 col-md-offset-1">
<breadcrumbs breadcrumbs="breadcrumbs"></breadcrumbs>
<alerts alerts="alerts"></alerts>
<div ng-show="!pvcs || !attach.resource">Loading...</div>

<div ng-show="pvcs && !pvcs.length && attach.resource" class="empty-state-message empty-state-full-page">
Expand Down Expand Up @@ -223,10 +222,7 @@ <h3>Volume</h3>
class="btn btn-primary btn-lg"
ng-click="attachPVC()"
ng-disabled="attachPVCForm.$invalid || disableInputs || !attachPVC">Add</button>
<a class="btn btn-default btn-lg"
role="button"
ng-click="confirm.doneEditing = true"
href="#" back>Cancel</a>
<a class="btn btn-default btn-lg" role="button" ng-click="cancel()">Cancel</a>
</div>
</fieldset>
</form>
Expand Down
Loading