aggiunta euristica di ordinamento luoghi
This commit is contained in:
parent
954348a323
commit
ae46d9adee
@ -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'">
|
||||||
|
<div>
|
||||||
<p-rating *ngIf="row.struttura.stelline.length"
|
<p-rating *ngIf="row.struttura.stelline.length"
|
||||||
[(ngModel)]="row.struttura.stelline.length"
|
[(ngModel)]="row.struttura.stelline.length"
|
||||||
[readonly]="true" />
|
[readonly]="true" />
|
||||||
<span class="font-light"> <b>{{ row.struttura.nome }}</b></span>
|
<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"
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user