2 * Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * 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.
18 routeUtil.growl=function(title,message,type){
20 icon: "fa fa-envelope-o fa-lg",
21 title: " "+$.i18n.prop('org_onap_msb_route_property_ttl')+title,
22 message: message+" "
28 routeUtil.cutString=function(str){
31 newStr=str.substring(0,20)+"...";
41 routeUtil.refreshRoute=function(){
42 $(".stats_box .routeDiv div[data-name='route_click_zone']").on({
44 $(".stats_box .routeDiv").removeClass("active");
45 $(this).parent().addClass("active");
49 $(".form-title a").click(function(){
50 $(this).parent().parent().next().collapse('toggle');
53 $('.collapseContent').on('show.bs.collapse', function () {
54 var icon = $(this).prev().find('i:first');
55 icon.removeClass('fa-chevron-down').addClass("fa-chevron-up");
58 $('.collapseContent').on('hidden.bs.collapse', function () {
59 var icon = $(this).prev().find('i:first');
60 icon.removeClass('fa-chevron-up').addClass("fa-chevron-down");
66 routeUtil.groupRouteByPort=function(resp){
67 var routeArray=new Array();
68 var routeGroupArray=[[]];
69 for(var i=0;i<resp.length;i++){
71 var publish_port=resp[i].publish_port;
74 //Loop all packet classification
75 if(routeArray[publish_port] == undefined){
78 routeArray[publish_port] = list;
80 routeArray[publish_port].push(resp[i]);
85 //Sorting through all quantity > 1
88 for(var groupServiceName in routeArray){
90 if(groupServiceName==""){
91 routeGroupArray[0]=routeArray[groupServiceName];
94 routeGroupArray.push(routeArray[groupServiceName]);
100 for(var i=0;i<routeGroupArray.length;i++){
102 routeGroupArray[i].sort(function(a,b){return a.serviceName>b.serviceName?1:-1});
107 return routeGroupArray;
111 routeUtil.showGroupPort=function(index,serviceArray){
113 var defaultPort=vm.route.routePort+" <span class='protocal'>http</span> / 443 <span class='protocal'>https</span>";
115 if(serviceArray[0]==null) {return defaultPort;}
117 var publish_port=serviceArray[0].publish_port
119 if(publish_port==""){ return defaultPort;}
120 else { return publish_port}
124 routeUtil.showPotocol=function(publish_port,publishProtocol){
126 if(publish_port=="") return "";
128 return "<div class=\"protocal\" style=\"float:right\">"+publishProtocol+"</div>";
134 //Sorting grouping custom service
135 routeUtil.groupRoute=function(resp){
136 var routeArray=new Array();
137 var routeGroupArray=[[]];
139 for(var i=0;i<resp.length;i++){
141 var fullServiceName=resp[i].serviceName;
142 var groupServiceName;
144 var reg_match1=/(\/.*?)\/.*$/
145 var reg_match2=/(\/.*?)$/
147 //Canonical decomposition grouping service name
148 if(reg_match1.test(fullServiceName)){
150 groupServiceName = fullServiceName.match(reg_match1)[1];
152 else if(reg_match2.test(fullServiceName)){
154 groupServiceName = fullServiceName.match(reg_match2)[1];
157 groupServiceName=$.i18n.prop('org_onap_msb_route_property_root');
161 //Loop all packet classification
162 if(routeArray[groupServiceName] == undefined){
165 routeArray[groupServiceName] = list;
167 routeArray[groupServiceName].push(resp[i]);
174 //Sorting through all quantity > 1
177 for(var groupServiceName in routeArray){
178 var routeGroup = routeArray[groupServiceName];
180 if(routeGroup.length>1){
182 routeGroupArray.push(routeGroup);
186 routeGroupArray[0].push(routeGroup[0]);
192 //Sort + place other grouping in the final
193 var defaultGroupRoute=routeGroupArray[0];
194 defaultGroupRoute.sort(function(a,b){return a.serviceName>b.serviceName?1:-1});
195 for(var i=0;i<routeGroupArray.length-1;i++){
196 routeGroupArray[i]=routeGroupArray[i+1];
197 routeGroupArray[i].sort(function(a,b){return a.serviceName>b.serviceName?1:-1});
201 routeGroupArray[routeGroupArray.length-1]=defaultGroupRoute;
206 vm.customGroupRouteArray=routeGroupArray;
212 routeUtil.showGroupName=function(index,serviceArray){
215 var maxGroupSN=vm.customGroupRouteArray.length-1;
216 if(index==maxGroupSN){
217 return $.i18n.prop('org_onap_msb_route_property_other_group');
220 var serviceName=serviceArray[0].serviceName;
221 var reg_match1=/(\/.*?)\/.*$/
222 var reg_match2=/(\/.*?)$/
224 //Canonical decomposition grouping service name
225 if(reg_match1.test(serviceName)){
227 return serviceName.match(reg_match1)[1];
229 else if(reg_match2.test(serviceName)){
231 return serviceName.match(reg_match2)[1];
237 routeUtil.currentTime=function()
239 var now = new Date();
241 var year = now.getFullYear(); //year
242 var month = now.getMonth() + 1; //month
243 var day = now.getDate(); //date
245 var hh = now.getHours(); //hour
246 var mm = now.getMinutes(); //minu
248 var clock = year + "-";
253 clock += month + "-";
264 if (mm < 10) clock += '0';
271 routeUtil.showStatus=function(status){
273 return " <span class='label label-success'>"+$.i18n.prop('org_onap_msb_route_property_normal')+"</span>";
275 else if(status === '0'){
276 return " <span class='label label-danger'>"+$.i18n.prop('org_onap_msb_route_property_disable')+"</span>";
279 return " <span class='label label-info'>"+$.i18n.prop('org_onap_msb_route_property_unknown')+"</span>";
285 routeUtil.showVisualRange=function(visualRange){
287 var rangArray=visualRange.split("|");
289 var visualRangeText="";
291 for(var i=0;i<rangArray.length;i++){
292 if(rangArray[i] === '0'){
293 visualRangeText+= $.i18n.prop('org_onap_msb_route_form_intersystem')+" ";
295 else if(rangArray[i] === '1'){
296 visualRangeText+= $.i18n.prop('org_onap_msb_route_form_insystem')+" ";
301 return visualRangeText;
308 routeUtil.formatDetail=function(nodes){
310 var tableDetail='<table class="table table-striped hostTable">'
311 +'<thead><tr><th>IP</th><th>PORT</th><th>TTL</th><th></th></tr></thead>'
314 for(var i=0;i<nodes.length;i++){
315 var node=nodes[i].split(":");
316 tableDetail+='<tr><td>'+node[0]+'</td><td>'+node[1]+'</td><td>'+node[2]+'</td><td></td>';
322 tableDetail+=' </tbody></table>';
327 routeUtil.ifAPIUrl=function(url){
328 if(url=="" || url ==null) return false;
330 var reg_api_match =new RegExp("^(\/"+apiRootPath+"\/.*?)$","im"); // re为/^\d+bl$/gim
331 // var reg_api_match=/^(\/api\/.*?)$/;
332 return reg_api_match.test(url);
337 routeUtil.changeTargetServiceUrl=function(){
338 var serviceName=vm.msbRouteInfo.serviceName==""?"serviceName":vm.msbRouteInfo.serviceName;
340 if(vm.msbRouteInfo.protocol=='UI'){
341 vm.targetFullServiceUrl=vm.targetServiceUrl+"/"+iuiRootPath+"/"+serviceName;
343 else if(vm.msbRouteInfo.protocol=='REST'){
344 var version=vm.msbRouteInfo.version==""?"":"/"+vm.msbRouteInfo.version
345 vm.targetFullServiceUrl=vm.targetServiceUrl+"/"+apiRootPath+"/"+serviceName+version;
347 else if(vm.msbRouteInfo.protocol=='HTTP'){
348 var reg_customName_match=/^(\/.*?)$/;
349 if(!reg_customName_match.test(serviceName)) serviceName="/"+serviceName;
350 vm.targetFullServiceUrl=vm.targetServiceUrl+serviceName;