Support property of type List<Map<String,String>>
[sdc.git] / catalog-ui / src / app / models / properties-inputs / property-fe-model.ts
index a0c087b..d4b4540 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (C) 2020 Nokia
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -19,7 +21,7 @@
  */
 
 import * as _ from "lodash";
-import {SchemaPropertyGroupModel, SchemaProperty} from '../aschema-property';
+import {SchemaPropertyGroupModel, SchemaProperty} from '../schema-property';
 import { PROPERTY_DATA, PROPERTY_TYPES } from 'app/utils';
 import { FilterPropertiesAssignmentData, PropertyBEModel, DerivedPropertyType, DerivedFEPropertyMap, DerivedFEProperty } from 'app/models';
 
@@ -40,6 +42,7 @@ export class PropertyFEModel extends PropertyBEModel {
     valueObjOrig: any; //this is valueObj representation as saved in server
     valueObjIsChanged: boolean;
     derivedDataType: DerivedPropertyType;
+    origName: string;
 
     constructor(property: PropertyBEModel){
         super(property);
@@ -52,6 +55,7 @@ export class PropertyFEModel extends PropertyBEModel {
         this.valueObj = null;
         this.updateValueObjOrig();
         this.resetValueObjValidation();
+        this.origName = this.name;
     }
 
 
@@ -153,7 +157,7 @@ export class PropertyFEModel extends PropertyBEModel {
                     _.set(this.valueObj, childPropName, null);
                 }
             } else {
-                _.set(this.valueObj, childPropName, childProp.valueObj);
+                _.set(this.valueObj, childPropName, childProp.valueObj);        
             }
             if (childProp.valueObjIsChanged) {
                 _.set(this.valueObjValidation, childPropName, childProp.valueObjIsValid);
@@ -171,7 +175,6 @@ export class PropertyFEModel extends PropertyBEModel {
         if (!childProp.isChildOfListOrMap || childProp.derivedDataType !== DerivedPropertyType.MAP) {
             return;
         }
-
         const childParentNames = this.getParentNamesArray(childProp.parentName);
         const oldActualMapKey = childProp.getActualMapKey();
 
@@ -228,7 +231,7 @@ export class PropertyFEModel extends PropertyBEModel {
     };
 
     /* Returns array of individual parents for given prop path, with list/map UUIDs replaced with index/mapkey */
-    public getParentNamesArray = (parentPropName: string, parentNames?: Array<string>): Array<string> => {
+    public getParentNamesArray = (parentPropName: string, parentNames?: Array<string>, noHashKeys:boolean = false): Array<string> => {
         parentNames = parentNames || [];
         if (parentPropName.indexOf("#") == -1) { return parentNames; } //finished recursing parents. return
 
@@ -236,7 +239,7 @@ export class PropertyFEModel extends PropertyBEModel {
         let nameToInsert: string = parentProp.name;
 
         if (parentProp.isChildOfListOrMap) {
-            if (parentProp.derivedDataType == DerivedPropertyType.MAP) {
+            if (!noHashKeys && parentProp.derivedDataType == DerivedPropertyType.MAP && !parentProp.mapInlist) {
                 nameToInsert = parentProp.getActualMapKey();
             } else { //LIST
                 let siblingProps = this.flattenedChildren.filter(prop => prop.parentName == parentProp.parentName).map(prop => prop.propertiesName);
@@ -245,7 +248,7 @@ export class PropertyFEModel extends PropertyBEModel {
         }
 
         parentNames.splice(0, 0, nameToInsert); //add prop name to array
-        return this.getParentNamesArray(parentProp.parentName, parentNames); //continue recursing
+        return this.getParentNamesArray(parentProp.parentName, parentNames, noHashKeys); //continue recursing
     }
 
     public hasValueObjChanged() {
@@ -271,8 +274,8 @@ export class PropertyFEModel extends PropertyBEModel {
             return JSON.stringify(valueObj);
         }
 
-        // return string value as is
-        return valueObj;
+        // return trimmed string value
+        return valueObj.trim();
     }
 
     static parseValueObj(value: string, propertyType: PROPERTY_TYPES, propertyDerivedType: DerivedPropertyType, defaultValue?: string): any {