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_openo_msb_route_property_ttl')+title,
22 message: message+" "
29 routeUtil.refreshRoute=function(){
30 $(".stats_box .routeDiv div[data-name='route_click_zone']").on({
32 $(".stats_box .routeDiv").removeClass("active");
33 $(this).parent().addClass("active");
37 $(".form-title a").click(function(){
38 $(this).parent().parent().next().collapse('toggle');
41 $('.collapseContent').on('show.bs.collapse', function () {
42 var icon = $(this).prev().find('i:first');
43 icon.removeClass('fa-chevron-down').addClass("fa-chevron-up");
46 $('.collapseContent').on('hidden.bs.collapse', function () {
47 var icon = $(this).prev().find('i:first');
48 icon.removeClass('fa-chevron-up').addClass("fa-chevron-down");
54 //Sorting grouping custom service
55 routeUtil.groupRoute=function(resp){
56 var routeArray=new Array();
57 var routeGroupArray=[[]];
59 for(var i=0;i<resp.length;i++){
61 var fullServiceName=resp[i].serviceName;
64 var reg_match1=/(\/.*?)\/.*$/
65 var reg_match2=/(\/.*?)$/
67 //Canonical decomposition grouping service name
68 if(reg_match1.test(fullServiceName)){
70 groupServiceName = fullServiceName.match(reg_match1)[1];
72 else if(reg_match2.test(fullServiceName)){
74 groupServiceName = fullServiceName.match(reg_match2)[1];
77 groupServiceName=$.i18n.prop('org_openo_msb_route_property_root');
81 //Loop all packet classification
82 if(routeArray[groupServiceName] == undefined){
85 routeArray[groupServiceName] = list;
87 routeArray[groupServiceName].push(resp[i]);
94 //Sorting through all quantity > 1
97 for(var groupServiceName in routeArray){
98 var routeGroup = routeArray[groupServiceName];
100 if(routeGroup.length>1){
102 routeGroupArray.push(routeGroup);
106 routeGroupArray[0].push(routeGroup[0]);
112 //Sort + place other grouping in the final
113 var defaultGroupRoute=routeGroupArray[0];
114 defaultGroupRoute.sort(function(a,b){return a.serviceName>b.serviceName?1:-1});
115 for(var i=0;i<routeGroupArray.length-1;i++){
116 routeGroupArray[i]=routeGroupArray[i+1];
117 routeGroupArray[i].sort(function(a,b){return a.serviceName>b.serviceName?1:-1});
121 routeGroupArray[routeGroupArray.length-1]=defaultGroupRoute;
126 vm.customGroupRouteArray=routeGroupArray;
132 routeUtil.showGroupName=function(index,serviceArray){
135 var maxGroupSN=vm.customGroupRouteArray.length-1;
136 if(index==maxGroupSN){
137 return $.i18n.prop('org_openo_msb_route_property_other_group');
140 var serviceName=serviceArray[0].serviceName;
141 var reg_match1=/(\/.*?)\/.*$/
142 var reg_match2=/(\/.*?)$/
144 //Canonical decomposition grouping service name
145 if(reg_match1.test(serviceName)){
147 return serviceName.match(reg_match1)[1];
149 else if(reg_match2.test(serviceName)){
151 return serviceName.match(reg_match2)[1];
157 routeUtil.currentTime=function()
159 var now = new Date();
161 var year = now.getFullYear(); //year
162 var month = now.getMonth() + 1; //month
163 var day = now.getDate(); //date
165 var hh = now.getHours(); //hour
166 var mm = now.getMinutes(); //minu
168 var clock = year + "-";
173 clock += month + "-";
184 if (mm < 10) clock += '0';
191 routeUtil.showStatus=function(status){
193 return " <span class='label label-success'>"+$.i18n.prop('org_openo_msb_route_property_normal')+"</span>";
195 else if(status === '0'){
196 return " <span class='label label-danger'>"+$.i18n.prop('org_openo_msb_route_property_disable')+"</span>";
199 return " <span class='label label-info'>"+$.i18n.prop('org_openo_msb_route_property_unknown')+"</span>";
205 routeUtil.showVisualRange=function(visualRange){
207 var rangArray=visualRange.split("|");
209 var visualRangeText="";
211 for(var i=0;i<rangArray.length;i++){
212 if(rangArray[i] === '0'){
213 visualRangeText+= $.i18n.prop('org_openo_msb_route_form_intersystem')+" ";
215 else if(rangArray[i] === '1'){
216 visualRangeText+= $.i18n.prop('org_openo_msb_route_form_insystem')+" ";
221 return visualRangeText;
228 routeUtil.formatDetail=function(nodes){
230 var tableDetail='<table class="table table-striped hostTable">'
231 +'<thead><tr><th>IP</th><th>PORT</th><th>TTL</th><th></th></tr></thead>'
234 for(var i=0;i<nodes.length;i++){
235 var node=nodes[i].split(":");
236 tableDetail+='<tr><td>'+node[0]+'</td><td>'+node[1]+'</td><td>'+node[2]+'</td><td></td>';
242 tableDetail+=' </tbody></table>';
247 routeUtil.ifAPIUrl=function(url){
248 if(url=="" || url ==null) return false;
250 var reg_api_match =new RegExp("^(\/"+apiRootPath+"\/.*?)$","im"); // re为/^\d+bl$/gim
251 // var reg_api_match=/^(\/api\/.*?)$/;
252 return reg_api_match.test(url);
257 routeUtil.changeTargetServiceUrl=function(){
258 var serviceName=vm.msbRouteInfo.serviceName==""?"serviceName":vm.msbRouteInfo.serviceName;
260 if(vm.msbRouteInfo.protocol=='UI'){
261 vm.targetFullServiceUrl=vm.targetServiceUrl+"/"+iuiRootPath+"/"+serviceName;
263 else if(vm.msbRouteInfo.protocol=='REST'){
264 if(routeUtil.ifAPIUrl(vm.msbRouteInfo.url)){
265 var version=vm.msbRouteInfo.version==""?"":"/"+vm.msbRouteInfo.version
266 vm.targetFullServiceUrl=vm.targetServiceUrl+"/"+apiRootPath+"/"+serviceName+version;
269 var reg_customName_match=/^(\/.*?)$/;
270 if(!reg_customName_match.test(serviceName)) serviceName="/"+serviceName;
271 vm.targetFullServiceUrl=vm.targetServiceUrl+serviceName;