1 import { Injectable } from '@angular/core';
2 import { DataTypeModel, PropertyFEModel, PropertyBEModel, SchemaProperty, DerivedFEProperty, DerivedFEPropertyMap, DerivedPropertyType, InputFEModel} from "app/models";
3 import { DataTypeService } from "./data-type.service";
4 import { PROPERTY_TYPES } from "app/utils";
5 import { ContentAfterLastDotPipe } from "../pipes/contentAfterLastDot.pipe";
6 import { UUID } from "angular2-uuid";
9 export class PropertiesService {
11 constructor(private dataTypeService: DataTypeService, private contentAfterLastDotPipe: ContentAfterLastDotPipe) {
14 public getParentPropertyFEModelFromPath = (properties: Array<PropertyFEModel>, path: string) => {
15 let parent: PropertyFEModel = _.find(properties, (property: PropertyFEModel): boolean => {
16 return property.name === path.substring(0, path.indexOf('#'));
21 //undo disabling of parent and child props=
22 public undoDisableRelatedProperties = (property: PropertyFEModel, childPath?: string): void => {
23 property.isDisabled = false;
25 property.isSelected = false;
26 property.flattenedChildren && property.flattenedChildren.map(child => child.isDisabled = false);
27 } else { //QND - unselect everything and then re-do the disabling of declared props. TODO: put a flag on propertyFEModel instead to indicate who's causing them to be disabled instead
28 property.flattenedChildren.filter(child => child.isDisabled && !child.isDeclared).map(child => child.isDisabled = false);
29 property.flattenedChildren.filter(child => child.isDeclared || child.isSelected).forEach((childProp) => { //handle brothers who are selected - redo their disabled relatives as well
30 this.disableRelatedProperties(property, childProp.propertiesName);
35 //disable parents and children of prop
36 public disableRelatedProperties = (property: PropertyFEModel, childPath?: string): void => {
37 if (!childPath) { //selecting the parent property
38 property.isSelected = true;
39 property.flattenedChildren && property.flattenedChildren.map(child => { child.isSelected = false; child.isDisabled = true; });
41 property.isSelected = false;
42 property.isDisabled = true;
43 property.flattenedChildren.filter((childProp: DerivedFEProperty) => {
44 return (childProp.propertiesName.indexOf(childPath + "#") === 0 //is child of prop to disable
45 || childPath.indexOf(childProp.propertiesName + "#") === 0); //is parent of prop to disable
46 }).map((child: DerivedFEProperty) => { child.isSelected = false; child.isDisabled = true; });
50 public getCheckedProperties = (properties: Array<PropertyFEModel>): Array<PropertyBEModel> => {
51 let selectedProps: Array<PropertyBEModel> = [];
52 properties.forEach(prop => {
53 if (prop.isSelected && !prop.isDeclared && !prop.isDisabled) {
54 selectedProps.push(new PropertyBEModel(prop));
55 } else if (prop.flattenedChildren) {
56 prop.flattenedChildren.forEach((child) => {
57 if (child.isSelected && !child.isDeclared && !child.isDisabled) {
58 let childProp = new PropertyBEModel(prop, child); //create it from the parent
59 selectedProps.push(childProp);