Skip to content

Commit

Permalink
Merge pull request #2237 from jeff-phillips-18/parameters
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue.

Service instance details configuration and edit

Depends on openshift/origin-web-catalog#474

Fixes #2278 with catalog version bump

Bumped origin-web-catalog to 0.0.56
  • Loading branch information
openshift-merge-robot committed Oct 19, 2017
2 parents 8244a38 + ce5a3ef commit f127c70
Show file tree
Hide file tree
Showing 13 changed files with 1,053 additions and 459 deletions.
114 changes: 97 additions & 17 deletions app/scripts/controllers/serviceInstance.js
Expand Up @@ -6,13 +6,19 @@ angular.module('openshiftConsole')
$routeParams,
APIService,
BindingService,
AuthorizationService,
Catalog,
DataService,
Logger,
ProjectsService,
SecretsService,
ServiceInstancesService) {
$scope.alerts = {};
$scope.projectName = $routeParams.project;
$scope.serviceInstance = null;
$scope.serviceClass = null;
$scope.serviceClasses = null;
$scope.editDialogShown = false;

$scope.breadcrumbs = [
{
Expand All @@ -28,9 +34,26 @@ angular.module('openshiftConsole')
ServiceInstancesService.deprovision($scope.serviceInstance, $scope.bindings);
};

$scope.showEditDialog = function() {
$scope.editDialogShown = true;
};

$scope.showParameterValues = false;

$scope.toggleShowParameterValues = function() {
$scope.showParameterValues = !$scope.showParameterValues;
};

$scope.closeEditDialog = function() {
$scope.editDialogShown = false;
};

var watches = [];
var secretWatchers = [];
var serviceClassPromise;

var serviceInstanceDisplayName = $filter('serviceInstanceDisplayName');
var serviceInstanceReady = $filter('isServiceInstanceReady');

// API Versions
var serviceBindingsVersion = APIService.getPreferredVersion('servicebindings');
Expand All @@ -42,28 +65,76 @@ angular.module('openshiftConsole')
});
};

var serviceClassPromise;
var updateParameterData = function() {
if (!$scope.serviceInstance || !$scope.parameterSchema) {
return;
}

DataService.unwatchAll(secretWatchers);
secretWatchers = [];

$scope.parameterData = {};
_.each(_.keys(_.get($scope.parameterSchema, 'properties')), function(key) {
$scope.parameterData[key] = $scope.parameterSchema.properties[key].default;
});

$scope.parameterData = angular.extend($scope.parameterData, _.get($scope.serviceInstance, 'spec.parameters', {}));

if (AuthorizationService.canI('secrets', 'get', $scope.projectName)) {
_.each(_.get($scope.serviceInstance, 'spec.parametersFrom'), function (parametersSource) {
secretWatchers.push(DataService.watchObject("secrets", _.get(parametersSource, 'secretKeyRef.name'), $scope.projectContext, function (secret) {
try {
_.extend($scope.parameterData, JSON.parse(SecretsService.decodeSecretData(secret.data)[parametersSource.secretKeyRef.key]));
} catch (e) {
Logger.warn('Unable to load parameters from secret ' + _.get(parametersSource, 'secretKeyRef.name'), e);
}
}));
});
}
};

var updateEditable = function() {
if (!$scope.plan || !$scope.serviceClass || !$scope.serviceInstance) {
return;
}

var updateSchema = _.get($scope.plan, 'spec.instanceUpdateParameterSchema');
var planUpdatable = (_.size(_.get(updateSchema, 'properties')) > 0) || (_.get($scope.serviceClass, 'spec.planUpdatable') && (_.size($scope.servicePlans) > 1));

$scope.editAvailable = planUpdatable && serviceInstanceReady($scope.serviceInstance) && !_.get($scope.serviceInstance, 'metadata.deletionTimestamp');
};

var updateParameterSchema = function() {
$scope.parameterFormDefinition = angular.copy(_.get($scope.plan, 'spec.externalMetadata.schemas.service_instance.update.openshift_form_definition'));
$scope.parameterSchema = _.get($scope.plan, 'spec.instanceCreateParameterSchema');
};

