aggiunta euristica di ordinamento luoghi

This commit is contained in:
Flavio Bontà 2025-11-14 14:54:16 +01:00
parent 954348a323
commit ae46d9adee
3 changed files with 51 additions and 15 deletions

View File

@ -1,4 +1,4 @@
{ {
"repoId": "bc5fa7a7-7313-4845-954c-7227b0073b63", "repoId": "bc5fa7a7-7313-4845-954c-7227b0073b63",
"lastSync": 0 "lastSync": 0
} }

View File

@ -213,7 +213,7 @@
responsiveLayout="stack" responsiveLayout="stack"
scrollHeight="400px" scrollHeight="400px"
[rowsPerPageOptions]="[10, 50, 100]" [rowsPerPageOptions]="[10, 50, 100]"
[globalFilterFields]="['struttura.nome']"> [globalFilterFields]="['struttura.nome', 'struttura.struttureTipiStrutture']">
<ng-template #caption> <ng-template #caption>
<div class="flex"> <div class="flex">
<p-iconfield iconPosition="left" <p-iconfield iconPosition="left"
@ -253,11 +253,20 @@
<tr> <tr>
<ng-container *ngFor="let col of cols" <ng-container *ngFor="let col of cols"
[ngSwitch]="col.field"> [ngSwitch]="col.field">
<td *ngSwitchCase="'struttura.struttureTipiStrutture'">
<div>
<ng-container *ngFor="let item of row.struttura.struttureTipiStrutture.split(',')">
<span class="font-light">{{ item.trim() }}</span><br />
</ng-container>
</div>
</td>
<td *ngSwitchCase="'struttura.nome'"> <td *ngSwitchCase="'struttura.nome'">
<p-rating *ngIf="row.struttura.stelline.length" <div>
[(ngModel)]="row.struttura.stelline.length" <p-rating *ngIf="row.struttura.stelline.length"
[readonly]="true" /> [(ngModel)]="row.struttura.stelline.length"
<span class="font-light"> <b>{{ row.struttura.nome }}</b></span> [readonly]="true" />
<p><b>{{ row.struttura.nome }}</b></p>
</div>
<div *ngIf="row.struttura.sitoWeb" <div *ngIf="row.struttura.sitoWeb"
class="mt-4 ont-light"> class="mt-4 ont-light">
<a class="cursor-pointer hover:underline text-primary-700" <a class="cursor-pointer hover:underline text-primary-700"

View File

@ -124,9 +124,11 @@ export class StrutturePubblicheComponent {
faHospital = faHospital; faHospital = faHospital;
struttureConCoords: StrutturePubblicheResDto[] = []; struttureConCoords: StrutturePubblicheResDto[] = [];
modelLuogo!: LuogoRes | null;
cols: TableColumn[] = [ cols: TableColumn[] = [
{
header: 'Tipologia',
field: 'struttura.struttureTipiStrutture',
},
{ {
header: 'Strutture', header: 'Strutture',
field: 'struttura.nome', field: 'struttura.nome',
@ -196,13 +198,24 @@ export class StrutturePubblicheComponent {
catchError((err) => { catchError((err) => {
return of(null); return of(null);
}), }),
map((res) => ({ map((res) => {
filteredLuoghiEsteso: const mapped =
res?.rows.map((res) => ({ res?.rows.map((r) => ({
...res, ...r,
dataKey: res.tipo + ' → ' + res.luogo, dataKey: r.tipo + ' → ' + r.luogo,
})) ?? [], })) ?? [];
})),
// ⭐ ORDINAMENTO EURISTICO LOCALE
const sorted = mapped.sort((a, b) => {
const rankA = this.rankLuogo(a, event.query);
const rankB = this.rankLuogo(b, event.query);
if (rankA !== rankB) return rankA - rankB;
return a.luogo!.localeCompare(b.luogo!);
});
return { filteredLuoghiEsteso: sorted };
}),
); );
this.state.connect(fetchCities$); this.state.connect(fetchCities$);
} }
@ -449,4 +462,18 @@ export class StrutturePubblicheComponent {
this.cercaStruttureForm.controls['luogo'].setValue(null); 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;
}
} }