aboutsummaryrefslogtreecommitdiffstats
path: root/msb-core/apiroute/apiroute-service/src/main/resources/iui-route/js/routeUtil.js
blob: 42629cc664ddde9a30ad5affe27ed6cdadbd74c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
 * Copyright 2016 2015-2016 ZTE, Inc. and others. 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.
 *
 *     Author: Zhaoxing Meng
 *     email: meng.zhaoxing1@zte.com.cn
 */
var routeUtil = {};

routeUtil.growl=function(title,message,type){
      $.growl({
		icon: "fa fa-envelope-o fa-lg",
		title: "  "+$.i18n.prop('org_openo_msb_route_property_ttl')+title,
		message: message+"        "
			},{
				type: type
			});
}


routeUtil.refreshRoute=function(){
     $(".stats_box .routeDiv div[data-name='route_click_zone']").on({
        click: function(){
        $(".stats_box .routeDiv").removeClass("active");
        $(this).parent().addClass("active");
        }
      });

     $(".form-title a").click(function(){
         $(this).parent().parent().next().collapse('toggle');
        });

        $('.collapseContent').on('show.bs.collapse', function () {
          var icon = $(this).prev().find('i:first');
         icon.removeClass('fa-chevron-down').addClass("fa-chevron-up");
        });

        $('.collapseContent').on('hidden.bs.collapse', function () {
          var icon = $(this).prev().find('i:first');
          icon.removeClass('fa-chevron-up').addClass("fa-chevron-down");
        });


}

//Sorting grouping custom service
routeUtil.groupRoute=function(resp){
    var routeArray=new Array();
    var routeGroupArray=[[]];

     for(var i=0;i<resp.length;i++){ 

          var fullServiceName=resp[i].serviceName;
          var groupServiceName;

          var reg_match1=/(\/.*?)\/.*$/
           var reg_match2=/(\/.*?)$/

           //Canonical decomposition grouping service name
          if(reg_match1.test(fullServiceName)){  
            
              groupServiceName = fullServiceName.match(reg_match1)[1];
          }
          else if(reg_match2.test(fullServiceName)){  
            
              groupServiceName = fullServiceName.match(reg_match2)[1];
          }
          else{
            groupServiceName=$.i18n.prop('org_openo_msb_route_property_root');
          }


            //Loop all packet classification
            if(routeArray[groupServiceName] == undefined){  
                var list = [];  
                list.push(resp[i]);  
                routeArray[groupServiceName] = list;  
            }else{  
                routeArray[groupServiceName].push(resp[i]);  
            }  

        }

           

            //Sorting through all quantity > 1
      
           
              for(var groupServiceName in routeArray){  
                 var routeGroup = routeArray[groupServiceName]; 

                 if(routeGroup.length>1){
                   
                    routeGroupArray.push(routeGroup);
                    
                }
                else{
                   routeGroupArray[0].push(routeGroup[0]); 
                }

          }


          //Sort + place other grouping in the final
          var defaultGroupRoute=routeGroupArray[0];
             defaultGroupRoute.sort(function(a,b){return a.serviceName>b.serviceName?1:-1}); 
          for(var i=0;i<routeGroupArray.length-1;i++){
            routeGroupArray[i]=routeGroupArray[i+1];
            routeGroupArray[i].sort(function(a,b){return a.serviceName>b.serviceName?1:-1}); 
          }

         
             routeGroupArray[routeGroupArray.length-1]=defaultGroupRoute;

          


        vm.customGroupRouteArray=routeGroupArray;


 
}

routeUtil.showGroupName=function(index,serviceArray){

  
    var maxGroupSN=vm.customGroupRouteArray.length-1;
    if(index==maxGroupSN){
        return $.i18n.prop('org_openo_msb_route_property_other_group');
    }
    else{
        var serviceName=serviceArray[0].serviceName;
        var reg_match1=/(\/.*?)\/.*$/
        var reg_match2=/(\/.*?)$/

           //Canonical decomposition grouping service name
          if(reg_match1.test(serviceName)){  
            
              return serviceName.match(reg_match1)[1];
          }
          else if(reg_match2.test(serviceName)){  
            
              return serviceName.match(reg_match2)[1];
          }
    }

}

