2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2020 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============================================
38 import { Component, OnInit, ViewChild } from '@angular/core';
39 import { MatTableDataSource, MatSort, MatPaginator } from '@angular/material';
40 import { ApplicationsService, UsersService } from 'src/app/shared/services';
41 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
42 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
43 import { UserAdminApps } from 'src/app/shared/model';
44 import { HttpErrorResponse } from '@angular/common/http';
45 import { NewUserModalComponent } from './new-user-modal/new-user-modal.component';
46 import { BulkUserComponent } from './bulk-user/bulk-user.component';
49 selector: 'app-users',
50 templateUrl: './users.component.html',
51 styleUrls: ['./users.component.scss']
53 export class UsersComponent implements OnInit {
54 multiAppAdmin: boolean;
56 selectApp = 'select-application';
59 noUsersInApp: boolean;
61 isAppSelectDisabled: boolean;
63 noAppSelected: boolean;
64 @ViewChild(MatSort) sort: MatSort;
65 @ViewChild(MatPaginator) paginator: MatPaginator;
66 displayedColumns: string[] = ['firstName', 'lastName', 'userId', 'roles'];
67 adminsDataSource = new MatTableDataSource(this.accountUsers);
72 constructor(private applicationsService: ApplicationsService, public ngbModal: NgbModal,
73 private usersService: UsersService) { }
77 this.accountUsers = [];
81 openAddNewUserModal() {
82 const modalRef = this.ngbModal.open(NewUserModalComponent);
83 modalRef.componentInstance.title = 'New User';
84 modalRef.componentInstance.dialogState = 1;
85 modalRef.componentInstance.disableBack = false;
86 modalRef.componentInstance.passBackNewUserPopup.subscribe((_result: any) => {
87 this.showSpinner = true;
88 this.updateUsersList();
89 }, (_reason: any) => {
94 openExistingUserModal(userData: any) {
95 const modalRef = this.ngbModal.open(NewUserModalComponent);
99 if(userData && userData.firstName && userData.firstName!=null){
100 firstName = userData.firstName;
102 if(userData && userData.lastName && userData.lastName!=null){
103 lastName = ',' + userData.lastName;
105 if(userData && userData.orgUserId && userData.orgUserId!=null){
106 orgUserId = ' (' +userData.orgUserId + ')';
108 modalRef.componentInstance.userTitle = `${firstName} ${lastName} ${orgUserId}` ;
109 modalRef.componentInstance.dialogState = 2;
110 modalRef.componentInstance.userModalData = userData;
111 modalRef.componentInstance.disableBack = true;
112 modalRef.componentInstance.passBackNewUserPopup.subscribe((_result: any) => {
113 this.showSpinner = true;
114 this.updateUsersList();
115 }, (_reason: any) => {
120 openBulkUserUploadModal() {
121 const modalRef = this.ngbModal.open(BulkUserComponent);
122 modalRef.componentInstance.title = 'Bulk User Upload';
123 modalRef.componentInstance.adminsAppsData = this.adminApps;
124 modalRef.componentInstance.passBackBulkUserPopup.subscribe((_result: any) => {
125 this.showSpinner = true;
126 this.updateUsersList();
127 }, (_reason: any) => {
132 applyDropdownFilter(_appValue: any) {
133 if (_appValue !== 'select-application') {
134 this.selectedApp = _appValue;
135 this.selectApp = this.selectedApp.value;
136 this.updateUsersList();
138 this.showSpinner = false;
139 this.noAppSelected = true;
140 this.accountUsers = [];
141 this.adminsDataSource = new MatTableDataSource(this.accountUsers);
145 applyFilter(filterValue: string) {
146 this.adminsDataSource.filter = filterValue.trim().toLowerCase();
150 this.showSpinner = true;
151 this.applicationsService.getAdminApps().subscribe((apps: Array<UserAdminApps>) => {
152 this.showSpinner = false;
157 if (apps.length >= 2) {
158 this.multiAppAdmin = true;
163 let sortedApps = apps.sort(this.getSortOrder("name"));
164 let realAppIndex = 1;
165 for (let i = 1; i <= sortedApps.length; i++) {
166 this.adminApps.push({
168 id: sortedApps[i - 1].id,
169 value: sortedApps[i - 1].name,
170 title: sortedApps[i - 1].name
172 realAppIndex = realAppIndex + 1;
174 this.selectApp = this.adminApps[0];
175 this.adminAppsIsNull = false;
176 if (this.selectApp != 'select-application') {
177 this.isAppSelectDisabled = false;
178 this.noUsersInApp = false;
179 this.noAppSelected = true;
181 }, (_err: HttpErrorResponse) => {
182 this.showSpinner = false;
183 if (_err.status === 403) {
184 this.adminAppsIsNull = true;
186 const modalErrorRef = this.ngbModal.open(ConfirmationModalComponent);
187 modalErrorRef.componentInstance.title = "Error";
188 if (_err.status) { //Conflict
189 modalErrorRef.componentInstance.message = 'Error Status: ' + _err.status + ' There was a unknown problem adding the portal admin.' + 'Please try again later.';
196 this.appsIsDown = false;
197 this.noUsersInApp = false;
198 // $log.debug('UsersCtrl::updateUsersList: Starting updateUsersList');
199 //reset search string
200 this.searchString = '';
201 //should i disable this too in case of moving between tabs?
202 this.isAppSelectDisabled = true;
204 this.showSpinner = true;
205 this.accountUsers = [];
206 this.adminsDataSource = new MatTableDataSource(this.accountUsers);
207 if (this.selectApp != 'select-application' && this.selectedApp) { // 'Select Application'
208 this.noAppSelected = false;
209 this.usersService.getAccountUsers(this.selectedApp.id)
210 .subscribe((accountUsers: []) => {
211 this.isAppSelectDisabled = false;
212 this.accountUsers = accountUsers;
213 if (!accountUsers || accountUsers.length === 0) {
214 this.noUsersInApp = true;
215 this.showSpinner = false;
218 this.showSpinner = false;
219 this.adminsDataSource = new MatTableDataSource(this.accountUsers);
220 this.adminsDataSource.paginator = this.paginator;
221 this.adminsDataSource.sort = this.sort;
222 }, (_err: HttpErrorResponse) => {
223 this.isAppSelectDisabled = false;
224 const modalErrorRef = this.ngbModal.open(ConfirmationModalComponent);
225 modalErrorRef.componentInstance.title = "Error";
226 modalErrorRef.componentInstance.message = 'Error Status: ' + _err.status + ' There was a problem updating the users List.' + 'Please try again later.';
227 this.appsIsDown = true;
228 this.showSpinner = false;
231 this.isAppSelectDisabled = false;
232 this.showSpinner = false;
233 this.noUsersInApp = false;
234 this.noAppSelected = true;
238 getSortOrder = (prop) => {
239 return function (a, b) {
240 if (a[prop] > b[prop]) {
242 } else if (a[prop] < b[prop]) {