115 lines
3.9 KiB
TypeScript
115 lines
3.9 KiB
TypeScript
import { CommonModule, NgOptimizedImage } 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 { InputGroupModule } from 'primeng/inputgroup';
|
|
import { InputTextModule } from 'primeng/inputtext';
|
|
import { PaginatorModule } from 'primeng/paginator';
|
|
import { StyleClassModule } from 'primeng/styleclass';
|
|
import { ToggleButtonModule } from 'primeng/togglebutton';
|
|
import { BusinessListing, User } 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 { UserService } from '../../../services/user.service';
|
|
import { getCriteriaStateObject, getSessionStorageHandler, resetCriteria } from '../../../utils/utils';
|
|
|
|
@Component({
|
|
selector: 'app-broker-listings',
|
|
standalone: true,
|
|
imports: [
|
|
CommonModule,
|
|
StyleClassModule,
|
|
ButtonModule,
|
|
CheckboxModule,
|
|
InputTextModule,
|
|
DropdownModule,
|
|
FormsModule,
|
|
StyleClassModule,
|
|
ToggleButtonModule,
|
|
RouterModule,
|
|
PaginatorModule,
|
|
InputGroupModule,
|
|
NgOptimizedImage,
|
|
],
|
|
templateUrl: './broker-listings.component.html',
|
|
styleUrls: ['./broker-listings.component.scss', '../../pages.scss'],
|
|
})
|
|
export class BrokerListingsComponent {
|
|
environment = environment;
|
|
listings: Array<BusinessListing>;
|
|
users: Array<User>;
|
|
filteredListings: Array<ListingType>;
|
|
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();
|
|
env = environment;
|
|
public category: 'business' | 'commercialProperty' | 'professionals_brokers' | undefined;
|
|
|
|
constructor(
|
|
public selectOptions: SelectOptionsService,
|
|
private listingsService: ListingsService,
|
|
private userService: UserService,
|
|
private activatedRoute: ActivatedRoute,
|
|
private router: Router,
|
|
private cdRef: ChangeDetectorRef,
|
|
private imageService: ImageService,
|
|
private route: ActivatedRoute,
|
|
) {
|
|
this.criteria = onChange(getCriteriaStateObject(), getSessionStorageHandler);
|
|
this.route.data.subscribe(async () => {
|
|
if (this.router.getCurrentNavigation().extras.state) {
|
|
resetCriteria(this.criteria);
|
|
} else {
|
|
this.first = this.criteria.page * this.criteria.length;
|
|
this.rows = this.criteria.length;
|
|
}
|
|
this.init();
|
|
});
|
|
}
|
|
async ngOnInit() {
|
|
const statesResult = await this.userService.getAllStates();
|
|
this.states = statesResult.map(ls => ({ name: this.selectOptions.getState(ls.state as string), value: ls.state, count: ls.count }));
|
|
}
|
|
async init() {
|
|
this.search();
|
|
}
|
|
refine() {
|
|
this.criteria.start = 0;
|
|
this.criteria.page = 0;
|
|
this.search();
|
|
}
|
|
async search() {
|
|
const usersReponse = await this.userService.search(this.criteria);
|
|
this.users = usersReponse.data;
|
|
this.totalRecords = usersReponse.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();
|
|
}
|
|
reset() {
|
|
this.criteria.name = '';
|
|
}
|
|
}
|