2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
23 var ComponentService = function($log, COMPONENT, UtilityService) {
\r
27 var componentList = [ {
\r
28 id : COMPONENT.NETWORK,
\r
29 displayName : "Network"
\r
31 id : COMPONENT.SERVICE,
\r
32 displayName : "Service Instance"
\r
34 id : COMPONENT.OLDVERSION,
\r
35 displayName : "Previous Version"
\r
38 displayName : "Virtual Network Function"
\r
40 id : COMPONENT.VF_MODULE,
\r
41 displayName : "VF Module"
\r
43 id: COMPONENT.VOLUME_GROUP,
\r
44 displayName: "Volume Group"
\r
46 id : COMPONENT.CONFIGURATION,
\r
47 displayName : "Port Mirroring Configuration"
\r
50 var getInventoryInfo = function(suffix, inventoryItem) {
\r
51 var pattern = new RegExp(suffix + "-");
\r
52 for ( var key in inventoryItem) {
\r
53 if (pattern.exec(key)) {
\r
54 return inventoryItem[key];
\r
60 * Converts 'id' to a user friendly version.
\r
62 * The algorithm used is:
\r
64 * 1) If "id" found in COMPONENT.FULL_NAME_MAP, return the name found in the
\r
67 * 2) Otherwise, if camel case, add "-" between camel case words.
\r
69 * 3) Split id into multiple "partial names" assuming "-" is the delimiter.
\r
71 * 4) Map any partial names found in COMPONENT.PARTIAL_NAME_MAP to the name
\r
74 * 5) Use partial names whenever not found in map.
\r
76 * 5) Return name by combining all partial names with " " delimiter.
\r
78 var getDisplayName = function(id) {
\r
79 var tmp = COMPONENT.FULL_NAME_MAP[id.toLowerCase()];
\r
80 if (UtilityService.hasContents(tmp)) {
\r
84 * Add "-" if camel case found.
\r
86 var id = id.replace(/([a-z](?=[A-Z]))/g, '$1-');
\r
88 var arg = id.split("-");
\r
89 for (var i = 0; i < arg.length; i++) {
\r
93 var tmp = COMPONENT.PARTIAL_NAME_MAP[arg[i].toLowerCase()];
\r
94 if (UtilityService.hasContents(tmp)) {
\r
97 name += arg[i].slice(0, 1).toUpperCase() + arg[i].slice(1);
\r
104 initialize : function(componentId) {
\r
105 for (var i = 0; i < componentList.length; i++) {
\r
106 if (componentList[i].id === componentId) {
\r
107 _this.componentId = componentList[i].id;
\r
108 return componentId;
\r
111 throw "ComponentService:initializeComponent: componentId not found: "
\r
114 getComponentDisplayName : function() {
\r
115 for (var i = 0; i < componentList.length; i++) {
\r
116 if (componentList[i].id === _this.componentId) {
\r
117 return componentList[i].displayName;
\r
121 getInventoryInfo : getInventoryInfo,
\r
122 getInventoryParameterList : function(suffix, inventoryItem, isPartial) {
\r
123 console.log ("getInventoryParameterList" ); console.log ( JSON.stringify ( inventoryItem, null, 4));
\r
124 var parameterList = new Array();
\r
125 var pattern = new RegExp("network-id|network-name");
\r
126 var pattern1 = new RegExp("neutron");
\r
128 if ( (suffix === COMPONENT.NETWORK) && (isPartial) ) {
\r
129 for ( var id in inventoryItem.object) {
\r
130 if (pattern.exec(id) && (!(pattern1.exec(id))) ) {
\r
131 parameterList.push({
\r
133 value : inventoryItem.object[id]
\r
138 else if (suffix === COMPONENT.NETWORK) {
\r
139 for ( var id in inventoryItem.object) {
\r
140 parameterList.push({
\r
142 value : inventoryItem.object[id]
\r
145 for ( var index in inventoryItem.subnets) {
\r
146 for (var fieldId in inventoryItem.subnets[index]) {
\r
147 parameterList.push({
\r
149 value : inventoryItem.subnets[index][fieldId]
\r
155 for ( var id in inventoryItem) {
\r
156 //if (pattern.exec(id)) {
\r
157 parameterList.push({
\r
159 value : inventoryItem[id]
\r
164 return parameterList;
\r
166 getDisplayNames : function(inputList) {
\r
167 var outputList = new Array();
\r
168 for (var i = 0; i < inputList.length; i++) {
\r
169 var entry = angular.copy(inputList[i]);
\r
170 if (!UtilityService.hasContents(entry.name)) {
\r
171 entry.name = getDisplayName(entry.id);
\r
173 outputList.push(entry);
\r
177 getFieldDisplayName : function(name) {
\r
178 return getDisplayName(name);
\r
183 appDS2.factory("ComponentService", [ "$log", "COMPONENT", "UtilityService",
\r
184 ComponentService ]);
\r