Skip to content

Commit 24901be

Browse files
Service instance details configuration and edit
1 parent ba1a820 commit 24901be

File tree

12 files changed

+845
-297
lines changed

12 files changed

+845
-297
lines changed

app/scripts/controllers/serviceInstance.js

+87-15
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
{
@@ -24,9 +29,25 @@ angular.module('openshiftConsole')
2429
ServiceInstancesService.deprovision($scope.serviceInstance);
2530
};
2631

32+
$scope.showEditDialog = function() {
33+
$scope.editDialogShown = true;
34+
};
35+
36+
$scope.showParameterValues = false;
37+
38+
$scope.toggleShowParameterValues = function() {
39+
$scope.showParameterValues = !$scope.showParameterValues;
40+
};
41+
42+
$scope.closeEditDialog = function() {
43+
$scope.editDialogShown = false;
44+
};
45+
2746
var watches = [];
47+
var secretWatchers = [];
2848

2949
var serviceInstanceDisplayName = $filter('serviceInstanceDisplayName');
50+
var serviceInstanceReady = $filter('isServiceInstanceReady');
3051

3152
// API Versions
3253
$scope.serviceInstancesVersion = APIService.getPreferredVersion('serviceinstances');
@@ -37,25 +58,69 @@ angular.module('openshiftConsole')
3758
});
3859
};
3960

61+
var updateParameterData = function() {
62+
DataService.unwatchAll(secretWatchers);
63+
secretWatchers = [];
64+
65+
$scope.parameterData = {};
66+
_.each(_.keys(_.get($scope.parameterSchema, 'properties')), function(key) {
67+
$scope.parameterData[key] = $scope.parameterSchema.properties[key].default;
68+
});
69+
70+
$scope.parameterData = angular.extend($scope.parameterData, _.get($scope.serviceInstance, 'spec.parameters', {}));
71+
72+
if (AuthorizationService.canI('secrets', 'get', $scope.projectName)) {
73+
_.each(_.get($scope.serviceInstance, 'spec.parametersFrom'), function (parametersSource) {
74+
secretWatchers.push(DataService.watchObject("secrets", _.get(parametersSource, 'secretKeyRef.name'), $scope.projectContext, function (secret) {
75+
try {
76+
_.extend($scope.parameterData, JSON.parse(SecretsService.decodeSecretData(secret.data)[parametersSource.key]));
77+
} catch (e) {
78+
}
79+
}));
80+
});
81+
}
82+
};
83+
84+
var updateParameterSchema = function() {
85+
$scope.parameterFormDefinition = angular.copy(_.get($scope.plan, 'spec.externalMetadata.schemas.service_instance.update.openshift_form_definition'));
86+
87+
$scope.parameterSchema = angular.copy(_.get($scope.plan, 'spec.instanceUpdateParameterSchema'));
88+
$scope.parameterSchema.readonly = true;
89+
$scope.parameterSchema.required = [];
90+
91+
_.each(_.get($scope.parameterSchema, 'properties'), function(property) {
92+
property.description = undefined;
93+
property.title = property.title + ":";
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+
40101
var updateServiceClass = function() {
41-
if ($scope.serviceClass) {
102+
if(!$scope.serviceInstance) {
42103
return;
43104
}
44105

45106
ServiceInstancesService.fetchServiceClassForInstance($scope.serviceInstance).then(function(serviceClass) {
46107
$scope.serviceClass = serviceClass;
47-
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, serviceClass);
108+
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, $scope.serviceClass);
109+
48110
updateBreadcrumbs();
49-
});
50-
};
51111

52-
var updatePlan = function() {
53-
if (ServiceInstancesService.isCurrentPlan($scope.serviceInstance, $scope.plan)) {
54-
return;
55-
}
112+
Catalog.getServicePlans().then(function(plans) {
113+
plans = plans.by('metadata.name');
114+
115+
var plansByServiceClassName = Catalog.groupPlansByServiceClassName(plans);
116+
$scope.servicePlans = plansByServiceClassName[$scope.serviceClass.metadata.name];
56117

57-
ServiceInstancesService.fetchServicePlanForInstance($scope.serviceInstance).then(function(plan) {
58-
$scope.plan = plan;
118+
var servicePlanName = _.get($scope.serviceInstance, 'spec.clusterServicePlanRef.name');
119+
$scope.plan = plans[servicePlanName];
120+
121+
updateParameterSchema();
122+
updateParameterData();
123+
});
59124
});
60125
};
61126

@@ -71,7 +136,6 @@ angular.module('openshiftConsole')
71136
}
72137

73138
updateServiceClass();
74-
updatePlan();
75139
};
76140

77141
ProjectsService
@@ -93,9 +157,17 @@ angular.module('openshiftConsole')
93157
details: $filter('getErrorDetails')(error)
94158
};
95159
});
160+
}, function(error) {
161+
$scope.loaded = true;
162+
$scope.alerts["load"] = {
163+
type: "error",
164+
message: "The service details could not be loaded.",
165+
details: $filter('getErrorDetails')(error)
166+
};
167+
}));
96168

97-
$scope.$on('$destroy', function(){
98-
DataService.unwatchAll(watches);
99-
});
100-
}));
169+
$scope.$on('$destroy', function(){
170+
DataService.unwatchAll(watches);
171+
DataService.unwatchAll(secretWatchers);
172+
});
101173
});

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)