1 define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
3 cpeui.register.controller('AdminPageCtrl',
4 function($scope, CpeuiSvc, CpeuiDialogs, $mdDialog, $mdMedia) {
8 $scope.selectedTenant = {};
10 $scope.updateTenantView = function() {
11 CpeuiSvc.getTenantList(function(tenant_list) {
12 $scope.tenantArray = tenant_list;
16 $scope.AddTenant = function() {
17 CpeuiSvc.addTenant($scope.tenantId, function() {
18 $scope.updateTenantView();
22 $scope.tenantDialog = new CpeuiDialogs.Dialog('AddTenant', {},
24 CpeuiSvc.addTenant(obj.id, function() {
25 $scope.updateTenantView();
29 $scope.DeleteTenant = function(tenantID) {
30 CpeuiDialogs.confirm(function() {
31 CpeuiSvc.deleteTenant(tenantID, function() {
32 $scope.updateTenantView();
39 $scope.updateProfilesView = function() {
40 CpeuiSvc.getProfiles(function(profiles) {
41 $scope.profiles = profiles;
45 var profileDialogController = function($scope, $mdDialog) {
47 $scope.getDefualtCbs = function(cir) {
48 return Math.round(cir * 0.0125);
51 $scope.done = function() {
52 if ($scope.obj.default_cbs) {
53 $scope.obj.cbs = $scope.getDefualtCbs($scope.obj.cir);
55 if ($scope.projectForm.$valid) {
56 $scope.callback($scope.obj);
62 $scope.addProfile = new CpeuiDialogs.Dialog('AddProfile', {}, function(obj) {
63 CpeuiSvc.addProfile(obj['bw-profile'], obj.cir, obj.cbs, function() {
64 $scope.updateProfilesView();
66 }, profileDialogController);
68 $scope.editProfile = function(profileName, cbs, cir) {
69 new CpeuiDialogs.Dialog('AddProfile', {}, function(obj) {
70 CpeuiSvc.editProfile(obj['bw-profile'], obj.cir, obj.cbs, function() {
71 $scope.updateProfilesView();
73 }, profileDialogController).show(null,{edit:true, profileName:profileName, cbs:cbs, cir:cir});
76 $scope.deleteProfile = function(profileName) {
77 CpeuiDialogs.confirm(function() {
78 CpeuiSvc.deleteProfile(profileName, function() {
79 $scope.updateProfilesView();
85 $scope.updateCesView = function() {
86 CpeuiSvc.getCes(function(ces) {
91 $scope.cesDialog = new CpeuiDialogs.Dialog('AddCE', {}, function(obj) {
92 CpeuiSvc.addCe(obj.id, obj.name, function() {
93 $scope.updateCesView();
97 $scope.deleteCe = function(tenantid, ceid) {
98 CpeuiDialogs.confirm(function() {
99 CpeuiSvc.removeCe(ceid, function() {
100 $scope.updateCesView();
105 $scope.assignCpeToTenant = function(cpeId) {
106 CpeuiDialogs.customConfirm("Are You Sure?",
107 "Are you sure you want to override all this CPE's unis tenants?",
109 for (var i = 0; i < $scope.unis.length; ++i) {
110 if ($scope.unis[i].device == cpeId) {
111 CpeuiSvc.updateUni($scope.unis[i]['uni-id'],
112 $scope.selectedTenant[cpeId]);
116 $scope.selectedTenant[cpeId] = undefined;
120 $scope.assignNetworkToTenant = function(svc) {
121 CpeuiDialogs.customConfirm("Are You Sure?",
122 "Are you sure you want to assign service "+ svc['svc-id'] +" to tenant " + $scope.selectedTenant[svc['svc-id']] +"?",
124 CpeuiSvc.addTenantToService(svc['svc-id'], $scope.selectedTenant[svc['svc-id']], function(){
125 svc['tenant-id'] = $scope.selectedTenant[svc['svc-id']];
127 $scope.selectedTenant[svc['svc-id']] = undefined;
130 $scope.selectedTenant[svc['svc-id']] = undefined;
134 function updateCpeTenants(unis) {
135 // update tenant cpe tenant column
136 var hasMultipleTenants = [];
137 var device2tenant = {};
138 for (var i = 0; i < $scope.unis.length; ++i) {
139 var tenant = $scope.unis[i]["tenant-id"];
141 if (hasMultipleTenants.indexOf($scope.unis[i].device) != -1) {
144 if (device2tenant[$scope.unis[i].device] == undefined) {
146 device2tenant[$scope.unis[i].device] = tenant;
148 device2tenant[$scope.unis[i].device] = ""; // none
150 } else if (device2tenant[$scope.unis[i].device] != tenant) {
151 if ((device2tenant[$scope.unis[i].device] != "") || (tenant)) {
152 device2tenant[$scope.unis[i].device] = true; // multiple
153 hasMultipleTenants.push($scope.unis[i].device);
157 var devices = Object.keys(device2tenant);
158 for (var i = 0; i < devices.length; ++i) {
159 if (device2tenant[devices[i]] == true) {
160 $scope.selectedTenant[devices[i]] = undefined;
162 $scope.selectedTenant[devices[i]] = device2tenant[devices[i]];
168 $scope.updateUniView = function() {
169 CpeuiSvc.getUnis(function(unis) {
171 updateCpeTenants(unis);
175 $scope.linkUniDialog = new CpeuiDialogs.Dialog('LinkUni', {}, function(
177 CpeuiSvc.updateUni(obj.id, obj.tenant, function() {
178 $scope.updateUniView();
182 $scope.deleteUni = function(id) {
183 CpeuiDialogs.confirm(function() {
184 CpeuiSvc.removeUni(id, function() {
185 $scope.updateUniView();
190 $scope.addCEName = function(ce){
192 var input = $('#INPUT_' +ce['dev-id']);
193 // hack to focus input after show is complete
194 setTimeout(function(){input.focus();},20);
195 input.parent().on('blur',function(){
196 setTimeout(function(){
202 input.bind("keyup", function (eventSubmit) {
203 if(eventSubmit.which === 13) {
204 $('#OK_' +ce['dev-id']).click();
205 } else if(eventSubmit.which === 27) {
206 input.parent().blur();
211 $scope.renameCE = function(ce){
212 CpeuiSvc.addCeName(ce, ce._new_name, function(){
213 ce['device-name'] = ce._new_name;
218 $scope.services = [];
219 $scope.networkNames = {};
221 $scope.updateNetworksView = function() {
222 CpeuiSvc.getAllServices(function(services) {
223 $scope.services = services;
225 CpeuiSvc.getNetworkNames(function(networks){
226 networks.forEach(function(net){
227 $scope.networkNames[net.uuid] = net.name;
233 $scope.updateView = function() {
234 if ($scope.isTabSet('admin',4)){
235 $scope.updateNetworksView();
237 $scope.updateTenantView();
238 $scope.updateCesView();
239 $scope.updateUniView();
240 $scope.updateProfilesView()