var updateServiceClass = function() {
// If we've previously loaded the service class or a request is in flight, don't do anything.
if ($scope.serviceClass || serviceClassPromise) {
if (!$scope.serviceInstance || $scope.serviceClass || serviceClassPromise) {
return;
}

serviceClassPromise = ServiceInstancesService.fetchServiceClassForInstance($scope.serviceInstance).then(function(serviceClass) {
serviceClassPromise = ServiceInstancesService.fetchServiceClassForInstance($scope.serviceInstance).then(function (serviceClass) {
$scope.serviceClass = serviceClass;
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, serviceClass);
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, $scope.serviceClass);

updateBreadcrumbs();
serviceClassPromise = null;
});
};

var updatePlan = function() {
if (ServiceInstancesService.isCurrentPlan($scope.serviceInstance, $scope.plan)) {
return;
}
Catalog.getServicePlans().then(function (plans) {
plans = plans.by('metadata.name');

var plansByServiceClassName = Catalog.groupPlansByServiceClassName(plans);
$scope.servicePlans = plansByServiceClassName[$scope.serviceClass.metadata.name];

ServiceInstancesService.fetchServicePlanForInstance($scope.serviceInstance).then(function(plan) {
$scope.plan = plan;
var servicePlanName = _.get($scope.serviceInstance, 'spec.clusterServicePlanRef.name');
$scope.plan = plans[servicePlanName];

updateParameterSchema();
updateParameterData();
updateEditable();
});
});
};

Expand All @@ -79,7 +150,8 @@ angular.module('openshiftConsole')
}

updateServiceClass();
updatePlan();
updateParameterData();
updateEditable();
};

ProjectsService
Expand All @@ -106,9 +178,17 @@ angular.module('openshiftConsole')
details: $filter('getErrorDetails')(error)
};
});
}, function(error) {
$scope.loaded = true;
$scope.alerts["load"] = {
type: "error",
message: "The service details could not be loaded.",
details: $filter('getErrorDetails')(error)
};
}));

$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
}));
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
DataService.unwatchAll(secretWatchers);
});
});
2 changes: 1 addition & 1 deletion app/scripts/controllers/serviceInstances.js
Expand Up @@ -32,7 +32,7 @@ angular.module('openshiftConsole')
};

