counties, pagination, filter count, show total results

This commit is contained in:
2024-07-19 18:06:56 +02:00
parent abcde3991d
commit 9db23c2177
25 changed files with 67207 additions and 509 deletions

View File

@@ -3,8 +3,9 @@ import { ChangeDetectorRef, Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { BusinessListing, User } from '../../../../../../bizmatch-server/src/models/db.model';
import { ListingType, UserListingCriteria, emailToDirName } from '../../../../../../bizmatch-server/src/models/main.model';
import { LISTINGS_PER_PAGE, ListingType, UserListingCriteria, emailToDirName } from '../../../../../../bizmatch-server/src/models/main.model';
import { environment } from '../../../../environments/environment';
import { PaginatorComponent } from '../../../components/paginator/paginator.component';
import { ImageService } from '../../../services/image.service';
import { ListingsService } from '../../../services/listings.service';
import { SearchService } from '../../../services/search.service';
@@ -15,7 +16,7 @@ import { getCriteriaStateObject } from '../../../utils/utils';
@Component({
selector: 'app-broker-listings',
standalone: true,
imports: [CommonModule, FormsModule, RouterModule, NgOptimizedImage],
imports: [CommonModule, FormsModule, RouterModule, NgOptimizedImage, PaginatorComponent],
templateUrl: './broker-listings.component.html',
styleUrls: ['./broker-listings.component.scss', '../../pages.scss'],
})
@@ -39,6 +40,8 @@ export class BrokerListingsComponent {
env = environment;
public category: 'business' | 'commercialProperty' | 'professionals_brokers' | undefined;
emailToDirName = emailToDirName;
page = 1;
pageCount = 1;
constructor(
public selectOptions: SelectOptionsService,
private listingsService: ListingsService,
@@ -51,14 +54,6 @@ export class BrokerListingsComponent {
private searchService: SearchService,
) {
this.criteria = getCriteriaStateObject('broker');
// this.route.data.subscribe(async () => {
// if (this.router.getCurrentNavigation().extras.state) {
// } else {
// this.first = this.criteria.page * this.criteria.length;
// this.rows = this.criteria.length;
// }
// this.init();
// });
this.init();
this.searchService.currentCriteria.subscribe(criteria => {
if (criteria && criteria.criteriaType === 'broker') {
@@ -74,24 +69,20 @@ export class BrokerListingsComponent {
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.results;
this.totalRecords = usersReponse.totalCount;
this.pageCount = this.totalRecords % LISTINGS_PER_PAGE === 0 ? this.totalRecords / LISTINGS_PER_PAGE : Math.floor(this.totalRecords / LISTINGS_PER_PAGE) + 1;
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;
onPageChange(page: any) {
this.criteria.start = (page - 1) * LISTINGS_PER_PAGE;
this.criteria.length = LISTINGS_PER_PAGE;
this.criteria.page = page;
this.search();
}
reset() {}
}