aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function')
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.html48
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.less98
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.spec.ts57
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.ts140
4 files changed, 343 insertions, 0 deletions
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.html b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.html
new file mode 100644
index 0000000000..6320058d9d
--- /dev/null
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.html
@@ -0,0 +1,48 @@
+<!--
+ ~ -
+ ~ ============LICENSE_START=======================================================
+ ~ Copyright (C) 2022 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=========================================================
+ -->
+
+<div class="component-container">
+ <ng-container [formGroup]="formGroup">
+ <div formArrayName="concatParameterList">
+ <div *ngFor="let parameter of parameters; let idx = index">
+ <div *ngIf="idx > 0" class="text-center"><span class="concat-plus-icon"></span></div>
+ <div class="parameter-card">
+ <div class="card-content">
+ <ng-container *ngIf="parameter.type === STRING_FUNCTION_TYPE">
+ <input type="text" [formControlName]="idx" [value]="parameter.value"/><br/>
+ </ng-container>
+ <ng-container *ngIf="parameter.type !== STRING_FUNCTION_TYPE">
+ <tosca-function [property]="propertyInputList[idx]" [componentInstanceMap]="componentInstanceMap" [allowClear]="false"
+ (onValidityChange)="onFunctionValidityChange($event, idx)">
+ </tosca-function>
+ </ng-container>
+ <div class="buttons-container">
+ <span class="delete-icon" (click)="removeParameter(idx)"></span>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </ng-container>
+ <div class="buttons-container">
+ <a class="add-link" (click)="addStringParameter()">String Value</a> <a class="add-link" (click)="addFunction()">String Value Expression</a>
+ </div>
+</div>
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.less b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.less
new file mode 100644
index 0000000000..b9c59831ad
--- /dev/null
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.less
@@ -0,0 +1,98 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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=========================================================
+ */
+
+@import "../../../../../../assets/styles/mixins.less";
+@import "../../../../../../assets/styles/sprite.less";
+
+.component-container {
+ max-height: 500px;
+ overflow: scroll;
+ padding: 0 5px;
+ &::-webkit-scrollbar-track {
+ border: 0;
+ }
+}
+
+.buttons-container {
+ display: flex;
+ flex-direction: row;
+ justify-content: flex-end;
+ gap: 10px;
+ margin-bottom: 10px;
+
+ .add-link {
+ .f-color.a();
+ .f-type._14_m();
+ cursor: pointer;
+
+ &:before {
+ .sprite-new();
+ .plus-icon();
+ margin-right: 5px;
+ content: "";
+ }
+
+ &:hover {
+ .f-color.b();
+ &:before {
+ .sprite-new();
+ .plus-icon-hover();
+ }
+ }
+ }
+
+ .delete-icon {
+ .sprite-new();
+ .delete-btn();
+ cursor: pointer;
+ }
+}
+
+.parameter-card {
+ border: 2px solid @main_color_o;
+ box-shadow: 0 0 0 0 rgba(0,0,0,0.2);
+ //padding: 10px;
+ border-radius: 2px;
+ transition: 0.3s;
+ margin-bottom: 5px;
+ &:hover {
+ box-shadow: 0 1px 8px 2px rgba(0,0,0,0.2);
+ }
+
+ .card-content {
+ padding: 5px 10px;
+ }
+
+ .text-center {
+ text-align: center;
+ }
+
+ input {
+ border: solid 1px @main_color_o;
+ }
+}
+
+.concat-plus-icon {
+ .sprite-new();
+ background-position: -216px -1388px;
+ width: 14px;
+ height: 14px;
+} \ No newline at end of file
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.spec.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.spec.ts
new file mode 100644
index 0000000000..5c9af47361
--- /dev/null
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.spec.ts
@@ -0,0 +1,57 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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=========================================================
+ */
+
+import {async, ComponentFixture, TestBed} from '@angular/core/testing';
+
+import {ToscaConcatFunctionComponent} from './tosca-concat-function.component';
+import {FormsModule, ReactiveFormsModule} from "@angular/forms";
+import {ToscaFunctionComponent} from "../tosca-function.component";
+import {TranslateModule} from "../../../../shared/translator/translate.module";
+import {ToscaGetFunctionComponent} from "../tosca-get-function/tosca-get-function.component";
+import {UiElementsModule} from "../../../../components/ui/ui-elements.module";
+
+describe('ToscaConcatFunctionComponent', () => {
+ let component: ToscaConcatFunctionComponent;
+ let fixture: ComponentFixture<ToscaConcatFunctionComponent>;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [ToscaConcatFunctionComponent, ToscaFunctionComponent, ToscaGetFunctionComponent],
+ imports: [
+ FormsModule,
+ ReactiveFormsModule,
+ TranslateModule,
+ UiElementsModule
+ ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(ToscaConcatFunctionComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.ts
new file mode 100644
index 0000000000..d808c284a8
--- /dev/null
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.ts
@@ -0,0 +1,140 @@
+import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
+import {FormArray, FormControl, FormGroup, Validators} from "@angular/forms";
+import {ToscaConcatFunction} from "../../../../../models/tosca-concat-function";
+import {ToscaFunctionParameter} from "../../../../../models/tosca-function-parameter";
+import {ToscaStringParameter} from "../../../../../models/tosca-string-parameter";
+import {ToscaFunctionType} from "../../../../../models/tosca-function-type.enum";
+import {PropertyBEModel} from "../../../../../models/properties-inputs/property-be-model";
+import {PROPERTY_TYPES} from "../../../../../utils/constants";
+import {InstanceFeDetails} from "../../../../../models/instance-fe-details";
+import {ToscaFunctionValidationEvent} from "../tosca-function.component";
+
+@Component({
+ selector: 'app-tosca-concat-function',
+ templateUrl: './tosca-concat-function.component.html',
+ styleUrls: ['./tosca-concat-function.component.less']
+})
+export class ToscaConcatFunctionComponent implements OnInit {
+
+ @Input() toscaConcatFunction: ToscaConcatFunction;
+ @Input() componentInstanceMap: Map<string, InstanceFeDetails> = new Map<string, InstanceFeDetails>();
+ @Output() onValidFunction: EventEmitter<ToscaConcatFunction> = new EventEmitter<ToscaConcatFunction>();
+ @Output() onValidityChange: EventEmitter<ToscaConcatFunctionValidationEvent> = new EventEmitter<ToscaConcatFunctionValidationEvent>();
+
+ concatParameterFormArray: FormArray = new FormArray([], Validators.minLength(2));
+ formGroup: FormGroup = new FormGroup(
+ {
+ 'concatParameterList': this.concatParameterFormArray
+ }
+ );
+
+ parameters: ToscaFunctionParameter[] = [];
+ propertyInputList: Array<PropertyBEModel> = [];
+
+ stringProperty: PropertyBEModel
+
+ STRING_FUNCTION_TYPE = ToscaFunctionType.STRING
+
+ constructor() {
+ this.stringProperty = new PropertyBEModel();
+ this.stringProperty.type = PROPERTY_TYPES.STRING
+ }
+
+ ngOnInit() {
+ this.initForm();
+ }
+
+ private initForm() {
+ this.formGroup.valueChanges.subscribe(() => {
+ this.onValidityChange.emit({
+ isValid: this.formGroup.valid,
+ toscaConcatFunction: this.formGroup.valid ? this.buildConcatFunctionFromForm() : undefined
+ })
+ if (this.formGroup.valid) {
+ this.onValidFunction.emit(this.buildConcatFunctionFromForm());
+ }
+ });
+ if (!this.toscaConcatFunction) {
+ return;
+ }
+
+ if (this.toscaConcatFunction.parameters) {
+ this.parameters = Array.from(this.toscaConcatFunction.parameters);
+ for (const parameter of this.parameters) {
+ if (parameter.type !== PROPERTY_TYPES.STRING) {
+ this.propertyInputList.push(this.createStringProperty(parameter));
+ this.concatParameterFormArray.push(
+ new FormControl(parameter, [Validators.required, Validators.minLength(1)])
+ );
+ } else {
+ this.propertyInputList.push(undefined);
+ this.concatParameterFormArray.push(
+ new FormControl(parameter.value, [Validators.required, Validators.minLength(1)])
+ );
+ }
+ }
+ }
+ }
+
+ private buildConcatFunctionFromForm(): ToscaConcatFunction {
+ const toscaConcatFunction1 = new ToscaConcatFunction();
+ this.concatParameterFormArray.controls.forEach(control => {
+ const value = control.value;
+ if (typeof value === 'string') {
+ const stringParameter = new ToscaStringParameter();
+ stringParameter.value = value;
+ toscaConcatFunction1.parameters.push(stringParameter);
+ } else {
+ toscaConcatFunction1.parameters.push(control.value);
+ }
+ });
+
+ return toscaConcatFunction1;
+ }
+
+ addFunction() {
+ this.propertyInputList.push(this.createStringProperty());
+ this.parameters.push({} as ToscaFunctionParameter);
+ this.concatParameterFormArray.push(
+ new FormControl(undefined, [Validators.required, Validators.minLength(1)])
+ );
+ }
+
+ addStringParameter() {
+ this.parameters.push({
+ type: ToscaFunctionType.STRING,
+ value: ''
+ });
+ this.propertyInputList.push(undefined);
+ this.concatParameterFormArray.push(
+ new FormControl('', [Validators.required, Validators.minLength(1)])
+ );
+ }
+
+ removeParameter(position) {
+ this.propertyInputList.splice(position, 1);
+ this.parameters.splice(position, 1);
+ this.concatParameterFormArray.removeAt(position);
+ }
+
+ createStringProperty(toscaFunctionParameter?: ToscaFunctionParameter) {
+ const property = new PropertyBEModel();
+ property.type = PROPERTY_TYPES.STRING;
+ property.toscaFunction = toscaFunctionParameter ? toscaFunctionParameter : undefined;
+ property.value = toscaFunctionParameter ? toscaFunctionParameter.value : undefined;
+ return property;
+ }
+
+ onFunctionValidityChange(event: ToscaFunctionValidationEvent, index: number) {
+ if (event.isValid && event.toscaFunction) {
+ this.concatParameterFormArray.controls[index].setValue(event.toscaFunction)
+ } else {
+ this.concatParameterFormArray.controls[index].setValue(undefined);
+ }
+ }
+}
+
+export interface ToscaConcatFunctionValidationEvent {
+ isValid: boolean,
+ toscaConcatFunction: ToscaConcatFunction,
+}