import { Component, OnInit, AfterViewChecked, Input, Output, EventEmitter, Pipe, PipeTransform, TemplateRef, ViewChild,HostListener } from '@angular/core'; import { LicenseService } from './license.service'; import { Router, ActivatedRoute } from '@angular/router'; import { FormControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { License } from '../userentity/datamodel'; import { BsDatepickerModule, BsDatepickerConfig } from 'ngx-bootstrap'; import { Http, Response } from '@angular/http'; import { DatePipe } from '@angular/common'; import { BsModalService } from 'ngx-bootstrap/modal'; import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service'; import { PagerComponent } from '../../shared/pager/pager.component'; import { LoadingService } from '../../shared/loading.service'; import { GlobalService } from '../../shared/global'; import { ConfirmService } from '../../shared/confirm/confirm.service'; declare var $: any; @Component({ templateUrl: './searchlicense.component.html' }) export class SearchLicense implements OnInit, AfterViewChecked { public lstLicenceType: any; public lstCountry: any; public lstState: any; public lstLicense: any; mode: string = 'Search'; license: License; licenses: Array; searchLicenseFrm: FormGroup; insertUpdateLicenseFrm: FormGroup; error: any; alerts: string; modalAlerts: string; divClass: string = ''; topPos: string = '2000px'; selectedRow: number = 0; datePipe: DatePipe = new DatePipe('en-US'); bsValue1: Date = null;//new Date(); bsValue2: Date = null;//new Date(); selectedId: number = 0; modalRef: BsModalRef; checkedRecords: Array; minDate = new Date(1110, 11, 1); maxDate = new Date(9999, 11, 31); bsConfig: Partial; NoRecord: string; @ViewChild(PagerComponent) pagerComponent: PagerComponent; recordCount: number; pageNo: number; pageLength: number; returnFrom: boolean; dateStartInvalid: boolean = false; dateEndInvalid: boolean = false; tempSearchParams: any = { accountNumber:'', licenseeFirstName:'', licenseeLastName:'', licenseTypeId:0, institutionName:'', stateId:0, countryId:0, subscriptionStartDate:'', subscriptionEndDate:'', isActive:true, emailId:'', sortColumn:'EntryDate', sortOrder:'asc', Id: 0, row: -1, pageNo: 1, pageLength: 10 }; // Declare height and width variables scrHeight:any; scrWidth:any; SearchField:any={ accountNumber:'', licenseeFirstName:'', licenseeLastName:'', licenseTypeId:0, institutionName:'', stateId:0, countryId:0, subscriptionStartDate:'', subscriptionEndDate:'', isActive:true, emailId:'', sortColumn:'EntryDate', sortOrder:'asc', pageNo:1, pageLength:10 } @HostListener('window:resize', ['$event']) getScreenSize(event?) { var $ua = navigator.userAgent; if (($ua.match(/(iPod|iPhone|iPad|android)/i))) { this.scrHeight = window.innerHeight-515; } else { this.scrHeight = window.innerHeight-460; } if(this.scrHeight<=300) this.scrHeight=300; $(".ft_container").css("height",this.scrHeight); } constructor(private licenseService: LicenseService, private router: Router, private activeRoute: ActivatedRoute, private fb: FormBuilder, private modalService: BsModalService, public global: GlobalService, private _loadingService: LoadingService, private _confirmService: ConfirmService) { this.getScreenSize();} ngOnInit(): void { this._loadingService.ShowLoading("global-loading"); this.bsConfig = Object.assign({}, { containerClass: 'theme-dark-blue' }); this.divClass = 'col-sm-12'; this.license = new License(); this.alerts = ''; this.NoRecord = this.global.NoRecords; this.searchLicenseFrm = this.fb.group({ accountNumber: [''], licenseeFirstName: [''], licenseeLastName: [''], licenseTypeId: [0], institutionName: [''], stateId: [0], countryId: [0], emailId: [''], subscriptionStartDate: [''], subscriptionEndDate: [''], isActive: [true], licenses: this.fb.array([]), }); this.GetLicenseType(); this.GetCountry(); this.GetState(); this.activeRoute.queryParams.subscribe(params => { if (params['Id'] != null) { this.searchLicenseFrm.controls['accountNumber'].setValue(params['accountNumber']); this.searchLicenseFrm.controls['licenseeFirstName'].setValue(params['licenseeFirstName']); this.searchLicenseFrm.controls['licenseeLastName'].setValue(params['licenseeLastName']); this.searchLicenseFrm.controls['licenseTypeId'].setValue(+params['licenseTypeId']); this.searchLicenseFrm.controls['institutionName'].setValue(params['institutionName']); this.searchLicenseFrm.controls['stateId'].setValue(+params['stateId']); this.searchLicenseFrm.controls['countryId'].setValue(+params['countryId']); this.searchLicenseFrm.controls['subscriptionStartDate'].setValue(params['subscriptionStartDate']); this.searchLicenseFrm.controls['subscriptionEndDate'].setValue(params['subscriptionEndDate']); if(params['isActive'] == 'true'){ this.searchLicenseFrm.controls['isActive'].setValue(true); } else{ this.searchLicenseFrm.controls['isActive'].setValue(false); } this.searchLicenseFrm.controls['emailId'].setValue(params['emailId']); this.selectedId = +params['Id']; this.selectedRow = +params['row']; this.pageNo = params['pageNo']; this.pageLength = params['pageLength']; var sortColumn=params['sortColumn']; var sortOrder=params['sortOrder']; this.tempSearchParams.accountNumber=params['accountNumber']; this.tempSearchParams.licenseeFirstName=params['licenseeFirstName']; this.tempSearchParams.licenseeLastName=params['licenseeLastName']; this.tempSearchParams.licenseTypeId=params['licenseTypeId']; this.tempSearchParams.institutionName=params['institutionName']; this.tempSearchParams.stateId=params['stateId']; this.tempSearchParams.countryId=params['countryId']; this.tempSearchParams.subscriptionStartDate=params['subscriptionStartDate']; this.tempSearchParams.subscriptionEndDate=params['subscriptionEndDate']; this.tempSearchParams.isActive=params['isActive']; this.tempSearchParams.emailId=params['emailId']; this.tempSearchParams.Id=this.selectedId; this.tempSearchParams.row=this.selectedId; this.tempSearchParams.sortColumn=sortColumn; this.tempSearchParams.sortOrder=sortOrder; this.tempSearchParams.pageNo=this.pageNo; this.tempSearchParams.pageLength=this.pageLength; this.SearchField.accountNumber=params['accountNumber']; this.SearchField.licenseeFirstName=params['licenseeFirstName']; this.SearchField.licenseeLastName=params['licenseeLastName']; this.SearchField.licenseTypeId=params['licenseTypeId']; this.SearchField.institutionName=params['institutionName']; this.SearchField.stateId=params['stateId']; this.SearchField.countryId=params['countryId']; this.SearchField.subscriptionStartDate=params['subscriptionStartDate']; this.SearchField.subscriptionEndDate=params['subscriptionEndDate']; this.SearchField.isActive=params['isActive']; this.SearchField.emailId=params['emailId']; this.SearchField.sortColumn=sortColumn; this.SearchField.sortOrder=sortOrder; this.SearchField.pageNo=this.pageNo; this.SearchField.pageLength=this.pageLength; this.returnFrom = true; } else { this.selectedRow = -1; this.selectedId = -1; this.pageNo = 1; this.pageLength = 10; this.returnFrom = false; } }); this.NoRecord = this.global.NoRecords; this.recordCount = 0; this.pagerComponent = new PagerComponent(); $('#fixed_hdr2').fxdHdrCol({ fixedCols: 0, width: "100%", height: this.scrHeight, colModal: [ { width: 120, align: 'center' }, { width: 130, align: 'center' }, { width: 150, align: 'Center' }, { width: 150, align: 'Center' }, { width: 150, align: 'Center' }, { width: 150, align: 'Center' }, { width: 150, align: 'Center' }, { width: 150, align: 'center' }, { width: 150, align: 'Center' }, { width: 130, align: 'center' }, { width: 150, align: 'center' }, { width: 130, align: 'center' }, { width: 90, align: 'center' }, { width: 130, align: 'center' }, { width: 120, align: 'center' }, { width: 120, align: 'Center' }, { width: 150, align: 'Center' }, { width: 100, align: 'center' }, { width: 120, align: 'center' }, ], sort: true }); 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) { 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'); 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); } }); } ngAfterViewChecked() { $('#fixed_hdr2 thead').css('width', $('#fixed_hdr2 tbody tr:eq(0)').width()); } openModal(template: TemplateRef) { this.modalRef = this.modalService.show(template); } public SetClickedRow(i: number, item: any) { this.selectedRow = i; this.selectedId = item['LicenseId']; this.license = item; this.tempSearchParams.Id = this.selectedId; this.tempSearchParams.row = this.selectedRow; this.tempSearchParams.pageNo = this.pageNo; this.tempSearchParams.pageLength = this.pageLength; this.tempSearchParams.sortColumn = this.SearchField.sortColumn; this.tempSearchParams.sortOrder = this.SearchField.sortOrder; } GetLicenseList() { $(".ft_rwrapper table thead tr th").removeClass('fx_sort_asc fx_sort_desc'); if (this.SearchField.sortOrder=='asc') { $(".ft_rwrapper table thead tr #"+this.SearchField.sortColumn).addClass('fx_sort_asc').removeClass('fx_sort_desc'); } else { $(".ft_rwrapper table thead tr #"+this.SearchField.sortColumn).addClass('fx_sort_desc').removeClass('fx_sort_asc'); } this._loadingService.ShowLoading("global-loading"); this.licenseService.GetLicenses(this.SearchField) .subscribe(x => { this.BindFormFields(x); }, error => this.error = error); } BindFormFields(data) { this.recordCount = data.RecordCount; this.licenses = data.LicenseList; this.license = this.licenses[0]; this.searchLicenseFrm.setControl('licenses', this.fb.array(this.licenses)); if(this.selectedId > -1){ this.license = this.searchLicenseFrm.controls['licenses'].value.find(C => C.LicenseId == this.selectedId); } if (this.licenses.length > 0) { this.NoRecord = ''; } if (this.licenses.length == 0) { this.NoRecord = this.global.NoRecords; } this._loadingService.HideLoading("global-loading"); } DateChange(dateValue: any) { this.alerts = ''; if (this.searchLicenseFrm.dirty) { if (dateValue._datepicker._elementRef.nativeElement.id == 'SubscriptionStartDate') { if (dateValue._bsValue == null) { if (dateValue._datepicker._elementRef.nativeElement.value != '') { this.dateStartInvalid = true; } else { this.dateStartInvalid = false; } } else { this.dateStartInvalid = false; if(dateValue._bsValue=='Invalid Date') { this.dateStartInvalid = true; } this.searchLicenseFrm.controls['subscriptionStartDate'].setValue(dateValue._bsValue); } } if (dateValue._datepicker._elementRef.nativeElement.id == 'SubscriptionEndDate') { if (dateValue._bsValue == null) { if (dateValue._datepicker._elementRef.nativeElement.value != '') { this.dateEndInvalid = true; } else { this.dateEndInvalid = false; } } else { this.dateEndInvalid = false; if(dateValue._bsValue=='Invalid Date') { this.dateEndInvalid = true; } this.searchLicenseFrm.controls['subscriptionEndDate'].setValue(dateValue._bsValue); } } if (!this.dateStartInvalid && !this.dateEndInvalid) { if (Date.parse(this.searchLicenseFrm.controls['subscriptionStartDate'].value) > Date.parse(this.searchLicenseFrm.controls['subscriptionEndDate'].value)) { this.alerts = 'Subscription start date must be less than the subscription end date
'; } } } } public SearchLicenses(evt: any) { if (!this.returnFrom) { this.selectedRow = -1; this.selectedId = -1; } if (this.returnFrom) this.returnFrom = false; var tempArr = evt.split(','); this.pageNo = parseInt(tempArr[0]); this.pageLength = parseInt(tempArr[1]); this.SearchField.pageNo=this.pageNo; this.SearchField.pageLength=this.pageLength; this.GetLicenseList(); } SortTableRecords(fieldName:string,sortType:string) { this.selectedRow = -1; this.SearchField.sortColumn=fieldName; this.SearchField.sortOrder=sortType; this.GetLicenseList(); } SearchRecords() { this.selectedRow = -1; this.pageNo=1; this.tempSearchParams = { 'accountNumber': this.searchLicenseFrm.controls['accountNumber'].value, 'licenseeFirstName': this.searchLicenseFrm.controls['licenseeFirstName'].value, 'licenseeLastName': this.searchLicenseFrm.controls['licenseeLastName'].value, 'licenseTypeId': this.searchLicenseFrm.controls['licenseTypeId'].value, 'institutionName': this.searchLicenseFrm.controls['institutionName'].value, 'stateId': this.searchLicenseFrm.controls['stateId'].value, 'countryId': this.searchLicenseFrm.controls['countryId'].value, 'subscriptionStartDate': this.searchLicenseFrm.controls['subscriptionStartDate'].value, 'subscriptionEndDate': this.searchLicenseFrm.controls['subscriptionEndDate'].value, 'isActive': this.searchLicenseFrm.controls['isActive'].value, 'emailId': this.searchLicenseFrm.controls['emailId'].value, 'Id': this.selectedId, 'row': this.selectedRow, 'pageNo': this.pageNo, 'pageLength': this.pageLength }; this.SearchField.accountNumber=this.searchLicenseFrm.controls['accountNumber'].value; this.SearchField.licenseeFirstName=this.searchLicenseFrm.controls['licenseeFirstName'].value; this.SearchField.licenseeLastName=this.searchLicenseFrm.controls['licenseeLastName'].value; this.SearchField.licenseTypeId=this.searchLicenseFrm.controls['licenseTypeId'].value; this.SearchField.institutionName=this.searchLicenseFrm.controls['institutionName'].value; this.SearchField.stateId=this.searchLicenseFrm.controls['stateId'].value; this.SearchField.countryId=this.searchLicenseFrm.controls['countryId'].value; this.SearchField.subscriptionStartDate=this.searchLicenseFrm.controls['subscriptionStartDate'].value; this.SearchField.subscriptionEndDate=this.searchLicenseFrm.controls['subscriptionEndDate'].value; this.SearchField.isActive=this.searchLicenseFrm.controls['isActive'].value; this.SearchField.emailId=this.searchLicenseFrm.controls['emailId'].value; this.SearchField.pageNo=this.pageNo; this.GetLicenseList(); } GetLicenseType() { this.licenseService.GetLicenceType() .subscribe(x => { this.lstLicenceType = x; }, error => this.error = error); } GetCountry() { this.licenseService.GetCountry() .subscribe(y => { this.lstCountry = y; }, error => this.error = error); } GetState() { this.licenseService.GetState() .subscribe(st => { this.lstState = st; }, error => this.error = error); } EditLicense() { this.router.navigate(['/editlicense'], { queryParams: this.tempSearchParams , skipLocationChange: true }); } AfterDeleteData(data, template) { if (data.Status == "false") { this.alerts = "License delete unsuccessfull"; } else { this._confirmService.activate("License deleted successfully.", "alertMsg"); // this.modalAlerts = "

License deleted successfully

"; //this.modalRef = this.modalService.show(template); this.GetLicenseList(); } } DeleteLicense(template: TemplateRef) { this.modalRef.hide(); this.alerts = ''; if (this.alerts == '') { var obj = this.license; return this.licenseService.DeleteLicense(obj) .subscribe( data => (this.AfterDeleteData(data, template)), error => { this.error = error; this.alerts = "" + this.error + ""; }); } } }