import { Component, OnInit, AfterViewInit, Input, Output, EventEmitter, Pipe, PipeTransform, TemplateRef } 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 } 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'; declare var $:any; @Component({ templateUrl: './sitelicenseaccount.component.html' }) export class SiteLicenseAccount implements OnInit { lstCountry: any; lstState: any; lstAccountNumbers: any; lstLicenseSites: any; licenseSite: any; mode: string = 'Search'; license: License; insertUpdateSiteLicenseFrm: FormGroup; error: any; alerts: string; modalAlerts: string; divClass: string = ''; topPos: string = '2000px'; selectedRow: number = 0; selectedId: number = 0; modalRef: BsModalRef; lstEdition: any; lstEditionLogins: any; lstSiteAccountEditions: any; lstClientAdmin: any; constructor(private licenseService: LicenseService, private router: Router, private activeRoute: ActivatedRoute, private fb: FormBuilder, private modalService: BsModalService) { } ngOnInit(): void { this.divClass = 'col-sm-12'; this.license = new License(); this.alerts = ''; this.insertUpdateSiteLicenseFrm = this.fb.group({ licenseId: [0], accountNumber: [{value: '', disabled: true}], siteId: [0], siteUrl: ['', Validators.required], siteUrlTo: [''], siteMasterUrlTo: [''], buildAccName: [''], institutionName: ['', Validators.required], departmentName: [''], address1: ['', Validators.required], address2: [''], city: ['', Validators.required], countryId: [0, Validators.min(1)], stateId: [0, Validators.min(1)], zip: ['', Validators.required], phone: ['', Validators.required], clientAdminId: [0, Validators.min(1)], clientAdminEmail: [{value: '', disabled: true}, Validators.email], isActive: [0], isMaster: [0], creationDate: [''], modifiedDate: [''], editionLoginArr: this.fb.array([]), }); this.GetCountry(); this.GetState(); this.GetEditions(); this.GetLicenseAccounts(); $('#fixed_hdr2').fxdHdrCol({ fixedCols: 0, width: "100%", height: 330, colModal: [ { width: 200, align: 'center' }, { width: 200, align: 'center' }, { width: 200, align: 'Center' }, { width: 200, align: 'Center' }, { width: 250, align: 'Center' }, { width: 200, align: 'Center' }, { width: 200, align: 'Center' }, { width: 200, align: 'Center' }, { width: 200, align: 'Center' }, ], sort: true }); document.getElementById("fixed_table_rc").remove(); var testScript = document.createElement("script"); testScript.setAttribute("id", "fixed_table_rc"); testScript.setAttribute("src", "../assets/scripts/fixed_table_rc.js"); testScript.setAttribute("type", "text/javascript"); document.body.appendChild(testScript); } openModal(template: TemplateRef) { this.modalRef = this.modalService.show(template); } public SetClickedRow(i: number, item: any) { this.selectedRow = i; this.selectedId = item['Id']; this.licenseSite = item; } BindFormFields(data){ this.selectedRow = 0; this.lstLicenseSites = data; this.selectedId = this.lstLicenseSites[this.selectedRow].siteId; } GetLicenseAccounts() { this.licenseService.GetLicenseAccounts(3) .subscribe(st => { this.lstAccountNumbers = st; }, error => this.error = error); } AccountNumberChanged(LicenseId: number){ this.license.LicenseId = LicenseId; this.lstLicenseSites = null; this.GetLicenseById(); } 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); } GetSiteById(){ this.licenseService.GetSiteById(this.selectedId) .subscribe(st => { this.licenseSite = st; this.insertUpdateSiteLicenseFrm.controls['siteId'].setValue(this.licenseSite.Id); this.insertUpdateSiteLicenseFrm.controls['buildAccName'].setValue(this.licenseSite.Title); this.insertUpdateSiteLicenseFrm.controls['siteUrl'].setValue(this.licenseSite.Ip); this.insertUpdateSiteLicenseFrm.controls['siteUrlTo'].setValue(this.licenseSite.SiteIpTo); this.insertUpdateSiteLicenseFrm.controls['siteMasterUrlTo'].setValue(this.licenseSite.MasterIpTo); this.insertUpdateSiteLicenseFrm.controls['institutionName'].setValue(this.licenseSite.InstituteName); this.insertUpdateSiteLicenseFrm.controls['departmentName'].setValue(this.licenseSite.Department); this.insertUpdateSiteLicenseFrm.controls['address1'].setValue(this.licenseSite.Address1); this.insertUpdateSiteLicenseFrm.controls['address2'].setValue(this.licenseSite.Address2); this.insertUpdateSiteLicenseFrm.controls['city'].setValue(this.licenseSite.City); this.insertUpdateSiteLicenseFrm.controls['phone'].setValue(this.licenseSite.Phone); this.insertUpdateSiteLicenseFrm.controls['zip'].setValue(this.licenseSite.Zip); this.insertUpdateSiteLicenseFrm.controls['countryId'].setValue(this.licenseSite.CountryId); this.insertUpdateSiteLicenseFrm.controls['stateId'].setValue(this.licenseSite.StateId); this.insertUpdateSiteLicenseFrm.controls['isActive'].setValue(this.licenseSite.IsActive); this.insertUpdateSiteLicenseFrm.controls['isMaster'].setValue(this.licenseSite.IsMaster); this.insertUpdateSiteLicenseFrm.controls['creationDate'].setValue(this.licenseSite.CreationDate); this.insertUpdateSiteLicenseFrm.controls['modifiedDate'].setValue(this.licenseSite.ModifiedDate); this.insertUpdateSiteLicenseFrm.controls['clientAdminId'].setValue(this.lstLicenseSites[0].SiteUserId); this.GetSiteAccountEditions(); }, error => this.error = error); } GetSiteAccountEditions(){ this.licenseService.GetSiteAccountEditions(this.licenseSite.Id, this.license.LicenseId) .subscribe(st => { this.lstSiteAccountEditions = st; this.lstEditionLogins.forEach(element => { this.lstSiteAccountEditions.forEach(elm => { if(elm.m_Item2 == element.Id){ element.Login = 1; } }); }); this.insertUpdateSiteLicenseFrm.setControl('editionLoginArr', this.fb.array(this.lstEditionLogins)); }, error => this.error = error); } GetLicenseSites(){ this.licenseService.GetLicenseSites(this.license.AccountNumber) .subscribe(st => { this.lstLicenseSites = st; this.insertUpdateSiteLicenseFrm.controls['clientAdminId'].setValue(this.lstLicenseSites[0].SiteUserId); this.insertUpdateSiteLicenseFrm.controls['clientAdminEmail'].setValue(this.lstLicenseSites[0].SiteUserEmailId); var tempArr = []; tempArr.push( { "Id": this.lstLicenseSites[0].SiteUserId, "Name": this.lstLicenseSites[0].SiteUserFirstName }); this.lstClientAdmin = tempArr; }, error => this.error = error); } GetEditions() { this.licenseService.GetEditions() .subscribe(x => { this.lstEdition = x; }, error => this.error = error); } onChange(item: any, isChecked: boolean){ if(this.license.LicenseTypeId == 3){ if(isChecked){ item.Login = 1; } else{ item.Login = 0; } } } GetLicenseById() { if(this.license.LicenseId != 0) { this.licenseService.GetLicenseById(this.license.LicenseId) .subscribe(st => { this.license = st; this.insertUpdateSiteLicenseFrm.controls['licenseId'].setValue(this.license.LicenseId); this.insertUpdateSiteLicenseFrm.controls['accountNumber'].setValue(this.license.AccountNumber); if(this.license.EditionLogins == null) return; var TempArr = this.license.EditionLogins.split('|'); this.lstEditionLogins = new Array(); this.lstEdition.forEach(element => { TempArr.forEach(elm => { var TempInnerArr = elm.split('-'); if(TempInnerArr[0] == element.Id){ this.lstEditionLogins.push({Id: element.Id, Title: element.Title, Login: 0}); } }); }); this.insertUpdateSiteLicenseFrm.setControl('editionLoginArr', this.fb.array(this.lstEditionLogins)); }, error => this.error = error); } } AfterDeleteData(data, template) { if (data.Status == "false") { this.alerts = "Site account delete unsuccessfull"; } else { this.modalAlerts = "

