Fix trips when Immich integration is not configured

This commit is contained in:
Eugene Burmakin 2024-11-29 11:52:57 +01:00
parent d0c66b68ac
commit ce88452be0
4 changed files with 45 additions and 14 deletions

View file

@ -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

View file

@ -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];

View file

@ -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

View file

@ -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,