summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app/models')
-rw-r--r--catalog-ui/src/app/models/metadata.ts31
-rw-r--r--catalog-ui/src/app/models/metadataEntry.ts25
-rw-r--r--catalog-ui/src/app/models/properties-inputs/input-fe-model.ts75
-rw-r--r--catalog-ui/src/app/models/properties-inputs/property-be-model.ts3
4 files changed, 133 insertions, 1 deletions
diff --git a/catalog-ui/src/app/models/metadata.ts b/catalog-ui/src/app/models/metadata.ts
new file mode 100644
index 0000000000..4db08006b4
--- /dev/null
+++ b/catalog-ui/src/app/models/metadata.ts
@@ -0,0 +1,31 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+'use strict';
+import * as _ from "lodash";
+
+export class Metadata {
+
+ constructor(metaDataValues?:Metadata) {
+ _.forEach(metaDataValues, (metaDataValue:string, key) => {
+ this[key] = metaDataValue;
+ });
+ }
+}
+
diff --git a/catalog-ui/src/app/models/metadataEntry.ts b/catalog-ui/src/app/models/metadataEntry.ts
new file mode 100644
index 0000000000..c8dddc8d30
--- /dev/null
+++ b/catalog-ui/src/app/models/metadataEntry.ts
@@ -0,0 +1,25 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+export class MetadataEntry {
+ public metaDataMapKey: string;
+ constructor(public key: string, public value: string) {
+ this.metaDataMapKey = key;
+ }
+} \ No newline at end of file
diff --git a/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts b/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts
index 85c514bcbc..909f712a4e 100644
--- a/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts
+++ b/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts
@@ -24,6 +24,8 @@ import {PropertyFEModel} from "../../models";
import {PROPERTY_DATA} from "../../utils/constants";
import {InputBEModel} from "./input-be-model";
import {DerivedPropertyType} from "./property-be-model";
+import { Metadata } from "app/models/metadata";
+import { MetadataEntry } from "app/models/metadataEntry";
export class InputFEModel extends InputBEModel {
isSimpleType: boolean;
@@ -35,6 +37,10 @@ export class InputFEModel extends InputBEModel {
defaultValueObjIsChanged:boolean;
derivedDataType: DerivedPropertyType;
requiredOrig: boolean;
+ metadataOrig: Metadata;
+ metadataIsValid:boolean;
+ metadataEntries: MetadataEntry[] = [];
+ metadataMapKeyError: string;
constructor(input?: InputBEModel) {
super(input);
@@ -50,6 +56,14 @@ export class InputFEModel extends InputBEModel {
this.updateDefaultValueObjOrig();
this.requiredOrig = this.required;
+ this.metadataOrig = _.cloneDeep(input.metadata);
+ this.metadataIsValid = true;
+
+ if (input.metadata){
+ for (let key of Object.keys(input.metadata)){
+ this.metadataEntries.push(new MetadataEntry(key, input.metadata[key]));
+ }
+ }
}
}
@@ -84,7 +98,66 @@ export class InputFEModel extends InputBEModel {
return this.required !== this.requiredOrig;
}
+ public updateMetadataKey(metadataEntry: MetadataEntry, newKey){
+ if (!newKey){
+ this.metadataIsValid = false;
+ this.metadataMapKeyError = 'Key cannot be empty.';
+ metadataEntry.key = newKey;
+ return;
+ } else if (metadataEntry.metaDataMapKey != newKey && this.metadata[newKey]){
+ this.metadataIsValid = false;
+ this.metadataMapKeyError = 'This key already exists!!.';
+ metadataEntry.key = newKey;
+ return;
+ }
+ this.metadataIsValid = true;
+ this.metadataMapKeyError = null;
+
+ if(metadataEntry.metaDataMapKey != newKey){
+ this.metadata[newKey] = _.cloneDeep(this.metadata[metadataEntry.metaDataMapKey]);
+ delete this.metadata[metadataEntry.metaDataMapKey];
+ metadataEntry.metaDataMapKey = newKey;
+ }
+ metadataEntry.key = newKey;
+ }
+
+ public updateMetadataValue(metadataEntry: MetadataEntry, value: string){
+ metadataEntry.value = value;
+ this.metadata[metadataEntry.key] = value;
+ }
+
+ public addMetadataEntry(metadataEntry: MetadataEntry){
+ this.metadataEntries.push(metadataEntry);
+ if (!this.metadata){
+ this.metadata = new Metadata;
+ }
+ this.metadata[metadataEntry.key] = metadataEntry.value;
+ }
+
+ public deleteMetadataEntry(metadataEntry: MetadataEntry){
+ let metadataEntryIndex = this.metadataEntries.findIndex(item => item.key === metadataEntry.key);
+ if (metadataEntryIndex != -1){
+ this.metadataEntries.splice(metadataEntryIndex, 1);
+ }
+ delete this.metadata[metadataEntry.key];
+ }
+
+ public resetMetadata = (): void => {
+ this.metadata = _.cloneDeep(this.metadataOrig);
+ this.metadataIsValid = true;
+
+ this.metadataEntries = [];
+ for (let key of Object.keys(this.metadata)){
+ this.metadataEntries.push(new MetadataEntry(key, this.metadata[key]));
+ }
+ }
+
+ hasMetadataChanged(): boolean {
+ return !_.isEqual(this.metadata, this.metadataOrig);
+ }
+
hasChanged(): boolean {
- return this.hasDefaultValueChanged() || this.hasRequiredChanged();
+ return this.hasDefaultValueChanged() || this.hasRequiredChanged() || this.hasMetadataChanged();
}
+
} \ No newline at end of file
diff --git a/catalog-ui/src/app/models/properties-inputs/property-be-model.ts b/catalog-ui/src/app/models/properties-inputs/property-be-model.ts
index 1d263bd8b0..b997ea4563 100644
--- a/catalog-ui/src/app/models/properties-inputs/property-be-model.ts
+++ b/catalog-ui/src/app/models/properties-inputs/property-be-model.ts
@@ -22,6 +22,7 @@ import { PROPERTY_DATA, PROPERTY_TYPES } from 'app/utils/constants';
import { SchemaProperty, SchemaPropertyGroupModel } from '../aschema-property';
import { ToscaPresentationData } from '../tosca-presentation';
import { PropertyInputDetail } from './property-input-detail';
+import { Metadata } from '../metadata';
export enum DerivedPropertyType {
SIMPLE,
@@ -63,6 +64,7 @@ export class PropertyBEModel {
subPropertyInputPath: string;
inputPath: string;
toscaPresentation: ToscaPresentationData;
+ metadata: Metadata;
constructor(property?: PropertyBEModel) {
if (property) {
@@ -87,6 +89,7 @@ export class PropertyBEModel {
this.toscaPresentation = property.toscaPresentation;
this.getPolicyValues = property.getPolicyValues;
this.inputPath = property.inputPath;
+ this.metadata = property.metadata;
}
if (!this.schema || !this.schema.property) {