import { Component, OnInit } from '@angular/core'; import { GeneralService } from '../../services/general/general.service'; import { IShippingProfileInfo } from '../../core/shipping/IShippingProfileInfo'; import { CookieService } from 'ngx-cookie-service'; import { SelectItem } from 'primeng/api'; @Component({ selector: 'app-shipping', templateUrl: './shipping.component.html', styleUrls: ['./shipping.component.scss'] }) export class ShippingComponent implements OnInit { shippingProfile: IShippingProfileInfo[] = []; cols: any; companyId: number; processigTimeList: SelectItem[]; constructor(private generalService: GeneralService, private cookieService: CookieService) { } ngOnInit() { this.companyId = +this.cookieService.get('CompanyId') this.getTableColums(); this.getTabledata(); } getTableColums() { this.cols = [ { field: 'ShippingProfile', header: 'Shipping Profile' }, { field: 'ProcessingTime', header: 'Processing Time' }, { field: 'ShippingOrigin', header: 'Shipping Origin' }, { field: 'ShippingOptions', header: '' } ]; } getProcessingTime() { this.processigTimeList = [ { label: '1 business day', value: 1 }, { label: '1-2 business days', value: 2 }, { label: '1-3 business days', value: 3 }, { label: '3-5 business days', value: 4 }, { label: '1-2 weeks', value: 5 }, { label: '2-3 weeks', value: 6 }, { label: '3-4 weeks', value: 7 }, { label: '4-6 weeks', value: 8 }, { label: '6-8 weeks', value: 9 }, { label: 'Custom range', value: 10 }, ]; } getTabledata() { this.getProcessingTime(); this.generalService.GetShippingProfileList(this.companyId, 0, "ALL").subscribe(data => { this.shippingProfile = data; this.shippingProfile.forEach(element => { element.ProcessTimeString = this.processigTimeList.find(x => x.value == element.ProcessTimeType).label; }); }) } // copy shipping profile copyShippingProfile(id: number) { this.generalService.GetShippingProfile(this.companyId, id, "BYID").subscribe(data => { var shippingProfile = data; this.generalService.SetShippingProfile(this.companyId, shippingProfile, "SET").subscribe(data => { this.getTabledata(); }) }) } // delete shipping profile deleteShippingProfile(id: number) { this.generalService.GetShippingProfileList(this.companyId, id, "DELETE").subscribe(data => { this.getTabledata(); }) } // To hide previously opened list option pop ups onDropdownMenuClick(event: Event) { //setTimeout(function (event: Event) { var allDropDownList = document.getElementsByClassName('shippingOptionDropdown') for (var i = 0; i < allDropDownList.length; i++) { if (allDropDownList[i].classList.contains('show')) { allDropDownList[i].classList.remove("show"); if (allDropDownList[i].parentElement.classList.contains('open')) { allDropDownList[i].parentElement.classList.remove("open"); } } } // }, 1000) } }