routeUtil.currentTime=function()
    { 
        var now = new Date();
       
        var year = now.getFullYear();       //year
        var month = now.getMonth() + 1;     //month
        var day = now.getDate();            //date
       
        var hh = now.getHours();            //hour
        var mm = now.getMinutes();          //minu
       
        var clock = year + "-";
       
        if(month < 10)
            clock += "0";
       
        clock += month + "-";
       
        if(day < 10)
            clock += "0";
           
        clock += day + " ";
       
        if(hh < 10)
            clock += "0";
           
        clock += hh + ":";
        if (mm < 10) clock += '0'; 
        clock += mm; 
        return clock; 
    } 



routeUtil.showStatus=function(status){
   if(status === '1'){
      return " <span class='label label-success'>"+$.i18n.prop('org_openo_msb_route_property_normal')+"</span>";
   }
   else if(status === '0'){
      return " <span class='label label-danger'>"+$.i18n.prop('org_openo_msb_route_property_disable')+"</span>";
   }
   else {
      return " <span class='label label-info'>"+$.i18n.prop('org_openo_msb_route_property_unknown')+"</span>";
   }


}

routeUtil.showVisualRange=function(visualRange){

    var rangArray=visualRange.split("|");

    var visualRangeText="";

    for(var i=0;i<rangArray.length;i++){
        if(rangArray[i] === '0'){
              visualRangeText+= $.i18n.prop('org_openo_msb_route_form_intersystem')+"   ";
           }
         else if(rangArray[i] === '1'){
              visualRangeText+= $.i18n.prop('org_openo_msb_route_form_insystem')+"   ";
           }

    }

return visualRangeText;

}




routeUtil.formatDetail=function(nodes){

 var tableDetail='<table class="table table-striped hostTable">'
                +'<thead><tr><th>IP</th><th>PORT</th><th>TTL</th><th></th></tr></thead>'
                +' <tbody>';

 for(var i=0;i<nodes.length;i++){ 
        var node=nodes[i].split(":");
        tableDetail+='<tr><td>'+node[0]+'</td><td>'+node[1]+'</td><td>'+node[2]+'</td><td></td>';
 }                                     
                                     
                                   


tableDetail+=' </tbody></table>';
return tableDetail;

}

routeUtil.ifAPIUrl=function(url){
  if(url=="" || url ==null) return false;
    
    var reg_api_match =new RegExp("^(\/"+apiRootPath+"\/.*?)$","im"); // re为/^\d+bl$/gim   
   // var reg_api_match=/^(\/api\/.*?)$/;
   return reg_api_match.test(url);
      
}


routeUtil.changeTargetServiceUrl=function(){
var serviceName=vm.msbRouteInfo.serviceName==""?"serviceName":vm.msbRouteInfo.serviceName;

  if(vm.msbRouteInfo.protocol=='UI'){
    vm.targetFullServiceUrl=vm.targetServiceUrl+"/"+iuiRootPath+"/"+serviceName;
  }
  else if(vm.msbRouteInfo.protocol=='REST'){
    if(routeUtil.ifAPIUrl(vm.msbRouteInfo.url)){
      var version=vm.msbRouteInfo.version==""?"":"/"+vm.msbRouteInfo.version
       vm.targetFullServiceUrl=vm.targetServiceUrl+"/"+apiRootPath+"/"+serviceName+version;
    }
    else{
       var reg_customName_match=/^(\/.*?)$/;
        if(!reg_customName_match.test(serviceName)) serviceName="/"+serviceName;
       vm.targetFullServiceUrl=vm.targetServiceUrl+serviceName;

    }
  }
}