90 lines
3.6 KiB
TypeScript
90 lines
3.6 KiB
TypeScript
import { CommonModule } from '@angular/common';
|
|
import { ChangeDetectorRef, Component } from '@angular/core';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
|
import onChange from 'on-change';
|
|
import { ButtonModule } from 'primeng/button';
|
|
import { CheckboxModule } from 'primeng/checkbox';
|
|
import { DropdownModule } from 'primeng/dropdown';
|
|
import { InputTextModule } from 'primeng/inputtext';
|
|
import { PaginatorModule } from 'primeng/paginator';
|
|
import { StyleClassModule } from 'primeng/styleclass';
|
|
import { ToggleButtonModule } from 'primeng/togglebutton';
|
|
import { CommercialPropertyListing } from '../../../../../../bizmatch-server/src/models/db.model';
|
|
import { ListingCriteria, ListingType } from '../../../../../../bizmatch-server/src/models/main.model';
|
|
import { environment } from '../../../../environments/environment';
|
|
import { ImageService } from '../../../services/image.service';
|
|
import { ListingsService } from '../../../services/listings.service';
|
|
import { SelectOptionsService } from '../../../services/select-options.service';
|
|
import { createGenericObject, getCriteriaStateObject, getSessionStorageHandler } from '../../../utils/utils';
|
|
|
|
@Component({
|
|
selector: 'app-commercial-property-listings',
|
|
standalone: true,
|
|
imports: [CommonModule, StyleClassModule, ButtonModule, CheckboxModule, InputTextModule, DropdownModule, FormsModule, StyleClassModule, ToggleButtonModule, RouterModule, PaginatorModule],
|
|
templateUrl: './commercial-property-listings.component.html',
|
|
styleUrl: './commercial-property-listings.component.scss',
|
|
})
|
|
export class CommercialPropertyListingsComponent {
|
|
environment = environment;
|
|
listings: Array<CommercialPropertyListing>;
|
|
filteredListings: Array<CommercialPropertyListing>;
|
|
criteria: ListingCriteria;
|
|
realEstateChecked: boolean;
|
|
|
|
maxPrice: string;
|
|
minPrice: string;
|
|
type: string;
|
|
states = [];
|
|
statesSet = new Set();
|
|
state: string;
|
|
first: number = 0;
|
|
rows: number = 12;
|
|
totalRecords: number = 0;
|
|
ts = new Date().getTime();
|
|
|
|
constructor(
|
|
public selectOptions: SelectOptionsService,
|
|
private listingsService: ListingsService,
|
|
private activatedRoute: ActivatedRoute,
|
|
private router: Router,
|
|
private cdRef: ChangeDetectorRef,
|
|
private imageService: ImageService,
|
|
) {
|
|
this.criteria = onChange(getCriteriaStateObject(), getSessionStorageHandler);
|
|
this.router.getCurrentNavigation();
|
|
this.activatedRoute.snapshot;
|
|
this.activatedRoute.params.subscribe(params => {
|
|
if (this.activatedRoute.snapshot.fragment === '') {
|
|
this.criteria = onChange(createGenericObject<ListingCriteria>(), getSessionStorageHandler);
|
|
this.first = 0;
|
|
}
|
|
this.init();
|
|
});
|
|
}
|
|
async ngOnInit() {}
|
|
async init() {
|
|
const statesResult = await this.listingsService.getAllStates('business');
|
|
this.states = statesResult.map(s => s.state).map(ls => ({ name: this.selectOptions.getState(ls as string), value: ls }));
|
|
this.search();
|
|
}
|
|
|
|
async search() {
|
|
const listingReponse = await this.listingsService.getListings(this.criteria, 'commercialProperty');
|
|
this.listings = listingReponse.data;
|
|
this.totalRecords = listingReponse.total;
|
|
this.cdRef.markForCheck();
|
|
this.cdRef.detectChanges();
|
|
}
|
|
onPageChange(event: any) {
|
|
this.criteria.start = event.first;
|
|
this.criteria.length = event.rows;
|
|
this.criteria.page = event.page;
|
|
this.criteria.pageCount = event.pageCount;
|
|
this.search();
|
|
}
|
|
imageErrorHandler(listing: ListingType) {
|
|
// listing.hideImage = true; // Bild ausblenden, wenn es nicht geladen werden kann
|
|
}
|
|
}
|