From 55e800009efb5dee73046a6bcafe0f9efbce9667 Mon Sep 17 00:00:00 2001 From: Andreas Knuth Date: Mon, 29 Jul 2024 21:23:26 +0200 Subject: [PATCH] landing page finished --- bizmatch-server/src/geo/geo.controller.ts | 4 + bizmatch-server/src/geo/geo.service.ts | 37 +++++++++ bizmatch-server/src/models/main.model.ts | 6 ++ bizmatch/package.json | 3 +- .../src/app/pages/home/home.component.html | 71 +++++++++------- .../src/app/pages/home/home.component.scss | 10 +-- bizmatch/src/app/pages/home/home.component.ts | 82 ++++++++++++++++--- bizmatch/src/app/services/geo.service.ts | 5 +- 8 files changed, 164 insertions(+), 54 deletions(-) diff --git a/bizmatch-server/src/geo/geo.controller.ts b/bizmatch-server/src/geo/geo.controller.ts index 0099247..cdc1bfd 100644 --- a/bizmatch-server/src/geo/geo.controller.ts +++ b/bizmatch-server/src/geo/geo.controller.ts @@ -10,6 +10,10 @@ export class GeoController { findByPrefix(@Param('prefix') prefix: string): any { return this.geoService.findCitiesStartingWith(prefix); } + @Get('citiesandstates/:prefix') + findByCitiesAndStatesByPrefix(@Param('prefix') prefix: string): any { + return this.geoService.findCitiesAndStatesStartingWith(prefix); + } @Get(':prefix/:state') findByPrefixAndState(@Param('prefix') prefix: string, @Param('state') state: string): any { diff --git a/bizmatch-server/src/geo/geo.service.ts b/bizmatch-server/src/geo/geo.service.ts index f486497..76b6c21 100644 --- a/bizmatch-server/src/geo/geo.service.ts +++ b/bizmatch-server/src/geo/geo.service.ts @@ -61,6 +61,43 @@ export class GeoService { }); return state ? result.filter(e => e.state_code.toLowerCase() === state.toLowerCase()) : result; } + findCitiesAndStatesStartingWith(prefix: string, state?: string): Array<{ id: string; name: string; type: 'city' | 'state'; state_code: string }> { + const results: Array<{ id: string; name: string; type: 'city' | 'state'; state_code: string }> = []; + + const lowercasePrefix = prefix.toLowerCase(); + + //for (const country of this.geo) { + // Suche nach passenden Staaten + for (const state of this.geo.states) { + if (state.name.toLowerCase().startsWith(lowercasePrefix)) { + results.push({ + id: state.id.toString(), + name: state.name, + type: 'state', + state_code: state.state_code, + }); + } + + // Suche nach passenden Städten + for (const city of state.cities) { + if (city.name.toLowerCase().startsWith(lowercasePrefix)) { + results.push({ + id: city.id.toString(), + name: city.name, + type: 'city', + state_code: state.state_code, + }); + } + } + //} + } + + return results.sort((a, b) => { + if (a.type === 'state' && b.type === 'city') return -1; + if (a.type === 'city' && b.type === 'state') return 1; + return a.name.localeCompare(b.name); + }); + } getCityWithCoords(state: string, city: string): City { return this.geo.states.find(s => s.state_code === state).cities.find(c => c.name === city); } diff --git a/bizmatch-server/src/models/main.model.ts b/bizmatch-server/src/models/main.model.ts index 972a7a3..a0aec0f 100644 --- a/bizmatch-server/src/models/main.model.ts +++ b/bizmatch-server/src/models/main.model.ts @@ -230,6 +230,12 @@ export interface GeoResult { state: string; state_code: string; } +export interface CityAndStateResult { + id: number; + name: string; + type: string; + state_code: string; +} export interface CountyResult { id: number; name: string; diff --git a/bizmatch/package.json b/bizmatch/package.json index a494ce5..0dbfa66 100644 --- a/bizmatch/package.json +++ b/bizmatch/package.json @@ -30,6 +30,7 @@ "@fortawesome/free-regular-svg-icons": "^6.5.2", "@fortawesome/free-solid-svg-icons": "^6.5.2", "@ng-select/ng-select": "^13.4.1", + "@ngneat/until-destroy": "^10.0.0", "@types/cropperjs": "^1.3.0", "@types/uuid": "^10.0.0", "browser-bunyan": "^1.8.0", @@ -69,4 +70,4 @@ "tailwindcss": "^3.4.4", "typescript": "~5.4.5" } -} \ No newline at end of file +} diff --git a/bizmatch/src/app/pages/home/home.component.html b/bizmatch/src/app/pages/home/home.component.html index 4bfe2a8..a669b44 100644 --- a/bizmatch/src/app/pages/home/home.component.html +++ b/bizmatch/src/app/pages/home/home.component.html @@ -77,18 +77,18 @@ @if(criteria){ -
-
-
+
+
+
@@ -96,29 +96,34 @@
-
- - @for (city of cities$ | async; track city.id) { - {{ city.city }} - {{ selectOptions.getStateInitials(city.state) }} - } - + +
+
+ + @for (city of cities$ | async; track city.id) { + {{ city.name }} - {{ city.state_code }} + } + +
-
-
+ @if (criteria.radius){ +
+