From 13ce0552dc7156b6e3e226c00295705f27780a40 Mon Sep 17 00:00:00 2001 From: DR695H Date: Tue, 7 Feb 2017 13:11:03 -0500 Subject: actually adding the files to the initial commit Change-Id: I2f0c09692c2ae70be61b8bb552fd1bd2983eb661 Signed-off-by: DR695H --- .../app/vid/scripts/services/componentService.js | 148 +++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 vid/src/main/webapp/app/vid/scripts/services/componentService.js (limited to 'vid/src/main/webapp/app/vid/scripts/services/componentService.js') diff --git a/vid/src/main/webapp/app/vid/scripts/services/componentService.js b/vid/src/main/webapp/app/vid/scripts/services/componentService.js new file mode 100644 index 000000000..7c1cfcb9c --- /dev/null +++ b/vid/src/main/webapp/app/vid/scripts/services/componentService.js @@ -0,0 +1,148 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +"use strict"; + +var ComponentService = function($log, COMPONENT, UtilityService) { + + var _this = this; + + var componentList = [ { + id : COMPONENT.NETWORK, + displayName : "Network" + }, { + id : COMPONENT.SERVICE, + displayName : "Service Instance" + }, { + id : COMPONENT.VNF, + displayName : "Virtual Network Function" + }, { + id : COMPONENT.VF_MODULE, + displayName : "VF Module" + }, { + id : COMPONENT.VOLUME_GROUP, + displayName : "Volume Group" + } ]; + + var getInventoryInfo = function(suffix, inventoryItem) { + var pattern = new RegExp(suffix + "-"); + for ( var key in inventoryItem) { + if (pattern.exec(key)) { + return inventoryItem[key]; + } + } + }; + + /* + * Converts 'id' to a user friendly version. + * + * The algorithm used is: + * + * 1) If "id" found in COMPONENT.FULL_NAME_MAP, return the name found in the + * map. + * + * 2) Otherwise, if camel case, add "-" between camel case words. + * + * 3) Split id into multiple "partial names" assuming "-" is the delimiter. + * + * 4) Map any partial names found in COMPONENT.PARTIAL_NAME_MAP to the name + * found in the map. + * + * 5) Use partial names whenever not found in map. + * + * 5) Return name by combining all partial names with " " delimiter. + */ + var getDisplayName = function(id) { + var tmp = COMPONENT.FULL_NAME_MAP[id.toLowerCase()]; + if (UtilityService.hasContents(tmp)) { + return tmp; + } + /* + * Add "-" if camel case found. + */ + var id = id.replace(/([a-z](?=[A-Z]))/g, '$1-'); + var name = ""; + var arg = id.split("-"); + for (var i = 0; i < arg.length; i++) { + if (i > 0) { + name += " "; + } + var tmp = COMPONENT.PARTIAL_NAME_MAP[arg[i].toLowerCase()]; + if (UtilityService.hasContents(tmp)) { + name += tmp; + } else { + name += arg[i].slice(0, 1).toUpperCase() + arg[i].slice(1); + } + } + return name; + }; + + return { + initialize : function(componentId) { + for (var i = 0; i < componentList.length; i++) { + if (componentList[i].id === componentId) { + _this.componentId = componentList[i].id; + return componentId; + } + } + throw "ComponentService:initializeComponent: componentId not found: " + + componentId; + }, + getComponentDisplayName : function() { + for (var i = 0; i < componentList.length; i++) { + if (componentList[i].id === _this.componentId) { + return componentList[i].displayName; + } + } + }, + getInventoryInfo : getInventoryInfo, + getInventoryParameterList : function(suffix, inventoryItem) { + var parameterList = new Array(); + // var pattern = new RegExp("-[intv][a-z]*$"); + // var inventoryInfo = getInventoryInfo(suffix, inventoryItem); + for ( var id in inventoryItem) { + //if (pattern.exec(id)) { + parameterList.push({ + id : id, + value : inventoryItem[id] + }); + //} + } + return parameterList; + }, + getDisplayNames : function(inputList) { + var outputList = new Array(); + for (var i = 0; i < inputList.length; i++) { + var entry = angular.copy(inputList[i]); + if (!UtilityService.hasContents(entry.name)) { + entry.name = getDisplayName(entry.id); + } + outputList.push(entry); + } + return outputList; + }, + getFieldDisplayName : function(name) { + return getDisplayName(name); + } + } +} + +app.factory("ComponentService", [ "$log", "COMPONENT", "UtilityService", + ComponentService ]); -- cgit 1.2.3-korg