Adding new components with portal-FE-common
[portal.git] / portal-FE-common / src / app / pages / admins / admins.component.ts
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
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';
44
45 @Component({
46   selector: 'app-admins',
47   templateUrl: './admins.component.html',
48   styleUrls: ['./admins.component.scss']
49 })
50 export class AdminsComponent implements OnInit {
51   availableApps: Array<{ index: number, title: string, value: string }> = [];
52
53   constructor(private adminsService: AdminsService, private applicationService: ApplicationsService,
54     public ngModal: NgbModal) { }
55
56   showSpinner = true;
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;
62   ngOnInit() {
63     this.adminsData = [];
64     this.getAccoutAdminsData();
65     this.getAllApps();
66   }
67
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) => {
74       modalRef.close();
75       this.showSpinner = true;
76       this.getAccoutAdminsData();
77     }, (_reason: any) => {
78       return;
79     });
80   }
81
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) => {
89       modalRef.close();
90       this.showSpinner = true;
91       this.getAccoutAdminsData();
92     }, (_reason: any) => {
93       return;
94     });
95   }
96
97   applyFilterByAppName(filterValue: string) {
98
99   }
100
101   applyFilter(filterValue: string) {
102     this.adminsDataSource.filter = filterValue.trim().toLowerCase();
103   }
104
105
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;
113     });
114   }
115
116   getAllApps() {
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({
122             index: realAppIndex,
123             title: _res[i - 1].title,
124             value: _res[i - 1].value
125           });
126           realAppIndex = realAppIndex + 1;
127         } else {
128         }
129       }
130     });
131   }
132
133 }