-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-'use strict';\r
-(function () {\r
- class UsersCtrl {\r
- constructor($log, applicationsService, usersService, confirmBoxService, $scope, ngDialog) {\r
- this.$log = $log;\r
- $scope.adminAppsIsNull = false;\r
- $scope.appsIsDown = false;\r
- $scope.noUsersInApp = false;\r
- $scope.multiAppAdmin = false;\r
-\r
- $log.info('UsersCtrl:: initializing...');\r
- /**\r
- * Handle all active HTTP requests\r
- * activeRequests @type {Array[requests with cancel option]}\r
- */\r
- let activeRequests = [];\r
- let clearReq = (req) => {\r
- activeRequests.splice(activeRequests.indexOf(req), 1);\r
- };\r
-\r
- let init = () => {\r
- this.isLoadingTable = false;\r
- this.selectedApp = null;\r
- this.isAppSelectDisabled = false;\r
- this.selectApp = 'Select application';\r
- this.adminApps = [{index: 0, id: 0, value: this.selectApp, title: this.selectApp}];\r
- getAdminApps();\r
-\r
- /*Table general configuration params*/\r
- this.searchString = '';\r
- /*Table data*/\r
- this.usersTableHeaders = ['First Name', 'Last Name', 'User ID', 'Roles'];\r
- this.accountUsers = [];\r
- };\r
-\r
- let getAdminApps = () => {\r
- $log.debug('UsersCtrl::getAdminApps: - Starting getAdminApps');\r
- try {\r
- this.isLoadingTable = true;\r
- let adminAppsReq = applicationsService.getAdminApps();\r
- adminAppsReq.promise().then(apps => {\r
- if (!apps || !apps.length) {\r
- $log.error('UsersCtrl::getAdminApps: - no apps found');\r
- return null;\r
- }\r
- $log.debug('UsersCtrl::getAdminApps: Apps for this user are: ' + JSON.stringify(apps));\r
- if (apps.length >= 2) {\r
- $log.info('UsersCtrl::getAdminApps: - more than one app for this admin:', apps.length, ' apps');\r
- $scope.multiAppAdmin = true;\r
- } else {\r
- this.adminApps = [] ;\r
- }\r
- let sortedApps = apps.sort(getSortOrder("name"));\r
- let realAppIndex = 1;\r
- for(let i=1; i<=sortedApps.length; i++){\r
- this.adminApps.push({\r
- index: realAppIndex,\r
- id: sortedApps[i - 1].id,\r
- value: sortedApps[i - 1].name,\r
- title: sortedApps[i - 1].name\r
- });\r
- realAppIndex = realAppIndex + 1;\r
- }\r
-\r
- $log.debug('UsersCtrl::getAdminApps: Apps for this user are: ' + JSON.stringify(this.adminApps));\r
-\r
- this.selectedApp = this.adminApps[0];\r
- clearReq(adminAppsReq);\r
- $scope.adminAppsIsNull = false;\r
- }).catch(e => {\r
- $scope.adminAppsIsNull = true;\r
- $log.error('UsersCtrl::getAdminApps: - getAdminApps() failed = '+ e.message);\r
- clearReq(adminAppsReq);\r
- confirmBoxService.showInformation('There was a problem retrieving the applications. ' +\r
- 'Please try again later.').then(isConfirmed => {});\r
-\r
- }).finally(() => {\r
- this.isLoadingTable = false;\r
- });\r
- } catch (e) {\r
- $scope.adminAppsIsNull = true;\r
- $log.error('UsersCtrl::getAdminApps: - getAdminApps() failed!');\r
- this.isLoadingTable = false;\r
- }\r
- };\r
-\r
- let getSortOrder = (prop) => {\r
- return function(a, b) {\r
- if (a[prop] > b[prop]) {\r
- return 1;\r
- } else if (a[prop] < b[prop]) {\r
- return -1;\r
- }\r
- return 0;\r
- }\r
- }\r
-\r
- this.updateUsersList = () => {\r
- $scope.appsIsDown = false;\r
- $scope.noUsersInApp = false;\r
- // $log.debug('UsersCtrl::updateUsersList: Starting updateUsersList');\r
- //reset search string\r
- this.searchString = '';\r
- //should i disable this too in case of moving between tabs?\r
- this.isAppSelectDisabled = true;\r
- //activate spinner\r
- this.isLoadingTable = true;\r
- \r
- if(this.adminApps!=null && this.selectedApp!=null){\r
- var tempSelected = null;\r
- for(let i=0; i<=this.adminApps.length; i++){\r
- if(typeof this.adminApps[i] != 'undefined' && this.selectedApp.value==this.adminApps[i].value){\r
- tempSelected=_.clone(this.adminApps[i]);\r
- }\r
- }\r
- if(tempSelected!=null){\r
- this.selectedApp= tempSelected;\r
- }\r
- }\r
- \r
- if (this.selectedApp.title != this.selectApp) { // 'Select Application'\r
- usersService.getAccountUsers(this.selectedApp.id)\r
- .then(accountUsers => {\r
- $log.debug('UsersCtrl::updateUsersList accountUsers: '+ accountUsers);\r
- if (angular.isObject(accountUsers)===false) {\r
- $log.error('UsersCtrl::updateUsersList accountUsers: App is down!');\r
- $scope.appsIsDown = true;\r
- }\r
- $log.debug('UsersCtrl::updateUsersList length: '+ Object.keys(accountUsers).length);\r
- this.isAppSelectDisabled = false;\r
- this.accountUsers = accountUsers;\r
- if (angular.isObject(accountUsers) && Object.keys(accountUsers).length === 0) {\r
- $log.debug('UsersCtrl::updateUsersList accountUsers: App has no users.');\r
- $scope.noUsersInApp = true;\r
- }\r
- }).catch(err => {\r
- this.isAppSelectDisabled = false;\r
- $log.error('UsersCtrl::updateUsersList error: ' + err);\r
- confirmBoxService.showInformation('There was a problem updating the users List. ' +\r
- 'Please try again later.').then(isConfirmed => {});\r
- $scope.appsIsDown = true;\r
- }).finally(() => {\r
- this.isLoadingTable = false;\r
- $scope.noAppSelected = false;\r
- });\r
- } else {\r
- // this.selectedApp = this.adminApps[0];\r
- this.isAppSelectDisabled = false;\r
- this.isLoadingTable = false;\r
- $scope.noUsersInApp = false;\r
- $scope.noAppSelected = true;\r
- }\r
- };\r
-\r
-\r
- this.openAddNewUserModal = (user) => {\r
- let data = null;\r
- if (user) {\r
- data = {\r
- dialogState: 3,\r
- selectedUser: {\r
- orgUserId: user.orgUserId,\r
- firstName: user.firstName,\r
- lastName: user.lastName\r
- }\r
- }\r
- }\r
- ngDialog.open({\r
- templateUrl: 'app/views/users/new-user-dialogs/new-user.modal.html',\r
- controller: 'NewUserModalCtrl',\r
- controllerAs: 'newUser',\r
- data: data\r
- }).closePromise.then(needUpdate => {\r
- if (needUpdate.value === true) {\r
- $log.debug('UsersCtrl::openAddNewUserModal updating table data...');\r
- this.updateUsersList();\r
- }\r
- });\r
- };\r
- \r
- this.openBulkUserUploadModal = (adminApps) => {\r
- let data = null;\r
- if (adminApps) {\r
- data = {\r
- dialogState: 3,\r
- selectedApplication: {\r
- appid: adminApps[0].appid,\r
- appName: adminApps[0].appName\r
- }\r
- }\r
- }\r
- ngDialog.open({\r
- templateUrl: 'app/views/users/new-user-dialogs/bulk-user.modal.html',\r
- controller: 'BulkUserModalCtrl',\r
- controllerAs: 'bulkUser',\r
- data: data\r
- }).closePromise.then(needUpdate => {\r
- this.updateUsersList();\r
- });\r
- };\r
-\r
-\r
- $scope.$watch('users.selectedApp.value', (newVal, oldVal) => {\r
- if (!newVal || _.isEqual(newVal, oldVal)) {\r
- return;\r
- }\r
- $log.debug('UsersCtrl::openAddNewUserModal:$watch selectedApp -> Fire with: ', newVal);\r
- this.accountUsers = []; //reset table and show swirl here\r
- this.updateUsersList();\r
- });\r
-\r
- $scope.$on('$destroy', () => {\r
- //cancel all active requests when closing the modal\r
- activeRequests.forEach(req => {\r
- req.cancel();\r
- });\r
- });\r
-\r
- init();\r
- }\r
- }\r
- UsersCtrl.$inject = ['$log', 'applicationsService', 'usersService', 'confirmBoxService', '$scope', 'ngDialog'];\r
- angular.module('ecompApp').controller('UsersCtrl', UsersCtrl);\r
-})();\r
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+'use strict';
+(function () {
+ class UsersCtrl {
+ constructor($log, applicationsService, usersService, confirmBoxService, $scope, ngDialog,$modal) {
+ this.$log = $log;
+ $scope.adminAppsIsNull = false;
+ $scope.appsIsDown = false;
+ $scope.noUsersInApp = false;
+ $scope.multiAppAdmin = false;
+
+ $log.info('UsersCtrl:: initializing...');
+ /**
+ * Handle all active HTTP requests
+ * activeRequests @type {Array[requests with cancel option]}
+ */
+ let activeRequests = [];
+ let clearReq = (req) => {
+ activeRequests.splice(activeRequests.indexOf(req), 1);
+ };
+
+ let init = () => {
+ this.isLoadingTable = false;
+ this.selectedApp = null;
+ this.isAppSelectDisabled = false;
+ this.selectApp = 'Select application';
+ this.adminApps = [{index: 0, id: 0, value: this.selectApp, title: this.selectApp}];
+ getAdminApps();
+
+ /*Table general configuration params*/
+ this.searchString = '';
+ /*Table data*/
+ this.usersTableHeaders = ['First Name', 'Last Name', 'User ID', 'Roles'];
+ this.accountUsers = [];
+ };
+
+ let getAdminApps = () => {
+ $log.debug('UsersCtrl::getAdminApps: - Starting getAdminApps');
+ try {
+ this.isLoadingTable = true;
+ let adminAppsReq = applicationsService.getAdminApps();
+ adminAppsReq.promise().then(apps => {
+ if (!apps || !apps.length) {
+ $log.error('UsersCtrl::getAdminApps: - no apps found');
+ return null;
+ }
+ $log.debug('UsersCtrl::getAdminApps: Apps for this user are: ' + JSON.stringify(apps));
+ if (apps.length >= 2) {
+ $log.info('UsersCtrl::getAdminApps: - more than one app for this admin:', apps.length, ' apps');
+ $scope.multiAppAdmin = true;
+ } else {
+ this.adminApps = [] ;
+ }
+ let sortedApps = apps.sort(getSortOrder("name"));
+ let realAppIndex = 1;
+ for(let i=1; i<=sortedApps.length; i++){
+ this.adminApps.push({
+ index: realAppIndex,
+ id: sortedApps[i - 1].id,
+ value: sortedApps[i - 1].name,
+ title: sortedApps[i - 1].name
+ });
+ realAppIndex = realAppIndex + 1;
+ }
+
+ $log.debug('UsersCtrl::getAdminApps: Apps for this user are: ' + JSON.stringify(this.adminApps));
+
+ this.selectedApp = this.adminApps[0];
+ clearReq(adminAppsReq);
+ $scope.adminAppsIsNull = false;
+ }).catch(e => {
+ $scope.adminAppsIsNull = true;
+ $log.error('UsersCtrl::getAdminApps: - getAdminApps() failed = '+ e.message);
+ clearReq(adminAppsReq);
+ confirmBoxService.showInformation('There was a problem retrieving the applications. ' +
+ 'Please try again later.').then(isConfirmed => {});
+
+ }).finally(() => {
+ this.isLoadingTable = false;
+ });
+ } catch (e) {
+ $scope.adminAppsIsNull = true;
+ $log.error('UsersCtrl::getAdminApps: - getAdminApps() failed!');
+ this.isLoadingTable = false;
+ }
+ };
+
+ let getSortOrder = (prop) => {
+ return function(a, b) {
+ if (a[prop] > b[prop]) {
+ return 1;
+ } else if (a[prop] < b[prop]) {
+ return -1;
+ }
+ return 0;
+ }
+ }
+
+ let updateUsersList = () => {
+ $scope.appsIsDown = false;
+ $scope.noUsersInApp = false;
+ // $log.debug('UsersCtrl::updateUsersList: Starting updateUsersList');
+ //reset search string
+ this.searchString = '';
+ //should i disable this too in case of moving between tabs?
+ this.isAppSelectDisabled = true;
+ //activate spinner
+ this.isLoadingTable = true;
+
+ if(this.adminApps!=null && this.selectedApp!=null){
+ var tempSelected = null;
+ for(let i=0; i<=this.adminApps.length; i++){
+ if(typeof this.adminApps[i] != 'undefined' && this.selectedApp.value==this.adminApps[i].value){
+ tempSelected=_.clone(this.adminApps[i]);
+ }
+ }
+ if(tempSelected!=null){
+ this.selectedApp= tempSelected;
+ }
+ }
+
+ if (this.selectedApp.title != this.selectApp) { // 'Select Application'
+ usersService.getAccountUsers(this.selectedApp.id)
+ .then(accountUsers => {
+ $log.debug('UsersCtrl::updateUsersList accountUsers: '+ accountUsers);
+ if (angular.isObject(accountUsers)===false) {
+ $log.error('UsersCtrl::updateUsersList accountUsers: App is down!');
+ $scope.appsIsDown = true;
+ }
+ $log.debug('UsersCtrl::updateUsersList length: '+ Object.keys(accountUsers).length);
+ this.isAppSelectDisabled = false;
+ this.accountUsers = accountUsers;
+ if (angular.isObject(accountUsers) && Object.keys(accountUsers).length === 0) {
+ $log.debug('UsersCtrl::updateUsersList accountUsers: App has no users.');
+ $scope.noUsersInApp = true;
+ }
+ }).catch(err => {
+ this.isAppSelectDisabled = false;
+ $log.error('UsersCtrl::updateUsersList error: ' + err);
+ confirmBoxService.showInformation('There was a problem updating the users List. ' +
+ 'Please try again later.').then(isConfirmed => {});
+ $scope.appsIsDown = true;
+ }).finally(() => {
+ this.isLoadingTable = false;
+ $scope.noAppSelected = false;
+ });
+ } else {
+ // this.selectedApp = this.adminApps[0];
+ this.isAppSelectDisabled = false;
+ this.isLoadingTable = false;
+ $scope.noUsersInApp = false;
+ $scope.noAppSelected = true;
+ }
+ };
+
+
+ this.openAddNewUserModal = (user) => {
+ let data = null;
+ if (user) {
+ data = {
+ dialogState: 3,
+ selectedUser: {
+ orgUserId: user.orgUserId,
+ firstName: user.firstName,
+ lastName: user.lastName,
+
+ }
+ }
+ }
+
+ var modalInstance = $modal.open({
+ templateUrl: 'app/views/users/new-user-dialogs/new-user.modal.html',
+ controller: 'NewUserModalCtrl as newUser',
+ sizeClass: 'modal-medium',
+ resolve: {
+ items: function () {
+ return data;
+ }
+ }
+ })
+
+ modalInstance.result.finally(function () {
+ $log.debug('UsersCtrl::openAddNewUserModal updating table data...');
+ updateUsersList();
+ });
+ };
+
+ this.openBulkUserUploadModal = (adminApps) => {
+ let data = null;
+ if (adminApps) {
+ data = {
+ dialogState: 3,
+ selectedApplication: {
+ appid: adminApps[0].appid,
+ appName: adminApps[0].appName
+ }
+ }
+ }
+ var modalInstance = $modal.open({
+ templateUrl: 'app/views/users/new-user-dialogs/bulk-user.modal.html',
+ controller: 'BulkUserModalCtrl as bulkUser',
+ sizeClass: 'modal-medium',
+ resolve: {
+ items: function () {
+ return data;
+ }
+ }
+ });
+
+ modalInstance.result.finally(function () {
+ $log.debug('UsersCtrl::openAddNewUserModal updating table data...');
+ updateUsersList();
+ });
+ };
+
+
+ $scope.$watch('users.selectedApp.value', (newVal, oldVal) => {
+ if (!newVal || _.isEqual(newVal, oldVal)) {
+ return;
+ }
+ $log.debug('UsersCtrl::openAddNewUserModal:$watch selectedApp -> Fire with: ', newVal);
+ this.accountUsers = []; //reset table and show swirl here
+ updateUsersList();
+ });
+
+ $scope.$on('$destroy', () => {
+ //cancel all active requests when closing the modal
+ activeRequests.forEach(req => {
+ req.cancel();
+ });
+ });
+
+ init();
+ }
+ }
+ UsersCtrl.$inject = ['$log', 'applicationsService', 'usersService', 'confirmBoxService', '$scope', 'ngDialog','$modal'];
+ angular.module('ecompApp').controller('UsersCtrl', UsersCtrl);
+})();