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, ContactServiceProxy, ContactListDto, PostalCodeServiceProxy, AddressTypeServiceProxy, FleetServiceProxy, FleetsServiceProxy, VendorsServiceProxy, GetVendorListDto, LocationServiceProxy, GetUserIdInputForResetPassword, DriversServiceProxy } 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 { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; import * as _ from 'lodash'; import * as moment from 'moment'; @Component({ templateUrl: './vendors.component.html', encapsulation: ViewEncapsulation.None, styleUrls: ['./vendors.component.less'], animations: [appModuleAnimation()] }) export class VendorsComponent extends AppComponentBase { @ViewChild('dataTable', {static: true}) dataTable: Table; @ViewChild('paginator', {static: true}) paginator: Paginator; @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; _entityTypeFullName = 'SprintTek.Authorization.Users.User'; entityHistoryEnabled = false; //Filters // filters: { // id: number; // firstName: string; // lastName: string; // filter: string, // postalCodeValue: string, // state: string, // city: string, // addressType: string, // emailAddress: string, // phoneNumber: string, // addressLine1: string, // addressLine2: string, // fleet: string // } = {}; filters: any; filteredPostal:any; filteredCountries:any; filteredStates:any; filteredCities:any; filteredAddressType:any; fleets: any; uploadUrl: string; nameFilter : string surnameFilter : string emailAddressFilter : string emailCompletedFilter : boolean = false; completed: boolean = false; onlyLockedUsers: boolean =false; locationIds: any; advancedFiltersAreShown = false; filteredLocations: any; saving : boolean; utcNow: Date = moment.utc().toDate(); fleetId: any; constructor( injector: Injector, private _contactService: ContactServiceProxy, private _addressTypeService: AddressTypeServiceProxy, private _postalCodeService: PostalCodeServiceProxy, private _activatedRoute: ActivatedRoute, private _httpClient: HttpClient, private _router: Router, private _fileDownloadService: FileDownloadService, private _fleetService: FleetsServiceProxy, private _vendorService: VendorsServiceProxy, private _locationServiceProxy: LocationServiceProxy, private _driverService: DriversServiceProxy, private router: Router, ) { super(injector); this.uploadUrl = AppConsts.remoteServiceBaseUrl + '/Import/ImportFromExcel'; } ngOnInit(){ this.getFleets() $('.kt-select2').select2(); this.setIsEntityHistoryEnabled(); this.filterLocations(); } 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: GetVendorListDto): void { this.entityTypeHistoryModal.show({ entityId: role.id.toString(), entityTypeFullName: this._entityTypeFullName, entityTypeDescription: "Vendor - " +role.name +" " +role.surname }); } getContact(event?: LazyLoadEvent) { // this.filters.postalCodeValue = (document.getElementById('postalCodeInput')).value!="0" ? (document.getElementById('postalCodeInput')).value : undefined; // this.filters.state = (document.getElementById('stateSelectInput')).value!="0" ? (document.getElementById('stateSelectInput')).value : undefined; // this.filters.city = (document.getElementById('citySelectInput')).value!="0" ? (document.getElementById('citySelectInput')).value : undefined; // this.filters.addressType = (document.getElementById('addressTypeSelectInput')).value!="0" ? (document.getElementById('addressTypeSelectInput')).value : undefined; // this.filters.fleet = (document.getElementById('fleetFilter')).value!="0" ? (document.getElementById('fleetFilter')).value : undefined; if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.locationIds = $("#locationFilter").val(); this.spinnerService.show(); this.fleetId = Number((document.getElementById('fleetFilter')).value) == 0 ? undefined : Number((document.getElementById('fleetFilter')).value) this._vendorService.getVendors( this.filters, this.emailAddressFilter, this.nameFilter, this.surnameFilter, this.emailCompletedFilter, this.onlyLockedUsers, this.locationIds, this.fleetId, 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(); }); } reloadPage(): void { this.paginator.changePage(this.paginator.getPage()); } deleteContact(vendor: GetVendorListDto): void { this.message.confirm( this.l('VendorDeleteWarningMessage', vendor.name+" "+vendor.surname), this.l('AreYouSure'), (isConfirmed) => { if (isConfirmed) { this._driverService.deleteDriver(vendor.id) .subscribe(() => { this.reloadPage(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } createOrEditVendor(url: any, id?: number){ if(id != null){ var myurl = `${url}/${id}`; }else{ var myurl = `${url}`; } this._router.navigateByUrl(myurl); } exportToExcel(): void { this.locationIds = $("#locationFilter").val(); this.spinnerService.show(); this.fleetId = Number((document.getElementById('fleetFilter')).value) == 0 ? undefined : Number((document.getElementById('fleetFilter')).value); console.log(Number((document.getElementById('fleetFilter')).value)); this._vendorService.getVendorsToExcel( this.filters, this.emailAddressFilter, this.nameFilter, this.surnameFilter, this.emailCompletedFilter, this.onlyLockedUsers, this.locationIds, this.fleetId, undefined, undefined, undefined, ).pipe(finalize(() => this.spinnerService.hide())).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(); } }); } filterPostal(): void { this._postalCodeService.getDistinctPostalCode( undefined ).subscribe(result => { this.filteredPostal = result.items; }); } filterStates(): void { this._postalCodeService.getDistinctState( undefined, undefined ).subscribe(result => { this.filteredStates = result.items; }); } filterCities(): void { this._postalCodeService.getDistinctCity( undefined, undefined ).subscribe(result => { this.filteredCities = result.items; }); } filterAddressTypes(): void { this._addressTypeService.getAddressType( undefined, undefined, undefined, undefined, undefined, undefined ).subscribe(result => { this.filteredAddressType = result.items; }); } getFleets(){ this._fleetService.getAllFleets(undefined, undefined, undefined, undefined, undefined) .subscribe(result=>{ this.fleets = result.items // console.log(this.fleets) }) } uploadExcel(data: { files: File }): void { //this.importRouteScheduleTracking.clearMessages(); // this.importRouteScheduleTracking.modal.show(); const formData: FormData = new FormData(); const file = data.files[0]; formData.append('file', file, file.name); formData.append('key','vendor'); // formData.append('entity','addresses','addresses'); this._httpClient .post(this.uploadUrl, formData) .subscribe(response => { if (response.success) { this.notify.success('Import process is queued. Please wait'); } else if (response.error != null) { this.notify.error(this.l('ImportFailed')); } }); } filterLocations(): void { this._locationServiceProxy.getLocationNames( undefined, undefined, undefined, undefined, undefined, undefined ).subscribe(result => { this.filteredLocations = result; console.log(this.filteredLocations); }); } unlockUser(record): void { this._driverService.unlockDriver(new EntityDtoOfInt64({ id: record.id })).subscribe(() => { this.notify.success(this.l('UnlockedTheUser', record.name +" " +record.surname)); }); this.filters = "" ; this.nameFilter = ""; this.surnameFilter = ""; this.emailAddressFilter = ""; var that = this; setTimeout(function () { that.getContact() }, 1000) } lockUser(record): void { this._driverService.lockDriver(new EntityDtoOfInt64({ id: record.id })).subscribe(() => { this.notify.success(this.l('LockedUser')+ " " +record.name +" " +record.surname); this.filters = "" ; this.nameFilter = ""; this.surnameFilter = ""; this.emailAddressFilter = ""; var that = this; setTimeout(function () { that.getContact() }, 500) }); } setLocked(record):void { if(record.isLocked){ this.unlockUser(record); }else{ this.lockUser(record); } } resetPassword(userId){ let input = new GetUserIdInputForResetPassword input.userId = userId var that = this; this.spinnerService.show this._driverService.updateResetUserPassword(input) .pipe(finalize(() => { this.saving = false; })) .subscribe(() => { this.notify.info(this.l('ResetPasswordSuccess')); this.spinnerService.hide this.filters = "" ; this.nameFilter = ""; this.surnameFilter = ""; this.emailAddressFilter = ""; setTimeout(function () { that.getContact() }, 200) }); } setEmailConfirm(record): void { this._driverService.driverEmailConfirm(new EntityDtoOfInt64({ id: record.id })).subscribe(() => { this.notify.success(this.l('EmailConfirm', record.name +" " +record.surname)); }); this.filters = "" ; this.nameFilter = ""; this.surnameFilter = ""; this.emailAddressFilter = ""; var that = this; setTimeout(function () { that.getContact() }, 1000) } }