2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 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 { AdminsService, ApplicationsService } from 'src/app/shared/services';
40 import { Admins, AllApps } from 'src/app/shared/model';
41 import { MatTableDataSource, MatSort, MatPaginator } from '@angular/material';
42 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
43 import { NewAdminComponent } from './new-admin/new-admin.component';
46 selector: 'app-admins',
47 templateUrl: './admins.component.html',
48 styleUrls: ['./admins.component.scss']
50 export class AdminsComponent implements OnInit {
51 availableApps: Array<{ index: number, title: string, value: string }> = [];
53 constructor(private adminsService: AdminsService, private applicationService: ApplicationsService,
54 public ngModal: NgbModal) { }
57 displayedColumns: string[] = ['firstName', 'lastName', 'userId', 'appName'];
58 adminsData: Admins[] = [];
59 adminsDataSource = new MatTableDataSource(this.adminsData);
60 @ViewChild(MatSort) sort: MatSort;
61 @ViewChild(MatPaginator) paginator: MatPaginator;
64 this.getAccoutAdminsData();
68 openAddNewAdminModal() {
69 const modalRef = this.ngModal.open(NewAdminComponent);
70 modalRef.componentInstance.title = 'New Admin';
71 modalRef.componentInstance.dialogState = 1;
72 modalRef.componentInstance.disableBack = false;
73 modalRef.componentInstance.passBackNewAdminPopup.subscribe((_result: any) => {
75 this.showSpinner = true;
76 this.getAccoutAdminsData();
77 }, (_reason: any) => {
82 openExistingAdminModal(_adminData: Admins) {
83 const modalRef = this.ngModal.open(NewAdminComponent);
84 modalRef.componentInstance.userTitle = `${_adminData.firstName}, ${_adminData.lastName} `+'('+`${_adminData.orgUserId}`+')';
85 modalRef.componentInstance.adminModalData = _adminData;
86 modalRef.componentInstance.dialogState = 2;
87 modalRef.componentInstance.disableBack = true;
88 modalRef.componentInstance.passBackNewAdminPopup.subscribe((_result: any) => {
90 this.showSpinner = true;
91 this.getAccoutAdminsData();
92 }, (_reason: any) => {
97 applyFilterByAppName(filterValue: string) {
101 applyFilter(filterValue: string) {
102 this.adminsDataSource.filter = filterValue.trim().toLowerCase();
106 getAccoutAdminsData() {
107 this.adminsService.getAccountAdmins().subscribe((_res: Admins[]) => {
108 this.showSpinner = false;
109 this.adminsData = _res;
110 this.adminsDataSource = new MatTableDataSource(this.adminsData);
111 this.adminsDataSource.sort = this.sort;
112 this.adminsDataSource.paginator = this.paginator;
117 this.applicationService.getAvailableApps().subscribe((_res: AllApps[]) => {
118 var realAppIndex = 1;
119 for (let i = 1; i <= _res.length; i++) {
120 if (!_res[i - 1].restrictedApp) {
121 this.availableApps.push({
123 title: _res[i - 1].title,
124 value: _res[i - 1].value
126 realAppIndex = realAppIndex + 1;