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 * ================================================================================
21 * Created by nnaffar on 12/20/15.
25 class NewCatalogModalCtrl {
26 constructor($scope, $log, usersService, catalogService, applicationsService, confirmBoxService) {
28 //$log.info('NewUserModalCtrl::init');
29 this.isSaving = false;
32 $scope.userAppRoles = [];
33 $scope.titleText = "Request for Access in MyLogins:";
34 $scope.title ="Request is pending in MyLogins for the following Roles";
35 this.isGettingAdminApps = false;
36 if($scope.ngDialogData && $scope.ngDialogData.selectedUser && $scope.ngDialogData.dialogState){
37 this.selectedUser = $scope.ngDialogData.selectedUser;
38 this.dialogState = $scope.ngDialogData.dialogState;
39 this.isShowBack = false;
40 if(this.dialogState === 2){
41 this.getUserAppsRoles();
46 this.appChanged = (index) => {
47 let myApp = this.adminApps[index];
48 //$log.debug('NewUserModalCtrl::appChanged: index: ', index, '; app id: ', myApp.id, 'app name: ',myApp.name);
49 myApp.isChanged = true;
50 this.anyChanges = true;
53 this.deleteApp = (app) => {
54 let appMessage = this.selectedUser.firstName + ' ' + this.selectedUser.lastName;
55 confirmBoxService.deleteItem(appMessage).then(isConfirmed => {
57 this.anyChanges = true;
59 app.isDeleted = true; // use this to hide the app in the display
60 app.appRoles.forEach(function(role){
61 role.isApplied = false;
65 $log.error('NewUserModalCtrl::deleteApp error: ',err);
66 confirmBoxService.showInformation('There was a problem deleting the the applications. ' +
67 'Please try again later. Error: ' + err.status).then(isConfirmed => {});
71 this.getUserAppsRoles = () => {
73 //$log.debug('NewUserModalCtrl::getUserAppsRoles: about to call getAdminAppsSimpler');
74 this.isGettingAdminApps = true;
75 catalogService.getAppCatalog().then((apps) => {
76 //$log.debug('NewUserModalCtrl::getUserAppsRoles: beginning of then for getAdminAppsSimpler');
78 this.isGettingAdminApps = false;
79 if (!apps || !apps.length) {
80 $log.error('NewUserModalCtrl::getUserApps error: no admin apps found');
83 //$log.debug('NewUserModalCtrl::getUserAppsRoles: then for getAdminAppsSimpler: step 2');
84 //$log.debug('NewUserModalCtrl::getUserAppsRoles: admin apps: ', apps);
87 this.isLoading = true;
88 this.adminApps = apps;
90 catalogService.getuserAppRolesCatalog(this.selectedUser.headerText).then(
92 // $log.debug('CatalogCtrl:storeSelection result is ', result);
94 $scope.userAppRoles = result;
95 $scope.displyUserAppCatalogRoles = true;
96 if(result.length === 1 && result[0].requestedRoleId === null)
98 $scope.title= "Removal Request is pending in MyLogins";
101 if($scope.userAppRoles.length==0)
103 $scope.displyUserAppCatalogRoles = false;
106 apps.forEach(app => {
107 if(app.name === this.selectedUser.headerText){
108 //$log.debug('NewUserModalCtrl::getUserAppsRoles: app: id: ', app.id, 'name: ',app.name);
109 // Keep track of which app has changed, so we know which apps to update using a BE API
110 app.isChanged = false;
111 // Each of these specifies a state, which corresponds to a different message and style that gets displayed
112 app.isLoading = true;
114 app.isDeleted = false;
115 app.printNoChanges = false;
116 app.isUpdating = false;
117 app.isErrorUpdating = false;
118 app.isDoneUpdating = false;
119 app.errorMessage = "";
120 usersService.getUserAppRoles(app.id, this.selectedUser.attuid).promise().then((userAppRolesResult) => {
121 //$log.debug('NewUserModalCtrl::getUserAppsRoles: got a result for app: ',app.id,': ',app.name,': ',userAppRolesResult);
122 app.appRoles = userAppRolesResult;
123 app.isLoading = false;
127 app.isLoading = false;
128 app.errorMessage = err.headers('FEErrorString');
129 //$log.debug('NewUserModalCtrl::getUserAppsRoles: in new-user.controller: response header: '+err.headers('FEErrorString'));
131 this.numberAppsProcessed++;
132 if (this.numberAppsProcessed === this.adminApps.length) {
133 this.isLoading = false;
147 * Update the selected user apps with the new roles.
148 * If no roles remain, set the user to inactive.
150 this.updateUserAppsRoles = () => {
151 // $log.debug('NewUserModalCtrl::updateUserAppsRoles: entering updateUserAppsRoles');
152 if(!this.selectedUser || !this.selectedUser.attuid || !this.adminApps){
153 $log.error('NewUserModalCtrl::updateUserAppsRoles: mmissing arguments');
156 this.isSaving = true;
157 confirmBoxService.makeUserAppRoleCatalogChanges('Are you sure you want to make these changes?')
159 if(confirmed === true){
160 //$log.debug('NewUserModalCtrl::updateUserAppsRoles: going to update user: ' + this.selectedUser.attuid);
161 this.numberAppsProcessed = 0;
162 this.numberAppsSucceeded = 0;
163 this.adminApps.forEach(app => {
165 //$log.debug('NewUserModalCtrl::updateUserAppsRoles: app roles have changed; going to update: id: ', app.id, '; name: ', app.name);
166 app.isUpdating = true;
167 var UserAppRolesRequest = {
168 attuid: this.selectedUser.attuid,
170 appRoles: app.appRoles,
173 this.isSaving = true;
174 $log.debug('going to update user: ' + this.selectedUser.attuid + ' with app roles: ' + JSON.stringify(this.adminAppsRoles));
175 applicationsService.saveUserAppsRoles(UserAppRolesRequest).then(res => {
176 app.isUpdating = false;
177 $scope.closeThisDialog(true);
179 $log.error('NewAdminModalCtrl.updateAdminAppsRoles:: Failed - ' + err);
181 this.isSaving = false;
186 this.isSaving = false;
196 * Navigate between dialog screens using step number: 1,2,...
198 this.navigateBack = () => {
199 if (this.dialogState === 1) {
200 //back from 1st screen?
202 if (this.dialogState === 3) {
203 this.dialogState = 1;
209 $scope.$on('$stateChangeStart', e => {
210 //Disable navigation when modal is opened
211 //**Nabil - note: this will cause the history back state to be replaced with current state
216 NewCatalogModalCtrl.$inject = ['$scope', '$log', 'usersService', 'catalogService', 'applicationsService', 'confirmBoxService'];
217 angular.module('ecompApp').controller('NewCatalogModalCtrl', NewCatalogModalCtrl);