Skip to content

Commit 7fe74fb

Browse files
Service instance details configuration and edit
1 parent 77ce2ce commit 7fe74fb

File tree

12 files changed

+848
-301
lines changed

12 files changed

+848
-301
lines changed

app/scripts/controllers/serviceInstance.js

+93-17
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ angular.module('openshiftConsole')
55
$filter,
66
$routeParams,
77
APIService,
8+
AuthorizationService,
9+
Catalog,
810
DataService,
911
ProjectsService,
12+
SecretsService,
1013
ServiceInstancesService) {
1114
$scope.alerts = {};
1215
$scope.projectName = $routeParams.project;
1316
$scope.serviceInstance = null;
1417
$scope.serviceClass = null;
18+
$scope.serviceClasses = null;
19+
$scope.editDialogShown = false;
1520

1621
$scope.breadcrumbs = [
1722
{
@@ -27,9 +32,26 @@ angular.module('openshiftConsole')
2732
ServiceInstancesService.deprovision($scope.serviceInstance);
2833
};
2934

35+
$scope.showEditDialog = function() {
36+
$scope.editDialogShown = true;
37+
};
38+
39+
$scope.showParameterValues = false;
40+
41+
$scope.toggleShowParameterValues = function() {
42+
$scope.showParameterValues = !$scope.showParameterValues;
43+
};
44+
45+
$scope.closeEditDialog = function() {
46+
$scope.editDialogShown = false;
47+
};
48+
3049
var watches = [];
50+
var secretWatchers = [];
51+
var serviceClassPromise;
3152

3253
var serviceInstanceDisplayName = $filter('serviceInstanceDisplayName');
54+
var serviceInstanceReady = $filter('isServiceInstanceReady');
3355

3456
// API Versions
3557
$scope.serviceInstancesVersion = APIService.getPreferredVersion('serviceinstances');
@@ -40,28 +62,74 @@ angular.module('openshiftConsole')
4062
});
4163
};
4264

43-
var serviceClassPromise;
65+
var updateParameterData = function() {
66+
DataService.unwatchAll(secretWatchers);
67+
secretWatchers = [];
68+
69+
$scope.parameterData = {};
70+
_.each(_.keys(_.get($scope.parameterSchema, 'properties')), function(key) {
71+
$scope.parameterData[key] = $scope.parameterSchema.properties[key].default;
72+
});
73+
74+
$scope.parameterData = angular.extend($scope.parameterData, _.get($scope.serviceInstance, 'spec.parameters', {}));
75+
76+
if (AuthorizationService.canI('secrets', 'get', $scope.projectName)) {
77+
_.each(_.get($scope.serviceInstance, 'spec.parametersFrom'), function (parametersSource) {
78+
secretWatchers.push(DataService.watchObject("secrets", _.get(parametersSource, 'secretKeyRef.name'), $scope.projectContext, function (secret) {
79+
try {
80+
_.extend($scope.parameterData, JSON.parse(SecretsService.decodeSecretData(secret.data)[parametersSource.key]));
81+
} catch (e) {
82+
}
83+
}));
84+
});
85+
}
86+
87+
// TODO: Convert any array types to string
88+
89+
};
90+
91+
var updateEditable = function() {
92+
if (!$scope.plan || !$scope.serviceClass || !$scope.serviceInstance) {
93+
return;
94+
}
95+
96+
var updateSchema = _.get($scope.plan, 'spec.instanceUpdateParameterSchema');
97+
var planUpdatable = (_.size(_.get(updateSchema, 'properties')) > 0) || (_.get($scope.serviceClass, 'spec.planUpdatable') && (_.size($scope.servicePlans) > 1));
98+
99+
$scope.editAvailable = planUpdatable && serviceInstanceReady($scope.serviceInstance) && !_.get($scope.serviceInstance, 'metadata.deletionTimestamp');
100+
};
101+
102+
var updateParameterSchema = function() {
103+
$scope.parameterFormDefinition = angular.copy(_.get($scope.plan, 'spec.externalMetadata.schemas.service_instance.update.openshift_form_definition'));
104+
$scope.parameterSchema = _.get($scope.plan, 'spec.instanceCreateParameterSchema');
105+
};
106+
44107
var updateServiceClass = function() {
45108
// If we've previously loaded the service class or a request is in flight, don't do anything.
46-
if ($scope.serviceClass || serviceClassPromise) {
109+
if (!$scope.serviceInstance || $scope.serviceClass || serviceClassPromise) {
47110
return;
48111
}
49112

50-
serviceClassPromise = ServiceInstancesService.fetchServiceClassForInstance($scope.serviceInstance).then(function(serviceClass) {
113+
serviceClassPromise = ServiceInstancesService.fetchServiceClassForInstance($scope.serviceInstance).then(function (serviceClass) {
51114
$scope.serviceClass = serviceClass;
52-
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, serviceClass);
115+
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, $scope.serviceClass);
116+
53117
updateBreadcrumbs();
54118
serviceClassPromise = null;
55-
});
56-
};
57119

58-
var updatePlan = function() {
59-
if (ServiceInstancesService.isCurrentPlan($scope.serviceInstance, $scope.plan)) {
60-
return;
61-
}
120+
Catalog.getServicePlans().then(function (plans) {
121+
plans = plans.by('metadata.name');
122+
123+
var plansByServiceClassName = Catalog.groupPlansByServiceClassName(plans);
124+
$scope.servicePlans = plansByServiceClassName[$scope.serviceClass.metadata.name];
62125

63-
ServiceInstancesService.fetchServicePlanForInstance($scope.serviceInstance).then(function(plan) {
64-
$scope.plan = plan;
126+
var servicePlanName = _.get($scope.serviceInstance, 'spec.clusterServicePlanRef.name');
127+
$scope.plan = plans[servicePlanName];
128+
129+
updateParameterSchema();
130+
updateParameterData();
131+
updateEditable();
132+
});
65133
});
66134
};
67135

@@ -77,7 +145,7 @@ angular.module('openshiftConsole')
77145
}
78146

