Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support bind parameters #409

Merged
merged 1 commit into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/mockServices/mockBinding.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as _ from 'lodash';

interface IBindingService {
bindingResource: any;
bindService(serviceInstance: any, application: any, serviceClass: any) : angular.IPromise < any >;
bindService(serviceInstance: any, application: any, serviceClass: any, parameters: any) : angular.IPromise < any >;
getServiceClassForInstance(serviceInstance: any, serviceClasses: any) : any;
isServiceBindable(serviceInstance: any, serviceClasses: any) : boolean;
}
Expand All @@ -29,7 +29,7 @@ export class BindingService implements IBindingService {
return _.get(serviceClasses, [serviceClassName]);
}

public bindService (serviceInstance: any, application: any, serviceClasses: any): angular.IPromise < any > {
public bindService (serviceInstance: any, application: any, serviceClass: any, parameters: any): angular.IPromise < any > {
let deferred = this.$q.defer();

var data: any = {};
Expand Down
110 changes: 67 additions & 43 deletions dist/origin-web-catalogs.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="config-top">
<form name="$ctrl.forms.bindParametersForm" class="config-form">
<catalog-parameters
ng-if="$ctrl.bindParameterSchema.properties"
model="$ctrl.bindParameterData"
parameter-schema="$ctrl.bindParameterSchema">
</catalog-parameters>
</form>
</div>
58 changes: 53 additions & 5 deletions src/components/order-service/order-service.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ export class OrderServiceController implements angular.IController {
private planStep: any;
private configStep: any;
private bindStep: any;
private bindParametersStep: any;
private reviewStep: any;
private selectedProjectWatch: any;
private bindTypeWatch: any;
private deploymentConfigs: any;
private deployments: any;
private replicationControllers: any;
Expand Down Expand Up @@ -64,6 +66,7 @@ export class OrderServiceController implements angular.IController {
this.ctrl.plans = _.get(this, 'ctrl.serviceClass.resource.plans', []);
this.ctrl.applications = [];
this.ctrl.parameterData = {};
this.ctrl.bindParameterData = {};
this.ctrl.forms = {};

this.ctrl.appToBind = null;
Expand Down Expand Up @@ -96,6 +99,15 @@ export class OrderServiceController implements angular.IController {
valid: true,
onShow: this.showBind
};
this.bindParametersStep = {
label: 'Parameters',
id: 'bind-parameters',
view: 'order-service/order-service-bind-parameters.html',
hidden: false,
allowed: false,
valid: true,
onShow: this.showBindParameters
};
this.reviewStep = {
label: 'Results',
id: 'results',
Expand All @@ -107,7 +119,7 @@ export class OrderServiceController implements angular.IController {
onShow: this.showResults
};

this.ctrl.steps = [this.planStep, this.configStep, this.bindStep, this.reviewStep];
this.ctrl.steps = [this.planStep, this.configStep, this.bindStep, this.bindParametersStep, this.reviewStep];
this.ctrl.nameTaken = false;
this.ctrl.wizardDone = false;
this.ctrl.bindType = "none";
Expand All @@ -127,6 +139,16 @@ export class OrderServiceController implements angular.IController {
this.onProjectUpdate
);

this.bindTypeWatch = this.$scope.$watch("$ctrl.bindType", (current: any, previous: any) => {
if (current === previous) {
return;
}

this.updateBindParametersStepVisibility();
this.ctrl.nextTitle = this.bindParametersStep.hidden ? 'Create' : 'Next >';
this.reviewStep.allowed = this.bindParametersStep.hidden && this.bindStep.valid;
});

this.AuthService.withUser().then((user) => {
this.user = user;
this.ctrl.wizardReady = true;
Expand Down Expand Up @@ -163,8 +185,8 @@ export class OrderServiceController implements angular.IController {
public showBind = () => {
this.clearValidityWatcher();
this.ctrl.configPageShown = false;
this.ctrl.nextTitle = 'Create';
this.reviewStep.allowed = this.bindStep.valid;
this.ctrl.nextTitle = this.bindParametersStep.hidden ? 'Create' : 'Next >';
this.reviewStep.allowed = this.bindParametersStep.hidden && this.bindStep.valid;

if (this.isNewProject()) {
this.ctrl.projectDisplayName = this.ctrl.selectedProject.metadata.annotations['new-display-name'] || this.ctrl.selectedProject.metadata.name;
Expand All @@ -174,7 +196,17 @@ export class OrderServiceController implements angular.IController {

this.validityWatcher = this.$scope.$watch("$ctrl.forms.bindForm.$valid", (isValid: any, lastValue: any) => {
this.bindStep.valid = isValid;
this.reviewStep.allowed = this.bindStep.valid;
this.bindParametersStep.allowed = isValid;
this.reviewStep.allowed = this.bindParametersStep.hidden && this.bindStep.valid;
});
};

public showBindParameters = () => {
this.clearValidityWatcher();
this.ctrl.nextTitle = 'Create';
this.validityWatcher = this.$scope.$watch("$ctrl.forms.bindParametersForm.$valid", (isValid: any, lastValue: any) => {
this.bindParametersStep.valid = isValid;
this.reviewStep.allowed = this.bindParametersStep.valid;
});
};

Expand Down Expand Up @@ -257,7 +289,10 @@ export class OrderServiceController implements angular.IController {
namespace: _.get(this.ctrl.selectedProject, 'metadata.name')
};
var application = this.ctrl.bindType === 'application' ? this.ctrl.appToBind : undefined;
this.BindingService.bindService(this.ctrl.serviceInstance, application, this.ctrl.serviceClass.resource).then((binding: any) => {
this.BindingService.bindService(this.ctrl.serviceInstance,
application,
this.ctrl.serviceClass.resource,
this.ctrl.bindParameterData).then((binding: any) => {
this.ctrl.binding = binding;

this.watches.push(this.DataService.watchObject(this.BindingService.bindingResource, _.get(this.ctrl.binding, 'metadata.name'), context, (binding: any) => {
Expand All @@ -271,6 +306,7 @@ export class OrderServiceController implements angular.IController {
public $onDestroy() {
this.DataService.unwatchAll(this.watches);
this.selectedProjectWatch();
this.bindTypeWatch();
this.clearValidityWatcher();
}

Expand All @@ -296,6 +332,8 @@ export class OrderServiceController implements angular.IController {
this.bindStep.hidden = !_.get(this.ctrl.serviceClass, "resource.bindable");
}

this.updateBindParametersStepVisibility();

if (this.ctrl.configPageShown) {
this.reviewStep.allowed = this.bindStep.hidden;

Expand All @@ -307,6 +345,14 @@ export class OrderServiceController implements angular.IController {
}
}

private updateBindParametersStepVisibility() {
// Show the bind parameters step if the bind step if not hidden and the plan has a bind parameter schema.
this.bindParametersStep.hidden = this.bindStep.hidden ||
this.ctrl.bindType === 'none' ||
!_.has(this.ctrl, 'bindParameterSchema.properties');
this.bindParametersStep.allowed = this.bindStep.valid;
};

private updateParameterSchema(plan: any) {
let schema: any = _.get(plan, 'alphaInstanceCreateParameterSchema');
if (_.has(schema, ['properties', OrderServiceController.REQUESTER_USERNAME_PARAM_NAME])) {
Expand All @@ -318,6 +364,8 @@ export class OrderServiceController implements angular.IController {
}
this.ctrl.parameterSchema = schema;
this.ctrl.parameterFormDefinition = _.get(this, 'ctrl.selectedPlan.externalMetadata.schemas.service_instance.create.openshift_form_definition');

this.ctrl.bindParameterSchema = _.get(plan, 'alphaBindingCreateParameterSchema');
}

private onProjectUpdate = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/order-service/order-service.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
on-finish="$ctrl.closePanel()"
on-cancel="$ctrl.closePanel()"
wizard-done="$ctrl.wizardDone">
<pf-wizard-step ng-repeat="step in $ctrl.steps track by $index"
<pf-wizard-step ng-repeat="step in $ctrl.steps track by step.id"
step-title="{{step.label}}"
wz-disabled="{{step.hidden}}"
allow-click-nav="step.allowed"
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ angular
$templateCache.put('order-service/order-service-plans.html', require('./components/order-service/order-service-plans.html'));
$templateCache.put('order-service/order-service-configure.html', require('./components/order-service/order-service-configure.html'));
$templateCache.put('order-service/order-service-bind.html', require('./components/order-service/order-service-bind.html'));
$templateCache.put('order-service/order-service-bind-parameters.html', require('./components/order-service/order-service-bind-parameters.html'));
$templateCache.put('order-service/order-service-review.html', require('./components/order-service/order-service-review.html'));

// Override the default angular-schema-form-bootstrap decorators for custom
Expand Down