[SDC] rebase 1710 code
[sdc.git] / catalog-ui / src / app / models / components / displayComponent.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 /**
21  * Created by obarda on 7/5/2016.
22  */
23
24 'use strict';
25 import {ComponentType} from "../../utils/constants";
26 import {ComponentMetadata} from "../component-metadata";
27 import {RequirementsGroup} from "../requirement";
28 import {CapabilitiesGroup} from "../capability";
29
30 export class LeftPaletteComponent {
31
32     uniqueId:string;
33     displayName:string;
34     version:string;
35     mainCategory:string;
36     subCategory:string;
37     iconClass:string;
38     componentSubType:string;
39     searchFilterTerms:string;
40     certifiedIconClass:string;
41     icon:string;
42     isRequirmentAndCapabilitiesLoaded:boolean;
43
44     uuid:string;
45     name:string;
46     lifecycleState:string;
47     allVersions:any;
48     componentType:string;
49     systemName:string;
50
51     capabilities:CapabilitiesGroup;
52     requirements:RequirementsGroup;
53
54     constructor(public component:ComponentMetadata) {
55         this.icon = component.icon;
56         this.version = component.version;
57         this.uniqueId = component.uniqueId;
58         this.isRequirmentAndCapabilitiesLoaded = false;
59         this.uuid = component.uuid;
60         this.name = component.name;
61         this.allVersions = component.allVersions;
62         this.componentType = component.componentType;
63         this.systemName = component.systemName;
64
65         if (component.categories && component.categories[0] && component.categories[0].subcategories && component.categories[0].subcategories[0]) {
66             this.mainCategory = component.categories[0].name;
67             this.subCategory = component.categories[0].subcategories[0].name;
68         } else {
69             this.mainCategory = 'Generic';
70             this.subCategory = 'Generic';
71         }
72
73         this.componentSubType = component.resourceType ? component.resourceType: 'SERVICE';
74         this.initDisplayName(component.name);
75         this.searchFilterTerms = (this.displayName + ' ' + component.description + ' ' + component.tags.join(' ')).toLowerCase() + ' ' + component.version;
76         this.initIconSprite(component.icon);
77         this.certifiedIconClass = component.lifecycleState != 'CERTIFIED' ? 'non-certified' : '';
78         if (component.icon === 'vl' || component.icon === 'cp') {
79             this.certifiedIconClass = this.certifiedIconClass + " " + 'smaller-icon';
80         }
81     }
82
83     public initDisplayName = (name:string):void => {
84         let newName =
85             _.last(_.last(_.last(_.last(_.last(_.last(_.last(_.last(name.split('tosca.nodes.'))
86                 .split('network.')).split('relationships.')).split('org.openecomp.')).split('resource.nfv.'))
87                 .split('nodes.module.')).split('cp.')).split('vl.'));
88         if (newName) {
89             this.displayName = newName;
90         } else {
91             this.displayName = name;
92         }
93     };
94
95     public initIconSprite = (icon:string):void => {
96         switch (this.componentSubType) {
97             case ComponentType.SERVICE:
98                 this.iconClass = "sprite-services-icons " + icon;
99                 break;
100             default:
101                 this.iconClass = "sprite-resource-icons " + icon;
102         }
103     }
104
105     public getComponentSubType = ():string => {
106         return this.componentSubType;
107     };
108 }