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.error('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 //if(!res || Object.prototype.toString.call(res) !== '[object Array]'){
59 // this.availableApps = [allPortalsFilterObject];
62 //this part overrides index param to fix ABS select bug
63 // (index has to be the same as location in array)
64 // todo:change BE object to contain only id and name
65 this.availableApps = [allPortalsFilterObject];
66 var res1 = res.sort(getSortOrder("title"));
68 for(let i=1; i<=res1.length; i++){
69 if (!res1[i-1].restrictedApp) {
70 //$log.debug('AdminsCtrl:getAvailableApps:: pushing: {index: ', realAppIndex, 'title: ', res1[i - 1].title,
71 // '| value: ', res1[i -1].value, '}');
72 this.availableApps.push({
74 title: res1[i - 1].title,
75 value: res1[i - 1].value
77 realAppIndex = realAppIndex + 1;
79 // $log.debug('AdminsCtrl:getAvailableApps:: Restricted/URL only App will not be used = ' + res1[i - 1].title);
83 $log.error('AdminsCtrl::ctor', err);
84 this.availableApps = [allPortalsFilterObject];
87 // Refactor this into a directive
88 let getSortOrder = (prop) => {
89 return function(a, b) {
90 // $log.debug('a = ' + JSON.stringify(a) + "| b = " + JSON.stringify(b));
91 if (a[prop].toLowerCase() > b[prop].toLowerCase()) {
93 } else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {
103 this.portalsRowFilter = (input) => {
104 if (this.filterByApp.value === '') {
107 return _.find(input.apps, {appName: this.filterByApp.value}) !== undefined;
110 this.openAddNewAdminModal = (user) => {
116 orgUserId: user.orgUserId,
117 firstName: user.firstName,
118 lastName: user.lastName
123 templateUrl: 'app/views/admins/add-admin-dialogs/new-admin.modal.html',
124 controller: 'NewAdminModalCtrl',
125 controllerAs: 'newAdmin',
127 }).closePromise.then(needUpdate => {
128 if(needUpdate.value === true){
129 // $log.debug('AdminsCtrl:openAddNewAdminModal:: updating table data...');
135 this.openEditUserModal = (loginId) => {
138 updateRemoteApp : false,
139 appId : this.selectedApp!=null?this.selectedApp.id:''
141 var modalInstance = ngDialog.open({
142 templateUrl: 'app/views/header/user-edit/edit-user.tpl.html',
143 controller: 'editUserController',
146 message: function message() {
153 }).closePromise.then(needUpdate => {
159 AdminsCtrl.$inject = ['$log', 'adminsService', 'applicationsService', 'ngDialog'];
160 angular.module('ecompApp').controller('AdminsCtrl', AdminsCtrl);