import { Component, NgZone, OnInit, ViewChild } from '@angular/core'; import { Router } from '@angular/router'; import { DataTableDirective } from 'angular-datatables'; import { Subject } from 'rxjs'; import { PricingSegment } from '../../../../../models/admin/company/pricing-segments-manager/pricing-segment'; import { PricingSegmentValue } from '../../../../../models/admin/company/pricing-segments-manager/pricing-segment-value'; import { CommonListResponse } from '../../../../../models/shared/commonlist'; import { PricingSegmentValueService } from '../../../../../services/admin/company/pricing-segments-manager/pricing-segment-value.service'; import { PricingSegmentService } from '../../../../../services/admin/company/pricing-segments-manager/pricing-segment.service'; import { CommonService } from '../../../../../services/common.service'; @Component({ selector: 'app-pricing-segments-list', templateUrl: './pricing-segments-list.component.html', styleUrls: ['./pricing-segments-list.component.css'] }) export class PricingSegmentsListComponent implements OnInit { lstPricingSegment: PricingSegment[]; lstPricingSegmentValue: PricingSegmentValue[]; pricingSegmentId: number=0; dtOptions: any = {} dtOptionsSegmentValue: any = {} dtTrigger: Subject = new Subject(); dtTriggerSegmentValue: Subject = new Subject(); @ViewChild(DataTableDirective) dtElement: DataTableDirective; @ViewChild(DataTableDirective) dtElementSegmentValue: DataTableDirective; selectedRow: number; lstPricingBasedOn: CommonListResponse[]; dataPricingSegment: any; dataPricingSegmentValue: any; PricingSegmentId: number; companyid: number = 1; showModal: boolean = false; historyModal; constructor( private router: Router, private servicePricingSegment: PricingSegmentService, private servicePricingSegmentValue: PricingSegmentValueService, private common: CommonService, ) { } ngOnInit(): void { this.dtOptions = this.common.dataTableOptionsForDA(true, false, false, true, false, false, 5, 'asc'); this.dtOptionsSegmentValue = this.common.dataTableOptionsForDA(true, false, false, false, false, false, 3, 'asc'); this.GetPricingSegmentsList(); } GetPricingSegmentsList() { this.servicePricingSegment.getPricingSegmentByCompanyId(this.companyid, data => { let ApiResponce = data; this.lstPricingSegment = data.objResponse.responseContent this.dataPricingSegment = ApiResponce.objResponse.responseContent; this.dtTrigger.next(); if (this.lstPricingSegment != null || this.lstPricingSegment != undefined) { this.pricingSegmentId = this.lstPricingSegment[0].PricingSegmentId; this.selectedRow = this.lstPricingSegment[0].PricingSegmentId; //highligh table row this.GetPricingSegmentsListById(this.pricingSegmentId); } }, (error) => { console.error('Error: ' + error); return error(error); }); } GetPricingSegmentsListById(pricingSegmentId: number) { this.servicePricingSegmentValue.getPricingSegmentValueListbySegmentId(pricingSegmentId, data => { let ApiResponce = data; this.lstPricingSegmentValue = data.objResponse.responseContent this.dataPricingSegmentValue = ApiResponce.objResponse.responseContent; this.dtElementSegmentValue.dtInstance.then((dtInstance: DataTables.Api) => { this.dtTriggerSegmentValue.unsubscribe(); }); this.dtTriggerSegmentValue.next(); }, (error) => { console.error('Error: ' + error); return error(error); }); } bindPricingSegmentValueList(pricingSegmentId: number) { this.selectedRow = pricingSegmentId; this.pricingSegmentId = pricingSegmentId; this.GetPricingSegmentsListById(pricingSegmentId) } EditPricingSegmentValue(PricingSegmentId, PricingSegmentValueId) { this.router.navigate(['/admin/admin-company/pricing-segments-value-add-component', Number(PricingSegmentId), Number(PricingSegmentValueId) ]); } navigateTo(url) { this.router.navigate([url]); } showHistoryModal(historyFor) { this.showModal = true; this.historyModal = { historyFor: historyFor } } getModalToggleValue(data) { this.showModal = data.toggle; } }