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.OpenTenantPortal = function(tenant) {
30 $scope.currentTenent = tenant;
31 window.location = "#cpeui/tenant/" + tenant.name +"/";
34 $scope.DeleteTenant = function(tenantID) {
35 CpeuiDialogs.confirm(function() {
36 CpeuiSvc.deleteTenant(tenantID, function() {
37 $scope.updateTenantView();
44 $scope.updateProfilesView = function() {
45 CpeuiSvc.getProfiles(function(profiles) {
46 $scope.profiles = profiles;
50 var profileDialogController = function($scope, $mdDialog) {
52 $scope.getDefualtCbs = function(cir) {
53 return Math.round(cir * 0.0125);
56 $scope.done = function() {
57 if ($scope.obj.default_cbs) {
58 $scope.obj.cbs = $scope.getDefualtCbs($scope.obj.cir);
60 if ($scope.projectForm.$valid) {
61 $scope.callback($scope.obj);
67 $scope.addProfile = new CpeuiDialogs.Dialog('AddProfile', {}, function(obj) {
68 CpeuiSvc.addProfile(obj['bw-profile'], obj.cir, obj.cbs, function() {
69 $scope.updateProfilesView();
71 }, profileDialogController);
73 $scope.editProfile = function(profileName, cbs, cir) {
74 new CpeuiDialogs.Dialog('AddProfile', {}, function(obj) {
75 CpeuiSvc.editProfile(obj['bw-profile'], obj.cir, obj.cbs, function() {
76 $scope.updateProfilesView();
78 }, profileDialogController).show(null,{edit:true, profileName:profileName, cbs:cbs, cir:cir});
81 $scope.deleteProfile = function(profileName) {
82 CpeuiDialogs.confirm(function() {
83 CpeuiSvc.deleteProfile(profileName, function() {
84 $scope.updateProfilesView();
90 $scope.updateCesView = function() {
91 CpeuiSvc.getCes(function(ces) {
96 $scope.cesDialog = new CpeuiDialogs.Dialog('AddCE', {}, function(obj) {
97 CpeuiSvc.addCe(obj.id, obj.name, function() {
98 $scope.updateCesView();
102 $scope.deleteCe = function(tenantid, ceid) {
103 CpeuiDialogs.confirm(function() {
104 CpeuiSvc.removeCe(ceid, function() {
105 $scope.updateCesView();
110 $scope.assignCpeToTenant = function(cpeId) {
111 CpeuiDialogs.customConfirm("Are You Sure?",
112 "Are you sure you want to override all this CPE's unis tenants?",
114 for (var i = 0; i < $scope.unis.length; ++i) {
115 if ($scope.unis[i].device == cpeId) {
116 CpeuiSvc.updateUni($scope.unis[i]['uni-id'],
117 $scope.selectedTenant[cpeId]);
121 $scope.selectedTenant[cpeId] = undefined;
125 $scope.assignNetworkToTenant = function(svc) {
126 CpeuiDialogs.customConfirm("Are You Sure?",
127 "Are you sure you want to assign service "+ svc['svc-id'] +" to tenant " + $scope.selectedTenant[svc['svc-id']] +"?",
129 CpeuiSvc.addTenantToService(svc['svc-id'], $scope.selectedTenant[svc['svc-id']], function(){
130 svc['tenant-id'] = $scope.selectedTenant[svc['svc-id']];
132 $scope.selectedTenant[svc['svc-id']] = undefined;
135 $scope.selectedTenant[svc['svc-id']] = undefined;
139 function updateCpeTenants(unis) {
140 // update tenant cpe tenant column
141 var hasMultipleTenants = [];
142 var device2tenant = {};
143 for (var i = 0; i < $scope.unis.length; ++i) {
144 var tenant = $scope.unis[i]["tenant-id"];
146 if (hasMultipleTenants.indexOf($scope.unis[i].device) != -1) {
149 if (device2tenant[$scope.unis[i].device] == undefined) {
151 device2tenant[$scope.unis[i].device] = tenant;
153 device2tenant[$scope.unis[i].device] = ""; // none
155 } else if (device2tenant[$scope.unis[i].device] != tenant) {
156 if ((device2tenant[$scope.unis[i].device] != "") || (tenant)) {
157 device2tenant[$scope.unis[i].device] = true; // multiple
158 hasMultipleTenants.push($scope.unis[i].device);
162 var devices = Object.keys(device2tenant);
163 for (var i = 0; i < devices.length; ++i) {
164 if (device2tenant[devices[i]] == true) {
165 $scope.selectedTenant[devices[i]] = undefined;
167 $scope.selectedTenant[devices[i]] = device2tenant[devices[i]];
173 $scope.updateUniView = function() {
174 CpeuiSvc.getUnis(function(unis) {
176 updateCpeTenants(unis);
180 $scope.linkUniDialog = new CpeuiDialogs.Dialog('LinkUni', {}, function(
182 CpeuiSvc.updateUni(obj.id, obj.tenant, function() {
183 $scope.updateUniView();
187 $scope.deleteUni = function(id) {
188 CpeuiDialogs.confirm(function() {
189 CpeuiSvc.removeUni(id, function() {
190 $scope.updateUniView();
195 $scope.addCEName = function(ce){
197 var input = $('#INPUT_' +ce['dev-id']);
198 // hack to focus input after show is complete
199 setTimeout(function(){input.focus();},20);
200 input.parent().on('blur',function(){
201 setTimeout(function(){
207 input.bind("keyup", function (eventSubmit) {
208 if(eventSubmit.which === 13) {
209 $('#OK_' +ce['dev-id']).click();
210 } else if(eventSubmit.which === 27) {
211 input.parent().blur();
216 $scope.renameCE = function(ce){
217 CpeuiSvc.addCeName(ce, ce._new_name, function(){
218 ce['device-name'] = ce._new_name;
223 $scope.services = [];
224 $scope.networkNames = {};
226 $scope.updateNetworksView = function() {
227 CpeuiSvc.getAllServices(function(services) {
228 $scope.services = services;
230 CpeuiSvc.getNetworkNames(function(networks){
231 networks.forEach(function(net){
232 $scope.networkNames[net.uuid] = net.name;
238 $scope.updateView = function() {
239 if ($scope.isTabSet('admin',4)){
240 $scope.updateNetworksView();
242 $scope.updateTenantView();
243 $scope.updateCesView();
244 $scope.updateUniView();
245 $scope.updateProfilesView()