79147
updateServiceClass();
80-
updatePlan();
148+
updateEditable();
81149
};
82150

83151
ProjectsService
@@ -99,9 +167,17 @@ angular.module('openshiftConsole')
99167
details: $filter('getErrorDetails')(error)
100168
};
101169
});
170+
}, function(error) {
171+
$scope.loaded = true;
172+
$scope.alerts["load"] = {
173+
type: "error",
174+
message: "The service details could not be loaded.",
175+
details: $filter('getErrorDetails')(error)
176+
};
177+
}));
102178

103-
$scope.$on('$destroy', function(){
104-
DataService.unwatchAll(watches);
105-
});
106-
}));
179+
$scope.$on('$destroy', function(){
180+
DataService.unwatchAll(watches);
181+
DataService.unwatchAll(secretWatchers);
182+
});
107183
});

app/scripts/controllers/serviceInstances.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ angular.module('openshiftConsole')
3131
};
3232

3333
$scope.getServiceClass = function(serviceInstance) {
34-
var serviceClassName = _.get(serviceInstance, 'spec.serviceClassRef.name');
34+
var serviceClassName = _.get(serviceInstance, 'spec.clusterServiceClassRef.name');
3535
return _.get($scope, ['serviceClasses', serviceClassName]);
3636
};
3737

app/scripts/directives/bindService.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
ctrl.serviceClass = ctrl.serviceClasses[serviceClassName];
167167
var servicePlanName = ServiceInstancesService.getServicePlanNameForInstance(instance);
168168
ctrl.plan = ctrl.servicePlans[servicePlanName];
169-
ctrl.parameterSchema = _.get(ctrl.plan, 'spec.serviceInstanceCredentialCreateParameterSchema');
169+
ctrl.parameterSchema = _.get(ctrl.plan, 'spec.serviceBindingCreateParameterSchema');
170170
ctrl.parameterFormDefinition = _.get(ctrl.plan, 'spec.externalMetadata.schemas.service_binding.create.openshift_form_definition');
171171
bindParametersStep.hidden = !_.has(ctrl.parameterSchema, 'properties');
172172
ctrl.nextTitle = bindParametersStep.hidden ? 'Bind' : 'Next >';

app/scripts/directives/serviceBinding.js

