reset criteria on home, show filter on home, new BOM generation, Schema overhaul
This commit is contained in:
@@ -84,7 +84,7 @@
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div class="mt-4 text-gray-600 text-sm md:text-base text-center">Or search using filters ▼</div>
|
||||
<div class="mt-4 text-gray-600 text-sm md:text-base text-center hover:cursor-pointer" (click)="openModal()">Or search using filters ▼</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,9 +5,12 @@ import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
||||
import { KeycloakService } from 'keycloak-angular';
|
||||
import onChange from 'on-change';
|
||||
import { BusinessListingCriteria, CommercialPropertyListingCriteria, KeycloakUser, UserListingCriteria } from '../../../../../bizmatch-server/src/models/main.model';
|
||||
import { ModalService } from '../../components/search-modal/modal.service';
|
||||
import { CriteriaChangeService } from '../../services/criteria-change.service';
|
||||
import { ListingsService } from '../../services/listings.service';
|
||||
import { SearchService } from '../../services/search.service';
|
||||
import { SelectOptionsService } from '../../services/select-options.service';
|
||||
import { getCriteriaStateObject, getSessionStorageHandlerWrapper, map2User } from '../../utils/utils';
|
||||
import { getCriteriaStateObject, map2User } from '../../utils/utils';
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
standalone: true,
|
||||
@@ -25,30 +28,54 @@ export class HomeComponent {
|
||||
isMenuOpen = false;
|
||||
user: KeycloakUser;
|
||||
prompt: string;
|
||||
public constructor(private router: Router, private activatedRoute: ActivatedRoute, public selectOptions: SelectOptionsService, public keycloakService: KeycloakService, private listingsService: ListingsService) {
|
||||
this.criteria = onChange(getCriteriaStateObject('business'), getSessionStorageHandlerWrapper(this.activeTabAction));
|
||||
}
|
||||
public constructor(
|
||||
private router: Router,
|
||||
private modalService: ModalService,
|
||||
private searchService: SearchService,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
public selectOptions: SelectOptionsService,
|
||||
public keycloakService: KeycloakService,
|
||||
private listingsService: ListingsService,
|
||||
private criteriaChangeService: CriteriaChangeService,
|
||||
) {}
|
||||
async ngOnInit() {
|
||||
const token = await this.keycloakService.getToken();
|
||||
sessionStorage.removeItem('business_criteria');
|
||||
sessionStorage.removeItem('commercialProperty_criteria');
|
||||
sessionStorage.removeItem('broker_criteria');
|
||||
this.criteria = this.createEnhancedProxy(getCriteriaStateObject('business'));
|
||||
this.user = map2User(token);
|
||||
// this.router.events.subscribe(event => {
|
||||
// if (event instanceof NavigationEnd) {
|
||||
// initFlowbite();
|
||||
// }
|
||||
// });
|
||||
}
|
||||
async changeTab(tabname: 'business' | 'commercialProperty' | 'broker') {
|
||||
this.activeTabAction = tabname;
|
||||
// if (this.activeTabAction === 'business' || this.activeTabAction === 'commercialProperty') {
|
||||
// const statesResult = await this.listingsService.getAllStates(this.activeTabAction);
|
||||
// this.states = statesResult.map(s => s.state).map(ls => ({ name: this.selectOptions.getState(ls as string), value: ls }));
|
||||
// } else {
|
||||
// this.states = this.selectOptions.states;
|
||||
// }
|
||||
if ('business' === tabname) {
|
||||
this.criteria = this.createEnhancedProxy(getCriteriaStateObject('business'));
|
||||
} else if ('commercialProperty' === tabname) {
|
||||
this.criteria = this.createEnhancedProxy(getCriteriaStateObject('commercialProperty'));
|
||||
} else if ('broker' === tabname) {
|
||||
this.criteria = this.createEnhancedProxy(getCriteriaStateObject('broker'));
|
||||
} else {
|
||||
this.criteria = undefined;
|
||||
}
|
||||
}
|
||||
private createEnhancedProxy(obj: any) {
|
||||
const component = this;
|
||||
|
||||
const sessionStorageHandler = function (path, value, previous, applyData) {
|
||||
let criteriaType = this.criteriaType;
|
||||
sessionStorage.setItem(`${criteriaType}_criteria`, JSON.stringify(this));
|
||||
};
|
||||
|
||||
return onChange(obj, function (path, value, previous, applyData) {
|
||||
// Call the original sessionStorageHandler
|
||||
sessionStorageHandler.call(this, path, value, previous, applyData);
|
||||
|
||||
// Notify about the criteria change using the component's context
|
||||
component.criteriaChangeService.notifyCriteriaChange();
|
||||
});
|
||||
}
|
||||
search() {
|
||||
const data = { keep: true };
|
||||
this.criteria.prompt = this.prompt;
|
||||
this.router.navigate([`${this.activeTabAction}Listings`]);
|
||||
}
|
||||
|
||||
@@ -63,4 +90,11 @@ export class HomeComponent {
|
||||
toggleMenu() {
|
||||
this.isMenuOpen = !this.isMenuOpen;
|
||||
}
|
||||
async openModal() {
|
||||
const accepted = await this.modalService.showModal(this.criteria);
|
||||
if (accepted) {
|
||||
//this.searchService.search(this.criteria);
|
||||
this.router.navigate([`${this.activeTabAction}Listings`]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user