import { Component, Injector, ViewChild, ViewEncapsulation, Input, Output, EventEmitter, OnInit, AfterViewInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppConsts } from '@shared/AppConsts'; import { AppComponentBase } from '@shared/common/app-component-base'; import { ClinicsServiceProxy, CreateOrEditClinicDto, RouteDefinitionsServiceProxy, RouteTypesServiceProxy } from '@shared/service-proxies/service-proxies'; import { AddressServiceProxy, CreateAddressInput } from '@shared/service-proxies/service-proxies'; import { EmailServiceProxy, CreateEmailInput, AddressTypeServiceProxy, PostalCodeServiceProxy, } from '@shared/service-proxies/service-proxies'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { finalize } from 'rxjs/operators'; import * as moment from 'moment'; import * as _ from 'lodash'; declare var KTWizard: any; declare var $: any; declare var KTApp: any; declare let swal: any; @Component({ templateUrl: './clinic-schedule.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], }) export class ClinicScheduleComponent extends AppComponentBase { @Input('selectedCountry') selectedCountry: string; @Input('selectedCity') selectedCity: string; @Input('selectedState') selectedState: string; @Input('postalCodeId') selectedPostalCodeId: number; @Input('postalCodeValue') selectedPostalCodeValue: string; active = false; saving = false; id: any; clinic: CreateOrEditClinicDto = new CreateOrEditClinicDto(); address: CreateAddressInput = new CreateAddressInput(); postalInfo: any; routeTypes: any; routeDefinitions: any; designation: any; schedules: any; constructor( injector: Injector, private _clinicsServiceProxy: ClinicsServiceProxy, private _addressService: AddressServiceProxy, private _emailService: EmailServiceProxy, private _postalCodeService: PostalCodeServiceProxy, private _addressTypeService: AddressTypeServiceProxy, private _routeDefinitionsServiceProxy: RouteDefinitionsServiceProxy, private _router: Router, private route: ActivatedRoute ) { super(injector); } dynamicArray: Array = []; newDynamic: any = {}; eta: Array = []; cutOff: Array = []; effectivityDate: Array = []; oorRate: Array = []; savedDesignation: Array = []; i: any; ngOnInit() { this.route.paramMap.subscribe(params => { this.id = params.get("id") }) var that = this; $('.kt-select2').select2(); let maxcount = 1000; //this.newDynamic = {routeCode: "", routeType: "",eta:"", cutOff:"", effectivityDate:"", designation:"auto",oor:"6.18"}; //this.dynamicArray.push(this.newDynamic); this._clinicsServiceProxy.getClinicForEdit(this.id).subscribe(result => { console.log(result); this.clinic = result.clinic; this.address = result.clinic.address; this._postalCodeService.getPostalCodeEdit(this.address.postalCodeId).subscribe(resultPostalCode => { this.selectedCountry = resultPostalCode.country; this.selectedState = resultPostalCode.state; this.selectedCity = resultPostalCode.city; this.selectedPostalCodeValue = resultPostalCode.value; }); }); this._routeDefinitionsServiceProxy.getAllRouteTypeForLookupTable( undefined, undefined, undefined, maxcount ).subscribe(result => { that.routeTypes = result.items; }); this._routeDefinitionsServiceProxy.getAll( undefined, undefined, undefined, undefined, undefined, undefined, undefined, maxcount ).subscribe(result => { that.routeDefinitions = result.items; }); var that = this; this._clinicsServiceProxy.getClinicSchedule(this.id).subscribe(result => { this.schedules = result.items; //this.schedules.estimatedTimeOfArrival = this.schedules.estimatedTimeOfArrival.toDate(); //console.log(result.items.length); result.items.forEach(function (value) { that.eta.push(value.estimatedTimeOfArrival.toDate()); that.cutOff.push(value.cutOff.toDate()) that.effectivityDate.push(value.effectivityDate.toDate()); if(value.oorRate == null) { that.oorRate.push(6.18); } else { that.oorRate.push(value.oorRate); } if(value.willCall) { that.savedDesignation.push("willCall"); } else if(value.automatic) { that.savedDesignation.push("auto"); } if(result.items.length == 0) { this.newDynamic = {routeCode: "", routeType: "",eta:"", cutOff:"", effectivityDate:"", designation:"auto",oor:"6.18"}; this.dynamicArray.push(this.newDynamic); } }); }); } save(): void { } addRow(index) { this.newDynamic = {routeCode:"",routeType:"",eta:"",cutOff:"",effectivityDate:"",designation:"auto",oor:"6.18"}; this.dynamicArray.push(this.newDynamic); return true; } deleteRow(index) { this.dynamicArray.splice(index, 1); return true; } createOrEditClinic(url: any, id?: number){ if(id != null){ var myurl = `${url}/${id}`; }else{ var myurl = `${url}`; } console.log(myurl); this._router.navigateByUrl(myurl); } }