44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { Component, inject } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { OedbApi } from '../../services/oedb-api';
|
|
import { AllEvents } from '../../maps/all-events/all-events';
|
|
|
|
@Component({
|
|
selector: 'app-events-docs',
|
|
imports: [CommonModule, AllEvents],
|
|
templateUrl: './events-docs.html',
|
|
styleUrl: './events-docs.scss'
|
|
})
|
|
export class EventsDocs {
|
|
private api = inject(OedbApi);
|
|
|
|
features: Array<any> = [];
|
|
counts: Array<{ what: string, count: number }> = [];
|
|
filtered: Array<any> = [];
|
|
selected: any | null = null;
|
|
|
|
ngOnInit() {
|
|
// Charger 1000 events récents
|
|
this.api.getEvents({ when: 'NEXT30DAYS', limit: 1000 }).subscribe((events: any) => {
|
|
this.features = Array.isArray(events?.features) ? events.features : [];
|
|
this.buildCounts();
|
|
this.filtered = this.features;
|
|
});
|
|
}
|
|
|
|
buildCounts() {
|
|
const map = new Map<string, number>();
|
|
for (const f of this.features) {
|
|
const w = (f?.properties?.what || '').trim();
|
|
if (!w) continue;
|
|
map.set(w, (map.get(w) || 0) + 1);
|
|
}
|
|
this.counts = Array.from(map.entries()).sort((a,b) => b[1]-a[1]).map(([what, count]) => ({ what, count }));
|
|
}
|
|
|
|
filterByWhat(what: string) {
|
|
this.filtered = this.features.filter(f => String(f?.properties?.what || '').startsWith(what));
|
|
}
|
|
}
|
|
|
|
|