unblockuser.component.ts 7.54 KB
import { Component, OnInit, AfterViewInit, ViewChild, TemplateRef,HostListener } from '@angular/core';
import { UserService } from './user.service';
import { Router } from '@angular/router';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { User } from '../userentity/datamodel';
import { Http, Response } from '@angular/http';
import { GlobalService } from '../../shared/global';
//import { DBOperation } from 'S';
import { Observable } from 'rxjs/Observable';
import { ConfirmService } from '../../shared/confirm/confirm.service';
import 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/filter';
import { LoadingService } from '../../shared/loading.service';
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
declare var $: any;

@Component({
  templateUrl:'./unblockuser.component.html' // '../../../../../wwwroot/html/UpdateProfile/updateuserprofile.component.html'
})

export class UnblockUser implements OnInit {
  
  modalTitle: string;
  UnBlockedUserFrm: FormGroup;
  alerts: string;
  public UserTypeList: any;
  public AccountTypeList: any;
  public UserList: any;
  error;
  modalRef: BsModalRef;
  checkedRecords: Array<number>;
  display = 'none';
  modalAlerts: string;
  buttonStatus: boolean;
  selectedRow: number = -1;
  licId:number;
  scrHeight:any;
  scrWidth:any;
  SearchField:any={
	  sortColumn:"Id",
	  sortOrder:"asc" 
    }
@HostListener('window:resize', ['$event'])
  getScreenSize(event?) {

    var $ua = navigator.userAgent;
    if (($ua.match(/(iPod|iPhone|iPad|android)/i))) {
      this.scrHeight = window.innerHeight-415;
    }
    else
    {
      this.scrHeight = window.innerHeight-350;
    }
     if(this.scrHeight<=360) this.scrHeight=360;
     
      $(".ft_container").css("height",this.scrHeight);
   }
  //@ViewChild("profileModal")
  //profileModal: ModalComponent;
  //errorMessage: any;
  constructor(private _loadingService: LoadingService,private userservice: UserService, private router: Router, private fb: FormBuilder, private http: Http,
    private _confirmService: ConfirmService, private modalService: BsModalService, public commonService: GlobalService
  ) { this.getScreenSize();}
 
  ngOnInit(): void {    
    this.alerts = '';
      //this.userservice.GetUserById(this.UserId);
    this.UnBlockedUserFrm = this.fb.group({
      //FirstName:[''],
      //LastName: [''],
      //EmailId:  [''],
      //AccountNumber: [''],
      //UserTypeId: [''],
      //AccountTypeId:['']
     // Gender: ['', Validators.required],
   //   Email: ['']
          
    }); this._loadingService.ShowLoading("global-loading");
    this.GetBlockUserList();
    //this.GetAccountType();
    this._loadingService.HideLoading("global-loading");
    
    //this.GetUserList();

    $('#fixed_hdr2').fxdHdrCol({
			fixedCols: 0,
			width: "100%",
			height: this.scrHeight,
			colModal: [
			{ width: 90, align: 'center' },
			{ width: 162, align: 'center' },
			{ width: 158, align: 'Center' },
			{ width: 110, align: 'Center' },
			{ width: 142, align: 'Center' },
      { width: 264, align: 'Center' },
      { width: 120, align: 'Center' },
      { width: 150, align: 'Center' },
			],
			sort: true
		});
    this.selectedRow = -1;

    var thisObject=this;//class object
		$(".ft_rwrapper table thead tr th").on("click",function(event){  
				
		  if(event.currentTarget.id!=undefined && event.currentTarget.id!="" && event.currentTarget.id!=null  && event.currentTarget.id!="unknown")
		  {
			var fieldName=event.currentTarget.id;
			var sortType=''
			var isAscSort = $(".ft_rwrapper table thead tr #"+fieldName).hasClass('fx_sort_asc'); 
			$(".ft_rwrapper table thead tr th").removeClass('fx_sort_asc fx_sort_desc'); 
		  $(".ft_rwrapper table thead tr #unknown").removeClass('fx_sort_bg');

			if (isAscSort) { 
			  $(".ft_rwrapper table thead tr #"+fieldName).addClass('fx_sort_desc').removeClass('fx_sort_asc'); 
			  sortType="desc";
			} else { 
			  $(".ft_rwrapper table thead tr #"+fieldName).addClass('fx_sort_asc').removeClass('fx_sort_desc'); 
			  sortType="asc";
			}
	  
			thisObject.SortTableRecords(fieldName,sortType);  

		  }
		 
		});




  }
  redirect() {
    this.router.navigate(['/']);
  }
  onChange(Idx: number, Id: number, isChecked: boolean) {
    if (isChecked) {
      this.checkedRecords[Idx] = Id;
      this.buttonStatus = true;
    }
    else {
      this.checkedRecords[Idx] = 0;
      this.buttonStatus = false;
    }
  }
  openModal(template: TemplateRef<any>) {
    this.display = 'block';
    if (this.checkedRecords.filter(C => C > 0).length == 0) return;
    this.modalRef = this.modalService.show(template);
  }
  UpdateUnBlockedUsers(template: TemplateRef<any>) {
    this.modalRef.hide();
    console.log(this.checkedRecords);
    this.alerts = '';
    if (this.alerts == '') {
      var obj = this.checkedRecords.filter(C => C > 0);
      return this.userservice.UpdateUnBlockedUser(obj)
        .subscribe(
        data => (this.AfterDeleteData(data, template)),
        error => {
          this.error = <any>error;
          this.alerts = "<span>" + this.error + "</span>";
        });
    }
  }
  AfterDeleteData(data, template) {  
    if (data.Status == "false") {
      this._confirmService.activate("We have encountered a technical error and same has been notified to our technical team.", "alertMsg");
    } else {
      //this.modalAlerts = "<p>Selected users has been unblocked now</p>";
      //this.modalRef = this.modalService.show(template);
      this.GetBlockUserList();
    }
  }
  
