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, adminsService, applicationsService, ngDialog) {
25 let allPortalsFilterObject = {index: 0, title: 'All applications', value: ''};
27 let updateTableData = () => {
28 this.isLoadingTable = true;
29 adminsService.getAccountAdmins().then(res=> {
30 if (!res || !res.length) {
31 $log.info('AdminsCtrl::updateTableData: no admins err handling');
32 this.adminsTableData = [];
35 this.adminsTableData = res;
37 $log.error('AdminsCtrl::updateTableData error: ', err);
39 this.isLoadingTable = false;
44 $log.info('AdminsCtrl:: ::initializing...');
45 this.isLoadingTable = false;
46 this.availableApps = [allPortalsFilterObject];
47 this.filterByApp = this.availableApps[0];
49 /* Table general configuration params*/
50 this.searchString= '';
52 this.adminsTableHeaders = ['First Name', 'Last Name', 'User ID', 'Applications'];
53 this.adminsTableData = [];
57 applicationsService.getAvailableApps().then(res=> {
58 this.availableApps = [allPortalsFilterObject];
59 var res1 = res.sort(getSortOrder("title"));
61 for(let i=1; i<=res1.length; i++){
62 if (!res1[i-1].restrictedApp) {
63 $log.debug('AdminsCtrl:getAvailableApps:: pushing: {index: ', realAppIndex, 'title: ', res1[i - 1].title,
64 '| value: ', res1[i -1].value, '}');
65 this.availableApps.push({
67 title: res1[i - 1].title,
68 value: res1[i - 1].value
70 realAppIndex = realAppIndex + 1;
72 $log.debug('AdminsCtrl:getAvailableApps:: Restricted/URL only App will not be used = ' + res1[i - 1].title);
77 this.availableApps = [allPortalsFilterObject];
80 let getSortOrder = (prop) => {
81 return function(a, b) {
82 if (a[prop].toLowerCase() > b[prop].toLowerCase()) {
84 } else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {
93 this.portalsRowFilter = (input) => {
94 if (this.filterByApp.value === '') {
97 return _.find(input.apps, {appName: this.filterByApp.value}) !== undefined;
100 this.openAddNewAdminModal = (user) => {
106 orgUserId: user.orgUserId,
107 firstName: user.firstName,
108 lastName: user.lastName
113 templateUrl: 'app/views/admins/add-admin-dialogs/new-admin.modal.html',
114 controller: 'NewAdminModalCtrl',
115 controllerAs: 'newAdmin',
117 }).closePromise.then(needUpdate => {
118 if(needUpdate.value === true){
119 $log.debug('AdminsCtrl:openAddNewAdminModal:: updating table data...');
125 this.openEditUserModal = (loginId) => {
128 updateRemoteApp : false,
129 appId : this.selectedApp!=null?this.selectedApp.id:''
131 var modalInstance = ngDialog.open({
132 templateUrl: 'app/views/header/user-edit/edit-user.tpl.html',
133 controller: 'editUserController',
136 message: function message() {
143 }).closePromise.then(needUpdate => {
149 AdminsCtrl.$inject = ['$log', 'adminsService', 'applicationsService', 'ngDialog'];
150 angular.module('ecompApp').controller('AdminsCtrl', AdminsCtrl);