2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import { PropertyInputDetail, SchemaPropertyGroupModel, SchemaProperty } from "app/models";
22 import { PROPERTY_DATA, PROPERTY_TYPES } from 'app/utils';
23 export enum DerivedPropertyType {
30 export class PropertyBEModel {
36 getInputValues: Array<PropertyInputDetail>
38 parentUniqueId: string;
41 schema: SchemaPropertyGroupModel;
46 constructor(property?: PropertyBEModel) {
48 this.defaultValue = property.defaultValue;
49 this.description = property.description;
50 this.fromDerived = property.fromDerived;
51 this.name = property.name;
52 this.parentUniqueId = property.parentUniqueId;
53 this.password = property.password;
54 this.required = property.required;
55 this.schema = property.schema;
56 this.type = property.type;
57 this.uniqueId = property.uniqueId;
58 this.value = property.value ? property.value : property.defaultValue;
59 this.definition = property.definition;
60 this.getInputValues = property.getInputValues;
63 if (!this.schema || !this.schema.property) {
64 this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
65 } else { //forcing creating new object, so editing different one than the object in the table
66 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(this.schema.property));
72 public toJSON = (): any => {
73 let temp = angular.copy(this);
74 temp.value = temp.value === "{}" || temp.value === "[]" ? undefined : temp.value;
75 temp.defaultValue = temp.defaultValue === "{}" || temp.defaultValue === "[]" ? undefined : temp.defaultValue;
79 public getDerivedPropertyType = () => {
80 if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1) {
81 return DerivedPropertyType.SIMPLE;
82 } else if (this.type == PROPERTY_TYPES.LIST) {
83 return DerivedPropertyType.LIST;
84 } else if (this.type == PROPERTY_TYPES.MAP) {
85 return DerivedPropertyType.MAP;
87 return DerivedPropertyType.COMPLEX;
94 // EXTRAS FROM CONSTRUCTOR:
95 // this.source = property.source;
96 // this.valueUniqueUid = property.valueUniqueUid;
97 // this.path = property.path;
98 // this.rules = property.rules;
99 // this.resourceInstanceUniqueId = property.resourceInstanceUniqueId;
100 // this.readonly = property.readonly;
101 // this.simpleType = property.simpleType;
102 // this.componentInstanceId = property.componentInstanceId;
103 // this.parentValue = property.parentValue;
104 //NEW PROPERTIES MAY NEED:
105 // export class PropertyFEModel extends PropertyBEModel {
106 // componentInstanceId: string;
107 // isAlreadySelected: boolean;
108 // filterTerm: string;
110 //FOR INPUTS, BE ALSO INCLUDES:
111 //export class InputFEModel extends PropertyBEModel {
114 // immutable: boolean;