2 * Copyright 2016 2015-2016 ZTE, Inc. and others. All rights reserved.
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.
16 * Author: Zhaoxing Meng
17 * email: meng.zhaoxing1@zte.com.cn
21 routeUtil.growl=function(title,message,type){
23 icon: "fa fa-envelope-o fa-lg",
24 title: " "+$.i18n.prop('org_openo_msb_route_property_ttl')+title,
25 message: message+" "
32 routeUtil.refreshRoute=function(){
33 $(".stats_box .routeDiv div[data-name='route_click_zone']").on({
35 $(".stats_box .routeDiv").removeClass("active");
36 $(this).parent().addClass("active");
40 $(".form-title a").click(function(){
41 $(this).parent().parent().next().collapse('toggle');
44 $('.collapseContent').on('show.bs.collapse', function () {
45 var icon = $(this).prev().find('i:first');
46 icon.removeClass('fa-chevron-down').addClass("fa-chevron-up");
49 $('.collapseContent').on('hidden.bs.collapse', function () {
50 var icon = $(this).prev().find('i:first');
51 icon.removeClass('fa-chevron-up').addClass("fa-chevron-down");
57 //Sorting grouping custom service
58 routeUtil.groupRoute=function(resp){
59 var routeArray=new Array();
60 var routeGroupArray=[[]];
62 for(var i=0;i<resp.length;i++){
64 var fullServiceName=resp[i].serviceName;
67 var reg_match1=/(\/.*?)\/.*$/
68 var reg_match2=/(\/.*?)$/
70 //Canonical decomposition grouping service name
71 if(reg_match1.test(fullServiceName)){
73 groupServiceName = fullServiceName.match(reg_match1)[1];
75 else if(reg_match2.test(fullServiceName)){
77 groupServiceName = fullServiceName.match(reg_match2)[1];
80 groupServiceName=$.i18n.prop('org_openo_msb_route_property_root');
84 //Loop all packet classification
85 if(routeArray[groupServiceName] == undefined){
88 routeArray[groupServiceName] = list;
90 routeArray[groupServiceName].push(resp[i]);
97 //Sorting through all quantity > 1
100 for(var groupServiceName in routeArray){
101 var routeGroup = routeArray[groupServiceName];
103 if(routeGroup.length>1){
105 routeGroupArray.push(routeGroup);
109 routeGroupArray[0].push(routeGroup[0]);
115 //Sort + place other grouping in the final
116 var defaultGroupRoute=routeGroupArray[0];
117 defaultGroupRoute.sort(function(a,b){return a.serviceName>b.serviceName?1:-1});
118 for(var i=0;i<routeGroupArray.length-1;i++){
119 routeGroupArray[i]=routeGroupArray[i+1];
120 routeGroupArray[i].sort(function(a,b){return a.serviceName>b.serviceName?1:-1});
124 routeGroupArray[routeGroupArray.length-1]=defaultGroupRoute;
129 vm.customGroupRouteArray=routeGroupArray;
135 routeUtil.showGroupName=function(index,serviceArray){
138 var maxGroupSN=vm.customGroupRouteArray.length-1;
139 if(index==maxGroupSN){
140 return $.i18n.prop('org_openo_msb_route_property_other_group');
143 var serviceName=serviceArray[0].serviceName;
144 var reg_match1=/(\/.*?)\/.*$/
145 var reg_match2=/(\/.*?)$/
147 //Canonical decomposition grouping service name
148 if(reg_match1.test(serviceName)){
150 return serviceName.match(reg_match1)[1];
152 else if(reg_match2.test(serviceName)){
154 return serviceName.match(reg_match2)[1];
160 routeUtil.currentTime=function()
162 var now = new Date();
164 var year = now.getFullYear(); //year
165 var month = now.getMonth() + 1; //month
166 var day = now.getDate(); //date
168 var hh = now.getHours(); //hour
169 var mm = now.getMinutes(); //minu
171 var clock = year + "-";
176 clock += month + "-";
187 if (mm < 10) clock += '0';
194 routeUtil.showStatus=function(status){
196 return " <span class='label label-success'>"+$.i18n.prop('org_openo_msb_route_property_normal')+"</span>";
198 else if(status === '0'){
199 return " <span class='label label-danger'>"+$.i18n.prop('org_openo_msb_route_property_disable')+"</span>";
202 return " <span class='label label-info'>"+$.i18n.prop('org_openo_msb_route_property_unknown')+"</span>";
208 routeUtil.showVisualRange=function(visualRange){
210 var rangArray=visualRange.split("|");
212 var visualRangeText="";
214 for(var i=0;i<rangArray.length;i++){
215 if(rangArray[i] === '0'){
216 visualRangeText+= $.i18n.prop('org_openo_msb_route_form_intersystem')+" ";
218 else if(rangArray[i] === '1'){
219 visualRangeText+= $.i18n.prop('org_openo_msb_route_form_insystem')+" ";
224 return visualRangeText;
231 routeUtil.formatDetail=function(nodes){
233 var tableDetail='<table class="table table-striped hostTable">'
234 +'<thead><tr><th>IP</th><th>PORT</th><th>TTL</th><th></th></tr></thead>'
237 for(var i=0;i<nodes.length;i++){
238 var node=nodes[i].split(":");
239 tableDetail+='<tr><td>'+node[0]+'</td><td>'+node[1]+'</td><td>'+node[2]+'</td><td></td>';
245 tableDetail+=' </tbody></table>';
250 routeUtil.ifAPIUrl=function(url){
251 if(url=="" || url ==null) return false;
253 var reg_api_match =new RegExp("^(\/"+apiRootPath+"\/.*?)$","im"); // re为/^\d+bl$/gim
254 // var reg_api_match=/^(\/api\/.*?)$/;
255 return reg_api_match.test(url);
260 routeUtil.changeTargetServiceUrl=function(){
261 var serviceName=vm.msbRouteInfo.serviceName==""?"serviceName":vm.msbRouteInfo.serviceName;
263 if(vm.msbRouteInfo.protocol=='UI'){
264 vm.targetFullServiceUrl=vm.targetServiceUrl+"/"+iuiRootPath+"/"+serviceName;
266 else if(vm.msbRouteInfo.protocol=='REST'){
267 if(routeUtil.ifAPIUrl(vm.msbRouteInfo.url)){
268 var version=vm.msbRouteInfo.version==""?"":"/"+vm.msbRouteInfo.version
269 vm.targetFullServiceUrl=vm.targetServiceUrl+"/"+apiRootPath+"/"+serviceName+version;
272 var reg_customName_match=/^(\/.*?)$/;
273 if(!reg_customName_match.test(serviceName)) serviceName="/"+serviceName;
274 vm.targetFullServiceUrl=vm.targetServiceUrl+serviceName;