up source events

This commit is contained in:
Tykayn 2025-09-21 19:18:43 +02:00 committed by tykayn
parent 7971e48636
commit f18383fb9e
3 changed files with 489 additions and 27 deletions

View file

@ -152,10 +152,11 @@ class DemoMainResource:
<li><a href="/event?what=music" >Search Music Events</a></li>
<li><a href="/event?what=sport" >Search Sport Events</a></li>
</ul>
<p><a href="/demo/add" class="add-event-btn" style="display: block; text-align: center; margin-top: 15px; padding: 8px; background-color: #0078ff; color: white; border-radius: 4px; font-weight: bold;">+ Add New Event</a></p>
<p><a href="/demo/traffic" class="add-event-btn" style="display: block; text-align: center; margin-top: 15px; padding: 8px; background-color: #0078ff; color: white; border-radius: 4px; font-weight: bold;">+ Traffic event</a></p>
<p><a href="/demo/add" class="add-event-btn" style="display: block; text-align: center; margin-top: 15px; padding: 8px; background-color: #0078ff; color: white; border-radius: 4px; font-weight: bold;">+ Any Event</a></p>
<p style="text-align: center; margin-top: 10px;">
<a href="https://source.cipherbliss.com/tykayn/oedb-backend" title="View Source Code on Cipherbliss" style="font-size: 24px;">
<i class="fas fa-code-branch"></i>
<i class="fas fa-code-branch"></i> sources
</a>
</p>
</div>
@ -279,8 +280,8 @@ class DemoMainResource:
// Function to fetch events from the API
function fetchEvents() {
// Fetch events from the API - using default behavior to get currently active events
fetch('/event')
// Fetch events from the API - using the external API endpoint
fetch('https://api.openeventdatabase.org/event?')
.then(response => response.json())
.then(data => {
if (data.features && data.features.length > 0) {
@ -349,6 +350,10 @@ class DemoMainResource:
displayValue = `<pre style="margin: 0; white-space: pre-wrap;">${JSON.stringify(value, null, 2)}</pre>`;
} else if (typeof value === 'string' && value.startsWith('http')) {
displayValue = `<a href="${value}" >${value}</a>`;
} else if (typeof value === 'string' && (key === 'start' || key === 'stop' || key.includes('date') || key.includes('time'))) {
// For date fields, show both the original date and the relative time
const relativeTime = getRelativeTimeString(value);
displayValue = `${value} <span style="color: #666; font-style: italic;">(il y a ${relativeTime})</span>`;
} else {
displayValue = String(value);
}
@ -425,6 +430,35 @@ class DemoMainResource:
});
}
// Function to calculate relative time (e.g., "2 hours 30 minutes ago")
function getRelativeTimeString(dateString) {
if (!dateString) return '';
// Parse the date string
const date = new Date(dateString);
if (isNaN(date.getTime())) return dateString; // Return original if invalid
// Calculate time difference in milliseconds
const now = new Date();
const diffMs = now - date;
// Convert to hours and minutes
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
const diffMinutes = Math.floor((diffMs % (1000 * 60 * 60)) / (1000 * 60));
// Format the relative time string
let relativeTime = '';
if (diffHours > 0) {
relativeTime += `${diffHours} heure${diffHours > 1 ? 's' : ''}`;
}
if (diffMinutes > 0 || diffHours === 0) {
if (diffHours > 0) relativeTime += ' ';
relativeTime += `${diffMinutes} minute${diffMinutes > 1 ? 's' : ''}`;
}
return relativeTime || "à l instant";
}
// Function to fit map to events bounds
function fitMapToBounds(geojson) {
if (geojson.features.length === 0) return;