Skip to content

Commit

Permalink
Support binding parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
spadgett committed Aug 29, 2017
1 parent 72f8452 commit 0483125
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 37 deletions.
4 changes: 2 additions & 2 deletions app/scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ angular.extend(window.OPENSHIFT_CONSTANTS, {
DISABLE_GLOBAL_EVENT_WATCH: false,
ENABLE_TECH_PREVIEW_FEATURE: {
// Enable the new landing page and service catalog experience
service_catalog_landing_page: false,
service_catalog_landing_page: true,
// Set to `true` when the template service broker is enabled for the cluster in master-config.yaml
template_service_broker: false,
pod_presets: false
pod_presets: true
},

SAMPLE_PIPELINE_TEMPLATE: {
Expand Down
113 changes: 81 additions & 32 deletions app/scripts/directives/bindService.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
DataService,
BindingService) {
var ctrl = this;
var validityWatcher;
var bindFormStep;
var bindParametersStep;
var resultsStep;
var selectionValidityWatcher;
var parametersValidityWatcher;
var bindingWatch;
var statusCondition = $filter('statusCondition');

Expand Down Expand Up @@ -69,17 +73,31 @@
};

var showBind = function() {
ctrl.nextTitle = 'Bind';
ctrl.nextTitle = bindParametersStep.hidden ? 'Bind' : 'Next >';
if (!selectionValidityWatcher) {
selectionValidityWatcher = $scope.$watch("ctrl.selectionForm.$valid", function(isValid) {
bindFormStep.valid = isValid;
});
}
};

validityWatcher = $scope.$watch("ctrl.selectionForm.$valid", function(isValid) {
ctrl.steps[0].valid = isValid;
});
var showParameters = function() {
ctrl.nextTitle = 'Bind';
if (!parametersValidityWatcher) {
parametersValidityWatcher = $scope.$watch("ctrl.parametersForm.$valid", function(isValid) {
bindParametersStep.valid = isValid;
});
}
};

var showResults = function() {
if (validityWatcher) {
validityWatcher();
validityWatcher = undefined;
if (selectionValidityWatcher) {
selectionValidityWatcher();
selectionValidityWatcher = undefined;
}
if (parametersValidityWatcher) {
parametersValidityWatcher();
parametersValidityWatcher = undefined;
}
ctrl.nextTitle = "Close";
ctrl.wizardComplete = true;
Expand Down Expand Up @@ -139,37 +157,64 @@
});
};

bindFormStep = {
id: 'bindForm',
label: 'Binding',
view: 'views/directives/bind-service/bind-service-form.html',
valid: true,
onShow: showBind
};

bindParametersStep = {
id: 'bindParameters',
label: 'Parameters',
view: 'views/directives/bind-service/bind-parameters.html',
hidden: true,
onShow: showParameters
};

resultsStep = {
id: 'results',
label: 'Results',
view: 'views/directives/bind-service/results.html',
valid: true,
onShow: showResults
};

var updateInstance = function() {
if (!ctrl.serviceClasses) {
return;
}

var instance = ctrl.target.kind === 'Instance' ? ctrl.target : ctrl.serviceToBind;
if (!instance) {
return;
}

ctrl.serviceClass = ctrl.serviceClasses[instance.spec.serviceClassName];
ctrl.serviceClassName = instance.spec.serviceClassName;
ctrl.plan = BindingService.getPlanForInstance(instance, ctrl.serviceClass);
ctrl.parameterSchema = _.get(ctrl.plan, 'alphaBindingCreateParameterSchema');
bindParametersStep.hidden = !_.has(ctrl.parameterSchema, 'properties');
ctrl.nextTitle = bindParametersStep.hidden ? 'Bind' : 'Next >';
};

$scope.$watch("ctrl.serviceToBind", updateInstance);

ctrl.$onInit = function() {
ctrl.serviceSelection = {};
ctrl.projectDisplayName = $filter('displayName')(ctrl.project);
ctrl.parameterData = {};

ctrl.steps = [
{
id: 'bindForm',
label: "Binding",
view: 'views/directives/bind-service/bind-service-form.html',
valid: true,
onShow: showBind
},
{
label: 'Results',
id: 'results',
view: 'views/directives/bind-service/results.html',
valid: true,
onShow: showResults
}
];
ctrl.steps = [ bindFormStep, bindParametersStep, resultsStep ];

// We will want ServiceClasses either way for display purposes
DataService.list({
group: 'servicecatalog.k8s.io',
resource: 'serviceclasses'
}, {}).then(function(serviceClasses) {
ctrl.serviceClasses = serviceClasses.by('metadata.name');
if (ctrl.target.kind === 'Instance') {
ctrl.serviceClass = ctrl.serviceClasses[ctrl.target.spec.serviceClassName];
ctrl.serviceClassName = ctrl.target.spec.serviceClassName;
}
updateInstance();
sortServiceInstances();
});

Expand All @@ -193,9 +238,13 @@
};

ctrl.$onDestroy = function() {
if (validityWatcher) {
validityWatcher();
validityWatcher = undefined;
if (selectionValidityWatcher) {
selectionValidityWatcher();
selectionValidityWatcher = undefined;
}
if (parametersValidityWatcher) {
parametersValidityWatcher();
parametersValidityWatcher = undefined;
}
if (bindingWatch) {
DataService.unwatch(bindingWatch);
Expand All @@ -211,7 +260,7 @@
};

var serviceClass = BindingService.getServiceClassForInstance(svcToBind, ctrl.serviceClasses);
BindingService.bindService(svcToBind, application, serviceClass).then(function(binding){
BindingService.bindService(svcToBind, application, serviceClass, ctrl.parameterData).then(function(binding){
ctrl.binding = binding;
ctrl.error = null;

Expand Down
4 changes: 1 addition & 3 deletions app/views/directives/bind-service.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
<pf-wizard
hide-header="true"
hide-sidebar="true"
hide-back-button="true"
step-class="bind-service-wizard-step"
wizard-ready="ctrl.wizardReady"
next-title="ctrl.nextTitle"
on-finish="ctrl.closeWizard()"
on-cancel="ctrl.closeWizard()"
wizard-done="ctrl.wizardComplete"
class="pf-wizard-no-back">
wizard-done="ctrl.wizardComplete">
<pf-wizard-step ng-repeat="step in ctrl.steps track by $index"
step-title="{{step.label}}"
next-enabled="step.valid"
Expand Down
3 changes: 3 additions & 0 deletions app/views/directives/bind-service/bind-parameters.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<form name="ctrl.parametersForm">
<catalog-parameters model="ctrl.parameterData" parameter-schema="ctrl.parameterSchema"></catalog-parameters>
</form>

0 comments on commit 0483125

Please sign in to comment.