$scope.getServiceClass = function(serviceInstance) {
var serviceClassName = _.get(serviceInstance, 'spec.serviceClassRef.name');
var serviceClassName = _.get(serviceInstance, 'spec.clusterServiceClassRef.name');
return _.get($scope, ['serviceClasses', serviceClassName]);
};

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/directives/bindService.js
Expand Up @@ -166,7 +166,7 @@
ctrl.serviceClass = ctrl.serviceClasses[serviceClassName];
var servicePlanName = ServiceInstancesService.getServicePlanNameForInstance(instance);
ctrl.plan = ctrl.servicePlans[servicePlanName];
ctrl.parameterSchema = _.get(ctrl.plan, 'spec.serviceInstanceCredentialCreateParameterSchema');
ctrl.parameterSchema = _.get(ctrl.plan, 'spec.serviceBindingCreateParameterSchema');
ctrl.parameterFormDefinition = _.get(ctrl.plan, 'spec.externalMetadata.schemas.service_binding.create.openshift_form_definition');
bindParametersStep.hidden = !_.has(ctrl.parameterSchema, 'properties');
ctrl.nextTitle = bindParametersStep.hidden ? 'Bind' : 'Next >';
Expand Down
55 changes: 50 additions & 5 deletions app/scripts/directives/serviceBinding.js
Expand Up @@ -3,8 +3,12 @@
(function() {
angular.module('openshiftConsole').component('serviceBinding', {
controller: [
"APIService",
"ServiceInstancesService",
'APIService',
'AuthorizationService',
'DataService',
'Logger',
'SecretsService',
'ServiceInstancesService',
ServiceBinding
],
controllerAs: '$ctrl',
Expand All @@ -20,23 +24,64 @@
});

function ServiceBinding(APIService,
AuthorizationService,
DataService,
Logger,
SecretsService,
ServiceInstancesService) {
var ctrl = this;
ctrl.serviceBindingsVersion = APIService.getPreferredVersion('servicebindings');
ctrl.showParameterValues = false;

var context = {
namespace: ctrl.namespace
};

var updateParameterData = function() {
ctrl.parameterData = angular.copy(_.get(ctrl.binding, 'spec.parameters', {}));
if (AuthorizationService.canI('secrets', 'get', ctrl.namespace)) {
_.each(_.get(ctrl.binding, 'spec.parametersFrom'), function (parametersSource) {
DataService.get('secrets', _.get(parametersSource, 'secretKeyRef.name'), context).then(function (secret) {
try {
_.extend(ctrl.parameterData, JSON.parse(SecretsService.decodeSecretData(secret.data)[parametersSource.secretKeyRef.key]));
} catch (e) {
Logger.warn('Unable to load parameters from secret ' + _.get(parametersSource, 'secretKeyRef.name'), e);
}
});
});
}
};

var updateParameterSchema = function() {
var resource = APIService.getPreferredVersion('clusterserviceplans');
DataService.get(resource, _.get(ctrl.serviceInstance, 'spec.clusterServicePlanRef.name'), context).then(function(servicePlan) {
ctrl.bindParameterFormDefinition = angular.copy(_.get(servicePlan, 'spec.externalMetadata.schemas.service_binding.create.openshift_form_definition'));
ctrl.bindParameterSchema = _.get(servicePlan, 'spec.serviceBindingCreateParameterSchema');
});
};

var updateServiceClass = function() {
if (_.get(ctrl.refApiObject, 'kind') !== 'ServiceInstance') {
var instanceName = _.get(ctrl.binding, 'spec.instanceRef.name');
var instance = _.get(ctrl.serviceInstances, [instanceName]);
var serviceClassName = ServiceInstancesService.getServiceClassNameForInstance(instance);
ctrl.serviceClass = _.get(ctrl.serviceClasses, [serviceClassName]);
ctrl.serviceInstance = _.get(ctrl.serviceInstances, [instanceName]);
} else {
ctrl.serviceInstance = ctrl.refApiObject;
}

var serviceClassName = ServiceInstancesService.getServiceClassNameForInstance(ctrl.serviceInstance);
ctrl.serviceClass = _.get(ctrl.serviceClasses, [serviceClassName]);
};

this.$onChanges = function(changes) {
if (changes.binding || changes.serviceInstances || changes.serviceClasses) {
updateServiceClass();
updateParameterSchema();
updateParameterData();
}
};

ctrl.toggleShowParameterValues = function() {
ctrl.showParameterValues = !ctrl.showParameterValues;
};
}
})();
23 changes: 23 additions & 0 deletions app/styles/_components.less
Expand Up @@ -196,6 +196,29 @@ code.command {
}
}

.service-binding-message {
margin-left: 20px;
}
.service-binding-parameters {
margin-left: 20px;
> a {
border-left: 1px solid @color-pf-black-300;
padding: 0 10px;

&:first-of-type {
border-left: 0;
}
}
.parameters-heading {
color: @color-pf-black-500;
text-transform: uppercase;
}
.parameter-title {
font-weight: 700;
text-align: right;
}
}

.service-binding-actions {
font-size: 13px;
font-weight: 400;
Expand Down
26 changes: 26 additions & 0 deletions app/styles/_core.less
Expand Up @@ -97,6 +97,32 @@
}

.resource-details {
.config-parameters-form {
margin-top: 5px;

.control-label {
padding-right: 0;
word-break: break-word;
}

form {
margin-top: 10px;
}

.form-group {
margin-bottom: 0;
}

.hide-show-link {
font-size: @font-size-base;
margin-left: 5px;
}

@media (min-width: @screen-lg-min) {
margin-bottom: 10px;
}
}

h3 {
border-bottom: 1px solid #eee;
padding-bottom: 10px;
Expand Down

0 comments on commit f127c70

Please sign in to comment.