2 * Created by rc2122 on 4/23/2017.
4 import {Component, Input, Output, EventEmitter} from "@angular/core";
5 import { PropertyFEModel} from "app/models";
6 import {PropertiesService} from "app/ng2/services/properties.service";
7 import { ContentAfterLastDotPipe } from "app/ng2/pipes/contentAfterLastDot.pipe";
8 import {UUID} from "angular2-uuid";
9 import {ComponentType} from "app/utils";
12 selector: 'list-property',
13 templateUrl: './list-property.component.html',
14 styleUrls: ['../properties-value-inner-table/properties-value-inner-table.component.less', './list-property.component.less']
16 export class ListPropertyComponent {
18 @Input() property: PropertyFEModel;
19 @Input() selectedPropertyId: string;
20 @Input() propertyNameSearchText:string;
22 @Output() valueChanged: EventEmitter<any> = new EventEmitter<any>();
23 @Output() selectChildProperty: EventEmitter<any> = new EventEmitter<PropertyFEModel>();
25 constructor ( private propertiesService:PropertiesService, private contentAfterLastDotPipe:ContentAfterLastDotPipe ){
28 propValueChanged = () => {
29 this.valueChanged.emit(this.property);
32 onChildPropertySelected = (property) => {
33 this.selectChildProperty.emit(property);
36 getNumber = (valueObjectRef: any): Array<any> => {
37 let num: number = (valueObjectRef) ? valueObjectRef.length : 0;
38 return new Array(num);
41 createNewChildProperty = ():void => {
42 let newProperty: PropertyFEModel = new PropertyFEModel(this.contentAfterLastDotPipe.transform(this.property.schema.property.type),
43 this.property.schema.property.type,
46 this.property.valueObjectRef[this.property.childrenProperties.length]
48 this.propertiesService.createPropertiesTreeForProp(newProperty);
49 this.property.childrenProperties.push(newProperty);
52 addListItem = ():void => {
53 this.property.valueObjectRef = this.property.valueObjectRef || [];
54 this.property.childrenProperties = this.property.childrenProperties || [];
55 if (this.property.schema.property.isSimpleType){
56 if( this.property.valueObjectRef.indexOf("") == -1 ) {//prevent insert multiple empty simple type items to list
57 this.property.valueObjectRef.push("");
60 this.property.valueObjectRef[this.property.childrenProperties.length] = {};
61 this.property.childrenProperties = this.property.childrenProperties || [];
62 this.createNewChildProperty();
63 this.valueChanged.emit(this.property);
67 deleteListItem = (indexInList:number):void => {
68 this.property.valueObjectRef.splice(indexInList, 1);
69 if(this.property.childrenProperties){
70 this.property.childrenProperties.splice(indexInList, 1);
72 if (!this.property.valueObjectRef.length) {//only when user removes all items from list - put the default
73 if ( this.property.defaultValue ) {
74 angular.copy(JSON.parse(this.property.defaultValue), this.property.valueObjectRef);
75 if (this.property.schema.property.isDataType){
76 _.forEach(this.property.valueObjectRef, () => {
77 this.createNewChildProperty();
82 this.valueChanged.emit(this.property);