Skip to content

Commit 2e578cf

Browse files
Service instance details configuration and edit
1 parent 77ce2ce commit 2e578cf

File tree

12 files changed

+871
-301
lines changed

12 files changed

+871
-301
lines changed

app/scripts/controllers/serviceInstance.js

+104-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,85 @@ 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 planUpdatable = _.get($scope.plan, 'spec.instanceUpdateParameterSchema') || (_.get($scope.serviceClass, 'spec.planUpdatable') && (_.size($scope.servicePlans) > 1));
97+
98+
$scope.editAvailable = planUpdatable && serviceInstanceReady($scope.serviceInstance) && !_.get($scope.serviceInstance, 'metadata.deletionTimestamp');
99+
};
100+
101+
var updateParameterSchema = function() {
102+
$scope.parameterFormDefinition = angular.copy(_.get($scope.plan, 'spec.externalMetadata.schemas.service_instance.update.openshift_form_definition'));
103+
104+
$scope.parameterSchema = angular.copy(_.get($scope.plan, 'spec.instanceCreateParameterSchema'));
105+
_.set($scope.parameterSchema, 'readonly', true);
106+
_.set($scope.parameterSchema, 'required', []);
107+
108+
_.each(_.get($scope.parameterSchema, 'properties'), function(property) {
109+
property.description = undefined;
110+
property.enum = undefined;
111+
property.title = property.title + ":";
112+
if (property.type === 'array') {
113+
property.type = 'string';
114+
}
115+
});
116+
};
117+
44118
var updateServiceClass = function() {
45119
// If we've previously loaded the service class or a request is in flight, don't do anything.
46-
if ($scope.serviceClass || serviceClassPromise) {
120+
if (!$scope.serviceInstance || $scope.serviceClass || serviceClassPromise) {
47121
return;
48122
}
49123

50-
serviceClassPromise = ServiceInstancesService.fetchServiceClassForInstance($scope.serviceInstance).then(function(serviceClass) {
124+
serviceClassPromise = ServiceInstancesService.fetchServiceClassForInstance($scope.serviceInstance).then(function (serviceClass) {
51125
$scope.serviceClass = serviceClass;
52-
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, serviceClass);
126+
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, $scope.serviceClass);
127+
53128
updateBreadcrumbs();
54129
serviceClassPromise = null;
55-
});
56-
};
57130

58-
var updatePlan = function() {
59-
if (ServiceInstancesService.isCurrentPlan($scope.serviceInstance, $scope.plan)) {
60-
return;
61-
}
131+
Catalog.getServicePlans().then(function (plans) {
132+
plans = plans.by('metadata.name');
62133

63-
ServiceInstancesService.fetchServicePlanForInstance($scope.serviceInstance).then(function(plan) {
64-
$scope.plan = plan;
134+
var plansByServiceClassName = Catalog.groupPlansByServiceClassName(plans);
135+
$scope.servicePlans = plansByServiceClassName[$scope.serviceClass.metadata.name];
136+
137+
var servicePlanName = _.get($scope.serviceInstance, 'spec.clusterServicePlanRef.name');
138+
$scope.plan = plans[servicePlanName];
139+
140+
updateParameterSchema();
141+
updateParameterData();
142+
updateEditable();
143+
});
65144
});
66145
};
67146

@@ -77,7 +156,7 @@ angular.module('openshiftConsole')
77156
}
78157

79158
updateServiceClass();
80-
updatePlan();
159+
updateEditable();
81160
};
82161

83162
ProjectsService
@@ -99,9 +178,17 @@ angular.module('openshiftConsole')
99178
details: $filter('getErrorDetails')(error)
100179
};
101180
});
181+
}, function(error) {
182+
$scope.loaded = true;
183+
$scope.alerts["load"] = {
184+
type: "error",
185+
message: "The service details could not be loaded.",
186+
details: $filter('getErrorDetails')(error)
187+
};
188+
}));
102189

103-
$scope.$on('$destroy', function(){
104-
DataService.unwatchAll(watches);
105-
});
106-
}));
190+
$scope.$on('$destroy', function(){
191+
DataService.unwatchAll(watches);
192+
DataService.unwatchAll(secretWatchers);
193+
});
107194
});

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

+52-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,67 @@
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 = angular.copy(_.get(servicePlan, 'spec.serviceBindingCreateParameterSchema'));
57+
_.set(ctrl.bindParameterSchema.readonly, true);
58+
_.each(_.get(ctrl.bindParameterSchema, 'properties'), function(property) {
59+
property.description = undefined;
60+
property.title = property.title + ":";
61+
});
62+
});
63+
};
2664

2765
var updateServiceClass = function() {
2866
if (_.get(ctrl.refApiObject, 'kind') !== 'ServiceInstance') {
2967
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]);
68+
ctrl.serviceInstance = _.get(ctrl.serviceInstances, [instanceName]);
69+
} else {
70+
ctrl.serviceInstance = ctrl.refApiObject;
3371
}
72+
73+
var serviceClassName = ServiceInstancesService.getServiceClassNameForInstance(ctrl.serviceInstance);
74+
ctrl.serviceClass = _.get(ctrl.serviceClasses, [serviceClassName]);
3475
};
3576

3677
this.$onChanges = function(changes) {
3778
if (changes.binding || changes.serviceInstances || changes.serviceClasses) {
3879
updateServiceClass();
80+
updateParameterSchema();
81+
updateParameterData();
3982
}
4083
};
84+
85+
ctrl.toggleShowParameterValues = function() {
86+
ctrl.showParameterValues = !ctrl.showParameterValues;
87+
};
4188
}
4289
})();

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)