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)
102 this.operationOutputCats = _.filter(
104 this.operationOutputs,
107 operationName: `${op.displayType()}.${op.name}`,
109 _.filter(op.outputs.listToscaDataDefinition, output => !this.param.type || output.type === this.param.type),
110 output => new DropdownValueType(
111 `${op.interfaceType}.${op.name}.${output.name}`,
119 category => category.outputs.length > 0
122 this.filteredCapabilitiesProps = _.filter(
124 this.capabilitiesProps,
127 capabilityName: cap.name,
129 _.filter(cap.properties, prop => !this.param.type || prop.type === this.param.type),
130 prop => new DropdownValueType(
139 capability => capability.properties.length > 0
142 if (this.param.inputId) {
143 const selProp = this.getSelectedProp();
144 if (selProp && selProp.type === this.param.type) {
145 this.param.inputId = '-1';
146 setTimeout(() => this.param.inputId = selProp.uniqueId || selProp.value);
148 this.param.inputId = null;
152 this.validityChanged();
156 const newProp = this.getSelectedProp();
158 if (!this.param.type) {
159 this.param.type = newProp.type;
163 if (!this.param.name) {
164 this.param.name = newProp.name || newProp.label;
167 this.validityChanged();
170 getPrimitiveSubtypes(): Array<InputBEModel> {
171 const flattenedProps: Array<any> = [];
172 const dataTypes = this.dataTypeService.getAllDataTypes();
174 _.forEach(this.inputProps, prop => {
175 const type:DataTypeModel = _.find(
176 _.toArray(dataTypes),
177 (type: DataTypeModel) => type.name === prop.type
179 flattenedProps.push(prop);
181 console.error('Could not find prop in dataTypes: ', prop);
183 if (type.properties) {
184 _.forEach(type.properties, subType => {
185 if (this.isTypePrimitive(subType.type)) {
186 flattenedProps.push({
188 name: `${prop.name}.${subType.name}`,
189 uniqueId: `${prop.uniqueId}.${subType.name}`
197 return flattenedProps;
202 this.getPrimitiveSubtypes(),
203 prop => this.param.inputId === prop.uniqueId
206 this.operationOutputCats,
207 (acc, cat) => [...acc, ...cat.outputs],
209 (out: DropdownValueType) => this.param.inputId === out.value
212 this.filteredCapabilitiesProps,
213 (acc, cap) => [...acc, ...cap.properties],
215 (prop: DropdownValueType) => this.param.inputId === prop.value
219 isTypePrimitive(type: string): boolean {
222 type === 'integer' ||