7bebd04ce7301b922daa4ca00972413e295f1343
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 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 } from '@angular/core';
40 import { ProfileService } from '../profile.service';
41 import { MatTableDataSource } from '@angular/material/table';
42 import { MatPaginator } from '@angular/material/paginator';
43 import { MatSort } from '@angular/material/sort';
44 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
45 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
46 import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';
47
48 @Component({
49   selector: 'app-search',
50   templateUrl: './search.component.html',
51   styleUrls: ['./search.component.scss']
52 })
53 export class SearchComponent implements OnInit {
54
55   showSpinner:boolean =false;
56   response: any;
57   result: any;
58   profileList:any;
59   userHeaders = ["User ID","Last Name","First Name","Email","ORG ID","Manager ORG ID","Edit","Active?"];
60   constructor(public profileservice:ProfileService, public ngbModal: NgbModal) { }
61   dataSource: MatTableDataSource<[]>;
62     
63   @ViewChild(MatPaginator, {}) paginator: MatPaginator;
64   @ViewChild(MatSort, {}) sort: MatSort;
65
66
67   ngOnInit() {
68     this.getUsers();
69   }
70
71   getUsers(){
72     this.showSpinner = true;
73     let response;
74     this.response = this.profileservice.getUserPagination();
75     this.response.subscribe(data => {
76       response = data;
77       this.result = JSON.parse(response.data);
78       this.profileList = JSON.parse(this.result.profileList);
79       this.dataSource = new MatTableDataSource(this.profileList);
80       this.dataSource.paginator = this.paginator;
81       this.dataSource.sort = this.sort; 
82       this.showSpinner = false;
83     });
84   }
85
86   toggleUserActive(user){
87     let activeOrInactive = (user.active) ? 'activate' : 'inactivate';
88     let confirmationMsg = 'You are about to ' + activeOrInactive + ' the user ' + user.firstName +" "+user.lastName+ '. Do you want to continue?';
89     const modalInfoRef = this.ngbModal.open(InformationModalComponent);
90     modalInfoRef.componentInstance.title = 'Confirmation';
91     modalInfoRef.componentInstance.message = confirmationMsg;
92     modalInfoRef.result.then((_res) => {
93       if (_res === 'Ok') {
94         this.showSpinner = true;
95         this.profileservice.toggleProfileActive(user.id)
96             .subscribe( _data => {
97               this.result = _data;
98               this.openConfirmationModal("Success",'Record updated successfully.');
99               this.showSpinner = false;
100             }, error => {
101               this.showSpinner = false;
102               console.log(error);
103               this.openConfirmationModal("Error",error);
104             });
105       } else {
106         user.active = !user.active;
107       }
108     }, (result) => {
109
110     })
111   }
112
113   applyFilter(filterValue: string) {
114     this.dataSource.filter = filterValue.trim().toLowerCase();
115   }
116
117   openConfirmationModal(_title: string, _message: string) {
118     const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent);
119     modalInfoRef.componentInstance.title = _title;
120     modalInfoRef.componentInstance.message = _message;
121   }
122
123   openInformationModal(_title: string, _message: string){
124     const modalInfoRef = this.ngbModal.open(InformationModalComponent);
125     modalInfoRef.componentInstance.title = _title;
126     modalInfoRef.componentInstance.message = _message;
127     return modalInfoRef;
128   }
129 }