Merge "InvalidRoleException-junits"
[portal.git] / portal-FE-common / src / app / pages / account-onboarding / account-onboarding.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
39 import { Component, OnInit, ViewChild, Input} from '@angular/core';
40 import { MatTableDataSource } from '@angular/material';
41 import { MatSort, MatPaginator } from '@angular/material';
42 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
43 import { BasicAuthAccountService } from '../../shared/services/index';
44 import { IAccountOnboarding } from 'src/app/shared/model/account-onboarding/accountOnboarding';
45 import { AccountAddDetailsComponent } from './account-add-details/account-add-details.component';
46 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
47 import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';
48
49 @Component({
50   selector: 'app-account-onboarding',
51   templateUrl: './account-onboarding.component.html',
52   styleUrls: ['./account-onboarding.component.scss']
53 })
54 export class AccountOnboardingComponent implements OnInit {
55
56   accountList: Array<IAccountOnboarding> = [];
57   result: any;
58   isEditMode: boolean = false;
59   displayedColumns: string[] = ['accountName', 'userName','delete'];
60   dataSource = new MatTableDataSource(this.accountList);
61   @ViewChild(MatSort) sort: MatSort;
62   @ViewChild(MatPaginator) paginator: MatPaginator;
63
64   constructor(public basicAuthAccountService: BasicAuthAccountService, public ngbModal: NgbModal) { }
65
66   ngOnInit() {
67     this.getOnboardingAccounts();
68   }
69
70   populateTableData(wigetList: Array<IAccountOnboarding>){
71     this.dataSource = new MatTableDataSource(wigetList);
72     this.dataSource.sort = this.sort;
73     this.dataSource.paginator = this.paginator;
74   };
75
76   getOnboardingAccounts(){
77     //console.log("getOnboardingAccounts called");
78     this.basicAuthAccountService.getAccountList()
79       .subscribe(_data => {
80           this.result = _data;
81           //console.log("getOnboardingAccounts Data :: ", _data);
82           if (this.result == null || this.result == 'undefined') {
83               //console.log('BasicAuthAccountService::getOnboardingAccounts Failed: Result or result.data is null');
84           }else {
85             this.accountList = this.result.response;
86             this.populateTableData(this.accountList);
87           }
88       }, error =>{
89         console.log(error);
90       });
91
92   };
93
94   openAddNewAccountModal(rowData: any){
95     //console.log("openAddNewAccountModal getting called...");
96     const modalRef = this.ngbModal.open(AccountAddDetailsComponent, { size: 'lg' });
97     modalRef.componentInstance.title = 'Account Details';
98     if(rowData != 'undefined' && rowData){
99       rowData.repassword = rowData.password;
100       modalRef.componentInstance.accountOnboarding = rowData;
101       this.isEditMode = true;
102     }else{
103       modalRef.componentInstance.accountOnboarding  = {};
104       this.isEditMode = false;
105     }
106     modalRef.componentInstance.passEntry.subscribe((receivedEntry: any) => {
107       //console.log("receivedEntry >>> ",receivedEntry);
108       if(receivedEntry){
109         this.accountList = [];
110         this.getOnboardingAccounts();
111       }
112     });
113   }
114
115   deleteAccount(selectedAccount : any){
116     let confirmationMsg = 'You are about to delete this account : ' + selectedAccount.applicationName + '. Click OK to continue.';
117     this.openInformationModal("Confirmation",confirmationMsg).result.then((result) => {
118       if (result === 'Ok') {
119         //console.log("deleteAccount called Account Onboarding");
120         if(!selectedAccount || selectedAccount == null || selectedAccount =='undefined'){
121           console.log('AccountOnboardingCtrl::deleteAccount: No Account or ID... cannot delete');
122           return;
123         }
124         //console.log("deleteAccount>>id",selectedAccount.id)
125         this.basicAuthAccountService.deleteAccount(selectedAccount.id)
126           .subscribe( _data => {
127             this.result = _data;
128             //console.log("deleteAccount response :: ",this.result);
129             this.accountList.splice(this.accountList.indexOf(selectedAccount), 1);
130             this.getOnboardingAccounts();
131           }, error => {
132             console.log(error);
133         });
134       }
135     }, (resut) => {
136       return;
137     })
138   }
139
140   openConfirmationModal(_title: string, _message: string) {
141     const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent);
142     modalInfoRef.componentInstance.title = _title;
143     modalInfoRef.componentInstance.message = _message;
144   }
145
146   openInformationModal(_title: string, _message: string){
147     const modalInfoRef = this.ngbModal.open(InformationModalComponent);
148     modalInfoRef.componentInstance.title = _title;
149     modalInfoRef.componentInstance.message = _message;
150     return modalInfoRef;
151   }
152
153 }