mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Compare commits
5 commits
b3e8155e43
...
9a326733c7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a326733c7 | ||
|
|
0295d3f2a0 | ||
|
|
b7e5296235 | ||
|
|
f4687a101c | ||
|
|
042696caeb |
11 changed files with 53 additions and 61 deletions
File diff suppressed because one or more lines are too long
|
|
@ -41,7 +41,8 @@ class MapController < ApplicationController
|
||||||
distance_km = Geocoder::Calculations.distance_between(
|
distance_km = Geocoder::Calculations.distance_between(
|
||||||
[_1[0], _1[1]], [_2[0], _2[1]], units: :km
|
[_1[0], _1[1]], [_2[0], _2[1]], units: :km
|
||||||
)
|
)
|
||||||
total_distance_meters += distance_km * 1000 # Convert km to meters
|
|
||||||
|
total_distance_meters += distance_km
|
||||||
end
|
end
|
||||||
|
|
||||||
total_distance_meters.round
|
total_distance_meters.round
|
||||||
|
|
|
||||||
|
|
@ -99,24 +99,6 @@ module ApplicationHelper
|
||||||
current_user&.theme == 'light' ? 'light' : 'dark'
|
current_user&.theme == 'light' ? 'light' : 'dark'
|
||||||
end
|
end
|
||||||
|
|
||||||
def sidebar_distance(distance_meters)
|
|
||||||
return unless distance_meters
|
|
||||||
|
|
||||||
# Convert from stored meters to user's preferred unit for display
|
|
||||||
user_unit = current_user.safe_settings.distance_unit
|
|
||||||
converted_distance = Stat.convert_distance(distance_meters, user_unit)
|
|
||||||
"#{converted_distance.round(2)} #{user_unit}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def sidebar_points(points)
|
|
||||||
return unless points
|
|
||||||
|
|
||||||
points_number = points.size
|
|
||||||
points_pluralized = pluralize(points_number, 'point')
|
|
||||||
|
|
||||||
"(#{points_pluralized})"
|
|
||||||
end
|
|
||||||
|
|
||||||
def active_class?(link_path)
|
def active_class?(link_path)
|
||||||
'btn-active' if current_page?(link_path)
|
'btn-active' if current_page?(link_path)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -122,10 +122,16 @@ export default class extends BaseController {
|
||||||
},
|
},
|
||||||
onAdd: (map) => {
|
onAdd: (map) => {
|
||||||
const div = L.DomUtil.create('div', 'leaflet-control-stats');
|
const div = L.DomUtil.create('div', 'leaflet-control-stats');
|
||||||
const distance = this.element.dataset.distance || '0';
|
let distance = parseInt(this.element.dataset.distance) || 0;
|
||||||
const pointsNumber = this.element.dataset.points_number || '0';
|
const pointsNumber = this.element.dataset.points_number || '0';
|
||||||
|
|
||||||
|
// Convert distance to miles if user prefers miles (assuming backend sends km)
|
||||||
|
if (this.distanceUnit === 'mi') {
|
||||||
|
distance = distance * 0.621371; // km to miles conversion
|
||||||
|
}
|
||||||
|
|
||||||
const unit = this.distanceUnit === 'mi' ? 'mi' : 'km';
|
const unit = this.distanceUnit === 'mi' ? 'mi' : 'km';
|
||||||
div.innerHTML = `${distance} ${unit} | ${pointsNumber} points`;
|
div.innerHTML = `${distance.toFixed(1)} ${unit} | ${pointsNumber} points`;
|
||||||
div.style.backgroundColor = 'white';
|
div.style.backgroundColor = 'white';
|
||||||
div.style.padding = '0 5px';
|
div.style.padding = '0 5px';
|
||||||
div.style.marginRight = '5px';
|
div.style.marginRight = '5px';
|
||||||
|
|
@ -226,10 +232,13 @@ export default class extends BaseController {
|
||||||
this.initializeDrawControl();
|
this.initializeDrawControl();
|
||||||
|
|
||||||
// Preload areas
|
// Preload areas
|
||||||
fetchAndDrawAreas(this.areasLayer, this.map, this.apiKey);
|
fetchAndDrawAreas(this.areasLayer, this.apiKey);
|
||||||
|
|
||||||
// Add right panel toggle
|
// Add right panel toggle
|
||||||
this.addTogglePanelButton();
|
this.addTogglePanelButton();
|
||||||
|
|
||||||
|
// Add visits buttons after calendar button to position them below
|
||||||
|
this.visitsManager.addDrawerButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {
|
disconnect() {
|
||||||
|
|
@ -1290,6 +1299,29 @@ export default class extends BaseController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initializeLayersFromSettings() {
|
||||||
|
// Initialize layer visibility based on user settings or defaults
|
||||||
|
// This method sets up the initial state of overlay layers
|
||||||
|
|
||||||
|
// Note: Don't automatically add layers to map here - let the layer control and user preferences handle it
|
||||||
|
// The layer control will manage which layers are visible based on user interaction
|
||||||
|
|
||||||
|
// Initialize photos layer if user wants it visible
|
||||||
|
if (this.userSettings.photos_enabled) {
|
||||||
|
fetchAndDisplayPhotos(this.photoMarkers, this.apiKey, this.userSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize fog of war if enabled in settings
|
||||||
|
if (this.userSettings.fog_of_war_enabled) {
|
||||||
|
this.updateFog(this.markers, this.clearFogRadius, this.fogLinethreshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize visits manager functionality
|
||||||
|
if (this.visitsManager && typeof this.visitsManager.fetchAndDisplayVisits === 'function') {
|
||||||
|
this.visitsManager.fetchAndDisplayVisits();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
toggleRightPanel() {
|
toggleRightPanel() {
|
||||||
if (this.rightPanel) {
|
if (this.rightPanel) {
|
||||||
const panel = document.querySelector('.leaflet-right-panel');
|
const panel = document.querySelector('.leaflet-right-panel');
|
||||||
|
|
|
||||||
|
|
@ -66,20 +66,6 @@ class Point < ApplicationRecord
|
||||||
Country.containing_point(lon, lat)
|
Country.containing_point(lon, lat)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.normalize_timestamp(timestamp)
|
|
||||||
case timestamp
|
|
||||||
when Integer
|
|
||||||
timestamp
|
|
||||||
when String, Numeric, DateTime, Time
|
|
||||||
timestamp.to_i
|
|
||||||
when nil
|
|
||||||
raise ArgumentError, 'Timestamp cannot be nil'
|
|
||||||
else
|
|
||||||
raise ArgumentError, "Cannot convert timestamp to integer: #{timestamp.class}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# rubocop:disable Metrics/MethodLength Metrics/AbcSize
|
# rubocop:disable Metrics/MethodLength Metrics/AbcSize
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ class Immich::ImportGeodata
|
||||||
latitude: asset['exifInfo']['latitude'],
|
latitude: asset['exifInfo']['latitude'],
|
||||||
longitude: asset['exifInfo']['longitude'],
|
longitude: asset['exifInfo']['longitude'],
|
||||||
lonlat: "SRID=4326;POINT(#{asset['exifInfo']['longitude']} #{asset['exifInfo']['latitude']})",
|
lonlat: "SRID=4326;POINT(#{asset['exifInfo']['longitude']} #{asset['exifInfo']['latitude']})",
|
||||||
timestamp: Point.normalize_timestamp(asset['exifInfo']['dateTimeOriginal'])
|
timestamp: Time.zone.parse(asset['exifInfo']['dateTimeOriginal']).to_i
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ class Photoprism::ImportGeodata
|
||||||
latitude: asset['Lat'],
|
latitude: asset['Lat'],
|
||||||
longitude: asset['Lng'],
|
longitude: asset['Lng'],
|
||||||
lonlat: "SRID=4326;POINT(#{asset['Lng']} #{asset['Lat']})",
|
lonlat: "SRID=4326;POINT(#{asset['Lng']} #{asset['Lat']})",
|
||||||
timestamp: Point.normalize_timestamp(asset['TakenAt'])
|
timestamp: Time.zone.parse(asset['TakenAt']).to_i
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,13 @@
|
||||||
<%= countries_and_cities_stat_for_month(stat) %>
|
<%= countries_and_cities_stat_for_month(stat) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<canvas id="distance-chart-<%= stat.id %>"
|
<%= area_chart(
|
||||||
data-daily-distance="<%= stat.daily_distance %>"
|
stat.daily_distance.map { |day, distance_meters|
|
||||||
data-distance-type="monthly"
|
[day, Stat.convert_distance(distance_meters, current_user.safe_settings.distance_unit).round(2)]
|
||||||
data-title="<%= Date::MONTHNAMES[stat.month] %> <%= stat.year %>"
|
},
|
||||||
data-y-axis-title="Distance"
|
height: '200px',
|
||||||
suffix: " <%= current_user.safe_settings.distance_unit %>",
|
suffix: " #{current_user.safe_settings.distance_unit}",
|
||||||
data-user-settings="<%= current_user.safe_settings.default_settings.to_json %>"></canvas>
|
xtitle: 'Day',
|
||||||
|
ytitle: 'Distance'
|
||||||
|
) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<div class="stats stats-vertical lg:stats-horizontal shadow w-full bg-base-200">
|
<div class="stats stats-vertical lg:stats-horizontal shadow w-full bg-base-200">
|
||||||
<div class="stat text-center">
|
<div class="stat text-center">
|
||||||
<div class="stat-value text-primary">
|
<div class="stat-value text-primary">
|
||||||
<%= number_with_delimiter(current_user.total_distance) %> <%= current_user.safe_settings.distance_unit %>
|
<%= number_with_delimiter(current_user.total_distance.round) %> <%= current_user.safe_settings.distance_unit %>
|
||||||
</div>
|
</div>
|
||||||
<div class="stat-title">Total distance</div>
|
<div class="stat-title">Total distance</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -121,17 +121,6 @@ RSpec.describe Point, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#recalculate_track' do
|
|
||||||
let(:point) { create(:point, track: track) }
|
|
||||||
let(:track) { create(:track) }
|
|
||||||
|
|
||||||
it 'recalculates the track' do
|
|
||||||
expect(track).to receive(:recalculate_path_and_distance!)
|
|
||||||
|
|
||||||
point.update(lonlat: 'POINT(-79.85581250721961 15.854775993302411)')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#trigger_incremental_track_generation' do
|
describe '#trigger_incremental_track_generation' do
|
||||||
let(:point) do
|
let(:point) do
|
||||||
create(:point, track: track, import_id: nil, timestamp: 1.hour.ago.to_i, reverse_geocoded_at: 1.hour.ago)
|
create(:point, track: track, import_id: nil, timestamp: 1.hour.ago.to_i, reverse_geocoded_at: 1.hour.ago)
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ RSpec.describe Tracks::TrackBuilder do
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(Track).to receive(:save!).and_return(false)
|
allow_any_instance_of(Track).to receive(:save).and_return(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns nil and logs error' do
|
it 'returns nil and logs error' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue