import { Component, OnInit } from '@angular/core'; import { GeneralService } from '../../services/general/general.service'; import { ITimeZone } from '../../core/general/ITimeZone'; import { CookieService } from 'ngx-cookie-service'; import { IStoreSetupGeneral } from '../../core/general/IStoreSetupGeneral'; import { SelectItem } from 'primeng/api'; import { ICurrency } from '../../core/general/ICurrency'; @Component({ selector: 'app-general', templateUrl: './general.component.html', styleUrls: ['./general.component.scss'] }) export class GeneralComponent implements OnInit { timeZoneList: ITimeZone[] = []; selectedTimeZone: ITimeZone; companyId: number; storeSetupGeneral: IStoreSetupGeneral; weightList: SelectItem[] = []; lengthList: SelectItem[] = []; showFormatting: boolean = false; currencyList: ICurrency[]=[]; selectedCurrency:ICurrency; constructor(private generalService: GeneralService, private cookieService: CookieService) { } ngOnInit() { //initialize this.storeSetupGeneral = { Id: 0, IsVisibleOnline: false, IsAcceptOrders: false, CustomCurrency: '', DecimalPlaces: 2, DecimalToken: '.', LengthMeasurement: 1, Prefix: '', StoreCurrencyId: 1, Suffix: '', ThousandsToken: ',', TimeZoneId: 1, WeightMeasurement: 1 } this.companyId = +this.cookieService.get('CompanyId'); this.weightList = [ { label: 'Miligrams', value: 1 }, { label: 'Grams', value: 2 }, { label: 'Kilograms', value: 3 }, ]; this.lengthList = [ { label: 'Milimeters', value: 1 }, { label: 'Centimeters', value: 2 }, { label: 'Meters', value: 3 }, ]; // bind time zone list this.getTimeZones(); } // get time zones getTimeZones() { this.generalService.GetTimeZones().subscribe(data => { this.timeZoneList = data; // bind generl setting this.getStoreSetupGeneral(); }) } // get general settings getStoreSetupGeneral() { this.generalService.GetStoreSetupGeneral(this.companyId).subscribe(data => { this.storeSetupGeneral = data; this.selectedTimeZone = (this.storeSetupGeneral.TimeZoneId>0) ? this.timeZoneList.find(x=>x.Id==this.storeSetupGeneral.TimeZoneId) : this.timeZoneList[0]; // get currency list this.GetCurrency(); }) } // save save() { this.storeSetupGeneral.TimeZoneId = this.selectedTimeZone.Id; this.storeSetupGeneral.StoreCurrencyId = this.selectedCurrency.Id; this.generalService.SetStoreSetupGeneral(this.companyId, this.storeSetupGeneral).subscribe(data => { }) } // cancel button cancel() { // bind generl setting this.getStoreSetupGeneral(); } // get currency list GetCurrency(){ this.generalService.GetCurrency().subscribe(data=>{ this.currencyList = data; this.selectedCurrency = (this.storeSetupGeneral.StoreCurrencyId > 0) ? this.currencyList.find(x=>x.Id == this.storeSetupGeneral.StoreCurrencyId) : this.currencyList[0] }) } }