  GetBlockUserList(this)
  {
    if (this.commonService.UserTypeName == "Client Admin" || this.commonService.UserTypeName == "District Admin") 
    {
        if(this.commonService.AccountNumber !=undefined && this.commonService.AccountNumber !="")
        {
            this.licId = this.commonService.AccLicId;
        }
        else
        {
          this.licId =0
        }
      
    }
    else
    {
      this.licId =0
    }
   
    var UserFilterControl = this.UnBlockedUserFrm.value;    
    $(".ft_rwrapper table thead tr #unknown").removeClass('fx_sort_bg');
    this.userservice.GetBlockUserList(
      {        
        UserTypeId: this.commonService.UserType,
        LicenseId: this.licId,
        sortColumn: this.SearchField.sortColumn,
	      sortOrder: this.SearchField.sortOrder,
      })

      .subscribe(x => {
      this.UserList = x; this.checkedRecords = new Array<number>(this.UserList.length);
      if (this.UserList.length>0) {
        this.buttonStatus = false;
      }
      else {
        this.buttonStatus = false;
      }
      }, error => this.error = <any>error);
    
  }
  AfterInsertData(data) {
  
    if (data == "success") {
      this._confirmService.activate("Userid Updated Successfully.", "alertMsg");
      
    } else  {
      this.alerts += '<span>' + data+'</span>';
      return false;
      
      
    }
    //if (this.closeflag) {
    //  this.close.emit(null);
    //}
    //else {
    //}
  }
  
  ResetFormFields() {
    //this.ChangeUserIdFrm.reset()
    //this.ChangeUserIdFrm.controls['id'].setValue(this.user.Id)
    //this.ChangeUserIdFrm.controls['loginid'].setValue(this.user.LoginId)
    //this.ChangeUserIdFrm.controls['newloginid'].setValue('')
    //this.ChangeUserIdFrm.controls['confirmloginid'].setValue('')
    this.alerts = '';
  }

  SortTableRecords(fieldName:string,sortType:string) {  
    this.selectedRow = -1;
	  this.SearchField.sortColumn=fieldName;
	  this.SearchField.sortOrder=sortType;	

	  this.GetBlockUserList();
   }

  
  
}