import { Component, Injector, ViewChild, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { AppConsts } from '@shared/AppConsts'; import { Router } from '@angular/router'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { EntityDtoOfInt64, LocationServiceProxy, RateServiceProxy, RateDto, OrderSourceRate } from '@shared/service-proxies/service-proxies'; import { FileDownloadService } from '@shared/utils/file-download.service'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { Paginator } from 'primeng/components/paginator/paginator'; import { Table } from 'primeng/components/table/table'; import { HttpClient } from '@angular/common/http'; import { FileUpload } from 'primeng/fileupload'; import { finalize } from 'rxjs/operators'; import * as moment from 'moment-timezone'; import { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; import { RatesDescriptionModalComponent } from './rates-description-modal.component'; import * as _ from 'lodash'; @Component({ templateUrl: './rates.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class RatesComponent extends AppComponentBase { @ViewChild('dataTable', {static: true}) dataTable: Table; @ViewChild('paginator', {static: true}) paginator: Paginator; @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; @ViewChild('ratesDescriptionModal', { static: true }) ratesDescriptionModal: RatesDescriptionModalComponent; _entityTypeFullName = 'SprintTek.Authorization.Users.User'; entityHistoryEnabled = false; //Filters filters : any; advancedFiltersAreShown = false; saving : boolean completed: boolean = false; filteredLocations: any; filteredOrderSource: any; locationIds: any; orderSourceId: any; constructor( injector: Injector, private _rateService: RateServiceProxy, private _activatedRoute: ActivatedRoute, private _httpClient: HttpClient, private _router: Router, private _locationServiceProxy: LocationServiceProxy, private router: Router, ) { super(injector); } ngOnInit(){ $('.kt-select2').select2({ placeholder: "Select.." }); this.setIsEntityHistoryEnabled(); this.filterLocations(); this.filteredOrderSources(); } private setIsEntityHistoryEnabled(): void { let customSettings = (abp as any).custom; this.entityHistoryEnabled = customSettings.EntityHistory && customSettings.EntityHistory.isEnabled && _.filter(customSettings.EntityHistory.enabledEntities, entityType => entityType === this._entityTypeFullName).length === 1; } showHistory(rate: RateDto): void { this.entityTypeHistoryModal.show({ entityId: rate.id.toString(), entityTypeFullName: this._entityTypeFullName, entityTypeDescription: "Rate - " +rate.id }); } /* exportToExcel(event?: LazyLoadEvent): void { this.locationIds = $("#locationFilter").val(); this.fleetIds = $("#driverFleetFilter").val(); this.spinnerService.show(); this._driverService.getDriversToExcel( this.filters || this.nameFilter || this.surnameFilter || this.emailAddressFilter, undefined, undefined, undefined, this.emailCompletedFilter, this.completed, this.onlyLockedUsers, this.locationIds, this.fleetIds, this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getMaxResultCount(this.paginator, event), this.primengTableHelper.getSkipCount(this.paginator, event) ).subscribe(result => { if(result!=undefined){ if(result.fileUrl!=undefined){ this.router.navigate([]).then(result1 => { window.open(result.fileUrl, '_blank'); }); this.spinnerService.hide(); }else{ this.spinnerService.hide(); } }else{ this.message.warn('', "No data to export"); this.spinnerService.hide(); } }) }*/ calcDisplay(count: any, rateType: any) { //console.log(rateType); let result = "" if(rateType == 0) { result = "Hour"; } else if(rateType == 1) { result = "Day" } else if(rateType == 2) { result = "Week" } else if(rateType == 3) { result = "Month" } else if(rateType == 4) { result = "Mile" } else if(rateType == 5) { result = "Package" } else if(rateType == 6) { result = "Gram" } else if(rateType == 7) { result = "Package Size" } else if(rateType == 8) { result = "Stop" } else if(rateType == 9) { result = "Route" } else if(rateType == 10) { result = "Misc" } if(count > 1) { if(rateType != 10) { result = result+"s"; } } return result; } valueDisplay(rateType: any) { //console.log(rateType); let result = "" if(rateType == 0) { result = "Hour"; } else if(rateType == 1) { result = "Day" } else if(rateType == 2) { result = "Week" } else if(rateType == 3) { result = "Month" } else if(rateType == 4) { result = "Mile" } else if(rateType == 5) { result = "Package" } else if(rateType == 6) { result = "Gram" } else if(rateType == 7) { result = "Package Size" } else if(rateType == 8) { result = "Stop" } else if(rateType == 9) { result = "Route" } else if(rateType == 10) { result = "Misc" } return result; } viewDescription(description: string): void { this.ratesDescriptionModal.show(description); } getRate(event?: LazyLoadEvent) { this.spinnerService.show(); this.locationIds = $("#locationFilter").val(); this.orderSourceId = $("#orderSourceFilter").val(); if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.spinnerService.show(); this.locationIds = $("#locationFilter").val(); this._rateService.getRate( this.filters, this.locationIds, this.orderSourceId, this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getSkipCount(this.paginator, event), this.primengTableHelper.getMaxResultCount(this.paginator, event) ).subscribe(result => { this.primengTableHelper.totalRecordsCount = result.totalCount; this.primengTableHelper.records = result.items; console.log(result.items); this.spinnerService.hide(); }); } reloadPage(): void { this.paginator.changePage(this.paginator.getPage()); } deleteRate(rate: RateDto): void { this.message.confirm( this.l('Delete'), this.l('AreYouSure'), (isConfirmed) => { if (isConfirmed) { this._rateService.delete(rate.id) .subscribe(() => { this.reloadPage(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } createOrEditRate(url: any, id?: any){ if(id != null){ var myurl = `${url}/${id}`; }else{ var myurl = `${url}`; } this._router.navigateByUrl(myurl); } filterLocations(): void { this._locationServiceProxy.getLocationNames( undefined, undefined, undefined, undefined, undefined, undefined ).subscribe(result => { this.filteredLocations = result; }); } filteredOrderSources(): void { this._rateService.getOrderSourceRate().subscribe(result => { console.log(result); this.filteredOrderSource = result; }); } }