From f3a3f5b3d6a33bbe34557fb47f9e5e40e674e63f Mon Sep 17 00:00:00 2001 From: benjaminapetersen Date: Wed, 3 May 2017 13:20:05 -0400 Subject: [PATCH] Add unbind action to provisioned services - Update delete binding from service-instance-row to use app names - Add unbind service to list-row - Update unbindService to support multiple apps per binding & display app names - Add serviceInstanceDisplayName filter --- app/index.html | 1 + app/scripts/directives/bindService.js | 10 +- .../directives/overview/serviceInstanceRow.js | 10 +- app/scripts/directives/unbindService.js | 106 ++++++++++++++++++ app/scripts/filters/resources.js | 13 +++ .../bind-service/delete-binding-result.html | 32 ++++++ .../delete-binding-select-form.html | 24 ++++ app/views/directives/unbind-service.html | 29 +++++ app/views/overview/_list-row-actions.html | 5 +- app/views/overview/_list-row.html | 6 + app/views/overview/_service-instance-row.html | 12 +- dist/scripts/scripts.js | 69 +++++++++++- dist/scripts/templates.js | 85 +++++++++++++- 13 files changed, 379 insertions(+), 23 deletions(-) create mode 100644 app/scripts/directives/unbindService.js create mode 100644 app/views/directives/bind-service/delete-binding-result.html create mode 100644 app/views/directives/bind-service/delete-binding-select-form.html create mode 100644 app/views/directives/unbind-service.html diff --git a/app/index.html b/app/index.html index 4a91611244..a2c0a7f8ae 100644 --- a/app/index.html +++ b/app/index.html @@ -337,6 +337,7 @@

JavaScript Required

