summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/view-models
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2020-12-15 16:12:59 +0000
committerMichael Morris <michael.morris@est.tech>2021-01-12 16:35:48 +0000
commit69779180f8f4e020606634f9bd8cac728daed2a2 (patch)
tree87167832f478509436365d07bd2e46a9c8970365 /catalog-ui/src/app/view-models
parent1f4756dab7b29843a89fb42943ae3dc0ee8b1ae9 (diff)
Support for category specific metadata
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-3412 Change-Id: I87392cc21dc25253b558bdc1d453d99659d049fa
Diffstat (limited to 'catalog-ui/src/app/view-models')
-rw-r--r--catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts59
-rw-r--r--catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html59
2 files changed, 116 insertions, 2 deletions
diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts
index e10dc98fac..cab4b6c236 100644
--- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts
+++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts
@@ -24,12 +24,13 @@ import {ModalsHandler, ValidationUtils, EVENTS, CHANGE_COMPONENT_CSAR_VERSION_FL
ResourceType, ComponentState, instantiationType, ComponentFactory} from "app/utils";
import { EventListenerService, ProgressService} from "app/services";
import {CacheService, OnboardingService, ImportVSPService} from "app/services-ng2";
-import {IAppConfigurtaion, IValidate, IMainCategory, Resource, ISubCategory,Service, ICsarComponent, Component} from "app/models";
+import {IAppConfigurtaion, IValidate, IMainCategory, Resource, ISubCategory,Service, ICsarComponent, Component, IMetadataKey} from "app/models";
import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
import {Dictionary} from "lodash";
import { PREVIOUS_CSAR_COMPONENT } from "../../../../utils/constants";
import { Observable, Subject } from "rxjs";
-
+import { MetadataEntry } from "app/models/metadataEntry";
+import { Metadata } from "app/models/metadata";
export class Validation {
componentNameValidationPattern:RegExp;
@@ -630,6 +631,20 @@ export class GeneralViewModel {
this.$scope.component.selectedCategory = this.$scope.componentCategories.selectedCategory;
this.$scope.component.categories = this.convertCategoryStringToOneArray();
this.$scope.component.icon = DEFAULT_ICON;
+ if (this.$scope.component.categories[0].metadataKeys) {
+ for (let metadataKey of this.$scope.component.categories[0].metadataKeys) {
+ if (!this.$scope.component.categorySpecificMetadata[metadataKey.name]) {
+ this.$scope.component.categorySpecificMetadata[metadataKey.name] = "";
+ }
+ }
+ }
+ if (this.$scope.component.categories[0].subcategories && this.$scope.component.categories[0].subcategories[0].metadataKeys) {
+ for (let metadataKey of this.$scope.component.categories[0].subcategories[0].metadataKeys) {
+ if (!this.$scope.component.categorySpecificMetadata[metadataKey.name]) {
+ this.$scope.component.categorySpecificMetadata[metadataKey.name] = "";
+ }
+ }
+ }
};
this.$scope.onEcompGeneratedNamingChange = (): void => {
@@ -645,11 +660,51 @@ export class GeneralViewModel {
};
this.EventListenerService.registerObserverCallback(EVENTS.ON_LIFECYCLE_CHANGE, this.$scope.reload);
+
+ this.$scope.isMetadataKeyMandatory = (key: string): boolean => {
+ let metadataKey = this.getMetadataKey(this.$scope.component.categories, key);
+ return metadataKey && metadataKey.mandatory;
+ }
+
+ this.$scope.getMetadataKeyValidValues = (key: string): string[] => {
+ let metadataKey = this.getMetadataKey(this.$scope.component.categories, key);
+ if (metadataKey) {
+ return metadataKey.validValues;
+ }
+ return [];
+ }
+
+ this.$scope.isMetadataKeyForComponentCategory = (key: string): boolean => {
+ return this.getMetadataKey(this.$scope.component.categories, key) != null;
+ }
+
}
private setUnsavedChanges = (hasChanges: boolean): void => {
this.$state.current.data.unsavedChanges = hasChanges;
}
+ private getMetadataKey(categories: IMainCategory[], key: string) : IMetadataKey {
+ let metadataKey = this.getSubcategoryMetadataKey(this.$scope.component.categories, key);
+ if (!metadataKey){
+ return this.getCategoryMetadataKey(this.$scope.component.categories, key);
+ }
+ return metadataKey;
+ }
+
+ private getSubcategoryMetadataKey(categories: IMainCategory[], key: string) : IMetadataKey {
+ if (categories[0].subcategories && categories[0].subcategories[0].metadataKeys && categories[0].subcategories[0].metadataKeys.some(metadataKey => metadataKey.name == key)) {
+ return categories[0].subcategories[0].metadataKeys.find(metadataKey => metadataKey.name == key);
+ }
+ return null;
+ }
+
+ private getCategoryMetadataKey(categories: IMainCategory[], key: string) : IMetadataKey {
+ if (categories[0].metadataKeys && categories[0].metadataKeys.some(metadataKey => metadataKey.name == key)) {
+ return categories[0].metadataKeys.find(metadataKey => metadataKey.name == key);
+ }
+ return null;
+ }
+
}
diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html
index 42a8aa3e68..a04948e460 100644
--- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html
+++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html
@@ -114,6 +114,65 @@
<!--------------------- CATEGORIES -------------------->
</div>
</div>
+
+ <!--------------------- Category Specific Metadata -------------------->
+
+ <div ng-if="component.selectedCategory">
+ <ng-container ng-repeat="(key, value) in component.categorySpecificMetadata"-->
+ <div ng-if="isMetadataKeyForComponentCategory(key) && getMetadataKeyValidValues(key) && isMetadataKeyMandatory(key)"
+ class="i-sdc-form-item"
+ data-ng-class="{'error': validateField(editForm['{{key}}'])}">
+ <label class="i-sdc-form-label required" translate="{{key}}"></label>
+ <select class="i-sdc-form-select"
+ name="{{key}}"
+ data-ng-class="{'view-mode': isViewMode()}"
+ data-ng-model="component.categorySpecificMetadata[key]"
+ data-tests-id="{{key}}"
+ data-required>
+ <option ng-repeat="value in getMetadataKeyValidValues(key)">{{value}}</option>
+ </select>
+ <div class="input-error" data-ng-show="validateField(editForm['{{key}}'])">
+ <span ng-show="editForm['{{key}}'].$error.required" translate="NEW_SERVICE_RESOURCE_ERROR_REQUIRED"></span>
+ </div>
+ </div>
+ <div ng-if="isMetadataKeyForComponentCategory(key) && getMetadataKeyValidValues(key) && !isMetadataKeyMandatory(key)"
+ class="i-sdc-form-item">
+ <label class="i-sdc-form-label" translate="{{key}}"></label>
+ <select class="i-sdc-form-select"
+ name="{{key}}"
+ data-ng-class="{'view-mode': isViewMode()}"
+ data-ng-model="component.categorySpecificMetadata[key]"
+ data-tests-id="{{key}}">
+ <option ng-repeat="value in getMetadataKeyValidValues(key)">{{value}}</option>
+ </select>
+ </div>
+ <div ng-if="isMetadataKeyForComponentCategory(key) && !getMetadataKeyValidValues(key) && isMetadataKeyMandatory(key)"
+ class="i-sdc-form-item"
+ data-ng-class="{'error': validateField(editForm['{{key}}'])}">
+ <label class="i-sdc-form-label required" translate="{{key}}"></label>
+ <input class="i-sdc-form-input" type="text"
+ data-required
+ data-ng-class="{'view-mode': isViewMode()}"
+ data-ng-model="component.categorySpecificMetadata[key]"
+ name="{{key}}"
+ data-tests-id="{{key}}"
+ />
+ <div class="input-error" data-ng-show="validateField(editForm['{{key}}'])">
+ <span ng-show="editForm['{{key}}'].$error.required" translate="NEW_SERVICE_RESOURCE_ERROR_REQUIRED"></span>
+ </div>
+ </div>
+ <div ng-if="isMetadataKeyForComponentCategory(key) && !getMetadataKeyValidValues(key) && !isMetadataKeyMandatory(key)"
+ class="i-sdc-form-item">
+ <label class="i-sdc-form-label" translate="{{key}}"></label>
+ <input class="i-sdc-form-input" type="text"
+ data-ng-class="{'view-mode': isViewMode()}"
+ data-ng-model="component.categorySpecificMetadata[key]"
+ name="{{key}}"
+ data-tests-id="{{key}}"
+ />
+ </div>
+ </ng-container>
+ </div>
<!--------------------- RESOURCE TAGS -------------------->
<div class="i-sdc-form-item" data-ng-class="{'error': validateField(editForm.tags)}">
<label class="i-sdc-form-label" translate="GENERAL_LABEL_TAGS"></label>