From ce88452be005d149cd05b34efe9561b27ca8f035 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Fri, 29 Nov 2024 11:52:57 +0100 Subject: [PATCH] Fix trips when Immich integration is not configured --- CHANGELOG.md | 10 +++++ app/javascript/controllers/maps_controller.js | 8 ++++ .../controllers/trips_controller.js | 39 ++++++++++++------- app/models/trip.rb | 2 + 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1373d0fe..a3eceee6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +# 0.18.1 - 2024-11-29 + +### Fixed + +- Fixed a bug where the trips interface was breaking when Immich integration is not configured. + +### Added + +- Flash messages are now being shown on the map when Immich integration is not configured. + # 0.18.0 - 2024-11-28 ## The Trips release diff --git a/app/javascript/controllers/maps_controller.js b/app/javascript/controllers/maps_controller.js index b00e6d16..20e058ee 100644 --- a/app/javascript/controllers/maps_controller.js +++ b/app/javascript/controllers/maps_controller.js @@ -137,6 +137,14 @@ export default class extends Controller { this.map.addControl(this.drawControl); } if (e.name === 'Photos') { + if (!this.userSettings.immich_url || !this.userSettings.immich_api_key) { + showFlashMessage( + 'error', + 'Immich integration is not configured. Please check your settings.' + ); + return; + } + const urlParams = new URLSearchParams(window.location.search); const startDate = urlParams.get('start_at')?.split('T')[0] || new Date().toISOString().split('T')[0]; const endDate = urlParams.get('end_at')?.split('T')[0] || new Date().toISOString().split('T')[0]; diff --git a/app/javascript/controllers/trips_controller.js b/app/javascript/controllers/trips_controller.js index 76ab87ba..00a2b497 100644 --- a/app/javascript/controllers/trips_controller.js +++ b/app/javascript/controllers/trips_controller.js @@ -11,6 +11,7 @@ import { esriWorldTopoMapLayer } from "../maps/layers" import { esriWorldImageryMapLayer } from "../maps/layers" import { esriWorldGrayCanvasMapLayer } from "../maps/layers" import { fetchAndDisplayPhotos } from '../maps/helpers'; +import { showFlashMessage } from "../maps/helpers"; export default class extends Controller { static targets = ["container", "startedAt", "endedAt"] @@ -77,22 +78,32 @@ export default class extends Controller { // Add event listener for layer changes this.map.on('overlayadd', (e) => { - if (e.name === 'Photos' && this.coordinates?.length > 0) { - const firstCoord = this.coordinates[0]; - const lastCoord = this.coordinates[this.coordinates.length - 1]; + if (e.name !== 'Photos') return; - const startDate = new Date(firstCoord[4] * 1000).toISOString().split('T')[0]; - const endDate = new Date(lastCoord[4] * 1000).toISOString().split('T')[0]; - - fetchAndDisplayPhotos({ - map: this.map, - photoMarkers: this.photoMarkers, - apiKey: this.apiKey, - startDate: startDate, - endDate: endDate, - userSettings: this.userSettings - }); + if (!this.userSettings.immich_url || !this.userSettings.immich_api_key) { + showFlashMessage( + 'error', + 'Immich integration is not configured. Please check your settings.' + ); + return; } + + if (!this.coordinates?.length) return; + + 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]; + + fetchAndDisplayPhotos({ + map: this.map, + photoMarkers: this.photoMarkers, + apiKey: this.apiKey, + startDate: startDate, + endDate: endDate, + userSettings: this.userSettings + }); }); // Add markers and route diff --git a/app/models/trip.rb b/app/models/trip.rb index fb67019c..52948bf4 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -18,6 +18,8 @@ class Trip < ApplicationRecord end def photos + return [] if user.settings['immich_url'].blank? || user.settings['immich_api_key'].blank? + immich_photos = Immich::RequestPhotos.new( user, start_date: started_at.to_date.to_s,