+ diff --git a/app/scripts/directives/bindService.js b/app/scripts/directives/bindService.js index 1a988a96ea..903c2f6d9a 100644 --- a/app/scripts/directives/bindService.js +++ b/app/scripts/directives/bindService.js @@ -55,15 +55,15 @@ } }; - var deploymentConfigs, deployments, replicationControllers, replicaSets, statefulSets; var sortApplications = function() { // Don't waste time sorting on each data load, just sort when we have them all if (deploymentConfigs && deployments && replicationControllers && replicaSets && statefulSets) { - var apiObjects = deploymentConfigs.concat(deployments) - .concat(replicationControllers) - .concat(replicaSets) - .concat(statefulSets); + var apiObjects = [].concat(deploymentConfigs) + .concat(deployments) + .concat(replicationControllers) + .concat(replicaSets) + .concat(statefulSets); ctrl.applications = _.sortByAll(apiObjects, ['metadata.name', 'kind']); ctrl.bindType = ctrl.applications.length ? "application" : "secret-only"; } diff --git a/app/scripts/directives/overview/serviceInstanceRow.js b/app/scripts/directives/overview/serviceInstanceRow.js index de9ba3cfe1..7575a4c2d4 100644 --- a/app/scripts/directives/overview/serviceInstanceRow.js +++ b/app/scripts/directives/overview/serviceInstanceRow.js @@ -30,13 +30,7 @@ _.extend(row, ListRowUtils.ui); var getErrorDetails = $filter('getErrorDetails'); - - var getDisplayName = function() { - var serviceClassName = row.apiObject.spec.serviceClassName; - var instanceName = row.apiObject.metadata.name; - var serviceClassDisplayName = _.get(row, ['state','serviceClasses', serviceClassName, 'externalMetadata', 'displayName']); - return serviceClassDisplayName || serviceClassName || instanceName; - }; + var serviceInstanceDisplayName = $filter('serviceInstanceDisplayName'); var getDescription = function() { var serviceClassName = row.apiObject.spec.serviceClassName; @@ -45,7 +39,7 @@ row.$doCheck = function() { row.notifications = ListRowUtils.getNotifications(row.apiObject, row.state); - row.displayName = getDisplayName(); + row.displayName = serviceInstanceDisplayName(row.apiObject, row.serviceClasses); row.description = getDescription(); }; diff --git a/app/scripts/directives/unbindService.js b/app/scripts/directives/unbindService.js new file mode 100644 index 0000000000..443e2b1f18 --- /dev/null +++ b/app/scripts/directives/unbindService.js @@ -0,0 +1,106 @@ +'use strict'; + +(function() { + + angular.module('openshiftConsole').component('unbindService', { + controller: [ + '$scope', + '$filter', + 'DataService', + UnbindService + ], + controllerAs: 'ctrl', + bindings: { + target: '<', + bindings: '<', + applicationsByBinding: '<', + onClose: '<' + }, + templateUrl: 'views/directives/unbind-service.html' + }); + + function UnbindService($scope, $filter, DataService) { + var ctrl = this; + var validityWatcher; + var context; + var serviceInstanceDisplayName = $filter('serviceInstanceDisplayName'); + + var unbindService = function() { + DataService.delete({ + group: 'servicecatalog.k8s.io', + resource: 'bindings' + }, ctrl.selectedBinding, context).then(_.noop, function(err) { + ctrl.error = err; + }); + }; + + var setupValidator = function() { + var firstStep = _.first(ctrl.steps); + firstStep.valid = false; + // TODO: auto-select if one option is kludgy. will follow-on a fix + // if(_.size(ctrl.bindings) === 1) { + // firstStep.valid = true; + // ctrl.selectedBinding = _.first(ctrl.bindings); + // } else { + validityWatcher = $scope.$watch("ctrl.selectedBinding", function(selectedBinding) { + firstStep.valid = !!selectedBinding; + }); + // } + }; + + var tearDownValidator = function() { + if(validityWatcher) { + validityWatcher(); + validityWatcher = undefined; + } + }; + + var showDeleteForm = function() { + ctrl.nextTitle = 'Delete'; + setupValidator(); + }; + + var showResults = function() { + ctrl.nextTitle = 'Close'; + ctrl.wizardComplete = true; + unbindService(); + tearDownValidator(); + }; + + ctrl.$onInit = function() { + var formStepLabel = (ctrl.target.kind === 'Instance') ? 'Applications' : 'Services'; + ctrl.displayName = serviceInstanceDisplayName(ctrl.target); + ctrl.steps = [{ + id: 'deleteForm', + label: formStepLabel, + view: 'views/directives/bind-service/delete-binding-select-form.html', + onShow: showDeleteForm + }, { + id: 'results', + label: 'Results', + view: 'views/directives/bind-service/delete-binding-result.html', + onShow: showResults + }]; + + context = { + namespace: _.get(ctrl.target, 'metadata.namespace') + }; + }; + + ctrl.appsForBinding = function(bindingName) { + return _.get(ctrl.applicationsByBinding, bindingName); + }; + + ctrl.closeWizard = function() { + if (_.isFunction(ctrl.onClose)) { + ctrl.onClose(); + } + }; + + ctrl.$onDestroy = function() { + tearDownValidator(); + }; + + } + +})(); diff --git a/app/scripts/filters/resources.js b/app/scripts/filters/resources.js index 097f9cc4ba..143455611e 100644 --- a/app/scripts/filters/resources.js +++ b/app/scripts/filters/resources.js @@ -1315,4 +1315,17 @@ angular.module('openshiftConsole') var alternateBackends = _.get(route, 'spec.alternateBackends', []); return !_.isEmpty(alternateBackends); }; + }) + // .filter('serviceClassDisplayName', function() { + // return function(serviceClass) { + // TODO: this filter may also be useful. + // }; + // }) + .filter('serviceInstanceDisplayName', function() { + return function(instance, serviceClasses) { + var serviceClassName = instance.spec.serviceClassName; + var instanceName = instance.metadata.name; + var serviceClassDisplayName = _.get(serviceClasses, [serviceClassName, 'externalMetadata', 'displayName']); + return serviceClassDisplayName || serviceClassName || instanceName; + }; }); diff --git a/app/views/directives/bind-service/delete-binding-result.html b/app/views/directives/bind-service/delete-binding-result.html new file mode 100644 index 0000000000..d1b4f17014 --- /dev/null +++ b/app/views/directives/bind-service/delete-binding-result.html @@ -0,0 +1,32 @@ +
+
+

+ Binding for the following has been deleted: +

+ +
+ {{appForBinding.metadata.name}} – {{ appForBinding.kind | humanizeKind : true}} +
+
+ + {{ctrl.selectedBinding}} – Binding +
+ +

+ You will need to redeploy your pods for this to take effect. +

+
+
+
Deletion of Binding Failed
+
+ + {{ctrl.error.data.message | upperFirst}} + + + An error occurred deleting the binding. + +
+
+
diff --git a/app/views/directives/bind-service/delete-binding-select-form.html b/app/views/directives/bind-service/delete-binding-select-form.html new file mode 100644 index 0000000000..f400f36793 --- /dev/null +++ b/app/views/directives/bind-service/delete-binding-select-form.html @@ -0,0 +1,24 @@ +

+ Select a binding to delete from {{ctrl.displayName}} +

+
+
+
+ +
+
+
diff --git a/app/views/directives/unbind-service.html b/app/views/directives/unbind-service.html new file mode 100644 index 0000000000..4bec1b4fc7 --- /dev/null +++ b/app/views/directives/unbind-service.html @@ -0,0 +1,29 @@ +
+
+
+
+
+
+
+
+
+
+
diff --git a/app/views/overview/_list-row-actions.html b/app/views/overview/_list-row-actions.html index 5f49ef4881..684c5dfdd1 100644 --- a/app/views/overview/_list-row-actions.html +++ b/app/views/overview/_list-row-actions.html @@ -25,9 +25,12 @@ -
  • +
  • Create Binding
  • +
  • + Delete Binding +
  • View Logs
  • diff --git a/app/views/overview/_list-row.html b/app/views/overview/_list-row.html index b9e8cadbd3..d5d205d578 100644 --- a/app/views/overview/_list-row.html +++ b/app/views/overview/_list-row.html @@ -18,4 +18,10 @@ +
    + +
    diff --git a/app/views/overview/_service-instance-row.html b/app/views/overview/_service-instance-row.html index 501f2f61ee..0f2135bb00 100644 --- a/app/views/overview/_service-instance-row.html +++ b/app/views/overview/_service-instance-row.html @@ -52,9 +52,12 @@

    uib-dropdown-toggle class="actions-dropdown-kebab">Actions