Site account deleted successfully

"; this.modalRef = this.modalService.show(template); this.GetLicenseSites(); } } AfterInsertData(data, template) { if (data.Status == "false") { this.alerts = "License site save unsuccessfull"; } else { this.modalAlerts = "

License site saved successfully

"; this.modalRef = this.modalService.show(template); } } AfterUpdateData(data, template) { if (data.Status == "false") { this.alerts = "License site update unsuccessfull"; } else { this.modalAlerts = "

License site updated successfully

"; this.modalRef = this.modalService.show(template); } } InsertUpdateSiteAccount(template: TemplateRef) { this.alerts = ''; var obj = this.insertUpdateSiteLicenseFrm.value; var temptext = ''; obj.editionLoginArr.forEach(element => { if(element.Login == 1){ temptext += element.Id + ','; } }); if(temptext == ''){ this.alerts = "Please select a product edition"; } if(this.alerts == ''){ return this.licenseService.InsertUpdateSiteAccount(obj) .subscribe( n => (this.AfterInsertData(n, template)), error => this.error = error); } } DeleteSiteAccount(template: TemplateRef){ this.modalRef.hide(); this.alerts = ''; if(this.alerts == ''){ var obj = this.licenseSite; obj.LicenseId = this.license.LicenseId; return this.licenseService.DeleteSiteAccount(obj) .subscribe( data => (this.AfterDeleteData(data, template)), error => { this.error = error; this.alerts = "" + this.error + ""; }); } } AddLicenseSite(template: TemplateRef){ this.mode = 'Add'; this.topPos = '100px'; this.alerts = ''; this.insertUpdateSiteLicenseFrm.controls['siteId'].setValue(0); this.insertUpdateSiteLicenseFrm.controls['buildAccName'].setValue(''); this.insertUpdateSiteLicenseFrm.controls['siteUrl'].setValue(''); this.insertUpdateSiteLicenseFrm.controls['siteUrlTo'].setValue(''); this.insertUpdateSiteLicenseFrm.controls['institutionName'].setValue(''); this.insertUpdateSiteLicenseFrm.controls['departmentName'].setValue(''); this.insertUpdateSiteLicenseFrm.controls['address1'].setValue(''); this.insertUpdateSiteLicenseFrm.controls['address2'].setValue(''); this.insertUpdateSiteLicenseFrm.controls['city'].setValue(''); this.insertUpdateSiteLicenseFrm.controls['phone'].setValue(''); this.insertUpdateSiteLicenseFrm.controls['zip'].setValue(''); this.insertUpdateSiteLicenseFrm.controls['countryId'].setValue(0); this.insertUpdateSiteLicenseFrm.controls['stateId'].setValue(0); this.insertUpdateSiteLicenseFrm.controls['isActive'].setValue(1); this.insertUpdateSiteLicenseFrm.controls['isMaster'].setValue(0); this.insertUpdateSiteLicenseFrm.controls['creationDate'].setValue(''); this.insertUpdateSiteLicenseFrm.controls['modifiedDate'].setValue(''); this.insertUpdateSiteLicenseFrm.controls['clientAdminId'].setValue(0); } EditLicenseSite(template: TemplateRef){ this.mode = 'Edit'; this.topPos = '100px'; this.alerts = ''; this.GetSiteById(); } CancelAddEdit(){ this.mode = 'Search'; this.topPos = '2000px'; this.GetLicenseSites(); this.selectedRow = this.lstLicenseSites.findIndex(C => C.Id == this.selectedId); this.SetClickedRow(this.selectedRow, this.lstLicenseSites[this.selectedRow]); } }