2 import { Component } from '@angular/core';
3 import { DataTypesMap, PropertyBEModel } from 'app/models';
4 import { DropdownValue } from 'app/ng2/components/ui/form-components/dropdown/ui-element-dropdown.component';
5 import { DataTypeService } from 'app/ng2/services/data-type.service';
6 import { PROPERTY_DATA } from 'app/utils';
7 import * as _ from 'lodash';
8 import { PROPERTY_TYPES } from '../../../../utils';
11 selector: 'property-creator',
12 templateUrl: './property-creator.component.html',
13 styleUrls: ['./property-creator.component.less'],
16 export class PropertyCreatorComponent {
18 typesProperties: DropdownValue[];
19 typesSchemaProperties: DropdownValue[];
20 propertyModel: PropertyBEModel;
21 // propertyNameValidationPattern:RegExp = /^[a-zA-Z0-9_:-]{1,50}$/;
22 // commentValidationPattern:RegExp = /^[\u0000-\u00BF]*$/;
23 // types:Array<string>;
24 dataTypes: DataTypesMap;
27 constructor(protected dataTypeService: DataTypeService) {}
30 this.propertyModel = new PropertyBEModel();
31 this.propertyModel.type = '';
32 this.propertyModel.schema.property.type = '';
33 const types: string[] = PROPERTY_DATA.TYPES; // All types - simple type + map + list
34 this.dataTypes = this.dataTypeService.getAllDataTypes(); // Get all data types in service
35 const nonPrimitiveTypes: string[] = _.filter(Object.keys(this.dataTypes), (type: string) => {
36 return types.indexOf(type) === -1;
39 this.typesProperties = _.map(PROPERTY_DATA.TYPES,
40 (type: string) => new DropdownValue(type, type)
42 const typesSimpleProperties = _.map(PROPERTY_DATA.SIMPLE_TYPES,
43 (type: string) => new DropdownValue(type, type)
45 const nonPrimitiveTypesValues = _.map(nonPrimitiveTypes,
46 (type: string) => new DropdownValue(type,
47 type.replace('org.openecomp.datatypes.heat.', ''))
49 .sort((a, b) => a.label.localeCompare(b.label));
50 this.typesProperties = _.concat(this.typesProperties, nonPrimitiveTypesValues);
51 this.typesSchemaProperties = _.concat(typesSimpleProperties, nonPrimitiveTypesValues);
52 this.typesProperties.unshift(new DropdownValue('', 'Select Type...'));
53 this.typesSchemaProperties.unshift(new DropdownValue('', 'Select Schema Type...'));
57 checkFormValidForSubmit() {
58 const showSchema: boolean = this.showSchema();
59 const isSchemaValid: boolean = (showSchema && !this.propertyModel.schema.property.type) ? false : true;
61 this.propertyModel.schema.property.type = '';
63 return this.propertyModel.name && this.propertyModel.type && isSchemaValid;
66 showSchema(): boolean {
67 return [PROPERTY_TYPES.LIST, PROPERTY_TYPES.MAP].indexOf(this.propertyModel.type) > -1;
70 onSchemaTypeChange(): void {
71 if (this.propertyModel.type === PROPERTY_TYPES.MAP) {
72 this.propertyModel.value = JSON.stringify({'': null});
73 } else if (this.propertyModel.type === PROPERTY_TYPES.LIST) {
74 this.propertyModel.value = JSON.stringify([]);