aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * Copyright (C) 2021 Nordix Foundation |
| 4 | * ================================================================================ |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | * SPDX-License-Identifier: Apache-2.0 |
| 17 | * ============LICENSE_END========================================================= |
| 18 | */ |
| 19 | |
| 20 | 'use strict'; |
| 21 | |
aribeiro | 1de1692 | 2021-10-01 11:30:49 +0100 | [diff] [blame] | 22 | import {ArtifactModel} from "./artifacts"; |
andre.schmid | f13f58e | 2022-02-09 19:00:35 +0000 | [diff] [blame] | 23 | import {SchemaPropertyGroupModel} from "./schema-property"; |
| 24 | import {PROPERTY_DATA, PROPERTY_TYPES} from "../utils/constants"; |
aribeiro | 1de1692 | 2021-10-01 11:30:49 +0100 | [diff] [blame] | 25 | |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 26 | export class InputOperationParameter { |
| 27 | name: string; |
| 28 | type: string; |
andre.schmid | f13f58e | 2022-02-09 19:00:35 +0000 | [diff] [blame] | 29 | schema: SchemaPropertyGroupModel; |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 30 | inputId: string; |
| 31 | toscaDefaultValue?: string; |
andre.schmid | f13f58e | 2022-02-09 19:00:35 +0000 | [diff] [blame] | 32 | value?: any; |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 33 | |
| 34 | constructor(param?: any) { |
| 35 | if (param) { |
| 36 | this.name = param.name; |
| 37 | this.type = param.type; |
andre.schmid | f13f58e | 2022-02-09 19:00:35 +0000 | [diff] [blame] | 38 | this.schema = param.schema; |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 39 | this.inputId = param.inputId; |
| 40 | this.toscaDefaultValue = param.toscaDefaultValue; |
andre.schmid | f13f58e | 2022-02-09 19:00:35 +0000 | [diff] [blame] | 41 | this.value = param.value; |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 42 | } |
andre.schmid | f13f58e | 2022-02-09 19:00:35 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | public getDefaultValue(): any { |
| 46 | if (this.isTypeNotSimple()) { |
| 47 | if (this.toscaDefaultValue) { |
| 48 | this.toscaDefaultValue = JSON.parse(this.toscaDefaultValue); |
| 49 | return JSON.parse(this.toscaDefaultValue); |
| 50 | } |
| 51 | switch (this.type) { |
| 52 | case PROPERTY_TYPES.LIST: |
| 53 | return []; |
| 54 | default: |
| 55 | return {}; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return this.toscaDefaultValue; |
| 60 | } |
| 61 | |
| 62 | private isTypeNotSimple() { |
| 63 | return PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) == -1; |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | |
aribeiro | 1de1692 | 2021-10-01 11:30:49 +0100 | [diff] [blame] | 67 | export class PropertyOperationParameter { |
| 68 | name: string; |
| 69 | type: string; |
| 70 | value?: string; |
| 71 | propertyId: string; |
| 72 | |
| 73 | constructor(param?: any) { |
| 74 | if (param) { |
| 75 | this.name = param.name; |
| 76 | this.type = param.type; |
| 77 | this.value = param.value; |
| 78 | this.propertyId = param.propertyId; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 83 | export interface IOperationParamsList { |
| 84 | listToscaDataDefinition: Array<InputOperationParameter>; |
| 85 | } |
| 86 | |
| 87 | export class BEInterfaceOperationModel { |
| 88 | name: string; |
| 89 | description: string; |
| 90 | uniqueId: string; |
| 91 | inputs: IOperationParamsList; |
aribeiro | 1de1692 | 2021-10-01 11:30:49 +0100 | [diff] [blame] | 92 | implementation: ArtifactModel; |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 93 | |
| 94 | constructor(operation?: any) { |
| 95 | if (operation) { |
| 96 | this.name = operation.name; |
| 97 | this.description = operation.description; |
| 98 | this.uniqueId = operation.uniqueId; |
| 99 | this.inputs = operation.inputs; |
| 100 | this.implementation = operation.implementation; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | export class InterfaceOperationModel extends BEInterfaceOperationModel { |
vasraz | 6cffd9e | 2022-03-31 13:35:04 +0100 | [diff] [blame] | 106 | isCollapsed: boolean = true; |
| 107 | isEllipsis: boolean; |
| 108 | MAX_LENGTH = 75; |
| 109 | |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 110 | interfaceType: string; |
| 111 | interfaceId: string; |
| 112 | operationType: string; |
| 113 | description: string; |
| 114 | uniqueId: string; |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 115 | inputParams: IOperationParamsList; |
aribeiro | 1de1692 | 2021-10-01 11:30:49 +0100 | [diff] [blame] | 116 | implementation: ArtifactModel; |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 117 | |
| 118 | constructor(operation?: any) { |
| 119 | super(operation); |
| 120 | if (operation) { |
| 121 | this.interfaceId = operation.interfaceId; |
| 122 | this.interfaceType = operation.interfaceType; |
| 123 | this.description = operation.description; |
| 124 | this.operationType = operation.operationType; |
| 125 | this.uniqueId = operation.uniqueId; |
| 126 | this.inputParams = operation.inputParams; |
aribeiro | 1de1692 | 2021-10-01 11:30:49 +0100 | [diff] [blame] | 127 | this.implementation = operation.implementation; |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
| 131 | public displayType(): string { |
| 132 | return displayType(this.interfaceType); |
| 133 | } |
vasraz | 6cffd9e | 2022-03-31 13:35:04 +0100 | [diff] [blame] | 134 | |
| 135 | getDescriptionEllipsis(): string { |
| 136 | if (this.isCollapsed && this.description.length > this.MAX_LENGTH) { |
| 137 | return this.description.substr(0, this.MAX_LENGTH - 3) + '...'; |
| 138 | } |
| 139 | return this.description; |
| 140 | } |
| 141 | |
| 142 | toggleCollapsed(e) { |
| 143 | e.stopPropagation(); |
| 144 | this.isCollapsed = !this.isCollapsed; |
| 145 | } |
| 146 | |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 147 | } |
| 148 | |
vasraz | 6cffd9e | 2022-03-31 13:35:04 +0100 | [diff] [blame] | 149 | export class ComponentInterfaceDefinitionModel { |
aribeiro | 5c1f575 | 2020-11-19 13:28:43 +0000 | [diff] [blame] | 150 | type: string; |
| 151 | uniqueId: string; |
| 152 | operations: Array<InterfaceOperationModel>; |
| 153 | |
| 154 | constructor(interfaceOperation?: any) { |
| 155 | if (interfaceOperation) { |
| 156 | this.type = interfaceOperation.type; |
| 157 | this.uniqueId = interfaceOperation.uniqueId; |
| 158 | this.operations = interfaceOperation.operations; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | public displayType(): string { |
| 163 | return displayType(this.type); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | const displayType = (type:string) => type && type.substr(type.lastIndexOf('.') + 1); |