diff --git a/.vscode/settings.json b/.vscode/settings.json index 6835e94..73357d6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,8 @@ { - "exportall.config.folderListener": ["/src/app/core/pipes"], + "exportall.config.folderListener": [ + "/src/app/core/pipes", + "/src/app/core/services" + ], "[typescript]": { "editor.codeActionsOnSave": { "source.organizeImports": "explicit" diff --git a/src/app/core/services/index.ts b/src/app/core/services/index.ts index 7d0165f..01c60c2 100644 --- a/src/app/core/services/index.ts +++ b/src/app/core/services/index.ts @@ -1,2 +1,4 @@ export * from './auth.service'; export * from './jwt.service'; +export * from './luoghi.service'; +export * from './utils.service'; diff --git a/src/app/core/services/luoghi.service.ts b/src/app/core/services/luoghi.service.ts new file mode 100644 index 0000000..b5d8ba7 --- /dev/null +++ b/src/app/core/services/luoghi.service.ts @@ -0,0 +1,15 @@ +export class LuoghiService { + rankLuogo(luogo: any, query: string): number { + const q = query.toLowerCase(); + const nome = luogo.luogo.toLowerCase(); + + // 1. Match perfetto (inizia per query) + if (nome.startsWith(q)) return 0; + + // 2. Match contenuto ma non all'inizio + if (nome.includes(q)) return 1; + + // 3. Nessun match diretto → meno rilevante + return 2; + } +} diff --git a/src/app/modules/public/strutture-pubbliche/strutture-pubbliche.component.html b/src/app/modules/public/strutture-pubbliche/strutture-pubbliche.component.html index 478c2ef..ec7bcc6 100644 --- a/src/app/modules/public/strutture-pubbliche/strutture-pubbliche.component.html +++ b/src/app/modules/public/strutture-pubbliche/strutture-pubbliche.component.html @@ -71,6 +71,7 @@ appendTo="body" minLength="1" [delay]="500" + scrollHeight="237px" emptyMessage="Nessun luogo trovato" [showClear]="true" class="flex-auto lg:flex-1 lg:mt-0 w-full mr-0 lg:mr-1 text-surface-900 dark:text-surface-0" @@ -86,7 +87,7 @@ #item>
@if (luogo.tipo === 'comune') { -
{{ luogo.comune @@ -95,14 +96,14 @@ ? ' (' + luogo.siglaProvincia + ')' : '' }} - - {{ + + {{ luogo.codiceStato === 'ITA' - ? 'Comune' - : ('Stato estero' | titlecase) - }}{{ + ? 'Comune: ' + : ('Stato estero: ' | titlecase) + }}{{ luogo.codiceStato === 'ITA' - ? ': Italia → ' + + ? 'Italia → ' + luogo.regione + ' → ' + luogo.provincia + @@ -112,11 +113,11 @@ }}
} @else if (luogo.tipo === 'stato') { -
{{ luogo.stato }} - + {{ luogo.codiceStato === 'ITA' ? ('Stato' | titlecase) @@ -128,19 +129,19 @@ [icon]="faMapLocationDot">
{{ luogo.regione }} - - Regione - {{ ': Italia → ' + luogo.regione }} + + Regione: + {{'Italia → ' + luogo.regione }}
} @else if (luogo.tipo === 'provincia') { -
{{ luogo.provincia }} - - Provincia + + Provincia: {{ - ': Italia → ' + luogo.regione + ' → ' + luogo.provincia + 'Italia → ' + luogo.regione + ' → ' + luogo.provincia }}
} diff --git a/src/app/modules/public/strutture-pubbliche/strutture-pubbliche.component.ts b/src/app/modules/public/strutture-pubbliche/strutture-pubbliche.component.ts index 1c441e0..7a77f62 100644 --- a/src/app/modules/public/strutture-pubbliche/strutture-pubbliche.component.ts +++ b/src/app/modules/public/strutture-pubbliche/strutture-pubbliche.component.ts @@ -13,7 +13,9 @@ import { MapInfoWindow, MapMarker, } from '@angular/google-maps'; +import { StrutturePubblicheControllerFindManyStrutture$Params } from '@api/fn/strutture-pubbliche/strutture-pubbliche-controller-find-many-strutture'; import { LuogoRes, StrutturePubblicheResDto, TipoStruttura } from '@api/models'; +import { LuoghiService } from '@core/services'; import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; import { faCity, @@ -46,7 +48,6 @@ import { switchMap, tap, } from 'rxjs'; -import { StrutturePubblicheControllerFindManyStrutture$Params } from '../../../../api/fn/strutture-pubbliche/strutture-pubbliche-controller-find-many-strutture'; import { TableColumn } from '../../shared'; import { StrutturePubblicheService } from './strutture-pubbliche.service'; @@ -96,7 +97,7 @@ type State = CercaStruttureComponentState; InputIconModule, RatingModule, ], - providers: [RxState], + providers: [RxState, LuoghiService], templateUrl: './strutture-pubbliche.component.html', styleUrl: './strutture-pubbliche.component.scss', }) @@ -147,6 +148,7 @@ export class StrutturePubblicheComponent { constructor( private strutturePubblicheService: StrutturePubblicheService, + private luoghiService: LuoghiService, public state: RxState, private messageService: MessageService, ) { @@ -207,8 +209,8 @@ export class StrutturePubblicheComponent { // ⭐ ORDINAMENTO EURISTICO LOCALE const sorted = mapped.sort((a, b) => { - const rankA = this.rankLuogo(a, event.query); - const rankB = this.rankLuogo(b, event.query); + const rankA = this.luoghiService.rankLuogo(a, event.query); + const rankB = this.luoghiService.rankLuogo(b, event.query); if (rankA !== rankB) return rankA - rankB; return a.luogo!.localeCompare(b.luogo!); @@ -462,18 +464,4 @@ export class StrutturePubblicheComponent { this.cercaStruttureForm.controls['luogo'].setValue(null); } } - - private rankLuogo(luogo: any, query: string): number { - const q = query.toLowerCase(); - const nome = luogo.luogo.toLowerCase(); - - // 1. Match perfetto (inizia per query) - if (nome.startsWith(q)) return 0; - - // 2. Match contenuto ma non all'inizio - if (nome.includes(q)) return 1; - - // 3. Nessun match diretto → meno rilevante - return 2; - } }