import { Component, EventEmitter, Injector, OnInit, Output, ViewChild } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { CreateVehicleToFleetInput, LocationNameDto, LocationServiceProxy, NameValueDto } from '@shared/service-proxies/service-proxies'; import * as _ from 'lodash'; import { ModalDirective } from 'ngx-bootstrap'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { Paginator } from 'primeng/components/paginator/paginator'; import { Table } from 'primeng/components/table/table'; import { Observable } from 'rxjs/internal/Observable'; import { finalize } from 'rxjs/internal/operators/finalize'; @Component({ selector: 'holidayAddLocation', templateUrl: './holiday-add-location.component.html', styleUrls: ['./holiday-add-location.component.less'] }) export class HolidayAddLocationComponent extends AppComponentBase implements OnInit { @ViewChild('holidayAddLocation', { static: true }) modal: ModalDirective; @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; @Output() itemSelected: EventEmitter = new EventEmitter(); isShown = false; filterText = ''; tenantId?: number; saving = false; locationIds : number[] = [] selectedLocation : LocationNameDto[] constructor( injector: Injector, private _locationsServiceProxy: LocationServiceProxy, ) { super(injector); } ngOnInit() { } show(locationIds? : number[]): void { this.locationIds = locationIds == null? undefined : locationIds; this.modal.show(); } refreshTable(): void { this.paginator.changePage(this.paginator.getPage()); } close(): void { this.modal.hide(); } shown(): void { this.isShown = true; this.getRecordsIfNeeds(null); this.setZIndexes() } getRecordsIfNeeds(event: LazyLoadEvent): void { if (!this.isShown) { return; } this.getRecords(event); } getRecords(event?: LazyLoadEvent): void { if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.spinnerService.show(); this._locationsServiceProxy.getUnassignedLocationInHoliday( undefined, this.locationIds, this.primengTableHelper.getMaxResultCount(this.paginator, event), this.primengTableHelper.getSkipCount(this.paginator, event), this.filterText ) .pipe(finalize(() => this.spinnerService.hide())) .subscribe(result => { this.primengTableHelper.totalRecordsCount = result.totalCount; this.primengTableHelper.records = result.items; this.spinnerService.hide(); }); } addLocations() { //let locations = _.map(this.selectedLocation, selectedLocation => Number(selectedLocation)); this.itemSelected.emit(this.selectedLocation); this.selectedLocation = []; this.close(); return; } setZIndexes(): void { let modalBackdrops = document.querySelectorAll('.modal-backdrop.fade.show'); let newZ = 1050; (modalBackdrops[modalBackdrops.length - 1] as HTMLElement).style.zIndex = newZ.toString(); } }