Skip to content

Commit 71cb917

Browse files
committed
Show toast notifications when attaching / removing PVCs
1 parent 7eed6c1 commit 71cb917

File tree

9 files changed

+151
-141
lines changed

9 files changed

+151
-141
lines changed

app/scripts/controllers/attachPVC.js

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ angular.module('openshiftConsole')
1919
DataService,
2020
QuotaService,
2121
Navigate,
22+
NotificationsService,
2223
ProjectsService,
2324
StorageService,
2425
RELATIVE_PATH_PATTERN) {
@@ -34,8 +35,9 @@ angular.module('openshiftConsole')
3435
'ReplicationController'
3536
];
3637

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

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

47-
$scope.alerts = {};
48-
$scope.renderOptions = {
49-
hideFilterWidget: true
50-
};
51-
5249
$scope.projectName = $routeParams.project;
5350
$scope.kind = $routeParams.kind;
5451
$scope.name = $routeParams.name;
@@ -81,7 +78,7 @@ angular.module('openshiftConsole')
8178

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

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

9289
var displayError = function(errorMessage, errorDetails) {
9390
$scope.disableInputs = true;
94-
$scope.alerts['attach-persistent-volume-claim'] = {
91+
NotificationsService.addNotification({
92+
id: "attach-pvc-error",
9593
type: "error",
9694
message: errorMessage,
9795
details: errorDetails
98-
};
96+
});
97+
};
98+
99+
var hideErrorNotifications = function() {
100+
NotificationsService.hideNotification("attach-pvc-error");
101+
};
102+
103+
var navigateBack = function() {
104+
_.set($scope, 'confirm.doneEditing', true);
105+
$window.history.back();
99106
};
100107

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

152159
$scope.attachPVC = function() {
153160
$scope.disableInputs = true;
161+
hideErrorNotifications();
154162

155163
if ($scope.attachPVCForm.$valid) {
156164
// generate a volume name if not provided
@@ -185,18 +193,35 @@ angular.module('openshiftConsole')
185193
podTemplate.spec.volumes = [];
186194
}
187195
podTemplate.spec.volumes.push(newVolume);
188-
$scope.alerts = {};
189196

190197
DataService.update(resourceGroupVersion, resource.metadata.name, $scope.attach.resource, context).then(
191198
function() {
192-
$window.history.back();
199+
var details;
200+
if (!mountPath) {
201+
// FIXME: This seems like a bad experience since we don't give users a way to mount it later.
202+
details = "The volume was added, but not mounted, since no mount path given.";
203+
} else {
204+
details = "Volume " + name + " was mounted at path " + mountPath;
205+
}
206+
NotificationsService.addNotification({
207+
type: "success",
208+
message: "Persistent volume claim " + persistentVolumeClaim.metadata.name +
209+
" added to " + humanizeKind($routeParams.kind) + " " + $routeParams.name + ".",
210+
details: details
211+
});
212+
navigateBack();
193213
},
194214
function(result) {
195-
displayError("An error occurred attaching the persistent volume claim to the " + $filter('humanizeKind')($routeParams.kind) + ".", getErrorDetails(result));
215+
displayError("An error occurred attaching the persistent volume claim to the " + humanizeKind($routeParams.kind) + ".", getErrorDetails(result));
196216
$scope.disableInputs = false;
197217
}
198218
);
199219
}
200220
};
221+
222+
$scope.cancel = function() {
223+
hideErrorNotifications();
224+
navigateBack();
225+
};
201226
}));
202227
});

app/scripts/controllers/deployment.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,8 @@ angular.module('openshiftConsole')
321321
cancelButtonText: "Cancel"
322322
});
323323

324-
var showError = function(e) {
325-
$scope.alerts["remove-volume-error"] = {
326-
type: "error",
327-
message: "An error occurred removing the volume.",
328-
details: $filter('getErrorDetails')(e)
329-
};
330-
};
331-
332324
var removeVolume = function() {
333-
// No-op on success since the page updates.
334-
StorageService
335-
.removeVolume($scope.deployment, volume, context)
336-
.then(_.noop, showError);
325+
StorageService.removeVolume($scope.deployment, volume, context);
337326
};
338327

339328
confirm.then(removeVolume);

