Skip to content

Commit

Permalink
Dynamic binding for service bus trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
alrod committed Apr 14, 2016
1 parent 2759e3d commit 5e72980
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {PopOverComponent} from './pop-over.component';
})

export class BindingInputComponent {
@Output() validChange = new EventEmitter<BindingInputBase<any>>();
@Output() validChange = new EventEmitter<BindingInputBase<any>>(false);
public disabled: boolean;
public enumInputs: DropDownElement<any>[];
private _input: BindingInputBase<any>;
Expand Down Expand Up @@ -82,6 +82,9 @@ export class BindingInputComponent {
}

inputChanged(value: any) {
if (this._input.changeValue) {
this._input.changeValue();
}
this.setClass(value);
this._broadcastService.broadcast(BroadcastEvent.IntegrateChanged);
}
Expand Down
68 changes: 66 additions & 2 deletions AzureFunctions.Client/app/components/binding.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component, ChangeDetectionStrategy, Input, Output, EventEmitter, OnInit, ElementRef, OnChanges, Inject, AfterContentChecked} from 'angular2/core';
import {BindingInputBase, CheckboxInput, TextboxInput, LabelInput, SelectInput, PickerInput} from '../models/binding-input';
import {Binding, DirectionType, SettingType, BindingType, UIFunctionBinding, UIFunctionConfig} from '../models/binding';
import {Binding, DirectionType, SettingType, BindingType, UIFunctionBinding, UIFunctionConfig, Rule} from '../models/binding';
import {BindingManager} from '../models/binding-manager';
import {BindingInputComponent} from './binding-input.component'
import {FunctionsService} from '../services/functions.service';
Expand Down Expand Up @@ -45,7 +45,7 @@ export class BindingComponent {
this.disabled = _broadcastService.getDirtyState("function_disabled");

this._broadcastService.subscribe(BroadcastEvent.IntegrateChanged, () => {
this.isDirty = this.model.isDirty();
this.isDirty = this.model.isDirty() || this.bindingValue.newBinding;

if (this.canDelete) {
if (this.isDirty) {
Expand Down Expand Up @@ -83,6 +83,67 @@ export class BindingComponent {

this.setLabel();
if (bindingSchema) {
if (bindingSchema.rules) {
bindingSchema.rules.forEach((rule) => {
if (rule.type === "exclusivity") {
var ddValue = rule.values[0].value;
var temp = this.bindingValue.settings;
name = this._bindingManager.guid();
rule.values.forEach((value) => {
var findResult = this.bindingValue.settings.find((s) => {
return s.name === value.value && s.value;
});
if (findResult) {
ddValue = value.value;
}
});

this.bindingValue.settings.push({
name: name,
value: ddValue,
noSave: true
});

let ddInput = new SelectInput();
ddInput.id = name;
ddInput.isHidden = false;
ddInput.label = rule.label;
ddInput.help = rule.help;
ddInput.value = ddValue;
ddInput.enum = rule.values;
ddInput.changeValue = () => {
var rules = <Rule[]><any>ddInput.enum;
rule.values.forEach((v) => {
if (ddInput.value == v.value) {
v.hiddenSettings.forEach((s) => {
v.shownSettings.forEach((s) => {
var setting = this.model.inputs.find((input) => {
return input.id === s;
});
if (setting) {
setting.isHidden = false;
setting.noSave = false;
}
});
v.hiddenSettings.forEach((s) => {
var setting = this.model.inputs.find((input) => {
return input.id === s;
});
if (setting) {
setting.isHidden = true;
setting.noSave = true;
}
});
});
}
});
this.model.orderInputs();
};
this.model.inputs.push(ddInput);
}
});
}

bindingSchema.settings.forEach((setting) => {

var functionSettingV = this.bindingValue.settings.find((s) => {
Expand Down Expand Up @@ -208,6 +269,9 @@ export class BindingComponent {
var input: BindingInputBase<any> = this.model.getInput(s.name);
if (input) {
s.value = input.value;
if (input.noSave) {
s.noSave = input.noSave;
}
}
});

Expand Down
8 changes: 6 additions & 2 deletions AzureFunctions.Client/app/models/binding-input-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export class BindingInputList {
saveOriginInputs() {
this.originInputs = JSON.parse(JSON.stringify(this.inputs));

this.orderInputs();
}

orderInputs() {

this.rightInputs = [];
this.leftInputs = [];
Expand All @@ -28,7 +32,7 @@ export class BindingInputList {
});
}

isDirty() : boolean {
isDirty(): boolean {
var result = false;
for (var i = 0; i < this.inputs.length; i++) {
if (this.inputs[i].value !== this.originInputs[i].value) {
Expand All @@ -40,7 +44,7 @@ export class BindingInputList {

isValid() {
var result = true;
this.inputs.forEach((input) => {
this.inputs.forEach((input) => {
if (!input.isValid) {
result = false;
}
Expand Down
2 changes: 2 additions & 0 deletions AzureFunctions.Client/app/models/binding-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class BindingInputBase<T>
isHidden: boolean = false;
errorText: string;
validators: Validator[] = [];
noSave: boolean = false;
changeValue: () => void;
}

export class CheckboxInput extends BindingInputBase<boolean>{
Expand Down
16 changes: 9 additions & 7 deletions AzureFunctions.Client/app/models/binding-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ export class BindingManager {
};

b.settings.forEach((s) => {
if (s.value === false) {
bindingToAdd[s.name] = false;
} else if (!s.value) {
bindingToAdd[s.name] = "";
} else {
bindingToAdd[s.name] = s.value;
}
if (!s.noSave) {
if (s.value === false) {
bindingToAdd[s.name] = false;
} else if (!s.value) {
bindingToAdd[s.name] = "";
} else {
bindingToAdd[s.name] = s.value;
}
}
});
bindingToAdd["direction"] = b.direction === DirectionType.trigger ? DirectionType.in.toString() : b.direction.toString();

Expand Down
16 changes: 16 additions & 0 deletions AzureFunctions.Client/app/models/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface Binding {
defaultParameterName?: string;
parameterNamePrompt?: string;
settings: Setting[];
rules: Rule[];
}

export interface Setting {
Expand All @@ -46,6 +47,20 @@ export interface Setting {
validators?: Validator[];
}

export interface Rule {
type: string,
values: RuleValue[];
label: string;
help: string;
}

export interface RuleValue {
value: string;
display: string;
hiddenSettings: string[];
shownSettings: string[];
}

export interface Validator {
expression: string;
errorText: string;
Expand Down Expand Up @@ -88,6 +103,7 @@ export interface UIFunctionConfig {
export interface FunctionSetting {
name: string;
value: any;
noSave?: boolean;
}

export interface FunctionBindingBase {
Expand Down

0 comments on commit 5e72980

Please sign in to comment.