1 define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
2 cpeui.register.controller('OpenTenantCtrl', function($scope, CpeuiSvc, CpeuiDialogs, $stateParams) {
4 $scope.curTenant = $stateParams.tenantid;
6 $scope.unisTables = {};
10 $scope.cesDisplayNames = {};
12 $scope.networkNames = {};
16 $scope.updateUnis(function(unis){
17 CpeuiSvc.getCes(function(ces) {
18 $scope.ces = ces.filter(function(item) {
20 var filteredUnis = unis.filterByField('device', item["dev-id"]);
21 filteredUnis = filteredUnis.filterByField('prettyID', 'br-int', true);
22 filteredUnis = filteredUnis.filter(function(i){return !(i.prettyID && i.prettyID.startsWith('tun'));});
24 return (filteredUnis.length);
26 ces.forEach(function(ce){
27 $scope.cesDisplayNames[ce['dev-id']] = ce['device-name'] ? ce['device-name'] : ce['dev-id'];
29 $scope.updateEvcView();
33 CpeuiSvc.getNetworkNames(function(networks){
34 networks.forEach(function(net){
35 $scope.networkNames[net.uuid] = net.name;
40 $scope.updateUnis = function(callback) {
41 CpeuiSvc.getUnis(function(unis) {
42 unis.forEach(function(u) {
43 u.prettyID = u['uni-id'].split(":")[u['uni-id'].split(":").length - 1];
44 $scope.unisMap[u['uni-id']] = u;
46 $scope.unis = unis.filter(function(u){return u["tenant-id"] == $scope.curTenant;});
49 callback($scope.unis);
54 $scope.updateEvcView = function() {
55 CpeuiSvc.getServices($scope.curTenant, function(services) {
57 $scope.evcs = services.filter(function(svc){ return svc.evc != undefined;});
58 $scope.ipvcs = services.filter(function(svc){ return svc.ipvc != undefined;});
62 $scope.ipvcs.forEach(function(e){
63 e.isTree = (e.ipvc['ipvc-type'] == 'rooted-multipoint');
66 $scope.evcs.forEach(function(e){
67 e.isTree = (e.evc['evc-type'] == 'rooted-multipoint');
69 if (e.evc.unis.uni != undefined){
70 e.evc.unis.uni.forEach(function(u){
71 if (e.device2unis[$scope.unisMap[u['uni-id']].device] == undefined){
72 e.device2unis[$scope.unisMap[u['uni-id']].device] = [];
74 u.prettyID = u['uni-id'].split(":")[u['uni-id'].split(":").length - 1];
75 e.device2unis[$scope.unisMap[u['uni-id']].device].push(u);
82 $scope.title = function(str) {
86 return str.split('-').map(function(s) {
87 return s[0].toUpperCase() + s.slice(1);
91 $scope.svcTypes = [ 'epl', 'evpl', 'eplan', 'evplan', 'eptree', 'evptree' ]
93 'epl' : 'point-to-point',
94 'evpl' : 'point-to-point',
95 'eplan' : 'multipoint-to-multipoint',
96 'evplan' : 'multipoint-to-multipoint',
97 'eptree' : 'rooted-multipoint',
98 'evptree' : 'rooted-multipoint'
101 var addEvcController = function($scope, $mdDialog) {
102 $scope.validate = function(form) {
103 form.svc_type.$setTouched(); // patch because angular bug http://stackoverflow.com/questions/36138442/error-not-showing-for-angular-material-md-select
109 $scope.evcDialog = new CpeuiDialogs.Dialog('AddEvc', {}, function(obj) {
110 CpeuiSvc.addEvc(obj, evcTypes[obj.svc_type], $scope.curTenant, function() {
111 $scope.updateEvcView();
113 }, addEvcController);
115 $scope.deleteEvc = function(svcid) {
116 CpeuiDialogs.confirm(function() {
117 CpeuiSvc.removeEvc(svcid, function() {
118 $scope.updateEvcView();
123 $scope.deleteEvcUni = function(svc_id, uni_id) {
124 CpeuiDialogs.confirm(function() {
125 CpeuiSvc.deleteEvcUni(svc_id, uni_id, function() {
126 $scope.updateEvcView();
131 var linkEvcUniController = function($scope, $mdDialog, params) {
132 $scope.params = params;
136 $scope.deleteVlan = function(vlan) {
137 $scope.obj.vlans.splice($scope.obj.vlans.indexOf(vlan), 1);
139 $scope.addVlan = function(vlan) {
140 if ($scope.obj.vlans.indexOf(vlan) == -1) {
141 $scope.obj.vlans.push(vlan);
144 $('#vlan_input').val(undefined);
147 $scope.filterUsedUnis = function(evc){
149 if (u.prettyID == 'br-int') {
152 if (u.prettyID && u.prettyID.startsWith('tun')) {
155 if (evc.evc.unis.uni == undefined){
156 evc.evc.unis.uni = [];
158 return evc.evc.unis.uni.filterByField('uni-id',u['uni-id']).length == 0;
163 $scope.linkEvcUniDialog = new CpeuiDialogs.Dialog('LinkEvcUni', {},
168 CpeuiSvc.addEvcUni(obj.svc_id, obj.uni_id, obj.role, obj.vlans,
170 $scope.updateEvcView();
172 }, linkEvcUniController);
174 var editVlanController = function($scope, $mdDialog, params) {
175 $scope.params = params;
177 $scope.deleteVlan = function(svc_id, uni_id, vlan, allvlans) {
178 CpeuiSvc.deleteVlan(svc_id, uni_id, vlan, function() {
179 allvlans.splice(allvlans.indexOf(vlan), 1)
182 $scope.addVlan = function(svc_id, uni_id, vlan, allvlans) {
183 if (allvlans == undefined) {
186 if (allvlans.indexOf(vlan) == -1) {
187 CpeuiSvc.addVlan(svc_id, uni_id, vlan, function() {
191 $('#vlan_input').val(undefined);
195 $scope.editVlanDialog = new CpeuiDialogs.Dialog('EditVlans', {}, undefined, editVlanController);
197 $scope.sortEvc = function(evc) {
198 return evc.evc['evc-id'];
200 $scope.sortUni = function(uni) {
201 return uni['uni-id'];
203 $scope.sortIpvc = function(ipvc) {
204 return ipvc['ipvc-id'];