mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Compare commits
No commits in common. "9a326733c79b1d0fc1544972de9607d09a181b86" and "b3e8155e43970d61736c838d8e93a0f0a295668c" have entirely different histories.
9a326733c7
...
b3e8155e43
11 changed files with 61 additions and 53 deletions
File diff suppressed because one or more lines are too long
|
|
@ -41,8 +41,7 @@ class MapController < ApplicationController
|
|||
distance_km = Geocoder::Calculations.distance_between(
|
||||
[_1[0], _1[1]], [_2[0], _2[1]], units: :km
|
||||
)
|
||||
|
||||
total_distance_meters += distance_km
|
||||
total_distance_meters += distance_km * 1000 # Convert km to meters
|
||||
end
|
||||
|
||||
total_distance_meters.round
|
||||
|
|
|
|||
|
|
@ -99,6 +99,24 @@ module ApplicationHelper
|
|||
current_user&.theme == 'light' ? 'light' : 'dark'
|
||||
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)
|
||||
'btn-active' if current_page?(link_path)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -122,16 +122,10 @@ export default class extends BaseController {
|
|||
},
|
||||
onAdd: (map) => {
|
||||
const div = L.DomUtil.create('div', 'leaflet-control-stats');
|
||||
let distance = parseInt(this.element.dataset.distance) || 0;
|
||||
const distance = this.element.dataset.distance || '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';
|
||||
div.innerHTML = `${distance.toFixed(1)} ${unit} | ${pointsNumber} points`;
|
||||
div.innerHTML = `${distance} ${unit} | ${pointsNumber} points`;
|
||||
div.style.backgroundColor = 'white';
|
||||
div.style.padding = '0 5px';
|
||||
div.style.marginRight = '5px';
|
||||
|
|
@ -232,13 +226,10 @@ export default class extends BaseController {
|
|||
this.initializeDrawControl();
|
||||
|
||||
// Preload areas
|
||||
fetchAndDrawAreas(this.areasLayer, this.apiKey);
|
||||
fetchAndDrawAreas(this.areasLayer, this.map, this.apiKey);
|
||||
|
||||
// Add right panel toggle
|
||||
this.addTogglePanelButton();
|
||||
|
||||
// Add visits buttons after calendar button to position them below
|
||||
this.visitsManager.addDrawerButton();
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
|
|
@ -1299,29 +1290,6 @@ 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() {
|
||||
if (this.rightPanel) {
|
||||
const panel = document.querySelector('.leaflet-right-panel');
|
||||
|
|
|
|||
|
|
@ -66,6 +66,20 @@ class Point < ApplicationRecord
|
|||
Country.containing_point(lon, lat)
|
||||
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
|
||||
|
||||
# rubocop:disable Metrics/MethodLength Metrics/AbcSize
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class Immich::ImportGeodata
|
|||
latitude: asset['exifInfo']['latitude'],
|
||||
longitude: asset['exifInfo']['longitude'],
|
||||
lonlat: "SRID=4326;POINT(#{asset['exifInfo']['longitude']} #{asset['exifInfo']['latitude']})",
|
||||
timestamp: Time.zone.parse(asset['exifInfo']['dateTimeOriginal']).to_i
|
||||
timestamp: Point.normalize_timestamp(asset['exifInfo']['dateTimeOriginal'])
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class Photoprism::ImportGeodata
|
|||
latitude: asset['Lat'],
|
||||
longitude: asset['Lng'],
|
||||
lonlat: "SRID=4326;POINT(#{asset['Lng']} #{asset['Lat']})",
|
||||
timestamp: Time.zone.parse(asset['TakenAt']).to_i
|
||||
timestamp: Point.normalize_timestamp(asset['TakenAt'])
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -18,13 +18,11 @@
|
|||
<%= countries_and_cities_stat_for_month(stat) %>
|
||||
</div>
|
||||
|
||||
<%= area_chart(
|
||||
stat.daily_distance.map { |day, distance_meters|
|
||||
[day, Stat.convert_distance(distance_meters, current_user.safe_settings.distance_unit).round(2)]
|
||||
},
|
||||
height: '200px',
|
||||
suffix: " #{current_user.safe_settings.distance_unit}",
|
||||
xtitle: 'Day',
|
||||
ytitle: 'Distance'
|
||||
) %>
|
||||
<canvas id="distance-chart-<%= stat.id %>"
|
||||
data-daily-distance="<%= stat.daily_distance %>"
|
||||
data-distance-type="monthly"
|
||||
data-title="<%= Date::MONTHNAMES[stat.month] %> <%= stat.year %>"
|
||||
data-y-axis-title="Distance"
|
||||
suffix: " <%= current_user.safe_settings.distance_unit %>",
|
||||
data-user-settings="<%= current_user.safe_settings.default_settings.to_json %>"></canvas>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<div class="stats stats-vertical lg:stats-horizontal shadow w-full bg-base-200">
|
||||
<div class="stat text-center">
|
||||
<div class="stat-value text-primary">
|
||||
<%= number_with_delimiter(current_user.total_distance.round) %> <%= current_user.safe_settings.distance_unit %>
|
||||
<%= number_with_delimiter(current_user.total_distance) %> <%= current_user.safe_settings.distance_unit %>
|
||||
</div>
|
||||
<div class="stat-title">Total distance</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -121,6 +121,17 @@ RSpec.describe Point, type: :model do
|
|||
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
|
||||
let(:point) do
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
it 'returns nil and logs error' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue