2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
23 constructor($log, applicationsService, usersService, $scope, ngDialog,$timeout) {
25 $scope.adminAppsIsNull = false;
26 $scope.appsIsDown = false;
28 $log.info('UsersCtrl:: initializing...');
29 let activeRequests = [];
30 let clearReq = (req) => {
31 activeRequests.splice(activeRequests.indexOf(req), 1);
34 let getAdminApps = () => {
35 $log.debug('UsersCtrl::getAdminApps: - Starting getAdminApps');
37 this.isLoadingTable = true;
38 var adminAppsReq = applicationsService.getAdminApps();
40 activeRequests.push(adminAppsReq);
41 adminAppsReq.promise().then(apps => {
42 $log.debug('UsersCtrl::getAdminApps: Apps for this user are: ' + JSON.stringify(apps));
43 $log.debug('UsersCtrl::getAdminApps: Apps length: ' + apps.length);
44 var res1 = apps.sort(getSortOrder("name"));
45 if (!res1 || !res1.length) {
46 $log.error('UsersCtrl::getAdminApps: - no apps found');
49 for (let i = 0; i < apps.length; i++) {
51 res1[i].value = apps[i].name;
52 res1[i].title = apps[i].name;
55 this.adminApps = apps;
56 this.selectedApp = apps[0];
57 clearReq(adminAppsReq);
58 $scope.adminAppsIsNull = false;
60 $scope.adminAppsIsNull = true;
61 $log.error('UsersCtrl::getAdminApps: - getAdminApps() failed = '+ e.message);
62 clearReq(adminAppsReq);
64 this.isLoadingTable = false;
67 $scope.adminAppsIsNull = true;
68 $log.error('UsersCtrl::getAdminApps: - getAdminApps() failed!');
69 this.isLoadingTable = false;
73 let getSortOrder = (prop) => {
74 return function(a, b) {
75 if (a[prop] > b[prop]) {
77 } else if (a[prop] < b[prop]) {
84 this.updateUsersList = () => {
85 $scope.appsIsDown = false;
86 $log.debug('UsersCtrl::updateUsersList: Starting updateUsersList');
87 this.searchString = '';
88 this.isAppSelectDisabled = true;
89 this.isLoadingTable = true;
90 usersService.getAccountUsers(this.selectedApp.id)
91 .then(accountUsers => {
92 $log.debug('UsersCtrl::updateUsersList length: '+ Object.keys(accountUsers).length);
93 this.isAppSelectDisabled = false;
94 this.accountUsers = accountUsers;
96 this.isAppSelectDisabled = false;
97 $log.error('UsersCtrl::updateUsersList: ' + err);
98 $scope.appsIsDown = true;
100 this.isLoadingTable = false;
106 this.isLoadingTable = false;
107 this.selectedApp = null;
108 this.isAppSelectDisabled = false;
111 this.searchString = '';
112 this.usersTableHeaders = ['First Name', 'Last Name', 'User ID', 'Roles'];
113 this.accountUsers = [];
116 this.openAddNewUserModal = (user) => {
122 orgUserId: user.orgUserId,
123 firstName: user.firstName,
124 lastName: user.lastName
129 templateUrl: 'app/views/users/new-user-dialogs/new-user.modal.html',
130 controller: 'NewUserModalCtrl',
131 controllerAs: 'newUser',
133 }).closePromise.then(needUpdate => {
134 if (needUpdate.value === true) {
135 $log.debug('UsersCtrl::openAddNewUserModal updating table data...');
136 this.updateUsersList();
141 this.openEditUserModal = (loginId) => {
144 updateRemoteApp : true,
145 appId : this.selectedApp!=null?this.selectedApp.id:''
147 var modalInstance = ngDialog.open({
148 templateUrl: 'app/views/header/user-edit/edit-user.tpl.html',
149 controller: 'editUserController',
152 message: function message() {
159 }).closePromise.then(needUpdate => {
160 //update selected app's database for this user.
161 console.log("'''''''''''''''''' now updating user list after update remote server");
162 $timeout(this.updateUsersList, 1500);
167 $scope.$watch('users.selectedApp', (newVal, oldVal) => {
168 if (!newVal || _.isEqual(newVal, oldVal)) {
171 $log.debug('UsersCtrl::openAddNewUserModal:$watch selectedApp -> Fire with: ', newVal);
172 this.accountUsers = [];
173 this.updateUsersList();
176 $scope.$on('$destroy', () => {
177 activeRequests.forEach(req => {
185 UsersCtrl.$inject = ['$log', 'applicationsService', 'usersService', '$scope', 'ngDialog','$timeout'];
186 angular.module('ecompApp').controller('UsersCtrl', UsersCtrl);