2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
41 constructor($log, adminsService, applicationsService, ngDialog, $modal) {
43 let allPortalsFilterObject = {index: 0, title: 'All applications', value: ''};
45 let updateTableData = () => {
46 this.isLoadingTable = true;
47 adminsService.getAccountAdmins().then(res=> {
48 if (!res || !res.length) {
49 $log.error('AdminsCtrl::updateTableData: no admins err handling');
50 this.adminsTableData = [];
53 this.adminsTableData = res;
55 $log.error('AdminsCtrl::updateTableData error: ', err);
57 this.isLoadingTable = false;
62 //$log.info('AdminsCtrl:: ::initializing...');
63 this.isLoadingTable = false;
64 this.availableApps = [allPortalsFilterObject];
65 this.filterByApp = this.availableApps[0];
67 /*Table general configuration params*/
68 this.searchString= '';
70 this.adminsTableHeaders = ['First Name', 'Last Name', 'User ID', 'Applications'];
71 this.adminsTableData = [];
75 applicationsService.getAvailableApps().then(res=> {
76 //if(!res || Object.prototype.toString.call(res) !== '[object Array]'){
77 // this.availableApps = [allPortalsFilterObject];
80 //this part overrides index param to fix ABS select bug
81 // (index has to be the same as location in array)
82 // todo:change BE object to contain only id and name
83 this.availableApps = [allPortalsFilterObject];
84 var res1 = res.sort(getSortOrder("title"));
86 for(let i=1; i<=res1.length; i++){
87 if (!res1[i-1].restrictedApp) {
88 //$log.debug('AdminsCtrl:getAvailableApps:: pushing: {index: ', realAppIndex, 'title: ', res1[i - 1].title,
89 // '| value: ', res1[i -1].value, '}');
90 this.availableApps.push({
92 title: res1[i - 1].title,
93 value: res1[i - 1].value
95 realAppIndex = realAppIndex + 1;
97 // $log.debug('AdminsCtrl:getAvailableApps:: Restricted/URL only App will not be used = ' + res1[i - 1].title);
101 $log.error('AdminsCtrl::ctor', err);
102 this.availableApps = [allPortalsFilterObject];
105 // Refactor this into a directive
106 let getSortOrder = (prop) => {
107 return function(a, b) {
108 // $log.debug('a = ' + JSON.stringify(a) + "| b = " + JSON.stringify(b));
109 if (a[prop].toLowerCase() > b[prop].toLowerCase()) {
111 } else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {
121 this.portalsRowFilter = (input) => {
122 if (this.filterByApp.value === '') {
125 return _.find(input.apps, {appName: this.filterByApp.value}) !== undefined;
128 this.openAddNewAdminModal = (user) => {
134 orgUserId: user.orgUserId,
135 firstName: user.firstName,
136 lastName: user.lastName
140 var modalInstance = $modal.open({
141 templateUrl: 'app/views/admins/add-admin-dialogs/new-admin.modal.html',
142 controller: 'NewAdminModalCtrl as newAdmin',
143 sizeClass: 'modal-medium',
151 modalInstance.result.finally(function () {
157 AdminsCtrl.$inject = ['$log', 'adminsService', 'applicationsService', 'ngDialog', '$modal'];
158 angular.module('ecompApp').controller('AdminsCtrl', AdminsCtrl);