app/scripts/controllers/deploymentConfig.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -416,19 +416,8 @@ angular.module('openshiftConsole')
416416
cancelButtonText: "Cancel"
417417
});
418418

419-
var showError = function(e) {
420-
$scope.alerts["remove-volume-error"] = {
421-
type: "error",
422-
message: "An error occurred removing the volume.",
423-
details: $filter('getErrorDetails')(e)
424-
};
425-
};
426-
427419
var removeVolume = function() {
428-
// No-op on success since the page updates.
429-
StorageService
430-
.removeVolume($scope.deploymentConfig, volume, context)
431-
.then(_.noop, showError);
420+
StorageService.removeVolume($scope.deploymentConfig, volume, context);
432421
};
433422

434423
confirm.then(removeVolume);

app/scripts/controllers/edit/deploymentConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ angular.module('openshiftConsole')
324324

325325
var doneEditing = function() {
326326
_.set($scope, 'confirm.doneEditing', true);
327-
}
327+
};
328328

329329
var hideErrorNotifications = function() {
330330
NotificationsService.hideNotification("edit-deployment-config-error");

app/scripts/controllers/replicaSet.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -618,19 +618,8 @@ angular.module('openshiftConsole')
618618
cancelButtonText: "Cancel"
619619
});
620620

621-
var showError = function(e) {
622-
$scope.alerts["remove-volume-error"] = {
623-
type: "error",
624-
message: "An error occurred removing the volume.",
625-
details: $filter('getErrorDetails')(e)
626-
};
627-
};
628-
629621
var removeVolume = function() {
630-
// No-op on success since the page updates.
631-
StorageService
632-
.removeVolume($scope.replicaSet, volume, context)
633-
.then(_.noop, showError);
622+
StorageService.removeVolume($scope.replicaSet, volume, context);
634623
};
635624

636625
confirm.then(removeVolume);

app/scripts/services/storage.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
'use strict';
22

33
angular.module("openshiftConsole")
4-
.factory("StorageService", function(APIService, DataService) {
4+
.factory("StorageService",
5+
function($filter,
6+
APIService,
7+
DataService,
8+
NotificationsService) {
9+
var getErrorDetails = $filter('getErrorDetails');
10+
var humanizeKind = $filter('humanizeKind');
11+
512
return {
613
createVolume: function(name, persistentVolumeClaim) {
714
return {
@@ -64,7 +71,19 @@ angular.module("openshiftConsole")
6471
});
6572

6673
var resource = APIService.objectToResourceGroupVersion(copy);
67-
return DataService.update(resource, copy.metadata.name, copy, context);
74+
return DataService.update(resource, copy.metadata.name, copy, context)
75+
.then(function() {
76+
NotificationsService.addNotification({
77+
type: "success",
78+
message: "Volume " + volume.name + " removed from " + humanizeKind(object.kind) + " " + object.metadata.name + "."
79+
});
80+
}, function(e) {
81+
NotificationsService.addNotification({
82+
type: "error",
83+
message: "An error occurred removing volume " + volume.name + " from " + humanizeKind(object.kind) + " " + object.metadata.name + ".",
84+
details: getErrorDetails(e)
85+
});
86+
});
6887
}
6988
};
7089
});

app/views/attach-pvc.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<div class="row">
1414
<div class="col-md-10 col-md-offset-1">
1515
<breadcrumbs breadcrumbs="breadcrumbs"></breadcrumbs>
16-
<alerts alerts="alerts"></alerts>
1716
<div ng-show="!pvcs || !attach.resource">Loading...</div>
1817

1918
<div ng-show="pvcs && !pvcs.length && attach.resource" class="empty-state-message empty-state-full-page">
@@ -223,10 +222,7 @@ <h3>Volume</h3>
223222
class="btn btn-primary btn-lg"
224223
ng-click="attachPVC()"
225224
ng-disabled="attachPVCForm.$invalid || disableInputs || !attachPVC">Add</button>
226-
<a class="btn btn-default btn-lg"
227-
role="button"
228-
ng-click="confirm.doneEditing = true"
229-
href="#" back>Cancel</a>
225+
<a class="btn btn-default btn-lg" role="button" ng-click="cancel()">Cancel</a>
230226
</div>
231227
</fieldset>
232228
</form>

0 commit comments

Comments
 (0)