734aaf0966b72e46b668047c6a259f20c7461c28
[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 import { Router } from '@angular/router';
48
49 @Component({
50   selector: 'app-search',
51   templateUrl: './search.component.html',
52   styleUrls: ['./search.component.scss']
53 })
54 export class SearchComponent implements OnInit {
55
56   showSpinner:boolean =false;
57   response: any;
58   result: any;
59   profileList:any;
60   userHeaders = ["User ID","Last Name","First Name","Email","Org User ID","Org Manager User ID","Edit","Active?"];
61   constructor(public profileservice:ProfileService, public ngbModal: NgbModal,private _router: Router) { }
62   dataSource: MatTableDataSource<[]>;
63     
64   @ViewChild(MatPaginator, {}) paginator: MatPaginator;
65   @ViewChild(MatSort, {}) sort: MatSort;
66
67   ngOnInit() {
68     this.getUsers();
69   }
70
71   getUsers(){
72     this.showSpinner = true;
73     let response;
74     this.response = this.profileservice.getAllUsers();
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, e){
87     let activeOrInactive = (e.checked) ? 'activate' : 'inactivate';
88     let confirmationMsg = 'You are about to ' + activeOrInactive + ' the user ' + user.first_name +" "+user.last_name+ '. 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         this.ngOnInit();
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
130
131   getUser(id: any) {
132     this._router.navigate(['v2/userProfile/self_profile'], { queryParams: { profile_id: id } });
133 }
134 }