import { Component, Injector, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { AppConsts } from '@shared/AppConsts'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { LocationListDto, LocationServiceProxy, AddressServiceProxy, ContactServiceProxy } from '@shared/service-proxies/service-proxies'; import { FileDownloadService } from '@shared/utils/file-download.service'; import * as moment from 'moment'; 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 { CreateLocationModalComponent } from './create-location-modal.component'; import * as _ from 'lodash'; import { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; @Component({ templateUrl: 'location.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class LocationsComponent extends AppComponentBase implements OnInit { @ViewChild('dataTable', {static: true}) dataTable: Table; @ViewChild('paginator', {static: true}) paginator: Paginator; @ViewChild('createLocationModal', {static: false}) createLocationModal: CreateLocationModalComponent; @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; _entityTypeFullName = 'SprintTek.Shipping.Locations.Location'; entityHistoryEnabled = false; filters: { id: number; filter: string; nameFilter: string; timeZoneFilter: string; name: string; CurrentPage: number; inactive: boolean; loadLimitFilter: number; } = {}; advancedFiltersAreShown = false; constructor( injector: Injector, private router: Router, private _locationService: LocationServiceProxy, private _fileDownloadService: FileDownloadService, private _addressService: AddressServiceProxy, private _contactService: ContactServiceProxy ) { super(injector); } ngOnInit(): void { this.filters.inactive = true; this.setIsEntityHistoryEnabled(); } exportToExcel(): void { this.spinnerService.show(); this._locationService.getLocationsToExcel( this.filters.filter, this.filters.nameFilter, this.filters.timeZoneFilter ).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(); } }); } getLocations(event?: LazyLoadEvent) { if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.spinnerService.show(); this._locationService.getLocation( this.filters.id, this.filters.filter, this.filters.nameFilter, this.filters.timeZoneFilter, !this.filters.inactive, this.filters.loadLimitFilter == null ? undefined : this.filters.loadLimitFilter, this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getMaxResultCount(this.paginator, event), this.primengTableHelper.getSkipCount(this.paginator, event) ).pipe(finalize(() => this.spinnerService.hide())).subscribe(result => { this.primengTableHelper.totalRecordsCount = result.totalCount; this.primengTableHelper.records = result.items; this.spinnerService.hide(); }); } createLocation(): void { this.createLocationModal.show(); } deleteLocation(location: LocationListDto): void { this.message.confirm( this.l('LocationWarningMessage', location.name), this.l('AreYouSure'), (isConfirmed) => { if (isConfirmed) { this._locationService.deleteLocation(location.id) .subscribe(() => { this.reloadPage(); this.notify.info(this.l('SuccessfullyDeleted')); }); } } ); } reloadPage(): void { this.paginator.changePage(this.paginator.getPage()); } createOrUpdate(url: any, id?: number){ if(id != null){ var myurl = `${url}/${id}`; }else{ var myurl = `${url}`; } console.log(myurl); this.router.navigateByUrl(myurl); } 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(role: LocationListDto): void { this.entityTypeHistoryModal.show({ entityId: role.id.toString(), entityTypeFullName: this._entityTypeFullName, entityTypeDescription: "Location - " +role.name }); } }