9ae59ca82dfe8f4c99591867300aed6b8fc8e847
[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","orgUserId","orgManagerUserId","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
68   ngOnInit() {
69     this.getUsers();
70   }
71
72   getUsers(){
73     this.showSpinner = true;
74     let response;
75     this.response = this.profileservice.getUserPagination();
76     this.response.subscribe(data => {
77       response = data;
78       this.result = JSON.parse(response.data);
79       this.profileList = JSON.parse(this.result.profileList);
80       this.dataSource = new MatTableDataSource(this.profileList);
81       this.dataSource.paginator = this.paginator;
82       this.dataSource.sort = this.sort; 
83       this.showSpinner = false;
84     });
85   }
86
87   toggleUserActive(user){
88     let activeOrInactive = (user.active) ? 'activate' : 'inactivate';
89     let confirmationMsg = 'You are about to ' + activeOrInactive + ' the user ' + user.firstName +" "+user.lastName+ '. Do you want to continue?';
90     const modalInfoRef = this.ngbModal.open(InformationModalComponent);
91     modalInfoRef.componentInstance.title = 'Confirmation';
92     modalInfoRef.componentInstance.message = confirmationMsg;
93     modalInfoRef.result.then((_res) => {
94       if (_res === 'Ok') {
95         this.showSpinner = true;
96         this.profileservice.toggleProfileActive(user.id)
97             .subscribe( _data => {
98               this.result = _data;
99               this.openConfirmationModal("Success",'Record updated successfully.');
100               this.showSpinner = false;
101             }, error => {
102               this.showSpinner = false;
103               console.log(error);
104               this.openConfirmationModal("Error",error);
105             });
106       } else {
107         user.active = !user.active;
108       }
109     }, (result) => {
110
111     })
112   }
113
114   applyFilter(filterValue: string) {
115     this.dataSource.filter = filterValue.trim().toLowerCase();
116   }
117
118   openConfirmationModal(_title: string, _message: string) {
119     const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent);
120     modalInfoRef.componentInstance.title = _title;
121     modalInfoRef.componentInstance.message = _message;
122   }
123
124   openInformationModal(_title: string, _message: string){
125     const modalInfoRef = this.ngbModal.open(InformationModalComponent);
126     modalInfoRef.componentInstance.title = _title;
127     modalInfoRef.componentInstance.message = _message;
128     return modalInfoRef;
129   }
130
131
132   getUser(id: any) {
133     this._router.navigate(['v2/userProfile/self_profile'], { queryParams: { profile_id: id } });
134 }
135 }