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() {
22 $scope.tenantDialog = new CpeuiDialogs.Dialog('AddTenant', {},
24 CpeuiSvc.addTenant(obj.id, function() {
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() {
44 $scope.updateProfilesView = function() {
45 CpeuiSvc.getProfiles(function(profiles) {
46 $scope.profiles = profiles;
50 $scope.addProfile = new CpeuiDialogs.Dialog('AddProfile', {}, function(obj) {
51 if (obj.default_cbs) {
52 obj.cbs = Math.floor(obj.cir/10);
54 CpeuiSvc.addProfile(obj['bw-profile'], obj.cir, obj.cbs, function() {
55 $scope.updateProfilesView();
59 $scope.editProfile = function(profileName, cbs, cir) {
60 new CpeuiDialogs.Dialog('AddProfile', {}, function(obj) {
61 if (obj.default_cbs) {
62 obj.cbs = Math.floor(obj.cir/10);
64 CpeuiSvc.editProfile(obj['bw-profile'], obj.cir, obj.cbs, function() {
65 $scope.updateProfilesView();
67 }).show(null,{edit:true, profileName:profileName, cbs:cbs, cir:cir});
70 $scope.deleteProfile = function(profileName) {
71 CpeuiDialogs.confirm(function() {
72 CpeuiSvc.deleteProfile(profileName, function() {
73 $scope.updateProfilesView();
79 $scope.updateCesView = function() {
80 CpeuiSvc.getCes(function(ces) {
85 $scope.cesDialog = new CpeuiDialogs.Dialog('AddCE', {}, function(obj) {
86 CpeuiSvc.addCe(obj.id, obj.name, function() {
87 $scope.updateCesView();
91 $scope.deleteCe = function(tenantid, ceid) {
92 CpeuiDialogs.confirm(function() {
93 CpeuiSvc.removeCe(ceid, function() {
94 $scope.updateCesView();
99 $scope.assignCpeToTenant = function(cpeId) {
100 CpeuiDialogs.customConfirm("Are You Sure?",
101 "Are you sure you want to override all this CPE's unis tenants?",
103 for (var i = 0; i < $scope.unis.length; ++i) {
104 if ($scope.unis[i].device == cpeId) {
105 CpeuiSvc.updateUni($scope.unis[i]['uni-id'],
106 $scope.selectedTenant[cpeId]);
110 $scope.selectedTenant[cpeId] = undefined;
114 $scope.assignNetworkToTenant = function(svc) {
115 CpeuiDialogs.customConfirm("Are You Sure?",
116 "Are you sure you want to assign service "+ svc['svc-id'] +" to tenant " + $scope.selectedTenant[svc['svc-id']] +"?",
118 CpeuiSvc.addTenantToService(svc['svc-id'], $scope.selectedTenant[svc['svc-id']], function(){
119 svc['tenant-id'] = $scope.selectedTenant[svc['svc-id']];
121 $scope.selectedTenant[svc['svc-id']] = undefined;
124 $scope.selectedTenant[svc['svc-id']] = undefined;
128 function updateCpeTenants(unis) {
129 // update tenant cpe tenant column
130 var hasMultipleTenants = [];
131 var device2tenant = {};
132 for (var i = 0; i < $scope.unis.length; ++i) {
133 var tenant = $scope.unis[i]["tenant-id"];
135 if (hasMultipleTenants.indexOf($scope.unis[i].device) != -1) {
138 if (device2tenant[$scope.unis[i].device] == undefined) {
140 device2tenant[$scope.unis[i].device] = tenant;
142 device2tenant[$scope.unis[i].device] = ""; // none
144 } else if (device2tenant[$scope.unis[i].device] != tenant) {
145 if ((device2tenant[$scope.unis[i].device] != "") || (tenant)) {
146 device2tenant[$scope.unis[i].device] = true; // multiple
147 hasMultipleTenants.push($scope.unis[i].device);
151 var devices = Object.keys(device2tenant);
152 for (var i = 0; i < devices.length; ++i) {
153 if (device2tenant[devices[i]] == true) {
154 $scope.selectedTenant[devices[i]] = undefined;
156 $scope.selectedTenant[devices[i]] = device2tenant[devices[i]];
162 $scope.updateUniView = function() {
163 CpeuiSvc.getUnis(function(unis) {
165 updateCpeTenants(unis);
169 $scope.linkUniDialog = new CpeuiDialogs.Dialog('LinkUni', {}, function(
171 CpeuiSvc.updateUni(obj.id, obj.tenant, function() {
172 $scope.updateUniView();
176 $scope.deleteUni = function(id) {
177 CpeuiDialogs.confirm(function() {
178 CpeuiSvc.removeUni(id, function() {
179 $scope.updateUniView();
184 $scope.addCEName = function(ce){
186 var input = $('#INPUT_' +ce['dev-id']);
187 // hack to focus input after show is complete
188 setTimeout(function(){input.focus();},20);
189 input.parent().on('blur',function(){
190 setTimeout(function(){
196 input.bind("keyup", function (eventSubmit) {
197 if(eventSubmit.which === 13) {
198 $('#OK_' +ce['dev-id']).click();
199 } else if(eventSubmit.which === 27) {
200 input.parent().blur();
205 $scope.renameCE = function(ce){
206 CpeuiSvc.addCeName(ce, ce._new_name, function(){
207 ce['device-name'] = ce._new_name;
212 $scope.services = [];
213 $scope.networkNames = {};
215 $scope.updateNetworksView = function() {
216 CpeuiSvc.getAllServices(function(services) {
217 $scope.services = services;
219 CpeuiSvc.getNetworkNames(function(networks){
220 networks.forEach(function(net){
221 $scope.networkNames[net.uuid] = net.name;
227 $scope.updateView = function() {
228 if ($scope.isTabSet('admin',4)){
229 $scope.updateNetworksView();
231 $scope.updateTenantView();
232 $scope.updateCesView();
233 $scope.updateUniView();
234 $scope.updateProfilesView()