From 080cb4df489ce49c17fe2072530cf7bdef5fd902 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Sun, 5 Oct 2025 00:24:43 +0200 Subject: [PATCH] up --- frontend/src/app/pages/agenda/agenda.html | 9 +++- frontend/src/app/pages/agenda/agenda.ts | 38 ++++++++++++++-- frontend/src/app/pages/home/home.html | 8 +--- frontend/src/app/pages/home/home.ts | 4 +- .../src/app/shared/what-filter/what-filter.ts | 44 +++++++++++++++++++ 5 files changed, 90 insertions(+), 13 deletions(-) create mode 100644 frontend/src/app/shared/what-filter/what-filter.ts diff --git a/frontend/src/app/pages/agenda/agenda.html b/frontend/src/app/pages/agenda/agenda.html index a5a4d01..277b869 100644 --- a/frontend/src/app/pages/agenda/agenda.html +++ b/frontend/src/app/pages/agenda/agenda.html @@ -11,6 +11,13 @@

Agenda

{{calendarEvents.length}} évènements +
@for (group of groupedEvents; track group.dateKey) {
@@ -41,7 +48,7 @@
diff --git a/frontend/src/app/pages/agenda/agenda.ts b/frontend/src/app/pages/agenda/agenda.ts index 75b3ab4..c5b6f06 100644 --- a/frontend/src/app/pages/agenda/agenda.ts +++ b/frontend/src/app/pages/agenda/agenda.ts @@ -5,6 +5,7 @@ import { OedbApi } from '../../services/oedb-api'; import { EditForm } from '../../forms/edit-form/edit-form'; import { CalendarComponent, CalendarEvent } from './calendar/calendar'; import oedb from '../../../oedb-types'; +import { WhatFilterComponent } from '../../shared/what-filter/what-filter'; interface OedbEvent { id: string; @@ -27,7 +28,7 @@ interface OedbEvent { @Component({ selector: 'app-agenda', standalone: true, - imports: [CommonModule, FormsModule, EditForm, CalendarComponent], + imports: [CommonModule, FormsModule, EditForm, CalendarComponent, WhatFilterComponent], templateUrl: './agenda.html', styleUrl: './agenda.scss' }) @@ -35,11 +36,15 @@ export class Agenda implements OnInit { private oedbApi = inject(OedbApi); events: OedbEvent[] = []; + filteredEvents: OedbEvent[] = []; calendarEvents: CalendarEvent[] = []; + filteredCalendarEvents: CalendarEvent[] = []; selectedEvent: OedbEvent | null = null; isLoading = false; groupedEvents: Array<{ dateKey: string; date: Date; items: OedbEvent[] }> = []; + availableWhatTypes: string[] = []; + selectedWhatFilter = ''; ngOnInit() { this.loadEvents(); @@ -61,14 +66,15 @@ export class Agenda implements OnInit { this.oedbApi.getEvents(params).subscribe((response: any) => { this.events = Array.isArray(response?.features) ? response.features : []; - this.convertToCalendarEvents(); - this.buildGroupedEvents(); + this.updateAvailableWhatTypes(); + this.applyWhatFilter(); this.isLoading = false; }); } convertToCalendarEvents() { - this.calendarEvents = this.events.map(event => { + const source = this.filteredEvents.length ? this.filteredEvents : this.events; + this.calendarEvents = source.map(event => { const startDate = this.parseEventDate(event.properties.start || event.properties.when); const endDate = event.properties.stop ? this.parseEventDate(event.properties.stop) : null; @@ -83,6 +89,7 @@ export class Agenda implements OnInit { properties: event.properties }; }); + this.filteredCalendarEvents = this.calendarEvents; } parseEventDate(dateString: string | undefined): Date { @@ -132,6 +139,29 @@ export class Agenda implements OnInit { } // Sidebar helpers + updateAvailableWhatTypes() { + const set = new Set(); + for (const e of this.events) { + const w = e?.properties?.what; + if (w) set.add(w); + } + this.availableWhatTypes = Array.from(set).sort(); + } + + applyWhatFilter() { + if (this.selectedWhatFilter) { + this.filteredEvents = this.events.filter(e => e?.properties?.what === this.selectedWhatFilter); + } else { + this.filteredEvents = [...this.events]; + } + this.convertToCalendarEvents(); + this.buildGroupedEvents(); + } + + onWhatFilterChange(value: string) { + this.selectedWhatFilter = value || ''; + this.applyWhatFilter(); + } private getEventStartDate(ev: OedbEvent): Date { const ds = ev.properties.start || ev.properties.when; return this.parseEventDate(ds); diff --git a/frontend/src/app/pages/home/home.html b/frontend/src/app/pages/home/home.html index ae4d237..a29457c 100644 --- a/frontend/src/app/pages/home/home.html +++ b/frontend/src/app/pages/home/home.html @@ -52,13 +52,7 @@
- - +
diff --git a/frontend/src/app/pages/home/home.ts b/frontend/src/app/pages/home/home.ts index bd50e86..dabb1df 100644 --- a/frontend/src/app/pages/home/home.ts +++ b/frontend/src/app/pages/home/home.ts @@ -8,6 +8,7 @@ import { OedbApi } from '../../services/oedb-api'; import { UnlocatedEvents } from '../../shared/unlocated-events/unlocated-events'; import { OsmAuth } from '../../services/osm-auth'; import { Osm } from '../../forms/osm/osm'; +import { WhatFilterComponent } from '../../shared/what-filter/what-filter'; @Component({ selector: 'app-home', standalone: true, @@ -17,7 +18,8 @@ import { Osm } from '../../forms/osm/osm'; UnlocatedEvents, EditForm, Osm, - FormsModule + FormsModule, + WhatFilterComponent ], templateUrl: './home.html', styleUrl: './home.scss' diff --git a/frontend/src/app/shared/what-filter/what-filter.ts b/frontend/src/app/shared/what-filter/what-filter.ts new file mode 100644 index 0000000..babd262 --- /dev/null +++ b/frontend/src/app/shared/what-filter/what-filter.ts @@ -0,0 +1,44 @@ +import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +@Component({ + selector: 'app-what-filter', + standalone: true, + imports: [CommonModule, FormsModule], + template: ` +
+ + +
+ `, + styles: [` + .what-filter { display: flex; flex-direction: column; gap: 6px; } + .filter-label { font-size: 0.9rem; color: #374151; } + .input { padding: 8px 10px; border: 1px solid #dee2e6; border-radius: 4px; font-size: 0.9rem; } + .input:focus { outline: none; border-color: #3498db; } + `] +}) +export class WhatFilterComponent { + @Input() available: string[] = []; + @Input() label: string | null = null; + + @Input() set selected(val: string) { + this.internalSelected = val || ''; + } + get selected(): string { return this.internalSelected; } + + @Output() selectedChange = new EventEmitter(); + + internalSelected = ''; + + onSelectedChange(value: string) { + this.internalSelected = value || ''; + this.selectedChange.emit(this.internalSelected); + } +} + +