Connectivity service synchronous write.
[unimgr.git] / dlux / cpeui / cpeui-module / src / main / resources / cpeui / tenant.controller.js
1 define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
2   cpeui.register.controller('OpenTenantCtrl', function($scope, CpeuiSvc, CpeuiDialogs, CpeUiUtils, $stateParams) {
3
4     $scope.curTenant = $stateParams.tenantid;
5     $scope.unisTables = {};
6     $scope.unis = [];
7     $scope.ces = [];
8     $scope.ipvcs = [];
9     $scope.evcs = [];
10     $scope.subnets = {};
11     $scope.profiles =[];
12     $scope.cesDisplayNames = {};
13     $scope.unisMap = {};
14     $scope.networkNames = {};
15     $scope.expandFlags = {
16         ipuni:{},
17         tuni:{},
18         L2:{},L3:{}
19     };
20
21     var tabIndexs = {
22         "inventory" : 0,
23         "L2" : 1,
24         "L3" : 2
25       }
26     if ($stateParams.tenantTabName in tabIndexs) {
27       $scope.tab.tenantData = tabIndexs[$stateParams.tenantTabName];
28     } else {
29         $scope.tab.tenantData = tabIndexs.inventory;
30     }
31
32     CpeuiSvc.getTenantList(function(tenant_list) {
33         if (tenant_list.filter(t => t.name == $scope.curTenant).length == 0) {
34             window.location = "#/cpeui/admin/tenants";
35         }
36     });
37
38     function init(){
39       $scope.updateUnis(function(unis){
40         CpeuiSvc.getCes(function(ces) {
41           $scope.ces = ces.filter(function(item) {
42
43             var filteredUnis = unis.filterByField('device', item["dev-id"]);
44             filteredUnis = filteredUnis.filterByField('prettyID', 'br-int', true);
45             filteredUnis = filteredUnis.filter(function(i){return !(i.prettyID && i.prettyID.startsWith('tun'));});
46
47             return (filteredUnis.length);
48           });
49           ces.forEach(function(ce){
50             $scope.cesDisplayNames[ce['dev-id']] = ce['device-name'] ? ce['device-name'] : ce['dev-id'];
51           });
52           $scope.updateEvcView();
53         });
54       });
55
56       CpeuiSvc.getNetworkNames(function(networks){
57         networks.forEach(function(net){
58           $scope.networkNames[net.uuid] = net.name;
59         });
60       });
61
62       CpeuiSvc.getProfiles(function(profiles) {
63         $scope.profiles = profiles;
64       });
65     }
66
67     $scope.updateUnis = function(callback) {
68       CpeuiSvc.getUnis(function(unis) {
69         unis.forEach(function(u) {
70           u.prettyID = u['uni-id'].split(":")[u['uni-id'].split(":").length - 1];
71           $scope.unisMap[u['uni-id']] = u;
72         });
73         $scope.unis = unis.filter(function(u){return u["tenant-id"] == $scope.curTenant;});
74
75         if (callback) {
76           callback($scope.unis);
77         }
78       });
79     };
80
81     $scope.updateEvcView = function() {
82       CpeuiSvc.getServices($scope.curTenant, function(services) {
83
84         $scope.evcs = services.filter(function(svc){ return svc.evc != undefined;});
85         $scope.ipvcs = services.filter(function(svc){ return svc.ipvc != undefined;});
86         $scope.updateUnis();
87         function mapUniToService(uni, service) {
88             var uniObj = $scope.unis.filterByField('uni-id',uni['uni-id'])[0];
89             if (uniObj === undefined) {
90                 return;
91             }
92             if (!uniObj.vlanToService) {
93                 uniObj.vlanToService = [];
94             }
95             uniObj.hasService = true;
96             if (uni['evc-uni-ce-vlans'] && uni['evc-uni-ce-vlans']['evc-uni-ce-vlan']){
97                 uni['evc-uni-ce-vlans']['evc-uni-ce-vlan'].forEach(function(v){
98                     uniObj.vlanToService.push({"vlan":v.vid, "svc":service});
99                 });
100             } else {
101                 if (uni["ip-uni-id"]) {
102                     var ipuni = $scope.unis.filterByField('uni-id',uni['uni-id'])[0];
103                     if (ipuni && ipuni["ip-unis"] && ipuni["ip-unis"]["ip-uni"]) {
104                         ipuni["ip-unis"]["ip-uni"].forEach(function(ipu){
105                             if (ipu['ip-uni-id'] == uni["ip-uni-id"]){
106                                 var vlan = ipu.vlan ? ipu.vlan : 0;
107                                 uniObj.vlanToService.push({"vlan":vlan, "svc":service});
108                             }
109                         });
110                     }
111                 } else {
112                     uniObj.vlanToService.push({"vlan":0, "svc":service});
113                 }
114             }
115         }
116
117         $scope.ipvcs.forEach(function(e){
118           if (e.ipvc.unis != undefined && e.ipvc.unis.uni != undefined){
119               e.ipvc.unis.uni.forEach(function(u){
120                 u.device = u['uni-id'].split(":")[u['uni-id'].split(":").length-2];
121                 u.prettyID = u['uni-id'].split(":")[u['uni-id'].split(":").length-1];
122                 mapUniToService(u,e);
123             });
124           }
125         });
126         $scope.evcs.forEach(function(e){
127           e.isTree = (e.evc['evc-type'] == 'rooted-multipoint');
128           e.device2unis = {};
129           if (e.evc.unis != undefined && e.evc.unis.uni != undefined){
130             e.evc.unis.uni.forEach(function(u){
131               if (e.device2unis[$scope.unisMap[u['uni-id']].device] == undefined){
132                 e.device2unis[$scope.unisMap[u['uni-id']].device] = [];
133               }
134               u.prettyID = u['uni-id'].split(":")[u['uni-id'].split(":").length - 1];
135               e.device2unis[$scope.unisMap[u['uni-id']].device].push(u);
136               mapUniToService(u,e);
137             });
138           }
139         });
140       });
141       CpeuiSvc.getAllIpUniSubnets(function(raw_subnets){
142           var subnets ={}
143           if (raw_subnets) {
144               raw_subnets.forEach(function(sub) {
145                 if (subnets[sub["uni-id"]] == undefined) {
146                   subnets[sub["uni-id"]] = {};
147                 }
148                 if (subnets[sub["uni-id"]][sub["ip-uni-id"]] == undefined) {
149                   subnets[sub["uni-id"]][sub["ip-uni-id"]] = [];
150                 }
151                 subnets[sub["uni-id"]][sub["ip-uni-id"]].push(sub);
152               });
153           }
154         $scope.subnets = subnets;
155       });
156     };
157
158     $scope.doesAllUniHasService = function(ceUnis) {
159         for (var i=0 ; i< ceUnis.length; ++i) {
160             if (!ceUnis[i].hasService) {
161                 return false;
162             }
163         }
164         return true;
165     }
166
167     $scope.title = function(str) {
168       if (!str) {
169         return str;
170         }
171       return str.split('-').map(function(s) {
172         return s[0].toUpperCase() + s.slice(1);
173       }).join(' ');
174     }
175
176     var evcTypes = {
177       'epl' : 'point-to-point',
178       'evpl' : 'point-to-point',
179       'eplan' : 'multipoint-to-multipoint',
180       'evplan' : 'multipoint-to-multipoint',
181       'eptree' : 'rooted-multipoint',
182       'evptree' : 'rooted-multipoint'
183     }
184
185     var addEvcController = function($scope, $mdDialog) {
186       $scope.initObj = function(svc) {
187           $scope.obj = angular.merge($scope.obj, svc);
188           if (!$scope.obj.evc) {
189               $scope.obj.evc = {};
190           }
191           if (!$scope.obj.evc['max-svc-frame-size']){
192               $scope.obj.evc['max-svc-frame-size'] = 1522;
193           }
194           if (!$scope.obj.evc['mac-timeout']){
195               $scope.obj.evc['mac-timeout'] = 300;
196           }
197       }
198       $scope.validate = function(form) {
199         form.svc_type.$setTouched(); // patch because angular bug http://stackoverflow.com/questions/36138442/error-not-showing-for-angular-material-md-select
200         console.log($scope);
201         return form.$valid;
202       };
203     };
204
205     $scope.editEvc = function($event, svc) {
206         new CpeuiDialogs.Dialog('AddEvc', {}, function(obj) {
207             obj['svc-id'] = svc['svc-id'];
208             CpeuiSvc.addEvc(obj, evcTypes[obj['svc-type']], $scope.curTenant, function() {
209                   $scope.updateEvcView();
210                 });
211           }, addEvcController).show($event, {svc:svc});
212     }
213
214     $scope.openMenu = function($mdOpenMenu, ev) {
215         originatorEv = ev;
216         $mdOpenMenu(ev);
217       };
218
219     $scope.evcDialog = new CpeuiDialogs.Dialog('AddEvc', {}, function(obj) {
220       CpeuiSvc.addEvc(obj, evcTypes[obj.svc_type], $scope.curTenant, function() {
221             $scope.updateEvcView();
222           });
223     }, addEvcController);
224
225     $scope.changeProfile = function(svcId, svcType, uni, profile) {
226         var uniKey = (svcType == 'evc') ? uni['uni-id'] : (uni['uni-id'] +'/' + uni['ip-uni-id']);
227         CpeuiDialogs.customConfirm("Are you sure?",
228                 "This will change " + uniKey + " bandwidth profile.",
229                 function() {
230                     CpeuiSvc.changeUniProfile(svcId, svcType, uniKey, profile);
231                 },function() {
232                     uni.selectedProfile = uni['ingress-bw-profile']
233                 });
234     }
235
236
237     $scope.ipvcDialog = new CpeuiDialogs.Dialog('AddIpvc', {}, function(obj) {
238       CpeuiSvc.addIpvc(obj, $scope.curTenant, function() {
239             $scope.updateEvcView();
240           });
241     });
242
243     $scope.linkIpvcUniDialog = new CpeuiDialogs.Dialog('LinkIpvcUni', {},
244         function(obj) {
245         CpeuiSvc.addIpUni(obj.uni['uni-id'], obj['ip-address'], obj.vlan, obj['segmentation-id'], function(ipUniId) {
246           CpeuiSvc.addIpvcUni(obj.svc_id, obj.uni['uni-id'], ipUniId, obj.profile_name,
247               function() {
248                   $scope.updateUnis($scope.updateEvcView);
249               });
250             });
251         });
252
253     var ipUniDialogController = function($scope, $mdDialog) {
254       $scope.hasVlans = false;
255       if ($scope.params.uni['ip-unis'] && $scope.params.uni['ip-unis']['ip-uni']) {
256         var ipunis = $scope.params.uni['ip-unis']['ip-uni'];
257         for (i = 0; i < ipunis.length; i++) {
258           if (ipunis[i].vlan){
259             $scope.hasVlans = true;
260           }
261         }
262       }
263     };
264
265     $scope.ipUniDialog = new CpeuiDialogs.Dialog('AddIpUni', {}, function(obj) {
266       CpeuiSvc.addIpUni(obj['uni-id'], obj['ip-address'], obj.vlan, obj['segmentation-id'], function() {
267           $scope.updateUnis();
268         });
269       }, ipUniDialogController);
270
271     $scope.openIpUniDialog = function(event,uni){
272       if (uni['ip-unis'] && (uni['ip-unis']['ip-uni'] != undefined)){
273         var ipunis = uni['ip-unis']['ip-uni'];
274         for (i = 0; i < ipunis.length; i++) {
275           if (!ipunis[i].vlan){
276             CpeuiDialogs.alert("Error","You Can't have more then one ip-uni with no vlan. please remove the non-vlan ip-uni before adding new.")
277             return;
278           }
279         }
280       }
281       $scope.ipUniDialog.show(event,{'uniid':uni['uni-id'], uni:uni})
282     }
283
284
285     var staticRoutingController = function($scope, $mdDialog, params) {
286         $scope.add = function(obj){
287             if ($scope.projectForm.$valid) {
288                 if (!obj.selectedUni.subnets) {
289                     obj.selectedUni.subnets = [];
290                 }
291                 obj.selectedUni.subnets.push({"subnet":obj.network,"gateway":obj.gateway});
292
293                 if (!$scope.toAdd) {
294                     $scope.toAdd = [];
295                 }
296                 $scope.toAdd.push(obj);
297
298                 // reset form
299                 $scope.obj={};
300                 $scope.projectForm.$setPristine();
301                 $scope.projectForm.$setUntouched();
302
303             }
304         };
305
306         $scope.removeSubnet = function(u,subnet) {
307             if (!$scope.toRemove) {
308                 $scope.toRemove = [];
309             }
310             u.subnets = u.subnets.filter(s=>s!=subnet);
311             $scope.toRemove.push({"uni":u, "subnet":subnet});
312         }
313
314         $scope.done = function() {
315             if (!$scope.toRemove && !$scope.toAdd) {
316                 $mdDialog.hide();
317                 return;
318             }
319             CpeuiSvc.getAllIpUniSubnets(function(subnets){
320                 if ($scope.toRemove) {
321                     $scope.toRemove.forEach(function(u){
322                         subnets = subnets.filter(function(s) {
323                             if (s['uni-id'] != u.uni['uni-id']) {
324                                 return true;
325                             } else if (s['ip-uni-id'] != u.uni['ip-uni-id']) {
326                                 return true;
327                             } else if (s.subnet != u.subnet.subnet) {
328                                 return true;
329                             }
330                             return false;
331                         });
332                     });
333                 }
334                 if ($scope.toAdd) {
335                     $scope.toAdd.forEach(function(added){
336                         var u = added.selectedUni;
337                         subnets.push({
338                             "ip-uni-id":u['ip-uni-id'],
339                             "subnet":added.network,
340                             "gateway":added.gateway,
341                             "uni-id":u['uni-id'],
342                         });
343                     });
344                 }
345                 CpeuiSvc.setAllSubnets(subnets, $scope.callback);
346             });
347           $mdDialog.hide();
348         };
349
350       };
351
352     $scope.openRoutingDialog = function(ipvc) {
353         if (ipvc.ipvc.unis && ipvc.ipvc.unis.uni) {
354             ipvc.ipvc.unis.uni.forEach(function(u){
355                 var mefUni = $scope.getMefInterfaceIpvc(u['uni-id'],u['ip-uni-id']);
356                 if (mefUni === undefined) {
357                     return;
358                 }
359                 u.ipAddress = mefUni['ip-address'];
360                 u.deviceName = $scope.cesDisplayNames[u.device];
361                 if ($scope.subnets[u['uni-id']]) {
362                     u.subnets = $scope.subnets[u['uni-id']][u['ip-uni-id']];
363                 }
364                 if (mefUni.vlan) { u.vlan = mefUni.vlan };
365             });
366         }
367         new CpeuiDialogs.Dialog('StaticRouting', {"ipvc":ipvc, "subnets":angular.copy($scope.subnets)}, function() {
368             $scope.updateEvcView();
369         }, staticRoutingController).show();
370     }
371     
372     var dhcpDialogController = function($scope, $mdDialog, params) {
373         
374         $scope.selectedNetworks = [];
375         $scope.vrfid = params.vrfId;
376         $scope._isAddingRow = false;
377         
378         $scope.selectAll = function(){
379             if (!$scope.isAllSelected()){
380                 $scope.selectedNetworks = $scope.getAvailableNetwork();                
381             } else {
382                 $scope.selectedNetworks = [];                
383             }
384         };
385         $scope.isPartialSelected = function(){
386             return ($scope.selectedNetworks.length != 0) && ($scope.selectedNetworks.length != $scope.getAvailableNetwork().length);
387         };
388         $scope.isAllSelected = function(){
389             return ($scope.selectedNetworks.length ==  $scope.getAvailableNetwork().length);
390         };
391         
392         $scope.updateEnabled = function() {
393             $scope.selectedNetworks.forEach(function(subnet){
394                 $scope.addDhcp(subnet);
395             });
396             $scope.selectedNetworks = [];
397             $('md-backdrop').click();// close md-select dropdown
398         };
399
400         $scope.openStaticAssigment = function(subnet) {
401             $scope.focusedSubnet = subnet;
402             CpeuiSvc.getDhcpStaticAllocation($scope.vrfid, subnet.subnet, function(allocations) {
403                 $scope.subnetAllocations = allocations;
404                 $scope.dialogState = 'STATIC';
405             });
406         };
407         $scope.openMain = function() {
408             $scope.dialogState = 'MAIN';
409         };
410         //confirmation
411         $scope.confirmationMsg = null;
412         $scope.okCallback = null;
413         $scope.previousState = null;
414
415         $scope.confirm = function(msg, okCallback) {
416             $scope.confirmationMsg = msg;
417             $scope.okCallback = okCallback;
418             $scope.previousState = $scope.dialogState;
419             $scope.dialogState = 'CONFIRM';
420         }
421         $scope.back = function() {
422             $scope.dialogState = $scope.previousState;
423         }
424         $scope.confirmed = function() {
425             $scope.okCallback()
426             $scope.dialogState = $scope.previousState;
427         }
428
429         $scope.updateDhcpData = function() {
430             CpeuiSvc.getDhcp($scope.vrfid, function(dhcps){
431                 $scope.dhcps = dhcps;
432                 //$scope.params.ipvcUnis = $scope.params.ipvcUnis.filter(x => $scope.dhcps[x.mefUni['ip-address']] == undefined);
433             });
434         }
435
436         $scope.getAvailableNetwork = function(){
437             if ($scope.dhcps !== undefined) {
438                 return $scope.params.ipvcUnis.filter(x => ($scope.dhcps[x.cidr] == undefined));
439             } else {
440                 return $scope.params.ipvcUnis;
441             }
442         }
443
444         $scope.addDhcp = function(subnet) {
445             CpeuiSvc.addDhcp($scope.vrfid, subnet.cidr, subnet.min ,subnet.max,function(){
446                 // TODO find a way to getDhcp only once, after the last add
447                 $scope.updateDhcpData();
448             });
449         }
450
451         $scope.removeDhcp = function(subnet) {
452             $scope.confirm("This will delete this dhcp configuration",function(){
453                 CpeuiSvc.removeDhcp($scope.vrfid, subnet, function(){
454                     $scope.updateDhcpData();
455                 });
456             });
457         };
458         $scope.isAddingRow = function() {
459             return $scope._isAddingRow;
460         }
461         $scope.setAddingRow = function(val) {
462             $scope._isAddingRow = val;
463         }
464         $scope.addAllocation = function(form, mac, ip) {
465             if (form.$valid) {
466                 CpeuiSvc.addDhcpStaticAllocation($scope.vrfid, $scope.focusedSubnet.subnet, [[mac,ip]], function(){
467                     CpeuiSvc.getDhcpStaticAllocation($scope.vrfid, $scope.focusedSubnet.subnet, function(allocations) {
468                         $scope.subnetAllocations = allocations;
469                     });
470                 });
471
472                 // reset form
473                 delete $scope.obj.mac;
474                 delete $scope.obj.ip;
475                 form.$setPristine();
476                 form.$setUntouched();
477                 $scope.setAddingRow(false);
478             }
479         }
480
481         $scope.removeAllocation = function(subnet, mac) {
482             $scope.confirm("Are you sure you want to remove this allocation?",function(){
483                 CpeuiSvc.removeDhcpStaticAllocation($scope.vrfid, subnet, mac, function(){
484                     CpeuiSvc.getDhcpStaticAllocation($scope.vrfid, subnet, function(allocations) {
485                         $scope.subnetAllocations = allocations;
486                     });
487                 });
488             });
489         };
490
491         $scope.setDNS = function(primaryDns, secondaryDns) {
492             for (var i in $scope.dhcps) {
493                 var allocPool = $scope.dhcps[i];
494                 CpeuiSvc.setDHCPDnsServers($scope.vrfid, allocPool.subnet, primaryDns, secondaryDns, $scope.updateDhcpData);
495             };
496         }
497
498         $scope.updateDhcpData();
499     };
500
501     $scope.openDhcpDialog = function(ipvc) {
502         CpeuiSvc.getServicesVrfId(ipvc['svc-id'],function(vrfId){
503             params = {ipvc:ipvc,ipvcUnis:[],vrfId:vrfId};
504             if (ipvc.ipvc.unis && ipvc.ipvc.unis.uni) {
505                 params.ipvcUnis = ipvc.ipvc.unis.uni.map(u => CpeUiUtils.getSubnetEdges($scope.getMefInterfaceIpvc(u['uni-id'],u['ip-uni-id'])['ip-address']));
506             }
507             new CpeuiDialogs.Dialog('DHCP', params, function() {
508                 $scope.updateEvcView();
509             }, dhcpDialogController).show();
510         });
511     }
512
513     $scope.ipUniSubnetDialog = new CpeuiDialogs.Dialog('AddIpUniSubnet', {}, function(obj) {
514       CpeuiSvc.addIpUniSubnet(obj.uniid, obj.ipuniid, obj.subnet, obj.gateway, function() {
515         if ($scope.subnets[obj.uniid] == undefined){
516           $scope.subnets[obj.uniid] = {};
517         }
518         if ($scope.subnets[obj.uniid][obj.ipuniid] == undefined) {
519           $scope.subnets[obj.uniid][obj.ipuniid] = [];
520         }
521         $scope.subnets[obj.uniid][obj.ipuniid].push({
522           "uni-id": obj.uniid,
523           "ip-uni-id": obj.ipuniid,
524           "subnet": obj.subnet,
525           "gateway": obj.gateway
526         });
527       });
528     });
529
530     $scope.deleteIpUni = function(uniid, ipuni_id) {
531         CpeuiDialogs.confirm(function() {
532           CpeuiSvc.deleteIpUni(uniid, ipuni_id, function() {
533             $scope.updateEvcView(); // TODO update unis only
534           });
535         });
536       };
537       $scope.deleteIpvcUni = function(svc_id, uni_id, ipuni_id) {
538         CpeuiDialogs.confirm(function() {
539           CpeuiSvc.deleteIpvcUni(svc_id, uni_id, ipuni_id, function() {
540             $scope.updateEvcView();
541           });
542         });
543       };
544       $scope.getMefInterfaceIpvc = function(uni_id,ipuni_id){
545         var uni = $scope.unis.filterByField('uni-id',uni_id)[0];
546         if ((uni == undefined) || (uni['ip-unis'] == undefined) || (uni['ip-unis']['ip-uni'] == undefined)) {
547           return undefined;
548         }
549         return uni['ip-unis']['ip-uni'].filterByField('ip-uni-id',ipuni_id)[0];
550       }
551
552       $scope.deleteIpUniSubnet = function(uniid, ipuni_id, subnet) {
553           CpeuiDialogs.confirm(function() {
554             CpeuiSvc.deleteIpUniSubnet(uniid, ipuni_id, subnet, function() {
555               $scope.updateEvcView(); // TODO update unis only
556             });
557           });
558     };
559
560     $scope.deleteEvc = function(svcid) {
561       CpeuiDialogs.confirm(function() {
562         CpeuiSvc.removeEvc(svcid, function() {
563           $scope.updateEvcView();
564         });
565       });
566     };
567
568     $scope.deleteEvcUni = function(svc_id, uni_id) {
569       CpeuiDialogs.confirm(function() {
570         CpeuiSvc.deleteEvcUni(svc_id, uni_id, function() {
571           $scope.updateEvcView();
572         });
573       });
574     };
575
576     var linkEvcUniController = function($scope, $mdDialog, params) {
577       $scope.params = params;
578       $scope.obj = {
579         vlans : []
580       };
581       $scope.deleteVlan = function(vlan) {
582         $scope.obj.vlans.splice($scope.obj.vlans.indexOf(vlan), 1);
583       };
584       $scope.addVlan = function(vlan) {
585         if ($scope.obj.vlans.indexOf(vlan) == -1) {
586           $scope.obj.vlans.push(vlan);
587           console.log(vlan);
588         }
589         $('#vlan_input').val(undefined);
590       };
591
592       $scope.filterUsedUnis = function(evc){
593         return function(u) {
594           if (u.prettyID == 'br-int') {
595             return false;
596           }
597           if (u.prettyID && u.prettyID.startsWith('tun')) {
598             return false;
599           }
600           if (evc.evc == undefined || evc.evc.unis.uni == undefined){
601             return true;
602           }
603           return evc.evc.unis.uni.filterByField('uni-id',u['uni-id']).length == 0;
604         };
605       };
606     };
607
608     $scope.linkEvcUniDialog = new CpeuiDialogs.Dialog('LinkEvcUni', {},
609         function(obj) {
610           if (!obj.role) {
611             obj.role = "root";
612           }
613           CpeuiSvc.addEvcUni(obj.svc_id, obj.uni_id, obj.role, obj.vlans, obj.profile_name,
614               function() {
615                 $scope.updateEvcView();
616               });
617         }, linkEvcUniController);
618
619     var editVlanController = function($scope, $mdDialog, params) {
620       $scope.params = params;
621
622       $scope.deleteVlan = function(svc_id, uni_id, vlan, allvlans) {
623         CpeuiSvc.deleteVlan(svc_id, uni_id, vlan, function() {
624           allvlans.splice(allvlans.indexOf(vlan), 1)
625         });
626       };
627       $scope.addVlan = function(svc_id, uni_id, vlan, allvlans) {
628         if (allvlans == undefined) {
629           allvlans = [];
630         }
631         if (allvlans.indexOf(vlan) == -1) {
632           CpeuiSvc.addVlan(svc_id, uni_id, vlan, function() {
633             allvlans.push(vlan);
634           });
635         }
636         $('#vlan_input').val(undefined);
637       };
638     };
639
640     $scope.editVlanDialog = new CpeuiDialogs.Dialog('EditVlans', {}, undefined, editVlanController);
641
642     $scope.sortUni = function(uni) {
643       return uni['uni-id'];
644     };
645
646     $scope.getKeys = function(obj){
647         var keys = [];
648         for(var keyName in obj){
649             keys.push(keyName)
650         }
651         return keys;
652     }
653     $scope.sortCeFromId = function(ce) {
654         return $scope.cesDisplayNames[ce];
655     };
656
657     $scope.isEmpty = function(obj){
658         return angular.equals({}, obj);
659     }
660
661     init();
662   });
663 });