Fix photos fetching with trip dates

This commit is contained in:
Eugene Burmakin 2025-01-24 15:35:35 +01:00
parent 9c102c1de8
commit 6e9c981329
3 changed files with 33 additions and 7 deletions

View file

@ -43,7 +43,6 @@ export default class extends Controller {
// Add event listener for coordinates updates
this.element.addEventListener('coordinates-updated', (event) => {
console.log("Coordinates updated:", event.detail.coordinates)
this.updateMapWithCoordinates(event.detail.coordinates)
})
}
@ -84,6 +83,15 @@ export default class extends Controller {
this.map.on('overlayadd', (e) => {
if (e.name !== 'Photos') return;
const startedAt = this.element.dataset.started_at;
const endedAt = this.element.dataset.ended_at;
console.log('Dataset values:', {
startedAt,
endedAt,
path: this.element.dataset.path
});
if ((!this.userSettings.immich_url || !this.userSettings.immich_api_key) && (!this.userSettings.photoprism_url || !this.userSettings.photoprism_api_key)) {
showFlashMessage(
'error',
@ -92,13 +100,26 @@ export default class extends Controller {
return;
}
if (!this.coordinates?.length) return;
// Try to get dates from coordinates first, then fall back to path data
let startDate, endDate;
const firstCoord = this.coordinates[0];
const lastCoord = this.coordinates[this.coordinates.length - 1];
const startDate = new Date(firstCoord[4] * 1000).toISOString().split('T')[0];
const endDate = new Date(lastCoord[4] * 1000).toISOString().split('T')[0];
if (this.coordinates?.length) {
const firstCoord = this.coordinates[0];
const lastCoord = this.coordinates[this.coordinates.length - 1];
startDate = new Date(firstCoord[4] * 1000).toISOString().split('T')[0];
endDate = new Date(lastCoord[4] * 1000).toISOString().split('T')[0];
} else if (startedAt && endedAt) {
// Parse the dates and format them correctly
startDate = new Date(startedAt).toISOString().split('T')[0];
endDate = new Date(endedAt).toISOString().split('T')[0];
} else {
console.log('No date range available for photos');
showFlashMessage(
'error',
'No date range available for photos. Please ensure the trip has start and end dates.'
);
return;
}
fetchAndDisplayPhotos({
map: this.map,
@ -174,6 +195,7 @@ export default class extends Controller {
const popupContent = createPopupContent(coord, this.timezone, this.distanceUnit)
marker.bindPopup(popupContent)
marker.addTo(this.polylinesLayer)
})
}

View file

@ -21,6 +21,8 @@
data-api_key="<%= current_user.api_key %>"
data-user_settings="<%= current_user.settings.to_json %>"
data-path="<%= trip.path.to_json %>"
data-started_at="<%= trip.started_at %>"
data-ended_at="<%= trip.ended_at %>"
data-timezone="<%= Rails.configuration.time_zone %>">
</div>
</div>

View file

@ -25,6 +25,8 @@
data-api_key="<%= current_user.api_key %>"
data-user_settings="<%= current_user.settings.to_json %>"
data-path="<%= @trip.path.to_json %>"
data-started_at="<%= @trip.started_at %>"
data-ended_at="<%= @trip.ended_at %>"
data-timezone="<%= Rails.configuration.time_zone %>">
<div data-trips-target="container" class="h-[25rem] w-full min-h-screen">
</div>