nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / views / portal-admin / portal-admin-controller.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 'use strict';
21 (function () {
22     class PortalAdminsCtrl {
23         constructor($log, portalAdminsService, ngDialog, confirmBoxService) {
24
25             let updateTableData = () => {
26                 this.isLoadingTable = true;
27                 portalAdminsService.getPortalAdmins().then(result=> {
28                     $log.debug('PortalAdminsCtrl::updateTableData: result: ' + JSON.stringify(result));
29                     if (!result || !result.length) {
30                         $log.info('PortalAdminsCtrl::updateTableData: no Portal Admins err handling');
31                         this.portalAdminsTableData = [];
32                         return;
33                     }
34                     this.portalAdminsTableData = result;
35                 }).catch(err=> {
36                     $log.error('PortalAdminsCtrl::updateTableData error :',err);
37                 }).finally(() => {
38                     this.isLoadingTable = false;
39                 });
40             };
41
42             let init = () => {
43                 $log.info('portalAdminsService.getPortalAdmins::initializing...');
44                 this.isLoadingTable = false;
45
46                 this.searchString= '';
47                 this.portalAdminsTableHeaders = ['First Name', 'Last Name', 'User ID', 'Delete'];
48                 this.portalAdminsTableData = [];
49                 updateTableData();
50             };
51
52             init();
53
54             this.removePortalAdmin = pAdmin => {
55                 $log.debug('pAdmin = ' + JSON.stringify(pAdmin));
56                 confirmBoxService.deleteItem(pAdmin.firstName + ' ' + pAdmin.lastName )
57                     .then(isConfirmed => {
58                     if(isConfirmed){
59                         if(!pAdmin || !pAdmin.userId){
60                             $log.error('PortalAdminsCtrl::removePortalAdmin No portal admin or ID... cannot delete');
61                             return;
62                         }
63                         portalAdminsService.removePortalAdmin(pAdmin.userId).then(() => {
64                             $log.info("PortalAdminsCtrl::removePortalAdmin removed admin");
65                             init();
66                         }).catch(err => {
67                             $log.error('PortalAdminsCtrl::removePortalAdmin.deleteItem error: '+ err);
68                         });
69                     }
70                 }).catch(err => {
71                     $log.error('PortalAdminsCtrl::removePortalAdmin.deleteItem error: '+ err);
72                 });
73             };
74             
75             this.openAddNewPortalAdminModal = (user) => {
76                 let data = null;
77                 if(user){
78                     data = {
79                         dialogState: 2,
80                         selectedUser:{
81                             userId: user.orgUserId,
82                             firstName: user.firstName,
83                             lastName: user.lastName
84                         }
85                     }
86                 }
87                 ngDialog.open({
88                     templateUrl: 'app/views/portal-admin/new-portal-admin/new-portal-admin.modal.html',
89                     controller: 'NewPortalAdminModalCtrl',
90                     controllerAs: 'newPortalAdmin',
91                     data: data
92                 }).closePromise.then(needUpdate => {
93                     if(needUpdate.value === true){
94                         $log.debug('PortalAdminsCtrl::openAddNewPortalAdminModal: updating Portal Admin table data...');
95                         updateTableData();
96                     }
97                 });
98             };
99             
100             this.openEditUserModal = (loginId) => {
101                 var data = {
102                                 loginId : loginId,
103                         updateRemoteApp : false,
104                         appId : this.selectedApp!=null?this.selectedApp.id:''
105                 }
106                 var modalInstance = ngDialog.open({
107                     templateUrl: 'app/views/header/user-edit/edit-user.tpl.html',
108                     controller: 'editUserController',
109                     data: data,
110                     resolve: {
111                         message: function message() {
112                             var message = {
113                                 type: 'Contact',
114                             };
115                             return message;
116                         }
117                     }
118                 }).closePromise.then(needUpdate => {                     
119                         updateTableData();
120                     });       
121             }
122             
123         }
124     }
125     PortalAdminsCtrl.$inject = ['$log', 'portalAdminsService', 'ngDialog', 'confirmBoxService'];
126     angular.module('ecompApp').controller('PortalAdminsCtrl', PortalAdminsCtrl);
127 })();