2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
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';
50 selector: 'app-search',
51 templateUrl: './search.component.html',
52 styleUrls: ['./search.component.scss']
54 export class SearchComponent implements OnInit {
56 showSpinner:boolean =false;
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<[]>;
64 @ViewChild(MatPaginator, {}) paginator: MatPaginator;
65 @ViewChild(MatSort, {}) sort: MatSort;
72 this.showSpinner = true;
74 this.response = this.profileservice.getAllUsers();
75 this.response.subscribe(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;
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) => {
94 this.showSpinner = true;
95 this.profileservice.toggleProfileActive(user.id)
96 .subscribe( _data => {
98 this.openConfirmationModal("Success",'Record updated successfully.');
99 this.showSpinner = false;
101 this.showSpinner = false;
103 this.openConfirmationModal("Error",error);
113 applyFilter(filterValue: string) {
114 this.dataSource.filter = filterValue.trim().toLowerCase();
117 openConfirmationModal(_title: string, _message: string) {
118 const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent);
119 modalInfoRef.componentInstance.title = _title;
120 modalInfoRef.componentInstance.message = _message;
123 openInformationModal(_title: string, _message: string){
124 const modalInfoRef = this.ngbModal.open(InformationModalComponent);
125 modalInfoRef.componentInstance.title = _title;
126 modalInfoRef.componentInstance.message = _message;
132 this._router.navigate(['v2/userProfile/self_profile'], { queryParams: { profile_id: id } });