1 import {Component, Input} from '@angular/core';
2 import {PROPERTY_DATA} from "app/utils";
3 import {DataTypeService} from "app/ng2/services/data-type.service";
4 import {OperationModel, OperationParameter, InputBEModel, DataTypeModel, Capability} from 'app/models';
5 import {DropdownValue} from "app/ng2/components/ui/form-components/dropdown/ui-element-dropdown.component";
7 class DropdownValueType extends DropdownValue {
10 constructor(value: string, label: string, type?: String) {
19 selector: 'param-row',
20 templateUrl: './param-row.component.html',
21 styleUrls: ['./param-row.component.less']
24 export class ParamRowComponent {
25 @Input() param: OperationParameter;
26 @Input() inputProps: Array<InputBEModel>;
27 @Input() operationOutputs: Array<OperationModel>;
28 @Input() capabilitiesProps: Array<Capability>;
29 @Input() onRemoveParam: Function;
30 @Input() isAssociateWorkflow: boolean;
31 @Input() readonly: boolean;
32 @Input() isInputParam: boolean;
33 @Input() validityChanged: Function;
35 propTypeEnum: Array<string> = [];
36 operationOutputCats: Array<{ operationName: string, outputs: Array<DropdownValueType> }> = [];
37 filteredInputProps: Array<DropdownValue> = [];
38 filteredCapabilitiesProps: Array<{capabilityName: string, properties: Array<DropdownValueType>}> = [];
40 constructor(private dataTypeService:DataTypeService) {}
43 if (this.isInputParam) {
44 this.propTypeEnum = _.uniq(
47 this.getPrimitiveSubtypes(),
49 this.operationOutputs,
50 (acc, op) => [...acc, ...op.outputs.listToscaDataDefinition],
53 this.capabilitiesProps,
54 (acc, capab) => [...acc, ...capab.properties],
61 const dataTypes: Array<DataTypeModel> = _.toArray(this.dataTypeService.getAllDataTypes());
62 this.propTypeEnum = _.concat(
66 type => this.isTypePrimitive(type.name)
73 type => !this.isTypePrimitive(type.name)
81 this.validityChanged();
85 this.validityChanged();
89 if (!this.isInputParam) {
90 this.validityChanged();
94 this.filteredInputProps = _.map(
96 this.getPrimitiveSubtypes(),
97 prop => !this.param.type || prop.type === this.param.type
99 prop => new DropdownValue(prop.uniqueId, prop.name)
101 this.filteredInputProps.unshift(new DropdownValue("",""));
103 this.operationOutputCats = _.filter(
105 this.operationOutputs,
108 operationName: `${op.displayType()}.${op.name}`,
110 _.filter(op.outputs.listToscaDataDefinition, output => !this.param.type || output.type === this.param.type),
111 output => new DropdownValueType(
112 `${op.interfaceType}.${op.name}.${output.name}`,
120 category => category.outputs.length > 0
123 this.filteredCapabilitiesProps = _.filter(
125 this.capabilitiesProps,
128 capabilityName: cap.name,
130 _.filter(cap.properties, prop => !this.param.type || prop.type === this.param.type),
131 prop => new DropdownValueType(
140 capability => capability.properties.length > 0
143 if (this.param.inputId) {
144 const selProp = this.getSelectedProp();
145 if (selProp && selProp.type === this.param.type) {
146 this.param.inputId = '-1';
147 setTimeout(() => this.param.inputId = selProp.uniqueId || selProp.value);
149 this.param.inputId = null;
153 this.validityChanged();
157 const newProp = this.getSelectedProp();
159 if (!this.param.type) {
160 this.param.type = newProp.type;
164 if (!this.param.name) {
165 this.param.name = newProp.name || newProp.label;
168 this.validityChanged();
171 getPrimitiveSubtypes(): Array<InputBEModel> {
172 const flattenedProps: Array<any> = [];
173 const dataTypes = this.dataTypeService.getAllDataTypes();
175 _.forEach(this.inputProps, prop => {
176 const type:DataTypeModel = _.find(
177 _.toArray(dataTypes),
178 (type: DataTypeModel) => type.name === prop.type
180 flattenedProps.push(prop);
182 console.error('Could not find prop in dataTypes: ', prop);
184 if (type.properties) {
185 _.forEach(type.properties, subType => {
186 if (this.isTypePrimitive(subType.type)) {
187 flattenedProps.push({
189 name: `${prop.name}.${subType.name}`,
190 uniqueId: `${prop.uniqueId}.${subType.name}`
198 return flattenedProps;
203 this.getPrimitiveSubtypes(),
204 prop => this.param.inputId === prop.uniqueId
207 this.operationOutputCats,
208 (acc, cat) => [...acc, ...cat.outputs],
210 (out: DropdownValueType) => this.param.inputId === out.value
213 this.filteredCapabilitiesProps,
214 (acc, cap) => [...acc, ...cap.properties],
216 (prop: DropdownValueType) => this.param.inputId === prop.value
220 isTypePrimitive(type: string): boolean {
223 type === 'integer' ||