aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts')
-rw-r--r--catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts b/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts
index fa71e47804..5718cdd9b5 100644
--- a/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts
+++ b/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
/**
* Created by rcohen on 9/15/2016.
*/
@@ -9,9 +29,11 @@ import {SchemaProperty} from "app/models";
export interface ITypeMapScope extends ng.IScope {
parentFormObj:ng.IFormController;
schemaProperty:SchemaProperty;
+ isMapKeysUnique:boolean;
isSchemaTypeDataType:boolean;
valueObjRef:any;
mapKeys:Array<string>;//array of map keys
+ mapKeysStatic:Array<string>;
MapKeyValidationPattern:RegExp;
fieldsPrefixName:string;
readOnly:boolean;
@@ -54,12 +76,15 @@ export class TypeMapDirective implements ng.IDirective {
link = (scope:ITypeMapScope, element:any, $attr:any) => {
scope.MapKeyValidationPattern = this.MapKeyValidationPattern;
+ scope.isMapKeysUnique = true;
//reset valueObjRef and mapKeys when schema type is changed
scope.$watchCollection('schemaProperty.type', (newData:any):void => {
scope.isSchemaTypeDataType = this.DataTypesService.isDataTypeForSchemaType(scope.schemaProperty);
if (scope.valueObjRef) {
scope.mapKeys = Object.keys(scope.valueObjRef);
+ //keeping another copy of the keys, as the mapKeys gets overridden sometimes
+ scope.mapKeysStatic = Object.keys(scope.valueObjRef);
}
});
@@ -69,6 +94,8 @@ export class TypeMapDirective implements ng.IDirective {
scope.valueObjRef = {};
}
scope.mapKeys = Object.keys(scope.valueObjRef);
+ //keeping another copy of the keys, as the mapKeys gets overridden sometimes
+ scope.mapKeysStatic = Object.keys(scope.valueObjRef);
if ($attr.defaultValue) {
scope.mapDefaultValue = JSON.parse($attr.defaultValue);
@@ -93,8 +120,10 @@ export class TypeMapDirective implements ng.IDirective {
let existsKeyIndex = Object.keys(scope.valueObjRef).indexOf(newKey);
if (existsKeyIndex > -1 && existsKeyIndex != index) {
scope.parentFormObj[fieldName].$setValidity('keyExist', false);
+ scope.isMapKeysUnique = false;
} else {
scope.parentFormObj[fieldName].$setValidity('keyExist', true);
+ scope.isMapKeysUnique = true;
if (!scope.parentFormObj[fieldName].$invalid) {
//To preserve the order of the keys, delete each one and recreate
let newObj = {};