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 { UserLocationListDto, UserLocationServiceProxy, LocationServiceProxy, GetUserListInput, NameValueDto, CreateUserLocationInput} 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 { CreateUserLocationModalComponent } from './create-user-location-modal.component'; import * as _ from 'lodash'; import { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; declare var $: any; @Component({ templateUrl: 'user-location.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class UserLocationComponent extends AppComponentBase implements OnInit { @ViewChild('dataTable', {static: true}) dataTable: Table; @ViewChild('paginator', {static: true}) paginator: Paginator; // @ViewChild('createUserLocationModal', {static: false}) createUserLocationModal: CreateUserLocationModalComponent; @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; @ViewChild('userList', { static: true }) userList: CreateUserLocationModalComponent; _entityTypeFullName = 'SprintTek.Shipping.Locations.UserLocation'; entityHistoryEnabled = false; filters: { id: number; userId: number; locationId: number; user: string; CurrentPage: number; filter: string; locationFilter: string } = {}; locationId: number; locations: any; advancedFiltersAreShown = false; defaultLocation:any; userLocation : UserLocationListDto; constructor( injector: Injector, private _locationService: LocationServiceProxy, private _userLocationService: UserLocationServiceProxy, private _fileDownloadService: FileDownloadService, private router: Router, ) { super(injector); } exportToExcel(): void{ this.spinnerService.show(); this._userLocationService.getUserLocationsToExcel( this.filters.id, this.filters.userId, this.filters.user, this.locationId, this.filters.filter, this.filters.user, this.filters.locationFilter, undefined, undefined, undefined ).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(); } }); } ngOnInit(): void { this.setIsEntityHistoryEnabled(); this.userList.configure({ title: this.l('Create User Location'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?: number) => { let input = new GetUserListInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; return this._userLocationService.pickUserList(input); } }); this.showAllocations(); } 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: UserLocationListDto): void { this.entityTypeHistoryModal.show({ entityId: role.id.toString(), entityTypeFullName: this._entityTypeFullName, entityTypeDescription: "User Location - " + role.userName }); } getUserLocations(event?: LazyLoadEvent) { $('.kt-select2').select2(); this.locationId = Number((document.getElementById('locationSelectInput')).value) != 0 ? Number((document.getElementById('locationSelectInput')).value) : undefined; if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.spinnerService.show(); this._userLocationService.getUserLocation( this.filters.id, this.filters.userId, this.filters.user, this.locationId, this.filters.filter, this.filters.user, this.filters.locationFilter, 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(); }); } createUserLocation(): void { this.userList.shown(); } reloadPage(): void { this.paginator.changePage(this.paginator.getPage()); } deleteUserLocation(id): void { this.message.confirm( '', '', isConfirmed => { if (isConfirmed) { this._userLocationService .deleteUserLocation(id) .subscribe(() => { this.reloadPage(); this.notify.success(this.l('Successfully Deleted')); }); } } ); } saveUserLocation(item: NameValueDto): void { let input = new CreateUserLocationInput(); input.userId = parseInt(item.value), input.locationIds = $("#locationSelectInput1").val(); this.spinnerService.show(); this._userLocationService.createUserLocation(input).subscribe(o => { this.spinnerService.hide(); }); } showAllocations(): void { this._locationService.getLocationTableOnly( undefined, undefined, undefined, undefined, undefined, undefined ).subscribe(result => { this.locations = result; }); } }