-/*-\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
-\r
-'use strict';\r
-(function () {\r
- class NewAdminModalCtrl {\r
- constructor($log, adminsService, $scope, confirmBoxService, utilsService, $location) {\r
-\r
- let init = () => {\r
- this.isSaving = false;\r
- this.originalApps = [];\r
- /* istanbul ignore if */\r
- if ($scope.ngDialogData && $scope.ngDialogData.selectedUser && $scope.ngDialogData.dialogState) {\r
- this.selectedUser = $scope.ngDialogData.selectedUser;\r
- this.dialogState = $scope.ngDialogData.dialogState;\r
- this.isShowBack = false;\r
- if (this.dialogState === 2) {\r
- this.getAdminAppsRoles();\r
- }\r
- } else {\r
- this.isShowBack = true;\r
- this.selectedUser = null;\r
- this.dialogState = 1;\r
- }\r
-\r
- //this.searchUsersInProgress = false;\r
- //this.showNewAdminAppDropdown = false;\r
- $log.info('NewAdminModalCtrl::initiated');\r
- this.appsOrder = [];\r
- };\r
-\r
- let orderList = (apps) => {\r
- this.appsOrder = [];\r
- for (var i = 0; i < apps.length; i++) {\r
- if (apps[i].isAdmin) {\r
- this.appsOrder.push(apps[i].id);\r
- }\r
- }\r
- };\r
-\r
- this.orderFilter = app => {\r
- if (!app || !app.id || !this.appsOrder.length) {\r
- return;\r
- }\r
- return this.appsOrder.indexOf(app.id);\r
- };\r
-\r
- /**\r
- * this function get the selected admin apps roles\r
- */\r
- this.getAdminAppsRoles = () => {\r
- if (!this.selectedUser || !this.selectedUser.orgUserId) {\r
- $log.error('No user is selected / searchUsers is InProgress');\r
- this.dialogState = 1;\r
- return;\r
- }\r
- adminsService.getAdminAppsRoles(this.selectedUser.orgUserId).then(roles => {\r
- $log.debug('apps roles res: ', JSON.stringify(roles));\r
- if (!roles.appsRoles) {\r
- return;\r
- }\r
-\r
- this.adminAppsRoles = [];\r
- for (var i = 0; i < roles.appsRoles.length; i++) {\r
- if (!roles.appsRoles[i].restrictedApp) {\r
- $log.debug('pushing: {id: ', roles.appsRoles[i].id,\r
- 'name: ', roles.appsRoles[i].appName,\r
- 'restrictedApp: ', roles.appsRoles[i].restrictedApp,\r
- 'isAdmin: ', roles.appsRoles[i].isAdmin, '}');\r
- this.adminAppsRoles.push({\r
- id: roles.appsRoles[i].id,\r
- appName: roles.appsRoles[i].appName,\r
- isAdmin: roles.appsRoles[i].isAdmin,\r
- restrictedApp: roles.appsRoles[i].restrictedApp\r
- });\r
- }\r
- }\r
- this.dialogState = 2;\r
- this.adminAppsRoles = this.adminAppsRoles.sort(getSortOrder("appName"));\r
-\r
- orderList(roles.appsRoles);\r
- if (this.appsOrder != null) {\r
- for (var j = 0; j < this.appsOrder.length; j++) {\r
- this.originalApps.push(this.appsOrder[j]);\r
- }\r
- }\r
- }).catch(err => {\r
- $log.error(err);\r
- });\r
- };\r
-\r
- // Refactor this into a directive\r
- let getSortOrder = (prop) => {\r
- return function (a, b) {\r
- if (a[prop].toLowerCase() > b[prop].toLowerCase()) {\r
- return 1;\r
- } else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {\r
- return -1;\r
- }\r
- return 0;\r
- }\r
- }\r
-\r
- /**\r
- * this function set the selected user\r
- * @param user: selected user object\r
- */\r
- this.setSelectedUser = (user) => {\r
- $log.debug('selected user: ', user);\r
- this.selectedUser = user;\r
- };\r
-\r
- /**\r
- * Mark the user as not admin of the selected app\r
- * @param app: selected app object\r
- */\r
- this.unadminApp = (app) => {\r
- confirmBoxService.deleteItem(app.appName).then(confirmed => {\r
- if (confirmed === true) {\r
- app.isAdmin = false;\r
- this.appsOrder.splice(this.appsOrder.indexOf(app.id), 1);\r
- }\r
- }).catch(err => {\r
- $log(err);\r
- });\r
- };\r
-\r
- /**\r
- * update the selected admin app with the new roles\r
- */\r
- this.updateAdminAppsRoles = () => {\r
- if (!this.selectedUser || !this.selectedUser.orgUserId || !this.adminAppsRoles) {\r
- return;\r
- }\r
- this.isSaving = true;\r
- $log.debug('going to update user: ' + this.selectedUser.orgUserId + ' with app roles: ' + JSON.stringify(this.adminAppsRoles));\r
- confirmBoxService.makeAdminChanges('Are you sure you want to make these admin changes?')\r
- .then(confirmed => {\r
- if(confirmed === true){\r
- adminsService.updateAdminAppsRoles({\r
- orgUserId: this.selectedUser.orgUserId,\r
- appsRoles: this.adminAppsRoles\r
- })\r
- .then(res => {\r
- $log.debug('Admin apps roles updated successfully!', res);\r
- //close and resolve dialog promise with true (to update the table)\r
- this.remindToAddUserIfNecessary();\r
- $scope.closeThisDialog(true);\r
- }).catch(err => {\r
- $log.error('NewAdminModalCtrl.updateAdminAppsRoles:: Failed - ' + err);\r
- }).finally(()=> {\r
- this.isSaving = false;\r
- })\r
- }else{\r
- this.isSaving = false;\r
- }\r
- });\r
- };\r
-\r
- /**\r
- * Navigate between dialog screens using step number: 1,2,...\r
- */\r
- this.navigateBack = () => {\r
- if (this.dialogState === 1) {\r
- //back from 1st screen?\r
- }\r
- if (this.dialogState === 2) {\r
- this.dialogState = 1;\r
- }\r
- };\r
-\r
- init();\r
-\r
- /**\r
- * each time new app is selected in the drop down,\r
- * add it to the user administrated apps list\r
- */\r
- $scope.$watch('newAdmin.selectedNewApp', (newVal) => {\r
- if (!newVal || newVal.isAdmin === undefined) {\r
- return;\r
- }\r
- //newVal.isAdmin = true; - track by ruined this, here is the workaround:\r
- let app = _.find(this.adminAppsRoles, {id: newVal.id});\r
- if (app) {\r
- app.isAdmin = true;\r
- this.appsOrder.push(app.id);\r
- }\r
- this.selectedNewApp = null;\r
- //this.showNewAdminAppDropdown = false;\r
- });\r
-\r
- $scope.$on('$stateChangeStart', e => {\r
- //Disable navigation when modal is opened\r
- //**Nabil - note: this will cause the history back state to be replaced with current state\r
- e.preventDefault();\r
- });\r
-\r
- /**\r
- * If an Admin was added for an application remind the portal admin to add the admin as a user\r
- */\r
- this.remindToAddUserIfNecessary = () => {\r
-\r
- var adminAddedToNewApp = false;\r
- if ((this.originalApps != null) && (this.originalApps.length > 0)) {\r
- for (var i = 0; i < this.appsOrder.length; i++) {\r
- var foundApp = false;\r
- for (var j = 0; j < this.originalApps.length; j++) {\r
- if (this.originalApps[j] === this.appsOrder[i]) {\r
- foundApp = true;\r
- }\r
- }\r
- if (foundApp === false) {\r
- adminAddedToNewApp = true;\r
- break;\r
- }\r
- }\r
- } else {\r
- adminAddedToNewApp = true;\r
- }\r
-\r
- if (adminAddedToNewApp === true) {\r
- confirmBoxService.confirm('Add this person as an application user? This allows them to access the application from ECOMP Portal. Press OK to go to the Add Users page.')\r
- .then(confirmed => {\r
- if (confirmed === true) {\r
- $location.path('/users');\r
- }\r
- });\r
- }\r
- }\r
-\r
- }\r
- }\r
- NewAdminModalCtrl.$inject = ['$log', 'adminsService', '$scope', 'confirmBoxService', 'utilsService', '$location'];\r
- angular.module('ecompApp').controller('NewAdminModalCtrl', NewAdminModalCtrl);\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 NewAdminModalCtrl {
+ constructor($log, adminsService, $scope, confirmBoxService, utilsService, $location) {
+
+ let init = () => {
+ this.isSaving = false;
+ this.originalApps = [];
+ /* istanbul ignore if */
+ if ($scope.ngDialogData && $scope.ngDialogData.selectedUser && $scope.ngDialogData.dialogState) {
+ this.selectedUser = $scope.ngDialogData.selectedUser;
+ this.dialogState = $scope.ngDialogData.dialogState;
+ this.isShowBack = false;
+ if (this.dialogState === 2) {
+ this.getAdminAppsRoles();
+ }
+ } else {
+ this.isShowBack = true;
+ this.selectedUser = null;
+ this.dialogState = 1;
+ }
+
+ //this.searchUsersInProgress = false;
+ //this.showNewAdminAppDropdown = false;
+ $log.info('NewAdminModalCtrl::initiated');
+ this.appsOrder = [];
+ };
+
+ let orderList = (apps) => {
+ this.appsOrder = [];
+ for (var i = 0; i < apps.length; i++) {
+ if (apps[i].isAdmin) {
+ this.appsOrder.push(apps[i].id);
+ }
+ }
+ };
+
+ this.orderFilter = app => {
+ if (!app || !app.id || !this.appsOrder.length) {
+ return;
+ }
+ return this.appsOrder.indexOf(app.id);
+ };
+
+ /**
+ * this function get the selected admin apps roles
+ */
+ this.getAdminAppsRoles = () => {
+ if (!this.selectedUser || !this.selectedUser.orgUserId) {
+ $log.error('No user is selected / searchUsers is InProgress');
+ this.dialogState = 1;
+ return;
+ }
+ adminsService.getAdminAppsRoles(this.selectedUser.orgUserId).then(roles => {
+ $log.debug('apps roles res: ', JSON.stringify(roles));
+ if (!roles.appsRoles) {
+ return;
+ }
+
+ this.adminAppsRoles = [];
+ for (var i = 0; i < roles.appsRoles.length; i++) {
+ if (!roles.appsRoles[i].restrictedApp) {
+ $log.debug('pushing: {id: ', roles.appsRoles[i].id,
+ 'name: ', roles.appsRoles[i].appName,
+ 'restrictedApp: ', roles.appsRoles[i].restrictedApp,
+ 'isAdmin: ', roles.appsRoles[i].isAdmin, '}');
+ this.adminAppsRoles.push({
+ id: roles.appsRoles[i].id,
+ appName: roles.appsRoles[i].appName,
+ isAdmin: roles.appsRoles[i].isAdmin,
+ restrictedApp: roles.appsRoles[i].restrictedApp
+ });
+ }
+ }
+ this.dialogState = 2;
+ this.adminAppsRoles = this.adminAppsRoles.sort(getSortOrder("appName"));
+
+ orderList(roles.appsRoles);
+ if (this.appsOrder != null) {
+ for (var j = 0; j < this.appsOrder.length; j++) {
+ this.originalApps.push(this.appsOrder[j]);
+ }
+ }
+ }).catch(err => {
+ $log.error(err);
+ });
+ };
+
+ // Refactor this into a directive
+ let getSortOrder = (prop) => {
+ return function (a, b) {
+ if (a[prop].toLowerCase() > b[prop].toLowerCase()) {
+ return 1;
+ } else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {
+ return -1;
+ }
+ return 0;
+ }
+ }
+
+ /**
+ * this function set the selected user
+ * @param user: selected user object
+ */
+ this.setSelectedUser = (user) => {
+ $log.debug('selected user: ', user);
+ this.selectedUser = user;
+ };
+
+ /**
+ * Mark the user as not admin of the selected app
+ * @param app: selected app object
+ */
+ this.unadminApp = (app) => {
+ confirmBoxService.deleteItem(app.appName).then(confirmed => {
+ if (confirmed === true) {
+ app.isAdmin = false;
+ this.appsOrder.splice(this.appsOrder.indexOf(app.id), 1);
+ }
+ }).catch(err => {
+ $log(err);
+ });
+ };
+
+ /**
+ * update the selected admin app with the new roles
+ */
+ this.updateAdminAppsRoles = () => {
+ if (!this.selectedUser || !this.selectedUser.orgUserId || !this.adminAppsRoles) {
+ return;
+ }
+ this.isSaving = true;
+ $log.debug('going to update user: ' + this.selectedUser.orgUserId + ' with app roles: ' + JSON.stringify(this.adminAppsRoles));
+ confirmBoxService.makeAdminChanges('Are you sure you want to make these admin changes?')
+ .then(confirmed => {
+ if(confirmed === true){
+ adminsService.updateAdminAppsRoles({
+ orgUserId: this.selectedUser.orgUserId,
+ appsRoles: this.adminAppsRoles
+ })
+ .then(res => {
+ $log.debug('Admin apps roles updated successfully!', res);
+ //close and resolve dialog promise with true (to update the table)
+ this.remindToAddUserIfNecessary();
+ $scope.closeThisDialog(true);
+ }).catch(err => {
+ $log.error('NewAdminModalCtrl.updateAdminAppsRoles:: Failed - ' + err);
+ }).finally(()=> {
+ this.isSaving = false;
+ })
+ }else{
+ this.isSaving = false;
+ }
+ });
+ };
+
+ /**
+ * Navigate between dialog screens using step number: 1,2,...
+ */
+ this.navigateBack = () => {
+ if (this.dialogState === 1) {
+ //back from 1st screen?
+ }
+ if (this.dialogState === 2) {
+ this.dialogState = 1;
+ }
+ };
+
+ init();
+
+ /**
+ * each time new app is selected in the drop down,
+ * add it to the user administrated apps list
+ */
+ $scope.$watch('newAdmin.selectedNewApp.value', (newVal) => {
+ var newVal= JSON.parse(newVal);
+ if (!newVal || newVal.isAdmin === undefined) {
+ return;
+ }
+ //newVal.isAdmin = true; - track by ruined this, here is the workaround:
+ let app = _.find(this.adminAppsRoles, {id: newVal.id});
+ if (app) {
+ app.isAdmin = true;
+ this.appsOrder.push(app.id);
+ }
+ this.selectedNewApp = null;
+ //this.showNewAdminAppDropdown = false;
+ });
+
+ $scope.$on('$stateChangeStart', e => {
+ //Disable navigation when modal is opened
+ //**Nabil - note: this will cause the history back state to be replaced with current state
+ e.preventDefault();
+ });
+
+ /**
+ * If an Admin was added for an application remind the portal admin to add the admin as a user
+ */
+ this.remindToAddUserIfNecessary = () => {
+
+ var adminAddedToNewApp = false;
+ if ((this.originalApps != null) && (this.originalApps.length > 0)) {
+ for (var i = 0; i < this.appsOrder.length; i++) {
+ var foundApp = false;
+ for (var j = 0; j < this.originalApps.length; j++) {
+ if (this.originalApps[j] === this.appsOrder[i]) {
+ foundApp = true;
+ }
+ }
+ if (foundApp === false) {
+ adminAddedToNewApp = true;
+ break;
+ }
+ }
+ } else {
+ adminAddedToNewApp = true;
+ }
+
+ if (adminAddedToNewApp === true) {
+ confirmBoxService.confirm('Add this person as an application user? This allows them to access the application from ECOMP Portal. Press OK to go to the Add Users page.')
+ .then(confirmed => {
+ if (confirmed === true) {
+ $location.path('/users');
+ }
+ });
+ }
+ }
+
+ }
+ }
+ NewAdminModalCtrl.$inject = ['$log', 'adminsService', '$scope', 'confirmBoxService', 'utilsService', '$location'];
+ angular.module('ecompApp').controller('NewAdminModalCtrl', NewAdminModalCtrl);
+})();