+47-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
(function() {
44
angular.module('openshiftConsole').component('serviceBinding', {
55
controller: [
6-
"APIService",
7-
"ServiceInstancesService",
6+
'APIService',
7+
'AuthorizationService',
8+
'DataService',
9+
'SecretsService',
10+
'ServiceInstancesService',
811
ServiceBinding
912
],
1013
controllerAs: '$ctrl',
@@ -20,23 +23,62 @@
2023
});
2124

2225
function ServiceBinding(APIService,
26+
AuthorizationService,
27+
DataService,
28+
SecretsService,
2329
ServiceInstancesService) {
2430
var ctrl = this;
2531
ctrl.serviceBindingsVersion = APIService.getPreferredVersion('servicebindings');
32+
ctrl.showParameterValues = false;
33+
34+
var context = {
35+
namespace: ctrl.namespace
36+
};
37+
38+
var updateParameterData = function() {
39+
ctrl.parameterData = angular.copy(_.get(ctrl.binding, 'spec.parameters', {}));
40+
if (AuthorizationService.canI('secrets', 'get', ctrl.namespace)) {
41+
_.each(_.get(ctrl.binding, 'spec.parametersFrom'), function (parametersSource) {
42+
DataService.get('secrets', _.get(parametersSource, 'secretKeyRef.name'), context).then(function (secret) {
43+
try {
44+
_.extend(ctrl.parameterData, SecretsService.decodeSecretData(secret.data).parameters);
45+
} catch (e) {
46+
}
47+
});
48+
});
49+
}
50+
};
51+
52+
var updateParameterSchema = function() {
53+
var resource = APIService.getPreferredVersion('clusterserviceplans');
54+
DataService.get(resource, _.get(ctrl.serviceInstance, 'spec.clusterServicePlanRef.name'), context).then(function(servicePlan) {
55+
ctrl.bindParameterFormDefinition = angular.copy(_.get(servicePlan, 'spec.externalMetadata.schemas.service_binding.create.openshift_form_definition'));
56+
ctrl.bindParameterSchema = _.get(servicePlan, 'spec.serviceBindingCreateParameterSchema');
57+
});
58+
};
2659

2760
var updateServiceClass = function() {
2861
if (_.get(ctrl.refApiObject, 'kind') !== 'ServiceInstance') {
2962
var instanceName = _.get(ctrl.binding, 'spec.instanceRef.name');
30-
var instance = _.get(ctrl.serviceInstances, [instanceName]);
31-
var serviceClassName = ServiceInstancesService.getServiceClassNameForInstance(instance);
32-
ctrl.serviceClass = _.get(ctrl.serviceClasses, [serviceClassName]);
63+
ctrl.serviceInstance = _.get(ctrl.serviceInstances, [instanceName]);
64+
} else {
65+
ctrl.serviceInstance = ctrl.refApiObject;
3366
}
67+
68+
var serviceClassName = ServiceInstancesService.getServiceClassNameForInstance(ctrl.serviceInstance);
69+
ctrl.serviceClass = _.get(ctrl.serviceClasses, [serviceClassName]);
3470
};
3571

3672
this.$onChanges = function(changes) {
3773
if (changes.binding || changes.serviceInstances || changes.serviceClasses) {
3874
updateServiceClass();
75+
updateParameterSchema();
76+
updateParameterData();
3977
}
4078
};
79+
80+
ctrl.toggleShowParameterValues = function() {
81+
ctrl.showParameterValues = !ctrl.showParameterValues;
82+
};
4183
}
4284
})();

app/styles/_components.less

+23
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,29 @@ code.command {
196196
}
197197
}
198198

199+
.service-binding-message {
200+
margin-left: 20px;
201+
}
202+
.service-binding-parameters {
203+
margin-left: 20px;
204+
> a {
205+
border-left: 1px solid @color-pf-black-300;
206+
padding: 0 10px;
207+
208+
&:first-of-type {
209+
border-left: 0;
210+
}
211+
}
212+
.parameters-heading {
213+
color: @color-pf-black-500;
214+
text-transform: uppercase;
215+
}
216+
.parameter-title {
217+
font-weight: 700;
218+
text-align: right;
219+
}
220+
}
221+
199222
.service-binding-actions {
200223
font-size: 13px;
201224
font-weight: 400;

app/styles/_core.less

+26
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,32 @@
105105
border-bottom: 0;
106106
padding-bottom: 0;
107107
}
108+
109+
.config-parameters-form {
110+
margin-top: 5px;
111+
112+
@media (min-width: @screen-lg-min) {
113+
margin-bottom: 10px;
114+
}
115+
116+
form {
117+
margin-top: 10px;
118+
}
119+
.control-label {
120+
padding-right: 0;
121+
word-break: break-word;
122+
}
123+
124+
.form-group {
125+
margin-bottom: 0;
126+
}
127+
128+
.hide-show-link {
129+
font-size: @font-size-base;
130+
margin-left: 5px;
131+
}
132+
}
133+
108134
}
109135

110136
.hide-tabs .nav-tabs {

0 commit comments

Comments
 (0)