import { Component, OnInit, AfterViewInit, Input, Output, EventEmitter, Pipe, PipeTransform, TemplateRef } from '@angular/core'; import { LicenseService } from './license.service'; import { GlobalService } from '../../Shared/global'; 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'; import { ContenteditableModelDirective } from '../../shared/contenteditabledirective' import { ConfirmService } from '../../Shared/Confirm/confirm.service'; @Component({ templateUrl: './licensemodulesettings.component.html' }) export class LicenseModuleSettings implements OnInit { lstAccountNumbers: any; tempLstAccountNumbers: any; lstModuleStatus: any; license: License; updateModuleSettingsFrm: FormGroup; error: any; alerts: string; modalAlerts: string; modalRef: BsModalRef; accountDropDownText: string; loopIdx: number; constructor(private licenseService: LicenseService, private globalService: GlobalService, private router: Router, private activeRoute: ActivatedRoute, private fb: FormBuilder, private modalService: BsModalService, private _confirmService: ConfirmService) { } ngOnInit(): void { this.license = new License(); this.license.LicenseId = 0; this.alerts = ''; this.accountDropDownText = 'Select'; this.loopIdx = 0; this.updateModuleSettingsFrm = this.fb.group({ licenseId: [0], accountNumber: [''], lstModuleStatus: [this.fb.array([])], }); this.GetLicenseAccounts(); } openModal(template: TemplateRef) { this.modalRef = this.modalService.show(template); } GetLicenseAccounts() { this.licenseService.GetLicenseAccounts(0) .subscribe(st => { this.lstAccountNumbers = st; this.tempLstAccountNumbers = []; this.loopIdx = 0; for (var i = 0; i < 1000; i++) { if(this.loopIdx < this.lstAccountNumbers.length){ this.tempLstAccountNumbers.push(this.lstAccountNumbers[this.loopIdx]); this.loopIdx++; } } }, error => this.error = error); } GetLicenseModulesStatus() { this.licenseService.GetLicenseModulesStatus(this.license.LicenseId) .subscribe(st => { this.lstModuleStatus = st; this.updateModuleSettingsFrm.setControl('lstModuleStatus', this.fb.array(this.lstModuleStatus)); }, error => this.error = error); } GetLicenseById() { if(this.license.LicenseId != 0) { this.licenseService.GetLicenseById(this.license.LicenseId) .subscribe(st => { this.license = st; this.updateModuleSettingsFrm.controls['licenseId'].setValue(this.license.LicenseId); this.updateModuleSettingsFrm.controls['accountNumber'].setValue(this.license.AccountNumber); this.GetLicenseModulesStatus(); }, error => this.error = error); } } AccountNumberChanged(LicenseId: number, SelectText: string){ this.accountDropDownText = SelectText; this.license.LicenseId = LicenseId; this.lstModuleStatus = null; this.GetLicenseById(); } onScroll($event){ if($event.target.scrollTop >= ($event.target.scrollHeight/2)){ for (var i = 0; i < 5000; i++) { if(this.loopIdx < this.lstAccountNumbers.length){ this.tempLstAccountNumbers.push(this.lstAccountNumbers[this.loopIdx]); this.loopIdx++; } } } } onOpenChange(data: boolean): void { if(!data){ this.loopIdx = 0; this.tempLstAccountNumbers = []; for (var i = 0; i < 1000; i++) { if(this.loopIdx < this.lstAccountNumbers.length){ this.tempLstAccountNumbers.push(this.lstAccountNumbers[this.loopIdx]); this.loopIdx++; } } } } AfterUpdateData(data, template) { if (data.Status == "false") { this.alerts = "License module status update unsuccessfull"; } else { // this.modalAlerts = "

License module status updated successfully

"; this._confirmService.activate("License module status updated successfully.", "alertMsg"); //this.modalRef = this.modalService.show(template); } } UpdateLicenseModulesStatus(template: TemplateRef){ this.alerts = ''; if(this.alerts == ''){ var obj = this.updateModuleSettingsFrm.value; return this.licenseService.UpdateLicenseModulesStatus(obj) .subscribe( n => (this.AfterUpdateData(n, template)), error => this.error = error); } } }