mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Compare commits
1 commit
9d0730532d
...
dd4fc77e5f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd4fc77e5f |
67 changed files with 362 additions and 2276 deletions
|
|
@ -1 +1 @@
|
||||||
0.37.2
|
0.37.1
|
||||||
|
|
|
||||||
23
CHANGELOG.md
23
CHANGELOG.md
|
|
@ -4,29 +4,6 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
# [0.37.3] - Unreleased
|
|
||||||
|
|
||||||
## Fixed
|
|
||||||
|
|
||||||
- Routes are now being drawn the very same way on Map V2 as in Map V1. #2132 #2086
|
|
||||||
|
|
||||||
## Changed
|
|
||||||
|
|
||||||
- Map V2 points loading is significantly sped up.
|
|
||||||
- Points size on Map V2 was reduced to prevent overlapping.
|
|
||||||
|
|
||||||
# [0.37.2] - 2026-01-04
|
|
||||||
|
|
||||||
## Fixed
|
|
||||||
|
|
||||||
- Months are now correctly ordered (Jan-Dec) in the year-end digest chart instead of being sorted alphabetically.
|
|
||||||
- Time spent in a country and city is now calculated correctly for the year-end digest email. #2104
|
|
||||||
- Updated Trix to fix a XSS vulnerability. #2102
|
|
||||||
- Map v2 UI no longer blocks when Immich/Photoprism integration has a bad URL or is unreachable. Added 10-second timeout to photo API requests and improved error handling to prevent UI freezing during initial load. #2085
|
|
||||||
|
|
||||||
## Added
|
|
||||||
- In Map v2 settings, you can now enable map to be rendered as a globe.
|
|
||||||
|
|
||||||
# [0.37.1] - 2025-12-30
|
# [0.37.1] - 2025-12-30
|
||||||
|
|
||||||
## Fixed
|
## Fixed
|
||||||
|
|
|
||||||
41
CLAUDE.md
41
CLAUDE.md
|
|
@ -238,47 +238,6 @@ bundle exec bundle-audit # Dependency security
|
||||||
- Respect expiration settings and disable sharing when expired
|
- Respect expiration settings and disable sharing when expired
|
||||||
- Only expose minimal necessary data in public sharing contexts
|
- Only expose minimal necessary data in public sharing contexts
|
||||||
|
|
||||||
### Route Drawing Implementation (Critical)
|
|
||||||
|
|
||||||
⚠️ **IMPORTANT: Unit Mismatch in Route Splitting Logic**
|
|
||||||
|
|
||||||
Both Map v1 (Leaflet) and Map v2 (MapLibre) contain an **intentional unit mismatch** in route drawing that must be preserved for consistency:
|
|
||||||
|
|
||||||
**The Issue**:
|
|
||||||
- `haversineDistance()` function returns distance in **kilometers** (e.g., 0.5 km)
|
|
||||||
- Route splitting threshold is stored and compared as **meters** (e.g., 500)
|
|
||||||
- The code compares them directly: `0.5 > 500` = always **FALSE**
|
|
||||||
|
|
||||||
**Result**:
|
|
||||||
- The distance threshold (`meters_between_routes` setting) is **effectively disabled**
|
|
||||||
- Routes only split on **time gaps** (default: 60 minutes between points)
|
|
||||||
- This creates longer, more continuous routes that users expect
|
|
||||||
|
|
||||||
**Code Locations**:
|
|
||||||
- **Map v1**: `app/javascript/maps/polylines.js:390`
|
|
||||||
- Uses `haversineDistance()` from `maps/helpers.js` (returns km)
|
|
||||||
- Compares to `distanceThresholdMeters` variable (value in meters)
|
|
||||||
|
|
||||||
- **Map v2**: `app/javascript/maps_maplibre/layers/routes_layer.js:82-104`
|
|
||||||
- Has built-in `haversineDistance()` method (returns km)
|
|
||||||
- Intentionally skips `/1000` conversion to replicate v1 behavior
|
|
||||||
- Comment explains this is matching v1's unit mismatch
|
|
||||||
|
|
||||||
**Critical Rules**:
|
|
||||||
1. ❌ **DO NOT "fix" the unit mismatch** - this would break user expectations
|
|
||||||
2. ✅ **Keep both versions synchronized** - they must behave identically
|
|
||||||
3. ✅ **Document any changes** - route drawing changes affect all users
|
|
||||||
4. ⚠️ If you ever fix this bug:
|
|
||||||
- You MUST update both v1 and v2 simultaneously
|
|
||||||
- You MUST migrate user settings (multiply existing values by 1000 or divide by 1000 depending on direction)
|
|
||||||
- You MUST communicate the breaking change to users
|
|
||||||
|
|
||||||
**Additional Route Drawing Details**:
|
|
||||||
- **Time threshold**: 60 minutes (default) - actually functional
|
|
||||||
- **Distance threshold**: 500 meters (default) - currently non-functional due to unit bug
|
|
||||||
- **Sorting**: Map v2 sorts points by timestamp client-side; v1 relies on backend ASC order
|
|
||||||
- **API ordering**: Map v2 must request `order: 'asc'` to match v1's chronological data flow
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
- **Main Branch**: `master`
|
- **Main Branch**: `master`
|
||||||
|
|
|
||||||
3
Gemfile
3
Gemfile
|
|
@ -12,7 +12,6 @@ gem 'aws-sdk-kms', '~> 1.96.0', require: false
|
||||||
gem 'aws-sdk-s3', '~> 1.177.0', require: false
|
gem 'aws-sdk-s3', '~> 1.177.0', require: false
|
||||||
gem 'bootsnap', require: false
|
gem 'bootsnap', require: false
|
||||||
gem 'chartkick'
|
gem 'chartkick'
|
||||||
gem 'connection_pool', '< 3' # Pin to 2.x - version 3.0+ has breaking API changes with Rails RedisCacheStore
|
|
||||||
gem 'data_migrate'
|
gem 'data_migrate'
|
||||||
gem 'devise'
|
gem 'devise'
|
||||||
gem 'foreman'
|
gem 'foreman'
|
||||||
|
|
@ -49,7 +48,7 @@ gem 'rswag-ui'
|
||||||
gem 'rubyzip', '~> 3.2'
|
gem 'rubyzip', '~> 3.2'
|
||||||
gem 'sentry-rails', '>= 5.27.0'
|
gem 'sentry-rails', '>= 5.27.0'
|
||||||
gem 'sentry-ruby'
|
gem 'sentry-ruby'
|
||||||
gem 'sidekiq', '8.0.10' # Pin to 8.0.x - sidekiq 8.1+ requires connection_pool 3.0+ which has breaking changes with Rails
|
gem 'sidekiq', '>= 8.0.5'
|
||||||
gem 'sidekiq-cron', '>= 2.3.1'
|
gem 'sidekiq-cron', '>= 2.3.1'
|
||||||
gem 'sidekiq-limit_fetch'
|
gem 'sidekiq-limit_fetch'
|
||||||
gem 'sprockets-rails'
|
gem 'sprockets-rails'
|
||||||
|
|
|
||||||
48
Gemfile.lock
48
Gemfile.lock
|
|
@ -109,7 +109,7 @@ GEM
|
||||||
base64 (0.3.0)
|
base64 (0.3.0)
|
||||||
bcrypt (3.1.20)
|
bcrypt (3.1.20)
|
||||||
benchmark (0.5.0)
|
benchmark (0.5.0)
|
||||||
bigdecimal (4.0.1)
|
bigdecimal (3.3.1)
|
||||||
bindata (2.5.1)
|
bindata (2.5.1)
|
||||||
bootsnap (1.18.6)
|
bootsnap (1.18.6)
|
||||||
msgpack (~> 1.2)
|
msgpack (~> 1.2)
|
||||||
|
|
@ -129,10 +129,10 @@ GEM
|
||||||
rack-test (>= 0.6.3)
|
rack-test (>= 0.6.3)
|
||||||
regexp_parser (>= 1.5, < 3.0)
|
regexp_parser (>= 1.5, < 3.0)
|
||||||
xpath (~> 3.2)
|
xpath (~> 3.2)
|
||||||
chartkick (5.2.1)
|
chartkick (5.2.0)
|
||||||
chunky_png (1.4.0)
|
chunky_png (1.4.0)
|
||||||
coderay (1.1.3)
|
coderay (1.1.3)
|
||||||
concurrent-ruby (1.3.6)
|
concurrent-ruby (1.3.5)
|
||||||
connection_pool (2.5.5)
|
connection_pool (2.5.5)
|
||||||
crack (1.0.1)
|
crack (1.0.1)
|
||||||
bigdecimal
|
bigdecimal
|
||||||
|
|
@ -215,7 +215,7 @@ GEM
|
||||||
csv
|
csv
|
||||||
mini_mime (>= 1.0.0)
|
mini_mime (>= 1.0.0)
|
||||||
multi_xml (>= 0.5.2)
|
multi_xml (>= 0.5.2)
|
||||||
i18n (1.14.8)
|
i18n (1.14.7)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
importmap-rails (2.2.2)
|
importmap-rails (2.2.2)
|
||||||
actionpack (>= 6.0.0)
|
actionpack (>= 6.0.0)
|
||||||
|
|
@ -227,7 +227,7 @@ GEM
|
||||||
rdoc (>= 4.0.0)
|
rdoc (>= 4.0.0)
|
||||||
reline (>= 0.4.2)
|
reline (>= 0.4.2)
|
||||||
jmespath (1.6.2)
|
jmespath (1.6.2)
|
||||||
json (2.18.0)
|
json (2.15.0)
|
||||||
json-jwt (1.17.0)
|
json-jwt (1.17.0)
|
||||||
activesupport (>= 4.2)
|
activesupport (>= 4.2)
|
||||||
aes_key_wrap
|
aes_key_wrap
|
||||||
|
|
@ -273,12 +273,11 @@ GEM
|
||||||
method_source (1.1.0)
|
method_source (1.1.0)
|
||||||
mini_mime (1.1.5)
|
mini_mime (1.1.5)
|
||||||
mini_portile2 (2.8.9)
|
mini_portile2 (2.8.9)
|
||||||
minitest (6.0.1)
|
minitest (5.26.2)
|
||||||
prism (~> 1.5)
|
|
||||||
msgpack (1.7.3)
|
msgpack (1.7.3)
|
||||||
multi_json (1.15.0)
|
multi_json (1.15.0)
|
||||||
multi_xml (0.8.0)
|
multi_xml (0.7.1)
|
||||||
bigdecimal (>= 3.1, < 5)
|
bigdecimal (~> 3.1)
|
||||||
net-http (0.6.0)
|
net-http (0.6.0)
|
||||||
uri
|
uri
|
||||||
net-imap (0.5.12)
|
net-imap (0.5.12)
|
||||||
|
|
@ -357,7 +356,7 @@ GEM
|
||||||
json
|
json
|
||||||
yaml
|
yaml
|
||||||
parallel (1.27.0)
|
parallel (1.27.0)
|
||||||
parser (3.3.10.0)
|
parser (3.3.9.0)
|
||||||
ast (~> 2.4.1)
|
ast (~> 2.4.1)
|
||||||
racc
|
racc
|
||||||
patience_diff (1.2.0)
|
patience_diff (1.2.0)
|
||||||
|
|
@ -370,7 +369,7 @@ GEM
|
||||||
pp (0.6.3)
|
pp (0.6.3)
|
||||||
prettyprint
|
prettyprint
|
||||||
prettyprint (0.2.0)
|
prettyprint (0.2.0)
|
||||||
prism (1.7.0)
|
prism (1.5.1)
|
||||||
prometheus_exporter (2.2.0)
|
prometheus_exporter (2.2.0)
|
||||||
webrick
|
webrick
|
||||||
pry (0.15.2)
|
pry (0.15.2)
|
||||||
|
|
@ -463,7 +462,7 @@ GEM
|
||||||
tsort
|
tsort
|
||||||
redis (5.4.1)
|
redis (5.4.1)
|
||||||
redis-client (>= 0.22.0)
|
redis-client (>= 0.22.0)
|
||||||
redis-client (0.26.2)
|
redis-client (0.26.1)
|
||||||
connection_pool
|
connection_pool
|
||||||
regexp_parser (2.11.3)
|
regexp_parser (2.11.3)
|
||||||
reline (0.6.3)
|
reline (0.6.3)
|
||||||
|
|
@ -513,7 +512,7 @@ GEM
|
||||||
rswag-ui (2.17.0)
|
rswag-ui (2.17.0)
|
||||||
actionpack (>= 5.2, < 8.2)
|
actionpack (>= 5.2, < 8.2)
|
||||||
railties (>= 5.2, < 8.2)
|
railties (>= 5.2, < 8.2)
|
||||||
rubocop (1.82.1)
|
rubocop (1.81.1)
|
||||||
json (~> 2.3)
|
json (~> 2.3)
|
||||||
language_server-protocol (~> 3.17.0.2)
|
language_server-protocol (~> 3.17.0.2)
|
||||||
lint_roller (~> 1.1.0)
|
lint_roller (~> 1.1.0)
|
||||||
|
|
@ -521,20 +520,20 @@ GEM
|
||||||
parser (>= 3.3.0.2)
|
parser (>= 3.3.0.2)
|
||||||
rainbow (>= 2.2.2, < 4.0)
|
rainbow (>= 2.2.2, < 4.0)
|
||||||
regexp_parser (>= 2.9.3, < 3.0)
|
regexp_parser (>= 2.9.3, < 3.0)
|
||||||
rubocop-ast (>= 1.48.0, < 2.0)
|
rubocop-ast (>= 1.47.1, < 2.0)
|
||||||
ruby-progressbar (~> 1.7)
|
ruby-progressbar (~> 1.7)
|
||||||
unicode-display_width (>= 2.4.0, < 4.0)
|
unicode-display_width (>= 2.4.0, < 4.0)
|
||||||
rubocop-ast (1.49.0)
|
rubocop-ast (1.47.1)
|
||||||
parser (>= 3.3.7.2)
|
parser (>= 3.3.7.2)
|
||||||
prism (~> 1.7)
|
prism (~> 1.4)
|
||||||
rubocop-rails (2.34.2)
|
rubocop-rails (2.33.4)
|
||||||
activesupport (>= 4.2.0)
|
activesupport (>= 4.2.0)
|
||||||
lint_roller (~> 1.1)
|
lint_roller (~> 1.1)
|
||||||
rack (>= 1.1)
|
rack (>= 1.1)
|
||||||
rubocop (>= 1.75.0, < 2.0)
|
rubocop (>= 1.75.0, < 2.0)
|
||||||
rubocop-ast (>= 1.44.0, < 2.0)
|
rubocop-ast (>= 1.44.0, < 2.0)
|
||||||
ruby-progressbar (1.13.0)
|
ruby-progressbar (1.13.0)
|
||||||
rubyzip (3.2.2)
|
rubyzip (3.2.0)
|
||||||
securerandom (0.4.1)
|
securerandom (0.4.1)
|
||||||
selenium-webdriver (4.35.0)
|
selenium-webdriver (4.35.0)
|
||||||
base64 (~> 0.2)
|
base64 (~> 0.2)
|
||||||
|
|
@ -542,15 +541,15 @@ GEM
|
||||||
rexml (~> 3.2, >= 3.2.5)
|
rexml (~> 3.2, >= 3.2.5)
|
||||||
rubyzip (>= 1.2.2, < 4.0)
|
rubyzip (>= 1.2.2, < 4.0)
|
||||||
websocket (~> 1.0)
|
websocket (~> 1.0)
|
||||||
sentry-rails (6.2.0)
|
sentry-rails (6.1.1)
|
||||||
railties (>= 5.2.0)
|
railties (>= 5.2.0)
|
||||||
sentry-ruby (~> 6.2.0)
|
sentry-ruby (~> 6.1.1)
|
||||||
sentry-ruby (6.2.0)
|
sentry-ruby (6.1.1)
|
||||||
bigdecimal
|
bigdecimal
|
||||||
concurrent-ruby (~> 1.0, >= 1.0.2)
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||||
shoulda-matchers (6.5.0)
|
shoulda-matchers (6.5.0)
|
||||||
activesupport (>= 5.2.0)
|
activesupport (>= 5.2.0)
|
||||||
sidekiq (8.0.10)
|
sidekiq (8.0.8)
|
||||||
connection_pool (>= 2.5.0)
|
connection_pool (>= 2.5.0)
|
||||||
json (>= 2.9.0)
|
json (>= 2.9.0)
|
||||||
logger (>= 1.6.2)
|
logger (>= 1.6.2)
|
||||||
|
|
@ -614,7 +613,7 @@ GEM
|
||||||
unicode (0.4.4.5)
|
unicode (0.4.4.5)
|
||||||
unicode-display_width (3.2.0)
|
unicode-display_width (3.2.0)
|
||||||
unicode-emoji (~> 4.1)
|
unicode-emoji (~> 4.1)
|
||||||
unicode-emoji (4.2.0)
|
unicode-emoji (4.1.0)
|
||||||
uri (1.1.1)
|
uri (1.1.1)
|
||||||
useragent (0.16.11)
|
useragent (0.16.11)
|
||||||
validate_url (1.0.15)
|
validate_url (1.0.15)
|
||||||
|
|
@ -663,7 +662,6 @@ DEPENDENCIES
|
||||||
bundler-audit
|
bundler-audit
|
||||||
capybara
|
capybara
|
||||||
chartkick
|
chartkick
|
||||||
connection_pool (< 3)
|
|
||||||
data_migrate
|
data_migrate
|
||||||
database_consistency (>= 2.0.5)
|
database_consistency (>= 2.0.5)
|
||||||
debug
|
debug
|
||||||
|
|
@ -713,7 +711,7 @@ DEPENDENCIES
|
||||||
sentry-rails (>= 5.27.0)
|
sentry-rails (>= 5.27.0)
|
||||||
sentry-ruby
|
sentry-ruby
|
||||||
shoulda-matchers
|
shoulda-matchers
|
||||||
sidekiq (= 8.0.10)
|
sidekiq (>= 8.0.5)
|
||||||
sidekiq-cron (>= 2.3.1)
|
sidekiq-cron (>= 2.3.1)
|
||||||
sidekiq-limit_fetch
|
sidekiq-limit_fetch
|
||||||
simplecov
|
simplecov
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@ module Api
|
||||||
include_untagged = tag_ids.include?('untagged')
|
include_untagged = tag_ids.include?('untagged')
|
||||||
|
|
||||||
if numeric_tag_ids.any? && include_untagged
|
if numeric_tag_ids.any? && include_untagged
|
||||||
# Both tagged and untagged: use OR logic to preserve eager loading
|
# Both tagged and untagged: return union (OR logic)
|
||||||
tagged_ids = current_api_user.places.with_tags(numeric_tag_ids).pluck(:id)
|
tagged = current_api_user.places.includes(:tags, :visits).with_tags(numeric_tag_ids)
|
||||||
untagged_ids = current_api_user.places.without_tags.pluck(:id)
|
untagged = current_api_user.places.includes(:tags, :visits).without_tags
|
||||||
combined_ids = (tagged_ids + untagged_ids).uniq
|
@places = Place.from("(#{tagged.to_sql} UNION #{untagged.to_sql}) AS places")
|
||||||
@places = current_api_user.places.includes(:tags, :visits).where(id: combined_ids)
|
.includes(:tags, :visits)
|
||||||
elsif numeric_tag_ids.any?
|
elsif numeric_tag_ids.any?
|
||||||
# Only tagged places with ANY of the selected tags (OR logic)
|
# Only tagged places with ANY of the selected tags (OR logic)
|
||||||
@places = @places.with_tags(numeric_tag_ids)
|
@places = @places.with_tags(numeric_tag_ids)
|
||||||
|
|
@ -30,16 +30,6 @@ module Api
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Support optional pagination (backward compatible - returns all if no page param)
|
|
||||||
if params[:page].present?
|
|
||||||
per_page = [params[:per_page]&.to_i || 100, 500].min
|
|
||||||
@places = @places.page(params[:page]).per(per_page)
|
|
||||||
|
|
||||||
response.set_header('X-Current-Page', @places.current_page.to_s)
|
|
||||||
response.set_header('X-Total-Pages', @places.total_pages.to_s)
|
|
||||||
response.set_header('X-Total-Count', @places.total_count.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
render json: @places.map { |place| serialize_place(place) }
|
render json: @places.map { |place| serialize_place(place) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -130,7 +120,7 @@ module Api
|
||||||
note: place.note,
|
note: place.note,
|
||||||
icon: place.tags.first&.icon,
|
icon: place.tags.first&.icon,
|
||||||
color: place.tags.first&.color,
|
color: place.tags.first&.color,
|
||||||
visits_count: place.visits.size,
|
visits_count: place.visits.count,
|
||||||
created_at: place.created_at,
|
created_at: place.created_at,
|
||||||
tags: place.tags.map do |tag|
|
tags: place.tags.map do |tag|
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class Api::V1::SettingsController < ApiController
|
||||||
:preferred_map_layer, :points_rendering_mode, :live_map_enabled,
|
:preferred_map_layer, :points_rendering_mode, :live_map_enabled,
|
||||||
:immich_url, :immich_api_key, :photoprism_url, :photoprism_api_key,
|
:immich_url, :immich_api_key, :photoprism_url, :photoprism_api_key,
|
||||||
:speed_colored_routes, :speed_color_scale, :fog_of_war_threshold,
|
:speed_colored_routes, :speed_color_scale, :fog_of_war_threshold,
|
||||||
:maps_v2_style, :maps_maplibre_style, :globe_projection,
|
:maps_v2_style, :maps_maplibre_style,
|
||||||
enabled_map_layers: []
|
enabled_map_layers: []
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,6 @@
|
||||||
class Api::V1::VisitsController < ApiController
|
class Api::V1::VisitsController < ApiController
|
||||||
def index
|
def index
|
||||||
visits = Visits::Finder.new(current_api_user, params).call
|
visits = Visits::Finder.new(current_api_user, params).call
|
||||||
|
|
||||||
# Support optional pagination (backward compatible - returns all if no page param)
|
|
||||||
if params[:page].present?
|
|
||||||
per_page = [params[:per_page]&.to_i || 100, 500].min
|
|
||||||
visits = visits.page(params[:page]).per(per_page)
|
|
||||||
|
|
||||||
response.set_header('X-Current-Page', visits.current_page.to_s)
|
|
||||||
response.set_header('X-Total-Pages', visits.total_pages.to_s)
|
|
||||||
response.set_header('X-Total-Count', visits.total_count.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
serialized_visits = visits.map do |visit|
|
serialized_visits = visits.map do |visit|
|
||||||
Api::VisitSerializer.new(visit).call
|
Api::VisitSerializer.new(visit).call
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -41,31 +41,19 @@ class Map::LeafletController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_distance
|
def calculate_distance
|
||||||
return 0 if @points.count(:id) < 2
|
return 0 if @coordinates.size < 2
|
||||||
|
|
||||||
# Use PostGIS window function for efficient distance calculation
|
total_distance = 0
|
||||||
# This is O(1) database operation vs O(n) Ruby iteration
|
|
||||||
sql = <<~SQL.squish
|
|
||||||
SELECT COALESCE(SUM(distance_m) / 1000.0, 0) as total_km FROM (
|
|
||||||
SELECT ST_Distance(
|
|
||||||
lonlat::geography,
|
|
||||||
LAG(lonlat::geography) OVER (ORDER BY timestamp)
|
|
||||||
) as distance_m
|
|
||||||
FROM points
|
|
||||||
WHERE user_id = :user_id
|
|
||||||
AND timestamp >= :start_at
|
|
||||||
AND timestamp <= :end_at
|
|
||||||
) distances
|
|
||||||
SQL
|
|
||||||
|
|
||||||
result = Point.connection.select_value(
|
@coordinates.each_cons(2) do
|
||||||
ActiveRecord::Base.sanitize_sql_array([
|
distance_km = Geocoder::Calculations.distance_between(
|
||||||
sql,
|
[_1[0], _1[1]], [_2[0], _2[1]], units: :km
|
||||||
{ user_id: current_user.id, start_at: start_at, end_at: end_at }
|
|
||||||
])
|
|
||||||
)
|
)
|
||||||
|
|
||||||
result&.to_f&.round || 0
|
total_distance += distance_km
|
||||||
|
end
|
||||||
|
|
||||||
|
total_distance.round
|
||||||
end
|
end
|
||||||
|
|
||||||
def parsed_start_at
|
def parsed_start_at
|
||||||
|
|
|
||||||
|
|
@ -80,14 +80,8 @@ class StatsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_stats
|
def build_stats
|
||||||
# Select only needed columns - avoid loading large JSONB fields
|
current_user.stats.group_by(&:year).transform_values do |stats|
|
||||||
# daily_distance and h3_hex_ids are never needed on index page
|
stats.sort_by(&:updated_at).reverse
|
||||||
columns = [:id, :year, :month, :distance, :updated_at, :user_id]
|
end.sort.reverse
|
||||||
columns << :toponyms if DawarichSettings.reverse_geocoding_enabled?
|
|
||||||
|
|
||||||
current_user.stats
|
|
||||||
.select(columns)
|
|
||||||
.order(year: :desc, updated_at: :desc)
|
|
||||||
.group_by(&:year)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ class Users::DigestsController < ApplicationController
|
||||||
|
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
before_action :authenticate_active_user!, only: [:create]
|
before_action :authenticate_active_user!, only: [:create]
|
||||||
before_action :set_digest, only: %i[show destroy]
|
before_action :set_digest, only: [:show]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@digests = current_user.digests.yearly.order(year: :desc)
|
@digests = current_user.digests.yearly.order(year: :desc)
|
||||||
|
|
@ -30,12 +30,6 @@ class Users::DigestsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
|
||||||
year = @digest.year
|
|
||||||
@digest.destroy!
|
|
||||||
redirect_to users_digests_path, notice: "Year-end digest for #{year} has been deleted", status: :see_other
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_digest
|
def set_digest
|
||||||
|
|
@ -48,7 +42,7 @@ class Users::DigestsController < ApplicationController
|
||||||
tracked_years = current_user.stats.select(:year).distinct.pluck(:year)
|
tracked_years = current_user.stats.select(:year).distinct.pluck(:year)
|
||||||
existing_digests = current_user.digests.yearly.pluck(:year)
|
existing_digests = current_user.digests.yearly.pluck(:year)
|
||||||
|
|
||||||
(tracked_years - existing_digests - [Time.current.year]).sort.reverse
|
(tracked_years - existing_digests).sort.reverse
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_year?(year)
|
def valid_year?(year)
|
||||||
|
|
|
||||||
|
|
@ -2,27 +2,6 @@
|
||||||
|
|
||||||
module Users
|
module Users
|
||||||
module DigestsHelper
|
module DigestsHelper
|
||||||
PROGRESS_COLORS = %w[
|
|
||||||
progress-primary progress-secondary progress-accent
|
|
||||||
progress-info progress-success progress-warning
|
|
||||||
].freeze
|
|
||||||
|
|
||||||
def progress_color_for_index(index)
|
|
||||||
PROGRESS_COLORS[index % PROGRESS_COLORS.length]
|
|
||||||
end
|
|
||||||
|
|
||||||
def city_progress_value(city_count, max_cities)
|
|
||||||
return 0 unless max_cities&.positive?
|
|
||||||
|
|
||||||
(city_count.to_f / max_cities * 100).round
|
|
||||||
end
|
|
||||||
|
|
||||||
def max_cities_count(toponyms)
|
|
||||||
return 0 if toponyms.blank?
|
|
||||||
|
|
||||||
toponyms.map { |country| country['cities']&.length || 0 }.max
|
|
||||||
end
|
|
||||||
|
|
||||||
def distance_with_unit(distance_meters, unit)
|
def distance_with_unit(distance_meters, unit)
|
||||||
value = Users::Digest.convert_distance(distance_meters, unit).round
|
value = Users::Digest.convert_distance(distance_meters, unit).round
|
||||||
"#{number_with_delimiter(value)} #{unit}"
|
"#{number_with_delimiter(value)} #{unit}"
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ export class AreaSelectionManager {
|
||||||
* Start area selection mode
|
* Start area selection mode
|
||||||
*/
|
*/
|
||||||
async startSelectArea() {
|
async startSelectArea() {
|
||||||
|
console.log('[Maps V2] Starting area selection mode')
|
||||||
|
|
||||||
// Initialize selection layer if not exists
|
// Initialize selection layer if not exists
|
||||||
if (!this.selectionLayer) {
|
if (!this.selectionLayer) {
|
||||||
this.selectionLayer = new SelectionLayer(this.map, {
|
this.selectionLayer = new SelectionLayer(this.map, {
|
||||||
|
|
@ -34,6 +36,8 @@ export class AreaSelectionManager {
|
||||||
type: 'FeatureCollection',
|
type: 'FeatureCollection',
|
||||||
features: []
|
features: []
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log('[Maps V2] Selection layer initialized')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize selected points layer if not exists
|
// Initialize selected points layer if not exists
|
||||||
|
|
@ -46,6 +50,8 @@ export class AreaSelectionManager {
|
||||||
type: 'FeatureCollection',
|
type: 'FeatureCollection',
|
||||||
features: []
|
features: []
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log('[Maps V2] Selected points layer initialized')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable selection mode
|
// Enable selection mode
|
||||||
|
|
@ -70,6 +76,8 @@ export class AreaSelectionManager {
|
||||||
* Handle area selection completion
|
* Handle area selection completion
|
||||||
*/
|
*/
|
||||||
async handleAreaSelected(bounds) {
|
async handleAreaSelected(bounds) {
|
||||||
|
console.log('[Maps V2] Area selected:', bounds)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Toast.info('Fetching data in selected area...')
|
Toast.info('Fetching data in selected area...')
|
||||||
|
|
||||||
|
|
@ -290,6 +298,7 @@ export class AreaSelectionManager {
|
||||||
Toast.success('Visit declined')
|
Toast.success('Visit declined')
|
||||||
await this.refreshSelectedVisits()
|
await this.refreshSelectedVisits()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('[Maps V2] Failed to decline visit:', error)
|
||||||
Toast.error('Failed to decline visit')
|
Toast.error('Failed to decline visit')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -318,6 +327,7 @@ export class AreaSelectionManager {
|
||||||
this.replaceVisitsWithMerged(visitIds, mergedVisit)
|
this.replaceVisitsWithMerged(visitIds, mergedVisit)
|
||||||
this.updateBulkActions()
|
this.updateBulkActions()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('[Maps V2] Failed to merge visits:', error)
|
||||||
Toast.error('Failed to merge visits')
|
Toast.error('Failed to merge visits')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -336,6 +346,7 @@ export class AreaSelectionManager {
|
||||||
this.selectedVisitIds.clear()
|
this.selectedVisitIds.clear()
|
||||||
await this.refreshSelectedVisits()
|
await this.refreshSelectedVisits()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('[Maps V2] Failed to confirm visits:', error)
|
||||||
Toast.error('Failed to confirm visits')
|
Toast.error('Failed to confirm visits')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -440,6 +451,8 @@ export class AreaSelectionManager {
|
||||||
* Cancel area selection
|
* Cancel area selection
|
||||||
*/
|
*/
|
||||||
cancelAreaSelection() {
|
cancelAreaSelection() {
|
||||||
|
console.log('[Maps V2] Cancelling area selection')
|
||||||
|
|
||||||
if (this.selectionLayer) {
|
if (this.selectionLayer) {
|
||||||
this.selectionLayer.disableSelectionMode()
|
this.selectionLayer.disableSelectionMode()
|
||||||
this.selectionLayer.clearSelection()
|
this.selectionLayer.clearSelection()
|
||||||
|
|
@ -502,10 +515,14 @@ export class AreaSelectionManager {
|
||||||
|
|
||||||
if (!confirmed) return
|
if (!confirmed) return
|
||||||
|
|
||||||
|
console.log('[Maps V2] Deleting', pointIds.length, 'points')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Toast.info('Deleting points...')
|
Toast.info('Deleting points...')
|
||||||
const result = await this.api.bulkDeletePoints(pointIds)
|
const result = await this.api.bulkDeletePoints(pointIds)
|
||||||
|
|
||||||
|
console.log('[Maps V2] Deleted', result.count, 'points')
|
||||||
|
|
||||||
this.cancelAreaSelection()
|
this.cancelAreaSelection()
|
||||||
|
|
||||||
await this.controller.loadMapData({
|
await this.controller.loadMapData({
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export class DataLoader {
|
||||||
performanceMonitor.mark('transform-geojson')
|
performanceMonitor.mark('transform-geojson')
|
||||||
data.pointsGeoJSON = pointsToGeoJSON(data.points)
|
data.pointsGeoJSON = pointsToGeoJSON(data.points)
|
||||||
data.routesGeoJSON = RoutesLayer.pointsToRoutes(data.points, {
|
data.routesGeoJSON = RoutesLayer.pointsToRoutes(data.points, {
|
||||||
distanceThresholdMeters: this.settings.metersBetweenRoutes || 500,
|
distanceThresholdMeters: this.settings.metersBetweenRoutes || 1000,
|
||||||
timeThresholdMinutes: this.settings.minutesBetweenRoutes || 60
|
timeThresholdMinutes: this.settings.minutesBetweenRoutes || 60
|
||||||
})
|
})
|
||||||
performanceMonitor.measure('transform-geojson')
|
performanceMonitor.measure('transform-geojson')
|
||||||
|
|
@ -56,36 +56,22 @@ export class DataLoader {
|
||||||
}
|
}
|
||||||
data.visitsGeoJSON = this.visitsToGeoJSON(data.visits)
|
data.visitsGeoJSON = this.visitsToGeoJSON(data.visits)
|
||||||
|
|
||||||
// Fetch photos - only if photos layer is enabled and integration is configured
|
// Fetch photos
|
||||||
// Skip API call if photos are disabled to avoid blocking on failed integrations
|
|
||||||
if (this.settings.photosEnabled) {
|
|
||||||
try {
|
try {
|
||||||
console.log('[Photos] Fetching photos from:', startDate, 'to', endDate)
|
console.log('[Photos] Fetching photos from:', startDate, 'to', endDate)
|
||||||
// Use Promise.race to enforce a client-side timeout
|
data.photos = await this.api.fetchPhotos({
|
||||||
const photosPromise = this.api.fetchPhotos({
|
|
||||||
start_at: startDate,
|
start_at: startDate,
|
||||||
end_at: endDate
|
end_at: endDate
|
||||||
})
|
})
|
||||||
const timeoutPromise = new Promise((_, reject) =>
|
|
||||||
setTimeout(() => reject(new Error('Photo fetch timeout')), 15000) // 15 second timeout
|
|
||||||
)
|
|
||||||
|
|
||||||
data.photos = await Promise.race([photosPromise, timeoutPromise])
|
|
||||||
console.log('[Photos] Fetched photos:', data.photos.length, 'photos')
|
console.log('[Photos] Fetched photos:', data.photos.length, 'photos')
|
||||||
console.log('[Photos] Sample photo:', data.photos[0])
|
console.log('[Photos] Sample photo:', data.photos[0])
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('[Photos] Failed to fetch photos (non-blocking):', error.message)
|
console.error('[Photos] Failed to fetch photos:', error)
|
||||||
data.photos = []
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log('[Photos] Photos layer disabled, skipping fetch')
|
|
||||||
data.photos = []
|
data.photos = []
|
||||||
}
|
}
|
||||||
data.photosGeoJSON = this.photosToGeoJSON(data.photos)
|
data.photosGeoJSON = this.photosToGeoJSON(data.photos)
|
||||||
console.log('[Photos] Converted to GeoJSON:', data.photosGeoJSON.features.length, 'features')
|
console.log('[Photos] Converted to GeoJSON:', data.photosGeoJSON.features.length, 'features')
|
||||||
if (data.photosGeoJSON.features.length > 0) {
|
|
||||||
console.log('[Photos] Sample feature:', data.photosGeoJSON.features[0])
|
console.log('[Photos] Sample feature:', data.photosGeoJSON.features[0])
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch areas
|
// Fetch areas
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
import { formatTimestamp } from 'maps_maplibre/utils/geojson_transformers'
|
import { formatTimestamp } from 'maps_maplibre/utils/geojson_transformers'
|
||||||
import { formatDistance, formatSpeed, minutesToDaysHoursMinutes } from 'maps/helpers'
|
|
||||||
import maplibregl from 'maplibre-gl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles map interaction events (clicks, info display)
|
* Handles map interaction events (clicks, info display)
|
||||||
|
|
@ -9,8 +7,6 @@ export class EventHandlers {
|
||||||
constructor(map, controller) {
|
constructor(map, controller) {
|
||||||
this.map = map
|
this.map = map
|
||||||
this.controller = controller
|
this.controller = controller
|
||||||
this.selectedRouteFeature = null
|
|
||||||
this.routeMarkers = [] // Store start/end markers for routes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -130,242 +126,4 @@ export class EventHandlers {
|
||||||
|
|
||||||
this.controller.showInfo(properties.name || 'Area', content, actions)
|
this.controller.showInfo(properties.name || 'Area', content, actions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle route hover
|
|
||||||
*/
|
|
||||||
handleRouteHover(e) {
|
|
||||||
const clickedFeature = e.features[0]
|
|
||||||
if (!clickedFeature) return
|
|
||||||
|
|
||||||
const routesLayer = this.controller.layerManager.getLayer('routes')
|
|
||||||
if (!routesLayer) return
|
|
||||||
|
|
||||||
// Get the full feature from source (not the clipped tile version)
|
|
||||||
// Fallback to clipped feature if full feature not found
|
|
||||||
const fullFeature = this._getFullRouteFeature(clickedFeature.properties) || clickedFeature
|
|
||||||
|
|
||||||
// If a route is selected and we're hovering over a different route, show both
|
|
||||||
if (this.selectedRouteFeature) {
|
|
||||||
// Check if we're hovering over the same route that's selected
|
|
||||||
const isSameRoute = this._areFeaturesSame(this.selectedRouteFeature, fullFeature)
|
|
||||||
|
|
||||||
if (!isSameRoute) {
|
|
||||||
// Show both selected and hovered routes
|
|
||||||
const features = [this.selectedRouteFeature, fullFeature]
|
|
||||||
routesLayer.setHoverRoute({
|
|
||||||
type: 'FeatureCollection',
|
|
||||||
features: features
|
|
||||||
})
|
|
||||||
// Create markers for both routes
|
|
||||||
this._createRouteMarkers(features)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// No selection, just show hovered route
|
|
||||||
routesLayer.setHoverRoute(fullFeature)
|
|
||||||
// Create markers for hovered route
|
|
||||||
this._createRouteMarkers(fullFeature)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle route mouse leave
|
|
||||||
*/
|
|
||||||
handleRouteMouseLeave(e) {
|
|
||||||
const routesLayer = this.controller.layerManager.getLayer('routes')
|
|
||||||
if (!routesLayer) return
|
|
||||||
|
|
||||||
// If a route is selected, keep showing only the selected route
|
|
||||||
if (this.selectedRouteFeature) {
|
|
||||||
routesLayer.setHoverRoute(this.selectedRouteFeature)
|
|
||||||
// Keep markers for selected route only
|
|
||||||
this._createRouteMarkers(this.selectedRouteFeature)
|
|
||||||
} else {
|
|
||||||
// No selection, clear hover and markers
|
|
||||||
routesLayer.setHoverRoute(null)
|
|
||||||
this._clearRouteMarkers()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get full route feature from source data (not clipped tile version)
|
|
||||||
* MapLibre returns clipped geometries from queryRenderedFeatures()
|
|
||||||
* We need the full geometry from the source for proper highlighting
|
|
||||||
*/
|
|
||||||
_getFullRouteFeature(properties) {
|
|
||||||
const routesLayer = this.controller.layerManager.getLayer('routes')
|
|
||||||
if (!routesLayer) return null
|
|
||||||
|
|
||||||
const source = this.map.getSource(routesLayer.sourceId)
|
|
||||||
if (!source) return null
|
|
||||||
|
|
||||||
// Get the source data (GeoJSON FeatureCollection)
|
|
||||||
// Try multiple ways to access the data
|
|
||||||
let sourceData = null
|
|
||||||
|
|
||||||
// Method 1: Internal _data property (most common)
|
|
||||||
if (source._data) {
|
|
||||||
sourceData = source._data
|
|
||||||
}
|
|
||||||
// Method 2: Serialize and deserialize (fallback)
|
|
||||||
else if (source.serialize) {
|
|
||||||
const serialized = source.serialize()
|
|
||||||
sourceData = serialized.data
|
|
||||||
}
|
|
||||||
// Method 3: Use cached data from layer
|
|
||||||
else if (routesLayer.data) {
|
|
||||||
sourceData = routesLayer.data
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sourceData || !sourceData.features) return null
|
|
||||||
|
|
||||||
// Find the matching feature by properties
|
|
||||||
return sourceData.features.find(feature => {
|
|
||||||
const props = feature.properties
|
|
||||||
return props.startTime === properties.startTime &&
|
|
||||||
props.endTime === properties.endTime &&
|
|
||||||
props.pointCount === properties.pointCount
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compare two features to see if they represent the same route
|
|
||||||
*/
|
|
||||||
_areFeaturesSame(feature1, feature2) {
|
|
||||||
if (!feature1 || !feature2) return false
|
|
||||||
|
|
||||||
// Compare by start/end times and point count (unique enough for routes)
|
|
||||||
const props1 = feature1.properties
|
|
||||||
const props2 = feature2.properties
|
|
||||||
|
|
||||||
return props1.startTime === props2.startTime &&
|
|
||||||
props1.endTime === props2.endTime &&
|
|
||||||
props1.pointCount === props2.pointCount
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create start/end markers for route(s)
|
|
||||||
* @param {Array|Object} features - Single feature or array of features
|
|
||||||
*/
|
|
||||||
_createRouteMarkers(features) {
|
|
||||||
// Clear existing markers first
|
|
||||||
this._clearRouteMarkers()
|
|
||||||
|
|
||||||
// Ensure we have an array
|
|
||||||
const featureArray = Array.isArray(features) ? features : [features]
|
|
||||||
|
|
||||||
featureArray.forEach(feature => {
|
|
||||||
if (!feature || !feature.geometry || feature.geometry.type !== 'LineString') return
|
|
||||||
|
|
||||||
const coords = feature.geometry.coordinates
|
|
||||||
if (coords.length < 2) return
|
|
||||||
|
|
||||||
// Start marker (🚥)
|
|
||||||
const startCoord = coords[0]
|
|
||||||
const startMarker = this._createEmojiMarker('🚥')
|
|
||||||
startMarker.setLngLat(startCoord).addTo(this.map)
|
|
||||||
this.routeMarkers.push(startMarker)
|
|
||||||
|
|
||||||
// End marker (🏁)
|
|
||||||
const endCoord = coords[coords.length - 1]
|
|
||||||
const endMarker = this._createEmojiMarker('🏁')
|
|
||||||
endMarker.setLngLat(endCoord).addTo(this.map)
|
|
||||||
this.routeMarkers.push(endMarker)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an emoji marker
|
|
||||||
* @param {String} emoji - The emoji to display
|
|
||||||
* @returns {maplibregl.Marker}
|
|
||||||
*/
|
|
||||||
_createEmojiMarker(emoji) {
|
|
||||||
const el = document.createElement('div')
|
|
||||||
el.className = 'route-emoji-marker'
|
|
||||||
el.textContent = emoji
|
|
||||||
el.style.fontSize = '24px'
|
|
||||||
el.style.cursor = 'pointer'
|
|
||||||
el.style.userSelect = 'none'
|
|
||||||
|
|
||||||
return new maplibregl.Marker({ element: el, anchor: 'center' })
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear all route markers
|
|
||||||
*/
|
|
||||||
_clearRouteMarkers() {
|
|
||||||
this.routeMarkers.forEach(marker => marker.remove())
|
|
||||||
this.routeMarkers = []
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle route click
|
|
||||||
*/
|
|
||||||
handleRouteClick(e) {
|
|
||||||
const clickedFeature = e.features[0]
|
|
||||||
const properties = clickedFeature.properties
|
|
||||||
|
|
||||||
// Get the full feature from source (not the clipped tile version)
|
|
||||||
// Fallback to clipped feature if full feature not found
|
|
||||||
const fullFeature = this._getFullRouteFeature(properties) || clickedFeature
|
|
||||||
|
|
||||||
// Store selected route (use full feature)
|
|
||||||
this.selectedRouteFeature = fullFeature
|
|
||||||
|
|
||||||
// Update hover layer to show selected route
|
|
||||||
const routesLayer = this.controller.layerManager.getLayer('routes')
|
|
||||||
if (routesLayer) {
|
|
||||||
routesLayer.setHoverRoute(fullFeature)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create markers for selected route
|
|
||||||
this._createRouteMarkers(fullFeature)
|
|
||||||
|
|
||||||
// Calculate duration
|
|
||||||
const durationSeconds = properties.endTime - properties.startTime
|
|
||||||
const durationMinutes = Math.floor(durationSeconds / 60)
|
|
||||||
const durationFormatted = minutesToDaysHoursMinutes(durationMinutes)
|
|
||||||
|
|
||||||
// Calculate average speed
|
|
||||||
let avgSpeed = properties.speed
|
|
||||||
if (!avgSpeed && properties.distance > 0 && durationSeconds > 0) {
|
|
||||||
avgSpeed = (properties.distance / durationSeconds) * 3600 // km/h
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get user preferences
|
|
||||||
const distanceUnit = this.controller.settings.distance_unit || 'km'
|
|
||||||
|
|
||||||
// Prepare route data object
|
|
||||||
const routeData = {
|
|
||||||
startTime: formatTimestamp(properties.startTime, this.controller.timezoneValue),
|
|
||||||
endTime: formatTimestamp(properties.endTime, this.controller.timezoneValue),
|
|
||||||
duration: durationFormatted,
|
|
||||||
distance: formatDistance(properties.distance, distanceUnit),
|
|
||||||
speed: avgSpeed ? formatSpeed(avgSpeed, distanceUnit) : null,
|
|
||||||
pointCount: properties.pointCount
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call controller method to display route info
|
|
||||||
this.controller.showRouteInfo(routeData)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear route selection
|
|
||||||
*/
|
|
||||||
clearRouteSelection() {
|
|
||||||
if (!this.selectedRouteFeature) return
|
|
||||||
|
|
||||||
this.selectedRouteFeature = null
|
|
||||||
|
|
||||||
const routesLayer = this.controller.layerManager.getLayer('routes')
|
|
||||||
if (routesLayer) {
|
|
||||||
routesLayer.setHoverRoute(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear markers
|
|
||||||
this._clearRouteMarkers()
|
|
||||||
|
|
||||||
// Close info panel
|
|
||||||
this.controller.closeInfo()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ export class LayerManager {
|
||||||
this.settings = settings
|
this.settings = settings
|
||||||
this.api = api
|
this.api = api
|
||||||
this.layers = {}
|
this.layers = {}
|
||||||
this.eventHandlersSetup = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -31,7 +30,7 @@ export class LayerManager {
|
||||||
performanceMonitor.mark('add-layers')
|
performanceMonitor.mark('add-layers')
|
||||||
|
|
||||||
// Layer order matters - layers added first render below layers added later
|
// Layer order matters - layers added first render below layers added later
|
||||||
// Order: scratch (bottom) -> heatmap -> areas -> tracks -> routes (visual) -> visits -> places -> photos -> family -> points -> routes-hit (interaction) -> recent-point (top) -> fog (canvas overlay)
|
// Order: scratch (bottom) -> heatmap -> areas -> tracks -> routes -> visits -> places -> photos -> family -> points -> recent-point (top) -> fog (canvas overlay)
|
||||||
|
|
||||||
await this._addScratchLayer(pointsGeoJSON)
|
await this._addScratchLayer(pointsGeoJSON)
|
||||||
this._addHeatmapLayer(pointsGeoJSON)
|
this._addHeatmapLayer(pointsGeoJSON)
|
||||||
|
|
@ -50,7 +49,6 @@ export class LayerManager {
|
||||||
|
|
||||||
this._addFamilyLayer()
|
this._addFamilyLayer()
|
||||||
this._addPointsLayer(pointsGeoJSON)
|
this._addPointsLayer(pointsGeoJSON)
|
||||||
this._addRoutesHitLayer() // Add hit target layer after points for better interactivity
|
|
||||||
this._addRecentPointLayer()
|
this._addRecentPointLayer()
|
||||||
this._addFogLayer(pointsGeoJSON)
|
this._addFogLayer(pointsGeoJSON)
|
||||||
|
|
||||||
|
|
@ -59,13 +57,8 @@ export class LayerManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup event handlers for layer interactions
|
* Setup event handlers for layer interactions
|
||||||
* Only sets up handlers once to prevent duplicates
|
|
||||||
*/
|
*/
|
||||||
setupLayerEventHandlers(handlers) {
|
setupLayerEventHandlers(handlers) {
|
||||||
if (this.eventHandlersSetup) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Click handlers
|
// Click handlers
|
||||||
this.map.on('click', 'points', handlers.handlePointClick)
|
this.map.on('click', 'points', handlers.handlePointClick)
|
||||||
this.map.on('click', 'visits', handlers.handleVisitClick)
|
this.map.on('click', 'visits', handlers.handleVisitClick)
|
||||||
|
|
@ -76,11 +69,6 @@ export class LayerManager {
|
||||||
this.map.on('click', 'areas-outline', handlers.handleAreaClick)
|
this.map.on('click', 'areas-outline', handlers.handleAreaClick)
|
||||||
this.map.on('click', 'areas-labels', handlers.handleAreaClick)
|
this.map.on('click', 'areas-labels', handlers.handleAreaClick)
|
||||||
|
|
||||||
// Route handlers - use routes-hit layer for better interactivity
|
|
||||||
this.map.on('click', 'routes-hit', handlers.handleRouteClick)
|
|
||||||
this.map.on('mouseenter', 'routes-hit', handlers.handleRouteHover)
|
|
||||||
this.map.on('mouseleave', 'routes-hit', handlers.handleRouteMouseLeave)
|
|
||||||
|
|
||||||
// Cursor change on hover
|
// Cursor change on hover
|
||||||
this.map.on('mouseenter', 'points', () => {
|
this.map.on('mouseenter', 'points', () => {
|
||||||
this.map.getCanvas().style.cursor = 'pointer'
|
this.map.getCanvas().style.cursor = 'pointer'
|
||||||
|
|
@ -106,13 +94,6 @@ export class LayerManager {
|
||||||
this.map.on('mouseleave', 'places', () => {
|
this.map.on('mouseleave', 'places', () => {
|
||||||
this.map.getCanvas().style.cursor = ''
|
this.map.getCanvas().style.cursor = ''
|
||||||
})
|
})
|
||||||
// Route cursor handlers - use routes-hit layer
|
|
||||||
this.map.on('mouseenter', 'routes-hit', () => {
|
|
||||||
this.map.getCanvas().style.cursor = 'pointer'
|
|
||||||
})
|
|
||||||
this.map.on('mouseleave', 'routes-hit', () => {
|
|
||||||
this.map.getCanvas().style.cursor = ''
|
|
||||||
})
|
|
||||||
// Areas hover handlers for all sub-layers
|
// Areas hover handlers for all sub-layers
|
||||||
const areaLayers = ['areas-fill', 'areas-outline', 'areas-labels']
|
const areaLayers = ['areas-fill', 'areas-outline', 'areas-labels']
|
||||||
areaLayers.forEach(layerId => {
|
areaLayers.forEach(layerId => {
|
||||||
|
|
@ -126,16 +107,6 @@ export class LayerManager {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Map-level click to deselect routes
|
|
||||||
this.map.on('click', (e) => {
|
|
||||||
const routeFeatures = this.map.queryRenderedFeatures(e.point, { layers: ['routes-hit'] })
|
|
||||||
if (routeFeatures.length === 0) {
|
|
||||||
handlers.clearRouteSelection()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
this.eventHandlersSetup = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -161,7 +132,6 @@ export class LayerManager {
|
||||||
*/
|
*/
|
||||||
clearLayerReferences() {
|
clearLayerReferences() {
|
||||||
this.layers = {}
|
this.layers = {}
|
||||||
this.eventHandlersSetup = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private methods for individual layer management
|
// Private methods for individual layer management
|
||||||
|
|
@ -227,32 +197,6 @@ export class LayerManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_addRoutesHitLayer() {
|
|
||||||
// Add invisible hit target layer for routes after points layer
|
|
||||||
// This ensures route interactions work even when points are on top
|
|
||||||
if (!this.map.getLayer('routes-hit') && this.map.getSource('routes-source')) {
|
|
||||||
this.map.addLayer({
|
|
||||||
id: 'routes-hit',
|
|
||||||
type: 'line',
|
|
||||||
source: 'routes-source',
|
|
||||||
layout: {
|
|
||||||
'line-join': 'round',
|
|
||||||
'line-cap': 'round'
|
|
||||||
},
|
|
||||||
paint: {
|
|
||||||
'line-color': 'transparent',
|
|
||||||
'line-width': 20, // Much wider for easier clicking/hovering
|
|
||||||
'line-opacity': 0
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// Match visibility with routes layer
|
|
||||||
const routesLayer = this.layers.routesLayer
|
|
||||||
if (routesLayer && !routesLayer.visible) {
|
|
||||||
this.map.setLayoutProperty('routes-hit', 'visibility', 'none')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_addVisitsLayer(visitsGeoJSON) {
|
_addVisitsLayer(visitsGeoJSON) {
|
||||||
if (!this.layers.visitsLayer) {
|
if (!this.layers.visitsLayer) {
|
||||||
this.layers.visitsLayer = new VisitsLayer(this.map, {
|
this.layers.visitsLayer = new VisitsLayer(this.map, {
|
||||||
|
|
|
||||||
|
|
@ -90,31 +90,22 @@ export class MapDataManager {
|
||||||
data.placesGeoJSON
|
data.placesGeoJSON
|
||||||
)
|
)
|
||||||
|
|
||||||
// Setup event handlers after layers are added
|
|
||||||
this.layerManager.setupLayerEventHandlers({
|
this.layerManager.setupLayerEventHandlers({
|
||||||
handlePointClick: this.eventHandlers.handlePointClick.bind(this.eventHandlers),
|
handlePointClick: this.eventHandlers.handlePointClick.bind(this.eventHandlers),
|
||||||
handleVisitClick: this.eventHandlers.handleVisitClick.bind(this.eventHandlers),
|
handleVisitClick: this.eventHandlers.handleVisitClick.bind(this.eventHandlers),
|
||||||
handlePhotoClick: this.eventHandlers.handlePhotoClick.bind(this.eventHandlers),
|
handlePhotoClick: this.eventHandlers.handlePhotoClick.bind(this.eventHandlers),
|
||||||
handlePlaceClick: this.eventHandlers.handlePlaceClick.bind(this.eventHandlers),
|
handlePlaceClick: this.eventHandlers.handlePlaceClick.bind(this.eventHandlers),
|
||||||
handleAreaClick: this.eventHandlers.handleAreaClick.bind(this.eventHandlers),
|
handleAreaClick: this.eventHandlers.handleAreaClick.bind(this.eventHandlers)
|
||||||
handleRouteClick: this.eventHandlers.handleRouteClick.bind(this.eventHandlers),
|
|
||||||
handleRouteHover: this.eventHandlers.handleRouteHover.bind(this.eventHandlers),
|
|
||||||
handleRouteMouseLeave: this.eventHandlers.handleRouteMouseLeave.bind(this.eventHandlers),
|
|
||||||
clearRouteSelection: this.eventHandlers.clearRouteSelection.bind(this.eventHandlers)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always use Promise-based approach for consistent timing
|
|
||||||
await new Promise((resolve) => {
|
|
||||||
if (this.map.loaded()) {
|
if (this.map.loaded()) {
|
||||||
addAllLayers().then(resolve)
|
await addAllLayers()
|
||||||
} else {
|
} else {
|
||||||
this.map.once('load', async () => {
|
this.map.once('load', async () => {
|
||||||
await addAllLayers()
|
await addAllLayers()
|
||||||
resolve()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -16,35 +16,17 @@ export class MapInitializer {
|
||||||
mapStyle = 'streets',
|
mapStyle = 'streets',
|
||||||
center = [0, 0],
|
center = [0, 0],
|
||||||
zoom = 2,
|
zoom = 2,
|
||||||
showControls = true,
|
showControls = true
|
||||||
globeProjection = false
|
|
||||||
} = settings
|
} = settings
|
||||||
|
|
||||||
const style = await getMapStyle(mapStyle)
|
const style = await getMapStyle(mapStyle)
|
||||||
|
|
||||||
const mapOptions = {
|
const map = new maplibregl.Map({
|
||||||
container,
|
container,
|
||||||
style,
|
style,
|
||||||
center,
|
center,
|
||||||
zoom
|
zoom
|
||||||
}
|
|
||||||
|
|
||||||
const map = new maplibregl.Map(mapOptions)
|
|
||||||
|
|
||||||
// Set globe projection after map loads
|
|
||||||
if (globeProjection === true || globeProjection === 'true') {
|
|
||||||
map.on('load', () => {
|
|
||||||
map.setProjection({ type: 'globe' })
|
|
||||||
|
|
||||||
// Add atmosphere effect
|
|
||||||
map.setSky({
|
|
||||||
'atmosphere-blend': [
|
|
||||||
'interpolate', ['linear'], ['zoom'],
|
|
||||||
0, 1, 5, 1, 7, 0
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showControls) {
|
if (showControls) {
|
||||||
map.addControl(new maplibregl.NavigationControl(), 'top-right')
|
map.addControl(new maplibregl.NavigationControl(), 'top-right')
|
||||||
|
|
|
||||||
|
|
@ -216,6 +216,8 @@ export class PlacesManager {
|
||||||
* Start create place mode
|
* Start create place mode
|
||||||
*/
|
*/
|
||||||
startCreatePlace() {
|
startCreatePlace() {
|
||||||
|
console.log('[Maps V2] Starting create place mode')
|
||||||
|
|
||||||
if (this.controller.hasSettingsPanelTarget && this.controller.settingsPanelTarget.classList.contains('open')) {
|
if (this.controller.hasSettingsPanelTarget && this.controller.settingsPanelTarget.classList.contains('open')) {
|
||||||
this.controller.toggleSettings()
|
this.controller.toggleSettings()
|
||||||
}
|
}
|
||||||
|
|
@ -240,6 +242,8 @@ export class PlacesManager {
|
||||||
* Handle place creation event - reload places and update layer
|
* Handle place creation event - reload places and update layer
|
||||||
*/
|
*/
|
||||||
async handlePlaceCreated(event) {
|
async handlePlaceCreated(event) {
|
||||||
|
console.log('[Maps V2] Place created, reloading places...', event.detail)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const selectedTags = this.getSelectedPlaceTags()
|
const selectedTags = this.getSelectedPlaceTags()
|
||||||
|
|
||||||
|
|
@ -247,6 +251,8 @@ export class PlacesManager {
|
||||||
tag_ids: selectedTags
|
tag_ids: selectedTags
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log('[Maps V2] Fetched places:', places.length)
|
||||||
|
|
||||||
const placesGeoJSON = this.dataLoader.placesToGeoJSON(places)
|
const placesGeoJSON = this.dataLoader.placesToGeoJSON(places)
|
||||||
|
|
||||||
console.log('[Maps V2] Converted to GeoJSON:', placesGeoJSON.features.length, 'features')
|
console.log('[Maps V2] Converted to GeoJSON:', placesGeoJSON.features.length, 'features')
|
||||||
|
|
@ -254,6 +260,7 @@ export class PlacesManager {
|
||||||
const placesLayer = this.layerManager.getLayer('places')
|
const placesLayer = this.layerManager.getLayer('places')
|
||||||
if (placesLayer) {
|
if (placesLayer) {
|
||||||
placesLayer.update(placesGeoJSON)
|
placesLayer.update(placesGeoJSON)
|
||||||
|
console.log('[Maps V2] Places layer updated successfully')
|
||||||
} else {
|
} else {
|
||||||
console.warn('[Maps V2] Places layer not found, cannot update')
|
console.warn('[Maps V2] Places layer not found, cannot update')
|
||||||
}
|
}
|
||||||
|
|
@ -266,6 +273,9 @@ export class PlacesManager {
|
||||||
* Handle place update event - reload places and update layer
|
* Handle place update event - reload places and update layer
|
||||||
*/
|
*/
|
||||||
async handlePlaceUpdated(event) {
|
async handlePlaceUpdated(event) {
|
||||||
|
console.log('[Maps V2] Place updated, reloading places...', event.detail)
|
||||||
|
|
||||||
|
// Reuse the same logic as creation
|
||||||
await this.handlePlaceCreated(event)
|
await this.handlePlaceCreated(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,11 +91,6 @@ export class SettingsController {
|
||||||
mapStyleSelect.value = this.settings.mapStyle || 'light'
|
mapStyleSelect.value = this.settings.mapStyle || 'light'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync globe projection toggle
|
|
||||||
if (controller.hasGlobeToggleTarget) {
|
|
||||||
controller.globeToggleTarget.checked = this.settings.globeProjection || false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sync fog of war settings
|
// Sync fog of war settings
|
||||||
const fogRadiusInput = controller.element.querySelector('input[name="fogOfWarRadius"]')
|
const fogRadiusInput = controller.element.querySelector('input[name="fogOfWarRadius"]')
|
||||||
if (fogRadiusInput) {
|
if (fogRadiusInput) {
|
||||||
|
|
@ -183,22 +178,6 @@ export class SettingsController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggle globe projection
|
|
||||||
* Requires page reload to apply since projection is set at map initialization
|
|
||||||
*/
|
|
||||||
async toggleGlobe(event) {
|
|
||||||
const enabled = event.target.checked
|
|
||||||
await SettingsManager.updateSetting('globeProjection', enabled)
|
|
||||||
|
|
||||||
Toast.info('Globe view will be applied after page reload')
|
|
||||||
|
|
||||||
// Prompt user to reload
|
|
||||||
if (confirm('Globe view requires a page reload to take effect. Reload now?')) {
|
|
||||||
window.location.reload()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update route opacity in real-time
|
* Update route opacity in real-time
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,8 @@ export class VisitsManager {
|
||||||
* Start create visit mode
|
* Start create visit mode
|
||||||
*/
|
*/
|
||||||
startCreateVisit() {
|
startCreateVisit() {
|
||||||
|
console.log('[Maps V2] Starting create visit mode')
|
||||||
|
|
||||||
if (this.controller.hasSettingsPanelTarget && this.controller.settingsPanelTarget.classList.contains('open')) {
|
if (this.controller.hasSettingsPanelTarget && this.controller.settingsPanelTarget.classList.contains('open')) {
|
||||||
this.controller.toggleSettings()
|
this.controller.toggleSettings()
|
||||||
}
|
}
|
||||||
|
|
@ -85,9 +87,12 @@ export class VisitsManager {
|
||||||
* Open visit creation modal
|
* Open visit creation modal
|
||||||
*/
|
*/
|
||||||
openVisitCreationModal(lat, lng) {
|
openVisitCreationModal(lat, lng) {
|
||||||
|
console.log('[Maps V2] Opening visit creation modal', { lat, lng })
|
||||||
|
|
||||||
const modalElement = document.querySelector('[data-controller="visit-creation-v2"]')
|
const modalElement = document.querySelector('[data-controller="visit-creation-v2"]')
|
||||||
|
|
||||||
if (!modalElement) {
|
if (!modalElement) {
|
||||||
|
console.error('[Maps V2] Visit creation modal not found')
|
||||||
Toast.error('Visit creation modal not available')
|
Toast.error('Visit creation modal not available')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -100,6 +105,7 @@ export class VisitsManager {
|
||||||
if (controller) {
|
if (controller) {
|
||||||
controller.open(lat, lng, this.controller)
|
controller.open(lat, lng, this.controller)
|
||||||
} else {
|
} else {
|
||||||
|
console.error('[Maps V2] Visit creation controller not found')
|
||||||
Toast.error('Visit creation controller not available')
|
Toast.error('Visit creation controller not available')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -108,6 +114,8 @@ export class VisitsManager {
|
||||||
* Handle visit creation event - reload visits and update layer
|
* Handle visit creation event - reload visits and update layer
|
||||||
*/
|
*/
|
||||||
async handleVisitCreated(event) {
|
async handleVisitCreated(event) {
|
||||||
|
console.log('[Maps V2] Visit created, reloading visits...', event.detail)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const visits = await this.api.fetchVisits({
|
const visits = await this.api.fetchVisits({
|
||||||
start_at: this.controller.startDateValue,
|
start_at: this.controller.startDateValue,
|
||||||
|
|
@ -124,6 +132,7 @@ export class VisitsManager {
|
||||||
const visitsLayer = this.layerManager.getLayer('visits')
|
const visitsLayer = this.layerManager.getLayer('visits')
|
||||||
if (visitsLayer) {
|
if (visitsLayer) {
|
||||||
visitsLayer.update(visitsGeoJSON)
|
visitsLayer.update(visitsGeoJSON)
|
||||||
|
console.log('[Maps V2] Visits layer updated successfully')
|
||||||
} else {
|
} else {
|
||||||
console.warn('[Maps V2] Visits layer not found, cannot update')
|
console.warn('[Maps V2] Visits layer not found, cannot update')
|
||||||
}
|
}
|
||||||
|
|
@ -136,6 +145,9 @@ export class VisitsManager {
|
||||||
* Handle visit update event - reload visits and update layer
|
* Handle visit update event - reload visits and update layer
|
||||||
*/
|
*/
|
||||||
async handleVisitUpdated(event) {
|
async handleVisitUpdated(event) {
|
||||||
|
console.log('[Maps V2] Visit updated, reloading visits...', event.detail)
|
||||||
|
|
||||||
|
// Reuse the same logic as creation
|
||||||
await this.handleVisitCreated(event)
|
await this.handleVisitCreated(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,6 @@ export default class extends Controller {
|
||||||
'speedColoredToggle',
|
'speedColoredToggle',
|
||||||
'speedColorScaleContainer',
|
'speedColorScaleContainer',
|
||||||
'speedColorScaleInput',
|
'speedColorScaleInput',
|
||||||
// Globe projection
|
|
||||||
'globeToggle',
|
|
||||||
// Family members
|
// Family members
|
||||||
'familyMembersList',
|
'familyMembersList',
|
||||||
'familyMembersContainer',
|
'familyMembersContainer',
|
||||||
|
|
@ -79,16 +77,7 @@ export default class extends Controller {
|
||||||
'infoDisplay',
|
'infoDisplay',
|
||||||
'infoTitle',
|
'infoTitle',
|
||||||
'infoContent',
|
'infoContent',
|
||||||
'infoActions',
|
'infoActions'
|
||||||
// Route info template
|
|
||||||
'routeInfoTemplate',
|
|
||||||
'routeStartTime',
|
|
||||||
'routeEndTime',
|
|
||||||
'routeDuration',
|
|
||||||
'routeDistance',
|
|
||||||
'routeSpeed',
|
|
||||||
'routeSpeedContainer',
|
|
||||||
'routePoints'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
async connect() {
|
async connect() {
|
||||||
|
|
@ -141,6 +130,7 @@ export default class extends Controller {
|
||||||
// Format initial dates
|
// Format initial dates
|
||||||
this.startDateValue = DateManager.formatDateForAPI(new Date(this.startDateValue))
|
this.startDateValue = DateManager.formatDateForAPI(new Date(this.startDateValue))
|
||||||
this.endDateValue = DateManager.formatDateForAPI(new Date(this.endDateValue))
|
this.endDateValue = DateManager.formatDateForAPI(new Date(this.endDateValue))
|
||||||
|
console.log('[Maps V2] Initial dates:', this.startDateValue, 'to', this.endDateValue)
|
||||||
|
|
||||||
this.loadMapData()
|
this.loadMapData()
|
||||||
}
|
}
|
||||||
|
|
@ -157,8 +147,7 @@ export default class extends Controller {
|
||||||
*/
|
*/
|
||||||
async initializeMap() {
|
async initializeMap() {
|
||||||
this.map = await MapInitializer.initialize(this.containerTarget, {
|
this.map = await MapInitializer.initialize(this.containerTarget, {
|
||||||
mapStyle: this.settings.mapStyle,
|
mapStyle: this.settings.mapStyle
|
||||||
globeProjection: this.settings.globeProjection
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,6 +169,8 @@ export default class extends Controller {
|
||||||
|
|
||||||
this.searchManager = new SearchManager(this.map, this.apiKeyValue)
|
this.searchManager = new SearchManager(this.map, this.apiKeyValue)
|
||||||
this.searchManager.initialize(this.searchInputTarget, this.searchResultsTarget)
|
this.searchManager.initialize(this.searchInputTarget, this.searchResultsTarget)
|
||||||
|
|
||||||
|
console.log('[Maps V2] Search manager initialized')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -204,6 +195,7 @@ export default class extends Controller {
|
||||||
this.startDateValue = startDate
|
this.startDateValue = startDate
|
||||||
this.endDateValue = endDate
|
this.endDateValue = endDate
|
||||||
|
|
||||||
|
console.log('[Maps V2] Date range changed:', this.startDateValue, 'to', this.endDateValue)
|
||||||
this.loadMapData()
|
this.loadMapData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -251,7 +243,6 @@ export default class extends Controller {
|
||||||
updateFogThresholdDisplay(event) { return this.settingsController.updateFogThresholdDisplay(event) }
|
updateFogThresholdDisplay(event) { return this.settingsController.updateFogThresholdDisplay(event) }
|
||||||
updateMetersBetweenDisplay(event) { return this.settingsController.updateMetersBetweenDisplay(event) }
|
updateMetersBetweenDisplay(event) { return this.settingsController.updateMetersBetweenDisplay(event) }
|
||||||
updateMinutesBetweenDisplay(event) { return this.settingsController.updateMinutesBetweenDisplay(event) }
|
updateMinutesBetweenDisplay(event) { return this.settingsController.updateMinutesBetweenDisplay(event) }
|
||||||
toggleGlobe(event) { return this.settingsController.toggleGlobe(event) }
|
|
||||||
|
|
||||||
// Area Selection Manager methods
|
// Area Selection Manager methods
|
||||||
startSelectArea() { return this.areaSelectionManager.startSelectArea() }
|
startSelectArea() { return this.areaSelectionManager.startSelectArea() }
|
||||||
|
|
@ -272,6 +263,8 @@ export default class extends Controller {
|
||||||
|
|
||||||
// Area creation
|
// Area creation
|
||||||
startCreateArea() {
|
startCreateArea() {
|
||||||
|
console.log('[Maps V2] Starting create area mode')
|
||||||
|
|
||||||
if (this.hasSettingsPanelTarget && this.settingsPanelTarget.classList.contains('open')) {
|
if (this.hasSettingsPanelTarget && this.settingsPanelTarget.classList.contains('open')) {
|
||||||
this.toggleSettings()
|
this.toggleSettings()
|
||||||
}
|
}
|
||||||
|
|
@ -283,26 +276,37 @@ export default class extends Controller {
|
||||||
)
|
)
|
||||||
|
|
||||||
if (drawerController) {
|
if (drawerController) {
|
||||||
|
console.log('[Maps V2] Area drawer controller found, starting drawing with map:', this.map)
|
||||||
drawerController.startDrawing(this.map)
|
drawerController.startDrawing(this.map)
|
||||||
} else {
|
} else {
|
||||||
|
console.error('[Maps V2] Area drawer controller not found')
|
||||||
Toast.error('Area drawer controller not available')
|
Toast.error('Area drawer controller not available')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleAreaCreated(event) {
|
async handleAreaCreated(event) {
|
||||||
|
console.log('[Maps V2] Area created:', event.detail.area)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Fetch all areas from API
|
// Fetch all areas from API
|
||||||
const areas = await this.api.fetchAreas()
|
const areas = await this.api.fetchAreas()
|
||||||
|
console.log('[Maps V2] Fetched areas:', areas.length)
|
||||||
|
|
||||||
// Convert to GeoJSON
|
// Convert to GeoJSON
|
||||||
const areasGeoJSON = this.dataLoader.areasToGeoJSON(areas)
|
const areasGeoJSON = this.dataLoader.areasToGeoJSON(areas)
|
||||||
|
console.log('[Maps V2] Converted to GeoJSON:', areasGeoJSON.features.length, 'features')
|
||||||
|
if (areasGeoJSON.features.length > 0) {
|
||||||
|
console.log('[Maps V2] First area GeoJSON:', JSON.stringify(areasGeoJSON.features[0], null, 2))
|
||||||
|
}
|
||||||
|
|
||||||
// Get or create the areas layer
|
// Get or create the areas layer
|
||||||
let areasLayer = this.layerManager.getLayer('areas')
|
let areasLayer = this.layerManager.getLayer('areas')
|
||||||
|
console.log('[Maps V2] Areas layer exists?', !!areasLayer, 'visible?', areasLayer?.visible)
|
||||||
|
|
||||||
if (areasLayer) {
|
if (areasLayer) {
|
||||||
// Update existing layer
|
// Update existing layer
|
||||||
areasLayer.update(areasGeoJSON)
|
areasLayer.update(areasGeoJSON)
|
||||||
|
console.log('[Maps V2] Areas layer updated')
|
||||||
} else {
|
} else {
|
||||||
// Create the layer if it doesn't exist yet
|
// Create the layer if it doesn't exist yet
|
||||||
console.log('[Maps V2] Creating areas layer')
|
console.log('[Maps V2] Creating areas layer')
|
||||||
|
|
@ -314,6 +318,7 @@ export default class extends Controller {
|
||||||
// Enable the layer if it wasn't already
|
// Enable the layer if it wasn't already
|
||||||
if (areasLayer) {
|
if (areasLayer) {
|
||||||
if (!areasLayer.visible) {
|
if (!areasLayer.visible) {
|
||||||
|
console.log('[Maps V2] Showing areas layer')
|
||||||
areasLayer.show()
|
areasLayer.show()
|
||||||
this.settings.layers.areas = true
|
this.settings.layers.areas = true
|
||||||
this.settingsController.saveSetting('layers.areas', true)
|
this.settingsController.saveSetting('layers.areas', true)
|
||||||
|
|
@ -329,6 +334,7 @@ export default class extends Controller {
|
||||||
|
|
||||||
Toast.success('Area created successfully!')
|
Toast.success('Area created successfully!')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('[Maps V2] Failed to reload areas:', error)
|
||||||
Toast.error('Failed to reload areas')
|
Toast.error('Failed to reload areas')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -359,6 +365,7 @@ export default class extends Controller {
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
if (response.status === 403) {
|
if (response.status === 403) {
|
||||||
|
console.warn('[Maps V2] Family feature not enabled or user not in family')
|
||||||
Toast.info('Family feature not available')
|
Toast.info('Family feature not available')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -476,46 +483,9 @@ export default class extends Controller {
|
||||||
this.switchToToolsTab()
|
this.switchToToolsTab()
|
||||||
}
|
}
|
||||||
|
|
||||||
showRouteInfo(routeData) {
|
|
||||||
if (!this.hasRouteInfoTemplateTarget) return
|
|
||||||
|
|
||||||
// Clone the template
|
|
||||||
const template = this.routeInfoTemplateTarget.content.cloneNode(true)
|
|
||||||
|
|
||||||
// Populate the template with data
|
|
||||||
const fragment = document.createDocumentFragment()
|
|
||||||
fragment.appendChild(template)
|
|
||||||
|
|
||||||
fragment.querySelector('[data-maps--maplibre-target="routeStartTime"]').textContent = routeData.startTime
|
|
||||||
fragment.querySelector('[data-maps--maplibre-target="routeEndTime"]').textContent = routeData.endTime
|
|
||||||
fragment.querySelector('[data-maps--maplibre-target="routeDuration"]').textContent = routeData.duration
|
|
||||||
fragment.querySelector('[data-maps--maplibre-target="routeDistance"]').textContent = routeData.distance
|
|
||||||
fragment.querySelector('[data-maps--maplibre-target="routePoints"]').textContent = routeData.pointCount
|
|
||||||
|
|
||||||
// Handle optional speed field
|
|
||||||
const speedContainer = fragment.querySelector('[data-maps--maplibre-target="routeSpeedContainer"]')
|
|
||||||
if (routeData.speed) {
|
|
||||||
fragment.querySelector('[data-maps--maplibre-target="routeSpeed"]').textContent = routeData.speed
|
|
||||||
speedContainer.style.display = ''
|
|
||||||
} else {
|
|
||||||
speedContainer.style.display = 'none'
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert fragment to HTML string for showInfo
|
|
||||||
const div = document.createElement('div')
|
|
||||||
div.appendChild(fragment)
|
|
||||||
|
|
||||||
this.showInfo('Route Information', div.innerHTML)
|
|
||||||
}
|
|
||||||
|
|
||||||
closeInfo() {
|
closeInfo() {
|
||||||
if (!this.hasInfoDisplayTarget) return
|
if (!this.hasInfoDisplayTarget) return
|
||||||
this.infoDisplayTarget.classList.add('hidden')
|
this.infoDisplayTarget.classList.add('hidden')
|
||||||
|
|
||||||
// Clear route selection when info panel is closed
|
|
||||||
if (this.eventHandlers) {
|
|
||||||
this.eventHandlers.clearRouteSelection()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -526,6 +496,7 @@ export default class extends Controller {
|
||||||
const id = button.dataset.id
|
const id = button.dataset.id
|
||||||
const entityType = button.dataset.entityType
|
const entityType = button.dataset.entityType
|
||||||
|
|
||||||
|
console.log('[Maps V2] Opening edit for', entityType, id)
|
||||||
|
|
||||||
switch (entityType) {
|
switch (entityType) {
|
||||||
case 'visit':
|
case 'visit':
|
||||||
|
|
@ -547,6 +518,8 @@ export default class extends Controller {
|
||||||
const id = button.dataset.id
|
const id = button.dataset.id
|
||||||
const entityType = button.dataset.entityType
|
const entityType = button.dataset.entityType
|
||||||
|
|
||||||
|
console.log('[Maps V2] Deleting', entityType, id)
|
||||||
|
|
||||||
switch (entityType) {
|
switch (entityType) {
|
||||||
case 'area':
|
case 'area':
|
||||||
this.deleteArea(id)
|
this.deleteArea(id)
|
||||||
|
|
@ -582,6 +555,7 @@ export default class extends Controller {
|
||||||
})
|
})
|
||||||
document.dispatchEvent(event)
|
document.dispatchEvent(event)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('[Maps V2] Failed to load visit:', error)
|
||||||
Toast.error('Failed to load visit details')
|
Toast.error('Failed to load visit details')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -618,6 +592,7 @@ export default class extends Controller {
|
||||||
|
|
||||||
Toast.success('Area deleted successfully')
|
Toast.success('Area deleted successfully')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('[Maps V2] Failed to delete area:', error)
|
||||||
Toast.error('Failed to delete area')
|
Toast.error('Failed to delete area')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -648,6 +623,7 @@ export default class extends Controller {
|
||||||
})
|
})
|
||||||
document.dispatchEvent(event)
|
document.dispatchEvent(event)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('[Maps V2] Failed to load place:', error)
|
||||||
Toast.error('Failed to load place details')
|
Toast.error('Failed to load place details')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ const MARKER_DATA_INDICES = {
|
||||||
* @param {number} size - Icon size in pixels (default: 8)
|
* @param {number} size - Icon size in pixels (default: 8)
|
||||||
* @returns {L.DivIcon} Leaflet divIcon instance
|
* @returns {L.DivIcon} Leaflet divIcon instance
|
||||||
*/
|
*/
|
||||||
export function createStandardIcon(color = 'blue', size = 4) {
|
export function createStandardIcon(color = 'blue', size = 8) {
|
||||||
return L.divIcon({
|
return L.divIcon({
|
||||||
className: 'custom-div-icon',
|
className: 'custom-div-icon',
|
||||||
html: `<div style='background-color: ${color}; width: ${size}px; height: ${size}px; border-radius: 50%;'></div>`,
|
html: `<div style='background-color: ${color}; width: ${size}px; height: ${size}px; border-radius: 50%;'></div>`,
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,12 @@ export class BaseLayer {
|
||||||
* @param {Object} data - GeoJSON or layer-specific data
|
* @param {Object} data - GeoJSON or layer-specific data
|
||||||
*/
|
*/
|
||||||
add(data) {
|
add(data) {
|
||||||
|
console.log(`[BaseLayer:${this.id}] add() called, visible:`, this.visible, 'features:', data?.features?.length || 0)
|
||||||
this.data = data
|
this.data = data
|
||||||
|
|
||||||
// Add source
|
// Add source
|
||||||
if (!this.map.getSource(this.sourceId)) {
|
if (!this.map.getSource(this.sourceId)) {
|
||||||
|
console.log(`[BaseLayer:${this.id}] Adding source:`, this.sourceId)
|
||||||
this.map.addSource(this.sourceId, this.getSourceConfig())
|
this.map.addSource(this.sourceId, this.getSourceConfig())
|
||||||
} else {
|
} else {
|
||||||
console.log(`[BaseLayer:${this.id}] Source already exists:`, this.sourceId)
|
console.log(`[BaseLayer:${this.id}] Source already exists:`, this.sourceId)
|
||||||
|
|
@ -30,6 +32,7 @@ export class BaseLayer {
|
||||||
console.log(`[BaseLayer:${this.id}] Adding ${layers.length} layer(s)`)
|
console.log(`[BaseLayer:${this.id}] Adding ${layers.length} layer(s)`)
|
||||||
layers.forEach(layerConfig => {
|
layers.forEach(layerConfig => {
|
||||||
if (!this.map.getLayer(layerConfig.id)) {
|
if (!this.map.getLayer(layerConfig.id)) {
|
||||||
|
console.log(`[BaseLayer:${this.id}] Adding layer:`, layerConfig.id, 'type:', layerConfig.type)
|
||||||
this.map.addLayer(layerConfig)
|
this.map.addLayer(layerConfig)
|
||||||
} else {
|
} else {
|
||||||
console.log(`[BaseLayer:${this.id}] Layer already exists:`, layerConfig.id)
|
console.log(`[BaseLayer:${this.id}] Layer already exists:`, layerConfig.id)
|
||||||
|
|
@ -37,6 +40,7 @@ export class BaseLayer {
|
||||||
})
|
})
|
||||||
|
|
||||||
this.setVisibility(this.visible)
|
this.setVisibility(this.visible)
|
||||||
|
console.log(`[BaseLayer:${this.id}] Layer added successfully`)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ export class RoutesLayer extends BaseLayer {
|
||||||
constructor(map, options = {}) {
|
constructor(map, options = {}) {
|
||||||
super(map, { id: 'routes', ...options })
|
super(map, { id: 'routes', ...options })
|
||||||
this.maxGapHours = options.maxGapHours || 5 // Max hours between points to connect
|
this.maxGapHours = options.maxGapHours || 5 // Max hours between points to connect
|
||||||
this.hoverSourceId = 'routes-hover-source'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getSourceConfig() {
|
getSourceConfig() {
|
||||||
|
|
@ -21,36 +20,6 @@ export class RoutesLayer extends BaseLayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Override add() to create both main and hover sources
|
|
||||||
*/
|
|
||||||
add(data) {
|
|
||||||
this.data = data
|
|
||||||
|
|
||||||
// Add main source
|
|
||||||
if (!this.map.getSource(this.sourceId)) {
|
|
||||||
this.map.addSource(this.sourceId, this.getSourceConfig())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add hover source (initially empty)
|
|
||||||
if (!this.map.getSource(this.hoverSourceId)) {
|
|
||||||
this.map.addSource(this.hoverSourceId, {
|
|
||||||
type: 'geojson',
|
|
||||||
data: { type: 'FeatureCollection', features: [] }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add layers
|
|
||||||
const layers = this.getLayerConfigs()
|
|
||||||
layers.forEach(layerConfig => {
|
|
||||||
if (!this.map.getLayer(layerConfig.id)) {
|
|
||||||
this.map.addLayer(layerConfig)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
this.setVisibility(this.visible)
|
|
||||||
}
|
|
||||||
|
|
||||||
getLayerConfigs() {
|
getLayerConfigs() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|
@ -72,93 +41,10 @@ export class RoutesLayer extends BaseLayer {
|
||||||
'line-width': 3,
|
'line-width': 3,
|
||||||
'line-opacity': 0.8
|
'line-opacity': 0.8
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'routes-hover',
|
|
||||||
type: 'line',
|
|
||||||
source: this.hoverSourceId,
|
|
||||||
layout: {
|
|
||||||
'line-join': 'round',
|
|
||||||
'line-cap': 'round'
|
|
||||||
},
|
|
||||||
paint: {
|
|
||||||
'line-color': '#ffff00', // Yellow highlight
|
|
||||||
'line-width': 8,
|
|
||||||
'line-opacity': 1.0
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Note: routes-hit layer is added separately in LayerManager after points layer
|
|
||||||
// for better interactivity (see _addRoutesHitLayer method)
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Override setVisibility to also control routes-hit layer
|
|
||||||
* @param {boolean} visible - Show/hide layer
|
|
||||||
*/
|
|
||||||
setVisibility(visible) {
|
|
||||||
// Call parent to handle main routes and routes-hover layers
|
|
||||||
super.setVisibility(visible)
|
|
||||||
|
|
||||||
// Also control routes-hit layer if it exists
|
|
||||||
if (this.map.getLayer('routes-hit')) {
|
|
||||||
const visibility = visible ? 'visible' : 'none'
|
|
||||||
this.map.setLayoutProperty('routes-hit', 'visibility', visibility)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update hover layer with route geometry
|
|
||||||
* @param {Object|null} feature - Route feature, FeatureCollection, or null to clear
|
|
||||||
*/
|
|
||||||
setHoverRoute(feature) {
|
|
||||||
const hoverSource = this.map.getSource(this.hoverSourceId)
|
|
||||||
if (!hoverSource) return
|
|
||||||
|
|
||||||
if (feature) {
|
|
||||||
// Handle both single feature and FeatureCollection
|
|
||||||
if (feature.type === 'FeatureCollection') {
|
|
||||||
hoverSource.setData(feature)
|
|
||||||
} else {
|
|
||||||
hoverSource.setData({
|
|
||||||
type: 'FeatureCollection',
|
|
||||||
features: [feature]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
hoverSource.setData({ type: 'FeatureCollection', features: [] })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Override remove() to clean up hover source and hit layer
|
|
||||||
*/
|
|
||||||
remove() {
|
|
||||||
// Remove layers
|
|
||||||
this.getLayerIds().forEach(layerId => {
|
|
||||||
if (this.map.getLayer(layerId)) {
|
|
||||||
this.map.removeLayer(layerId)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Remove routes-hit layer if it exists
|
|
||||||
if (this.map.getLayer('routes-hit')) {
|
|
||||||
this.map.removeLayer('routes-hit')
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove main source
|
|
||||||
if (this.map.getSource(this.sourceId)) {
|
|
||||||
this.map.removeSource(this.sourceId)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove hover source
|
|
||||||
if (this.map.getSource(this.hoverSourceId)) {
|
|
||||||
this.map.removeSource(this.hoverSourceId)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.data = null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate haversine distance between two points in kilometers
|
* Calculate haversine distance between two points in kilometers
|
||||||
* @param {number} lat1 - First point latitude
|
* @param {number} lat1 - First point latitude
|
||||||
|
|
@ -181,7 +67,6 @@ export class RoutesLayer extends BaseLayer {
|
||||||
/**
|
/**
|
||||||
* Convert points to route LineStrings with splitting
|
* Convert points to route LineStrings with splitting
|
||||||
* Matches V1's route splitting logic for consistency
|
* Matches V1's route splitting logic for consistency
|
||||||
* Also handles International Date Line (IDL) crossings
|
|
||||||
* @param {Array} points - Points from API
|
* @param {Array} points - Points from API
|
||||||
* @param {Object} options - Splitting options
|
* @param {Object} options - Splitting options
|
||||||
* @returns {Object} GeoJSON FeatureCollection
|
* @returns {Object} GeoJSON FeatureCollection
|
||||||
|
|
@ -192,9 +77,7 @@ export class RoutesLayer extends BaseLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default thresholds (matching V1 defaults from polylines.js)
|
// Default thresholds (matching V1 defaults from polylines.js)
|
||||||
// Note: V1 has a unit mismatch bug where it compares km to meters directly
|
const distanceThresholdKm = (options.distanceThresholdMeters || 500) / 1000
|
||||||
// We replicate this behavior for consistency with V1
|
|
||||||
const distanceThresholdKm = options.distanceThresholdMeters || 500
|
|
||||||
const timeThresholdMinutes = options.timeThresholdMinutes || 60
|
const timeThresholdMinutes = options.timeThresholdMinutes || 60
|
||||||
|
|
||||||
// Sort by timestamp
|
// Sort by timestamp
|
||||||
|
|
@ -217,7 +100,7 @@ export class RoutesLayer extends BaseLayer {
|
||||||
// Calculate time difference in minutes
|
// Calculate time difference in minutes
|
||||||
const timeDiff = (curr.timestamp - prev.timestamp) / 60
|
const timeDiff = (curr.timestamp - prev.timestamp) / 60
|
||||||
|
|
||||||
// Split if any threshold is exceeded
|
// Split if either threshold is exceeded (matching V1 logic)
|
||||||
if (distance > distanceThresholdKm || timeDiff > timeThresholdMinutes) {
|
if (distance > distanceThresholdKm || timeDiff > timeThresholdMinutes) {
|
||||||
if (currentSegment.length > 1) {
|
if (currentSegment.length > 1) {
|
||||||
segments.push(currentSegment)
|
segments.push(currentSegment)
|
||||||
|
|
@ -234,36 +117,7 @@ export class RoutesLayer extends BaseLayer {
|
||||||
|
|
||||||
// Convert segments to LineStrings
|
// Convert segments to LineStrings
|
||||||
const features = segments.map(segment => {
|
const features = segments.map(segment => {
|
||||||
// Unwrap coordinates to handle International Date Line (IDL) crossings
|
const coordinates = segment.map(p => [p.longitude, p.latitude])
|
||||||
// This ensures routes draw the short way across IDL instead of wrapping around globe
|
|
||||||
const coordinates = []
|
|
||||||
let offset = 0 // Cumulative longitude offset for unwrapping
|
|
||||||
|
|
||||||
for (let i = 0; i < segment.length; i++) {
|
|
||||||
const point = segment[i]
|
|
||||||
let lon = point.longitude + offset
|
|
||||||
|
|
||||||
// Check for IDL crossing between consecutive points
|
|
||||||
if (i > 0) {
|
|
||||||
const prevLon = coordinates[i - 1][0]
|
|
||||||
const lonDiff = lon - prevLon
|
|
||||||
|
|
||||||
// If longitude jumps more than 180°, we crossed the IDL
|
|
||||||
if (lonDiff > 180) {
|
|
||||||
// Crossed from east to west (e.g., 170° to -170°)
|
|
||||||
// Subtract 360° to make it continuous (e.g., 170° to -170° becomes 170° to -170°-360° = -530°)
|
|
||||||
offset -= 360
|
|
||||||
lon -= 360
|
|
||||||
} else if (lonDiff < -180) {
|
|
||||||
// Crossed from west to east (e.g., -170° to 170°)
|
|
||||||
// Add 360° to make it continuous (e.g., -170° to 170° becomes -170° to 170°+360° = 530°)
|
|
||||||
offset += 360
|
|
||||||
lon += 360
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
coordinates.push([lon, point.latitude])
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate total distance for the segment
|
// Calculate total distance for the segment
|
||||||
let totalDistance = 0
|
let totalDistance = 0
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ export class ApiClient {
|
||||||
end_at,
|
end_at,
|
||||||
page: page.toString(),
|
page: page.toString(),
|
||||||
per_page: per_page.toString(),
|
per_page: per_page.toString(),
|
||||||
slim: 'true',
|
slim: 'true'
|
||||||
order: 'asc'
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const response = await fetch(`${this.baseURL}/points?${params}`, {
|
const response = await fetch(`${this.baseURL}/points?${params}`, {
|
||||||
|
|
@ -41,83 +40,43 @@ export class ApiClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch all points for date range (handles pagination with parallel requests)
|
* Fetch all points for date range (handles pagination)
|
||||||
* @param {Object} options - { start_at, end_at, onProgress, maxConcurrent }
|
* @param {Object} options - { start_at, end_at, onProgress }
|
||||||
* @returns {Promise<Array>} All points
|
* @returns {Promise<Array>} All points
|
||||||
*/
|
*/
|
||||||
async fetchAllPoints({ start_at, end_at, onProgress = null, maxConcurrent = 3 }) {
|
async fetchAllPoints({ start_at, end_at, onProgress = null }) {
|
||||||
// First fetch to get total pages
|
const allPoints = []
|
||||||
const firstPage = await this.fetchPoints({ start_at, end_at, page: 1, per_page: 1000 })
|
let page = 1
|
||||||
const totalPages = firstPage.totalPages
|
let totalPages = 1
|
||||||
|
|
||||||
|
do {
|
||||||
|
const { points, currentPage, totalPages: total } =
|
||||||
|
await this.fetchPoints({ start_at, end_at, page, per_page: 1000 })
|
||||||
|
|
||||||
|
allPoints.push(...points)
|
||||||
|
totalPages = total
|
||||||
|
page++
|
||||||
|
|
||||||
// If only one page, return immediately
|
|
||||||
if (totalPages === 1) {
|
|
||||||
if (onProgress) {
|
if (onProgress) {
|
||||||
|
// Avoid division by zero - if no pages, progress is 100%
|
||||||
|
const progress = totalPages > 0 ? currentPage / totalPages : 1.0
|
||||||
onProgress({
|
onProgress({
|
||||||
loaded: firstPage.points.length,
|
loaded: allPoints.length,
|
||||||
currentPage: 1,
|
currentPage,
|
||||||
totalPages: 1,
|
|
||||||
progress: 1.0
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return firstPage.points
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize results array with first page
|
|
||||||
const pageResults = [{ page: 1, points: firstPage.points }]
|
|
||||||
let completedPages = 1
|
|
||||||
|
|
||||||
// Create array of remaining page numbers
|
|
||||||
const remainingPages = Array.from(
|
|
||||||
{ length: totalPages - 1 },
|
|
||||||
(_, i) => i + 2
|
|
||||||
)
|
|
||||||
|
|
||||||
// Process pages in batches of maxConcurrent
|
|
||||||
for (let i = 0; i < remainingPages.length; i += maxConcurrent) {
|
|
||||||
const batch = remainingPages.slice(i, i + maxConcurrent)
|
|
||||||
|
|
||||||
// Fetch batch in parallel
|
|
||||||
const batchPromises = batch.map(page =>
|
|
||||||
this.fetchPoints({ start_at, end_at, page, per_page: 1000 })
|
|
||||||
.then(result => ({ page, points: result.points }))
|
|
||||||
)
|
|
||||||
|
|
||||||
const batchResults = await Promise.all(batchPromises)
|
|
||||||
pageResults.push(...batchResults)
|
|
||||||
completedPages += batchResults.length
|
|
||||||
|
|
||||||
// Call progress callback after each batch
|
|
||||||
if (onProgress) {
|
|
||||||
const progress = totalPages > 0 ? completedPages / totalPages : 1.0
|
|
||||||
onProgress({
|
|
||||||
loaded: pageResults.reduce((sum, r) => sum + r.points.length, 0),
|
|
||||||
currentPage: completedPages,
|
|
||||||
totalPages,
|
totalPages,
|
||||||
progress
|
progress
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
} while (page <= totalPages)
|
||||||
|
|
||||||
// Sort by page number to ensure correct order
|
return allPoints
|
||||||
pageResults.sort((a, b) => a.page - b.page)
|
|
||||||
|
|
||||||
// Flatten into single array
|
|
||||||
return pageResults.flatMap(r => r.points)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch visits for date range (paginated)
|
* Fetch visits for date range
|
||||||
* @param {Object} options - { start_at, end_at, page, per_page }
|
|
||||||
* @returns {Promise<Object>} { visits, currentPage, totalPages }
|
|
||||||
*/
|
*/
|
||||||
async fetchVisitsPage({ start_at, end_at, page = 1, per_page = 500 }) {
|
async fetchVisits({ start_at, end_at }) {
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({ start_at, end_at })
|
||||||
start_at,
|
|
||||||
end_at,
|
|
||||||
page: page.toString(),
|
|
||||||
per_page: per_page.toString()
|
|
||||||
})
|
|
||||||
|
|
||||||
const response = await fetch(`${this.baseURL}/visits?${params}`, {
|
const response = await fetch(`${this.baseURL}/visits?${params}`, {
|
||||||
headers: this.getHeaders()
|
headers: this.getHeaders()
|
||||||
|
|
@ -127,63 +86,20 @@ export class ApiClient {
|
||||||
throw new Error(`Failed to fetch visits: ${response.statusText}`)
|
throw new Error(`Failed to fetch visits: ${response.statusText}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const visits = await response.json()
|
return response.json()
|
||||||
|
|
||||||
return {
|
|
||||||
visits,
|
|
||||||
currentPage: parseInt(response.headers.get('X-Current-Page') || '1'),
|
|
||||||
totalPages: parseInt(response.headers.get('X-Total-Pages') || '1')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch all visits for date range (handles pagination)
|
* Fetch places optionally filtered by tags
|
||||||
* @param {Object} options - { start_at, end_at, onProgress }
|
|
||||||
* @returns {Promise<Array>} All visits
|
|
||||||
*/
|
*/
|
||||||
async fetchVisits({ start_at, end_at, onProgress = null }) {
|
async fetchPlaces({ tag_ids = [] } = {}) {
|
||||||
const allVisits = []
|
const params = new URLSearchParams()
|
||||||
let page = 1
|
|
||||||
let totalPages = 1
|
|
||||||
|
|
||||||
do {
|
|
||||||
const { visits, currentPage, totalPages: total } =
|
|
||||||
await this.fetchVisitsPage({ start_at, end_at, page, per_page: 500 })
|
|
||||||
|
|
||||||
allVisits.push(...visits)
|
|
||||||
totalPages = total
|
|
||||||
page++
|
|
||||||
|
|
||||||
if (onProgress) {
|
|
||||||
const progress = totalPages > 0 ? currentPage / totalPages : 1.0
|
|
||||||
onProgress({
|
|
||||||
loaded: allVisits.length,
|
|
||||||
currentPage,
|
|
||||||
totalPages,
|
|
||||||
progress
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} while (page <= totalPages)
|
|
||||||
|
|
||||||
return allVisits
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch places (paginated)
|
|
||||||
* @param {Object} options - { tag_ids, page, per_page }
|
|
||||||
* @returns {Promise<Object>} { places, currentPage, totalPages }
|
|
||||||
*/
|
|
||||||
async fetchPlacesPage({ tag_ids = [], page = 1, per_page = 500 } = {}) {
|
|
||||||
const params = new URLSearchParams({
|
|
||||||
page: page.toString(),
|
|
||||||
per_page: per_page.toString()
|
|
||||||
})
|
|
||||||
|
|
||||||
if (tag_ids && tag_ids.length > 0) {
|
if (tag_ids && tag_ids.length > 0) {
|
||||||
tag_ids.forEach(id => params.append('tag_ids[]', id))
|
tag_ids.forEach(id => params.append('tag_ids[]', id))
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `${this.baseURL}/places?${params.toString()}`
|
const url = `${this.baseURL}/places${params.toString() ? '?' + params.toString() : ''}`
|
||||||
|
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
headers: this.getHeaders()
|
headers: this.getHeaders()
|
||||||
|
|
@ -193,45 +109,7 @@ export class ApiClient {
|
||||||
throw new Error(`Failed to fetch places: ${response.statusText}`)
|
throw new Error(`Failed to fetch places: ${response.statusText}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const places = await response.json()
|
return response.json()
|
||||||
|
|
||||||
return {
|
|
||||||
places,
|
|
||||||
currentPage: parseInt(response.headers.get('X-Current-Page') || '1'),
|
|
||||||
totalPages: parseInt(response.headers.get('X-Total-Pages') || '1')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch all places optionally filtered by tags (handles pagination)
|
|
||||||
* @param {Object} options - { tag_ids, onProgress }
|
|
||||||
* @returns {Promise<Array>} All places
|
|
||||||
*/
|
|
||||||
async fetchPlaces({ tag_ids = [], onProgress = null } = {}) {
|
|
||||||
const allPlaces = []
|
|
||||||
let page = 1
|
|
||||||
let totalPages = 1
|
|
||||||
|
|
||||||
do {
|
|
||||||
const { places, currentPage, totalPages: total } =
|
|
||||||
await this.fetchPlacesPage({ tag_ids, page, per_page: 500 })
|
|
||||||
|
|
||||||
allPlaces.push(...places)
|
|
||||||
totalPages = total
|
|
||||||
page++
|
|
||||||
|
|
||||||
if (onProgress) {
|
|
||||||
const progress = totalPages > 0 ? currentPage / totalPages : 1.0
|
|
||||||
onProgress({
|
|
||||||
loaded: allPlaces.length,
|
|
||||||
currentPage,
|
|
||||||
totalPages,
|
|
||||||
progress
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} while (page <= totalPages)
|
|
||||||
|
|
||||||
return allPlaces
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,11 @@ const DEFAULT_SETTINGS = {
|
||||||
routeOpacity: 0.6,
|
routeOpacity: 0.6,
|
||||||
fogOfWarRadius: 100,
|
fogOfWarRadius: 100,
|
||||||
fogOfWarThreshold: 1,
|
fogOfWarThreshold: 1,
|
||||||
metersBetweenRoutes: 500,
|
metersBetweenRoutes: 1000,
|
||||||
minutesBetweenRoutes: 60,
|
minutesBetweenRoutes: 60,
|
||||||
pointsRenderingMode: 'raw',
|
pointsRenderingMode: 'raw',
|
||||||
speedColoredRoutes: false,
|
speedColoredRoutes: false,
|
||||||
speedColorScale: '0:#00ff00|15:#00ffff|30:#ff00ff|50:#ffff00|100:#ff3300',
|
speedColorScale: '0:#00ff00|15:#00ffff|30:#ff00ff|50:#ffff00|100:#ff3300'
|
||||||
globeProjection: false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mapping between v2 layer names and v1 layer names in enabled_map_layers array
|
// Mapping between v2 layer names and v1 layer names in enabled_map_layers array
|
||||||
|
|
@ -42,8 +41,7 @@ const BACKEND_SETTINGS_MAP = {
|
||||||
minutesBetweenRoutes: 'minutes_between_routes',
|
minutesBetweenRoutes: 'minutes_between_routes',
|
||||||
pointsRenderingMode: 'points_rendering_mode',
|
pointsRenderingMode: 'points_rendering_mode',
|
||||||
speedColoredRoutes: 'speed_colored_routes',
|
speedColoredRoutes: 'speed_colored_routes',
|
||||||
speedColorScale: 'speed_color_scale',
|
speedColorScale: 'speed_color_scale'
|
||||||
globeProjection: 'globe_projection'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SettingsManager {
|
export class SettingsManager {
|
||||||
|
|
@ -154,8 +152,6 @@ export class SettingsManager {
|
||||||
value = parseInt(value) || DEFAULT_SETTINGS.minutesBetweenRoutes
|
value = parseInt(value) || DEFAULT_SETTINGS.minutesBetweenRoutes
|
||||||
} else if (frontendKey === 'speedColoredRoutes') {
|
} else if (frontendKey === 'speedColoredRoutes') {
|
||||||
value = value === true || value === 'true'
|
value = value === true || value === 'true'
|
||||||
} else if (frontendKey === 'globeProjection') {
|
|
||||||
value = value === true || value === 'true'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
frontendSettings[frontendKey] = value
|
frontendSettings[frontendKey] = value
|
||||||
|
|
@ -223,8 +219,6 @@ export class SettingsManager {
|
||||||
value = parseInt(value).toString()
|
value = parseInt(value).toString()
|
||||||
} else if (frontendKey === 'speedColoredRoutes') {
|
} else if (frontendKey === 'speedColoredRoutes') {
|
||||||
value = Boolean(value)
|
value = Boolean(value)
|
||||||
} else if (frontendKey === 'globeProjection') {
|
|
||||||
value = Boolean(value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
backendSettings[backendKey] = value
|
backendSettings[backendKey] = value
|
||||||
|
|
|
||||||
8
app/jobs/cache/preheating_job.rb
vendored
8
app/jobs/cache/preheating_job.rb
vendored
|
|
@ -28,14 +28,6 @@ class Cache::PreheatingJob < ApplicationJob
|
||||||
user.cities_visited_uncached,
|
user.cities_visited_uncached,
|
||||||
expires_in: 1.day
|
expires_in: 1.day
|
||||||
)
|
)
|
||||||
|
|
||||||
# Preheat total_distance cache
|
|
||||||
total_distance_meters = user.stats.sum(:distance)
|
|
||||||
Rails.cache.write(
|
|
||||||
"dawarich/user_#{user.id}_total_distance",
|
|
||||||
Stat.convert_distance(total_distance_meters, user.safe_settings.distance_unit),
|
|
||||||
expires_in: 1.day
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ class Users::Digests::CalculatingJob < ApplicationJob
|
||||||
queue_as :digests
|
queue_as :digests
|
||||||
|
|
||||||
def perform(user_id, year)
|
def perform(user_id, year)
|
||||||
recalculate_monthly_stats(user_id, year)
|
|
||||||
Users::Digests::CalculateYear.new(user_id, year).call
|
Users::Digests::CalculateYear.new(user_id, year).call
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
create_digest_failed_notification(user_id, e)
|
create_digest_failed_notification(user_id, e)
|
||||||
|
|
@ -12,12 +11,6 @@ class Users::Digests::CalculatingJob < ApplicationJob
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def recalculate_monthly_stats(user_id, year)
|
|
||||||
(1..12).each do |month|
|
|
||||||
Stats::CalculateMonth.new(user_id, year, month).call
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_digest_failed_notification(user_id, error)
|
def create_digest_failed_notification(user_id, error)
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,14 @@ class Users::MailerSendingJob < ApplicationJob
|
||||||
def perform(user_id, email_type, **options)
|
def perform(user_id, email_type, **options)
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
|
|
||||||
return if should_skip_email?(user, email_type)
|
if should_skip_email?(user, email_type)
|
||||||
|
ExceptionReporter.call(
|
||||||
|
'Users::MailerSendingJob',
|
||||||
|
"Skipping #{email_type} email for user ID #{user_id} - #{skip_reason(user, email_type)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
params = { user: user }.merge(options)
|
params = { user: user }.merge(options)
|
||||||
|
|
||||||
|
|
@ -30,4 +37,15 @@ class Users::MailerSendingJob < ApplicationJob
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def skip_reason(user, email_type)
|
||||||
|
case email_type.to_s
|
||||||
|
when 'trial_expires_soon', 'trial_expired'
|
||||||
|
'user is already subscribed'
|
||||||
|
when 'post_trial_reminder_early', 'post_trial_reminder_late'
|
||||||
|
user.active? ? 'user is subscribed' : 'user is not in trial state'
|
||||||
|
else
|
||||||
|
'unknown reason'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -45,22 +45,25 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
|
||||||
|
|
||||||
def countries_visited
|
def countries_visited
|
||||||
Rails.cache.fetch("dawarich/user_#{id}_countries_visited", expires_in: 1.day) do
|
Rails.cache.fetch("dawarich/user_#{id}_countries_visited", expires_in: 1.day) do
|
||||||
countries_visited_uncached
|
points
|
||||||
|
.without_raw_data
|
||||||
|
.where.not(country_name: [nil, ''])
|
||||||
|
.distinct
|
||||||
|
.pluck(:country_name)
|
||||||
|
.compact
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def cities_visited
|
def cities_visited
|
||||||
Rails.cache.fetch("dawarich/user_#{id}_cities_visited", expires_in: 1.day) do
|
Rails.cache.fetch("dawarich/user_#{id}_cities_visited", expires_in: 1.day) do
|
||||||
cities_visited_uncached
|
points.where.not(city: [nil, '']).distinct.pluck(:city).compact
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_distance
|
def total_distance
|
||||||
Rails.cache.fetch("dawarich/user_#{id}_total_distance", expires_in: 1.day) do
|
|
||||||
total_distance_meters = stats.sum(:distance)
|
total_distance_meters = stats.sum(:distance)
|
||||||
Stat.convert_distance(total_distance_meters, safe_settings.distance_unit)
|
Stat.convert_distance(total_distance_meters, safe_settings.distance_unit)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def total_countries
|
def total_countries
|
||||||
countries_visited.size
|
countries_visited.size
|
||||||
|
|
@ -136,47 +139,17 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
|
||||||
Time.zone.name
|
Time.zone.name
|
||||||
end
|
end
|
||||||
|
|
||||||
# Aggregate countries from all stats' toponyms
|
|
||||||
# This is more accurate than raw point queries as it uses processed data
|
|
||||||
def countries_visited_uncached
|
def countries_visited_uncached
|
||||||
countries = Set.new
|
points
|
||||||
|
.without_raw_data
|
||||||
stats.find_each do |stat|
|
.where.not(country_name: [nil, ''])
|
||||||
toponyms = stat.toponyms
|
.distinct
|
||||||
next unless toponyms.is_a?(Array)
|
.pluck(:country_name)
|
||||||
|
.compact
|
||||||
toponyms.each do |toponym|
|
|
||||||
next unless toponym.is_a?(Hash)
|
|
||||||
|
|
||||||
countries.add(toponym['country']) if toponym['country'].present?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
countries.to_a.sort
|
|
||||||
end
|
|
||||||
|
|
||||||
# Aggregate cities from all stats' toponyms
|
|
||||||
# This respects MIN_MINUTES_SPENT_IN_CITY since toponyms are already filtered
|
|
||||||
def cities_visited_uncached
|
def cities_visited_uncached
|
||||||
cities = Set.new
|
points.where.not(city: [nil, '']).distinct.pluck(:city).compact
|
||||||
|
|
||||||
stats.find_each do |stat|
|
|
||||||
toponyms = stat.toponyms
|
|
||||||
next unless toponyms.is_a?(Array)
|
|
||||||
|
|
||||||
toponyms.each do |toponym|
|
|
||||||
next unless toponym.is_a?(Hash)
|
|
||||||
next unless toponym['cities'].is_a?(Array)
|
|
||||||
|
|
||||||
toponym['cities'].each do |city|
|
|
||||||
next unless city.is_a?(Hash)
|
|
||||||
|
|
||||||
cities.add(city['city']) if city['city'].present?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
cities.to_a.sort
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def home_place_coordinates
|
def home_place_coordinates
|
||||||
|
|
|
||||||
|
|
@ -132,11 +132,6 @@ class Users::Digest < ApplicationRecord
|
||||||
(all_time_stats['total_distance'] || 0).to_i
|
(all_time_stats['total_distance'] || 0).to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def untracked_days
|
|
||||||
days_in_year = Date.leap?(year) ? 366 : 365
|
|
||||||
[days_in_year - total_tracked_days, 0].max.round(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
def distance_km
|
def distance_km
|
||||||
distance.to_f / 1000
|
distance.to_f / 1000
|
||||||
end
|
end
|
||||||
|
|
@ -156,15 +151,4 @@ class Users::Digest < ApplicationRecord
|
||||||
def generate_sharing_uuid
|
def generate_sharing_uuid
|
||||||
self.sharing_uuid ||= SecureRandom.uuid
|
self.sharing_uuid ||= SecureRandom.uuid
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_tracked_days
|
|
||||||
(total_tracked_minutes / 1440.0).round(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
def total_tracked_minutes
|
|
||||||
# Use total_country_minutes if available (new digests),
|
|
||||||
# fall back to summing top_countries_by_time (existing digests)
|
|
||||||
time_spent_by_location['total_country_minutes'] ||
|
|
||||||
top_countries_by_time.sum { |country| country['minutes'].to_i }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,7 @@ class Api::UserSerializer
|
||||||
photoprism_url: user.safe_settings.photoprism_url,
|
photoprism_url: user.safe_settings.photoprism_url,
|
||||||
visits_suggestions_enabled: user.safe_settings.visits_suggestions_enabled?,
|
visits_suggestions_enabled: user.safe_settings.visits_suggestions_enabled?,
|
||||||
speed_color_scale: user.safe_settings.speed_color_scale,
|
speed_color_scale: user.safe_settings.speed_color_scale,
|
||||||
fog_of_war_threshold: user.safe_settings.fog_of_war_threshold,
|
fog_of_war_threshold: user.safe_settings.fog_of_war_threshold
|
||||||
globe_projection: user.safe_settings.globe_projection
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
7
app/services/cache/clean.rb
vendored
7
app/services/cache/clean.rb
vendored
|
|
@ -9,7 +9,6 @@ class Cache::Clean
|
||||||
delete_years_tracked_cache
|
delete_years_tracked_cache
|
||||||
delete_points_geocoded_stats_cache
|
delete_points_geocoded_stats_cache
|
||||||
delete_countries_cities_cache
|
delete_countries_cities_cache
|
||||||
delete_total_distance_cache
|
|
||||||
Rails.logger.info('Cache cleaned')
|
Rails.logger.info('Cache cleaned')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -41,11 +40,5 @@ class Cache::Clean
|
||||||
Rails.cache.delete("dawarich/user_#{user.id}_cities_visited")
|
Rails.cache.delete("dawarich/user_#{user.id}_cities_visited")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_total_distance_cache
|
|
||||||
User.find_each do |user|
|
|
||||||
Rails.cache.delete("dawarich/user_#{user.id}_total_distance")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
5
app/services/cache/invalidate_user_caches.rb
vendored
5
app/services/cache/invalidate_user_caches.rb
vendored
|
|
@ -14,7 +14,6 @@ class Cache::InvalidateUserCaches
|
||||||
invalidate_countries_visited
|
invalidate_countries_visited
|
||||||
invalidate_cities_visited
|
invalidate_cities_visited
|
||||||
invalidate_points_geocoded_stats
|
invalidate_points_geocoded_stats
|
||||||
invalidate_total_distance
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def invalidate_countries_visited
|
def invalidate_countries_visited
|
||||||
|
|
@ -29,10 +28,6 @@ class Cache::InvalidateUserCaches
|
||||||
Rails.cache.delete("dawarich/user_#{user_id}_points_geocoded_stats")
|
Rails.cache.delete("dawarich/user_#{user_id}_points_geocoded_stats")
|
||||||
end
|
end
|
||||||
|
|
||||||
def invalidate_total_distance
|
|
||||||
Rails.cache.delete("dawarich/user_#{user_id}_total_distance")
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
attr_reader :user_id
|
attr_reader :user_id
|
||||||
|
|
|
||||||
|
|
@ -49,17 +49,6 @@ class CountriesAndCities
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_duration_in_minutes(timestamps)
|
def calculate_duration_in_minutes(timestamps)
|
||||||
return 0 if timestamps.size < 2
|
((timestamps.max - timestamps.min).to_i / 60)
|
||||||
|
|
||||||
sorted = timestamps.sort
|
|
||||||
total_minutes = 0
|
|
||||||
gap_threshold_seconds = ::MIN_MINUTES_SPENT_IN_CITY * 60
|
|
||||||
|
|
||||||
sorted.each_cons(2) do |prev_ts, curr_ts|
|
|
||||||
interval_seconds = curr_ts - prev_ts
|
|
||||||
total_minutes += (interval_seconds / 60) if interval_seconds < gap_threshold_seconds
|
|
||||||
end
|
|
||||||
|
|
||||||
total_minutes
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,7 @@ class Immich::RequestPhotos
|
||||||
while page <= max_pages
|
while page <= max_pages
|
||||||
response = JSON.parse(
|
response = JSON.parse(
|
||||||
HTTParty.post(
|
HTTParty.post(
|
||||||
immich_api_base_url,
|
immich_api_base_url, headers: headers, body: request_body(page)
|
||||||
headers: headers,
|
|
||||||
body: request_body(page),
|
|
||||||
timeout: 10
|
|
||||||
).body
|
).body
|
||||||
)
|
)
|
||||||
Rails.logger.debug('==== IMMICH RESPONSE ====')
|
Rails.logger.debug('==== IMMICH RESPONSE ====')
|
||||||
|
|
@ -49,9 +46,6 @@ class Immich::RequestPhotos
|
||||||
end
|
end
|
||||||
|
|
||||||
data.flatten
|
data.flatten
|
||||||
rescue HTTParty::Error, Net::OpenTimeout, Net::ReadTimeout => e
|
|
||||||
Rails.logger.error("Immich photo fetch failed: #{e.message}")
|
|
||||||
[]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def headers
|
def headers
|
||||||
|
|
|
||||||
|
|
@ -43,17 +43,13 @@ class Photoprism::RequestPhotos
|
||||||
end
|
end
|
||||||
|
|
||||||
data.flatten
|
data.flatten
|
||||||
rescue HTTParty::Error, Net::OpenTimeout, Net::ReadTimeout => e
|
|
||||||
Rails.logger.error("Photoprism photo fetch failed: #{e.message}")
|
|
||||||
[]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_page(offset)
|
def fetch_page(offset)
|
||||||
response = HTTParty.get(
|
response = HTTParty.get(
|
||||||
photoprism_api_base_url,
|
photoprism_api_base_url,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
query: request_params(offset),
|
query: request_params(offset)
|
||||||
timeout: 10
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if response.code != 200
|
if response.code != 200
|
||||||
|
|
|
||||||
|
|
@ -50,13 +50,11 @@ class Stats::CalculateMonth
|
||||||
def points
|
def points
|
||||||
return @points if defined?(@points)
|
return @points if defined?(@points)
|
||||||
|
|
||||||
# Select all needed columns to avoid duplicate queries
|
|
||||||
# Used for both distance calculation and toponyms extraction
|
|
||||||
@points = user
|
@points = user
|
||||||
.points
|
.points
|
||||||
.without_raw_data
|
.without_raw_data
|
||||||
.where(timestamp: start_timestamp..end_timestamp)
|
.where(timestamp: start_timestamp..end_timestamp)
|
||||||
.select(:lonlat, :timestamp, :city, :country_name)
|
.select(:lonlat, :timestamp)
|
||||||
.order(timestamp: :asc)
|
.order(timestamp: :asc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -65,8 +63,14 @@ class Stats::CalculateMonth
|
||||||
end
|
end
|
||||||
|
|
||||||
def toponyms
|
def toponyms
|
||||||
# Reuse already-loaded points instead of making a duplicate query
|
toponym_points =
|
||||||
CountriesAndCities.new(points).call
|
user
|
||||||
|
.points
|
||||||
|
.without_raw_data
|
||||||
|
.where(timestamp: start_timestamp..end_timestamp)
|
||||||
|
.select(:city, :country_name, :timestamp)
|
||||||
|
|
||||||
|
CountriesAndCities.new(toponym_points).call
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_stats_update_failed_notification(user, error)
|
def create_stats_update_failed_notification(user, error)
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
module Users
|
module Users
|
||||||
module Digests
|
module Digests
|
||||||
class CalculateYear
|
class CalculateYear
|
||||||
MINUTES_PER_DAY = 1440
|
|
||||||
|
|
||||||
def initialize(user_id, year)
|
def initialize(user_id, year)
|
||||||
@user = ::User.find(user_id)
|
@user = ::User.find(user_id)
|
||||||
@year = year.to_i
|
@year = year.to_i
|
||||||
|
|
@ -52,7 +50,7 @@ module Users
|
||||||
next unless toponym.is_a?(Hash)
|
next unless toponym.is_a?(Hash)
|
||||||
|
|
||||||
country = toponym['country']
|
country = toponym['country']
|
||||||
next if country.blank?
|
next unless country.present?
|
||||||
|
|
||||||
if toponym['cities'].is_a?(Array)
|
if toponym['cities'].is_a?(Array)
|
||||||
toponym['cities'].each do |city|
|
toponym['cities'].each do |city|
|
||||||
|
|
@ -66,7 +64,7 @@ module Users
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
country_cities.sort_by { |_country, cities| -cities.size }.map do |country, cities|
|
country_cities.sort_by { |country, _| country }.map do |country, cities|
|
||||||
{
|
{
|
||||||
'country' => country,
|
'country' => country,
|
||||||
'cities' => cities.to_a.sort.map { |city| { 'city' => city } }
|
'cities' => cities.to_a.sort.map { |city| { 'city' => city } }
|
||||||
|
|
@ -90,111 +88,18 @@ module Users
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_time_spent
|
def calculate_time_spent
|
||||||
country_minutes = calculate_actual_country_minutes
|
country_time = Hash.new(0)
|
||||||
|
|
||||||
{
|
|
||||||
'countries' => format_top_countries(country_minutes),
|
|
||||||
'cities' => calculate_city_time_spent,
|
|
||||||
'total_country_minutes' => country_minutes.values.sum
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def format_top_countries(country_minutes)
|
|
||||||
country_minutes
|
|
||||||
.sort_by { |_, minutes| -minutes }
|
|
||||||
.first(10)
|
|
||||||
.map { |name, minutes| { 'name' => name, 'minutes' => minutes } }
|
|
||||||
end
|
|
||||||
|
|
||||||
def calculate_actual_country_minutes
|
|
||||||
points_by_date = group_points_by_date
|
|
||||||
country_minutes = Hash.new(0)
|
|
||||||
|
|
||||||
points_by_date.each do |_date, day_points|
|
|
||||||
countries_on_day = day_points.map(&:country_name).uniq
|
|
||||||
|
|
||||||
if countries_on_day.size == 1
|
|
||||||
# Single country day - assign full day
|
|
||||||
country_minutes[countries_on_day.first] += MINUTES_PER_DAY
|
|
||||||
else
|
|
||||||
# Multi-country day - calculate proportional time
|
|
||||||
calculate_proportional_time(day_points, country_minutes)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
country_minutes
|
|
||||||
end
|
|
||||||
|
|
||||||
def group_points_by_date
|
|
||||||
points = fetch_year_points_with_country_ordered
|
|
||||||
|
|
||||||
points.group_by do |point|
|
|
||||||
Time.zone.at(point.timestamp).to_date
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def calculate_proportional_time(day_points, country_minutes)
|
|
||||||
country_spans = Hash.new(0)
|
|
||||||
points_by_country = day_points.group_by(&:country_name)
|
|
||||||
|
|
||||||
points_by_country.each do |country, country_points|
|
|
||||||
timestamps = country_points.map(&:timestamp)
|
|
||||||
span_seconds = timestamps.max - timestamps.min
|
|
||||||
# Minimum 60 seconds (1 min) for single-point countries
|
|
||||||
country_spans[country] = [span_seconds, 60].max
|
|
||||||
end
|
|
||||||
|
|
||||||
total_spans = country_spans.values.sum.to_f
|
|
||||||
|
|
||||||
country_spans.each do |country, span|
|
|
||||||
proportional_minutes = (span / total_spans * MINUTES_PER_DAY).round
|
|
||||||
country_minutes[country] += proportional_minutes
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def fetch_year_points_with_country_ordered
|
|
||||||
start_of_year = Time.zone.local(year, 1, 1, 0, 0, 0)
|
|
||||||
end_of_year = start_of_year.end_of_year
|
|
||||||
|
|
||||||
user.points
|
|
||||||
.without_raw_data
|
|
||||||
.where('timestamp >= ? AND timestamp <= ?', start_of_year.to_i, end_of_year.to_i)
|
|
||||||
.where.not(country_name: [nil, ''])
|
|
||||||
.select(:country_name, :timestamp)
|
|
||||||
.order(timestamp: :asc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def calculate_city_time_spent
|
|
||||||
city_time = aggregate_city_time_from_monthly_stats
|
|
||||||
|
|
||||||
city_time
|
|
||||||
.sort_by { |_, minutes| -minutes }
|
|
||||||
.first(10)
|
|
||||||
.map { |name, minutes| { 'name' => name, 'minutes' => minutes } }
|
|
||||||
end
|
|
||||||
|
|
||||||
def aggregate_city_time_from_monthly_stats
|
|
||||||
city_time = Hash.new(0)
|
city_time = Hash.new(0)
|
||||||
|
|
||||||
monthly_stats.each do |stat|
|
monthly_stats.each do |stat|
|
||||||
process_stat_toponyms(stat, city_time)
|
|
||||||
end
|
|
||||||
|
|
||||||
city_time
|
|
||||||
end
|
|
||||||
|
|
||||||
def process_stat_toponyms(stat, city_time)
|
|
||||||
toponyms = stat.toponyms
|
toponyms = stat.toponyms
|
||||||
return unless toponyms.is_a?(Array)
|
next unless toponyms.is_a?(Array)
|
||||||
|
|
||||||
toponyms.each do |toponym|
|
toponyms.each do |toponym|
|
||||||
process_toponym_cities(toponym, city_time)
|
next unless toponym.is_a?(Hash)
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def process_toponym_cities(toponym, city_time)
|
country = toponym['country']
|
||||||
return unless toponym.is_a?(Hash)
|
next unless toponym['cities'].is_a?(Array)
|
||||||
return unless toponym['cities'].is_a?(Array)
|
|
||||||
|
|
||||||
toponym['cities'].each do |city|
|
toponym['cities'].each do |city|
|
||||||
next unless city.is_a?(Hash)
|
next unless city.is_a?(Hash)
|
||||||
|
|
@ -202,9 +107,17 @@ module Users
|
||||||
stayed_for = city['stayed_for'].to_i
|
stayed_for = city['stayed_for'].to_i
|
||||||
city_name = city['city']
|
city_name = city['city']
|
||||||
|
|
||||||
|
country_time[country] += stayed_for if country.present?
|
||||||
city_time[city_name] += stayed_for if city_name.present?
|
city_time[city_name] += stayed_for if city_name.present?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
{
|
||||||
|
'countries' => country_time.sort_by { |_, v| -v }.first(10).map { |name, minutes| { 'name' => name, 'minutes' => minutes } },
|
||||||
|
'cities' => city_time.sort_by { |_, v| -v }.first(10).map { |name, minutes| { 'name' => name, 'minutes' => minutes } }
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def calculate_first_time_visits
|
def calculate_first_time_visits
|
||||||
FirstTimeVisitsCalculator.new(user, year).call
|
FirstTimeVisitsCalculator.new(user, year).call
|
||||||
|
|
@ -216,8 +129,8 @@ module Users
|
||||||
|
|
||||||
def calculate_all_time_stats
|
def calculate_all_time_stats
|
||||||
{
|
{
|
||||||
'total_countries' => user.countries_visited_uncached.size,
|
'total_countries' => user.countries_visited.count,
|
||||||
'total_cities' => user.cities_visited_uncached.size,
|
'total_cities' => user.cities_visited.count,
|
||||||
'total_distance' => user.stats.sum(:distance).to_s
|
'total_distance' => user.stats.sum(:distance).to_s
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class Users::ExportData::Points
|
||||||
|
|
||||||
output_file.write('[')
|
output_file.write('[')
|
||||||
|
|
||||||
user.points.find_in_batches(batch_size: BATCH_SIZE).with_index do |batch, _batch_index|
|
user.points.find_in_batches(batch_size: BATCH_SIZE).with_index do |batch, batch_index|
|
||||||
batch_sql = build_batch_query(batch.map(&:id))
|
batch_sql = build_batch_query(batch.map(&:id))
|
||||||
result = ActiveRecord::Base.connection.exec_query(batch_sql, 'Points Export Batch')
|
result = ActiveRecord::Base.connection.exec_query(batch_sql, 'Points Export Batch')
|
||||||
|
|
||||||
|
|
@ -188,14 +188,14 @@ class Users::ExportData::Points
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless row['visit_name']
|
if row['visit_name']
|
||||||
|
|
||||||
point_hash['visit_reference'] = {
|
point_hash['visit_reference'] = {
|
||||||
'name' => row['visit_name'],
|
'name' => row['visit_name'],
|
||||||
'started_at' => row['visit_started_at'],
|
'started_at' => row['visit_started_at'],
|
||||||
'ended_at' => row['visit_ended_at']
|
'ended_at' => row['visit_ended_at']
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def log_progress(processed, total)
|
def log_progress(processed, total)
|
||||||
percentage = (processed.to_f / total * 100).round(1)
|
percentage = (processed.to_f / total * 100).round(1)
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,7 @@ class Users::SafeSettings
|
||||||
'visits_suggestions_enabled' => 'true',
|
'visits_suggestions_enabled' => 'true',
|
||||||
'enabled_map_layers' => %w[Routes Heatmap],
|
'enabled_map_layers' => %w[Routes Heatmap],
|
||||||
'maps_maplibre_style' => 'light',
|
'maps_maplibre_style' => 'light',
|
||||||
'digest_emails_enabled' => true,
|
'digest_emails_enabled' => true
|
||||||
'globe_projection' => false
|
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def initialize(settings = {})
|
def initialize(settings = {})
|
||||||
|
|
@ -53,8 +52,7 @@ class Users::SafeSettings
|
||||||
speed_color_scale: speed_color_scale,
|
speed_color_scale: speed_color_scale,
|
||||||
fog_of_war_threshold: fog_of_war_threshold,
|
fog_of_war_threshold: fog_of_war_threshold,
|
||||||
enabled_map_layers: enabled_map_layers,
|
enabled_map_layers: enabled_map_layers,
|
||||||
maps_maplibre_style: maps_maplibre_style,
|
maps_maplibre_style: maps_maplibre_style
|
||||||
globe_projection: globe_projection
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
# rubocop:enable Metrics/MethodLength
|
# rubocop:enable Metrics/MethodLength
|
||||||
|
|
@ -143,10 +141,6 @@ class Users::SafeSettings
|
||||||
settings['maps_maplibre_style']
|
settings['maps_maplibre_style']
|
||||||
end
|
end
|
||||||
|
|
||||||
def globe_projection
|
|
||||||
ActiveModel::Type::Boolean.new.cast(settings['globe_projection'])
|
|
||||||
end
|
|
||||||
|
|
||||||
def digest_emails_enabled?
|
def digest_emails_enabled?
|
||||||
value = settings['digest_emails_enabled']
|
value = settings['digest_emails_enabled']
|
||||||
return true if value.nil?
|
return true if value.nil?
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ module Visits
|
||||||
|
|
||||||
def call
|
def call
|
||||||
Visit
|
Visit
|
||||||
.includes(:place, :area)
|
.includes(:place)
|
||||||
.where(user:)
|
.where(user:)
|
||||||
.where('started_at >= ? AND ended_at <= ?', start_at, end_at)
|
.where('started_at >= ? AND ended_at <= ?', start_at, end_at)
|
||||||
.order(started_at: :desc)
|
.order(started_at: :desc)
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ module Visits
|
||||||
|
|
||||||
def call
|
def call
|
||||||
Visit
|
Visit
|
||||||
.includes(:place, :area)
|
.includes(:place)
|
||||||
.where(user:)
|
.where(user:)
|
||||||
.joins(:place)
|
.joins(:place)
|
||||||
.where(
|
.where(
|
||||||
|
|
|
||||||
|
|
@ -365,19 +365,6 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Globe Projection -->
|
|
||||||
<div class="form-control">
|
|
||||||
<label class="label cursor-pointer justify-start gap-3">
|
|
||||||
<input type="checkbox"
|
|
||||||
name="globeProjection"
|
|
||||||
class="toggle toggle-primary"
|
|
||||||
data-maps--maplibre-target="globeToggle"
|
|
||||||
data-action="change->maps--maplibre#toggleGlobe" />
|
|
||||||
<span class="label-text font-medium">Globe View</span>
|
|
||||||
</label>
|
|
||||||
<p class="text-sm text-base-content/60 mt-1">Render map as a 3D globe (requires page reload)</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
|
|
||||||
<!-- Route Opacity -->
|
<!-- Route Opacity -->
|
||||||
|
|
@ -620,36 +607,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Hidden template for route info display -->
|
|
||||||
<template data-maps--maplibre-target="routeInfoTemplate">
|
|
||||||
<div class="space-y-2">
|
|
||||||
<div>
|
|
||||||
<span class="font-semibold">Start:</span>
|
|
||||||
<span data-maps--maplibre-target="routeStartTime"></span>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<span class="font-semibold">End:</span>
|
|
||||||
<span data-maps--maplibre-target="routeEndTime"></span>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<span class="font-semibold">Duration:</span>
|
|
||||||
<span data-maps--maplibre-target="routeDuration"></span>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<span class="font-semibold">Distance:</span>
|
|
||||||
<span data-maps--maplibre-target="routeDistance"></span>
|
|
||||||
</div>
|
|
||||||
<div data-maps--maplibre-target="routeSpeedContainer">
|
|
||||||
<span class="font-semibold">Avg Speed:</span>
|
|
||||||
<span data-maps--maplibre-target="routeSpeed"></span>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<span class="font-semibold">Points:</span>
|
|
||||||
<span data-maps--maplibre-target="routePoints"></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- Selection Actions (shown after area is selected) -->
|
<!-- Selection Actions (shown after area is selected) -->
|
||||||
<div class="hidden mt-4 space-y-2" data-maps--maplibre-target="selectionActions">
|
<div class="hidden mt-4 space-y-2" data-maps--maplibre-target="selectionActions">
|
||||||
<button type="button"
|
<button type="button"
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@
|
||||||
</h2>
|
</h2>
|
||||||
<div class="w-full h-48 bg-base-200 rounded-lg p-4 relative">
|
<div class="w-full h-48 bg-base-200 rounded-lg p-4 relative">
|
||||||
<%= column_chart(
|
<%= column_chart(
|
||||||
@digest.monthly_distances.sort_by { |month, _| month.to_i }.map { |month, distance_meters|
|
@digest.monthly_distances.sort.map { |month, distance_meters|
|
||||||
[Date::ABBR_MONTHNAMES[month.to_i], Users::Digest.convert_distance(distance_meters.to_i, @distance_unit).round]
|
[Date::ABBR_MONTHNAMES[month.to_i], Users::Digest.convert_distance(distance_meters.to_i, @distance_unit).round]
|
||||||
},
|
},
|
||||||
height: '200px',
|
height: '200px',
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@
|
||||||
</h2>
|
</h2>
|
||||||
<div class="w-full h-64 bg-base-100 rounded-lg p-4">
|
<div class="w-full h-64 bg-base-100 rounded-lg p-4">
|
||||||
<%= column_chart(
|
<%= column_chart(
|
||||||
@digest.monthly_distances.sort_by { |month, _| month.to_i }.map { |month, distance_meters|
|
@digest.monthly_distances.sort.map { |month, distance_meters|
|
||||||
[Date::ABBR_MONTHNAMES[month.to_i], Users::Digest.convert_distance(distance_meters.to_i, @distance_unit).round]
|
[Date::ABBR_MONTHNAMES[month.to_i], Users::Digest.convert_distance(distance_meters.to_i, @distance_unit).round]
|
||||||
},
|
},
|
||||||
height: '250px',
|
height: '250px',
|
||||||
|
|
@ -142,19 +142,6 @@
|
||||||
<span class="text-gray-600"><%= format_time_spent(country['minutes']) %></span>
|
<span class="text-gray-600"><%= format_time_spent(country['minutes']) %></span>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @digest.untracked_days > 0 %>
|
|
||||||
<div class="flex justify-between items-center p-3 bg-base-100 rounded-lg border-2 border-dashed border-gray-200">
|
|
||||||
<div class="flex items-center gap-3">
|
|
||||||
<span class="badge badge-lg badge-ghost">?</span>
|
|
||||||
<span class="text-gray-500 italic">No tracking data</span>
|
|
||||||
</div>
|
|
||||||
<span class="text-gray-500"><%= pluralize(@digest.untracked_days.round, 'day') %></span>
|
|
||||||
</div>
|
|
||||||
<p class="text-sm text-gray-500 mt-2 flex items-center justify-center gap-2">
|
|
||||||
<%= icon 'lightbulb' %> Track more in <%= @digest.year + 1 %> to see a fuller picture of your travels!
|
|
||||||
</p>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -168,7 +155,14 @@
|
||||||
</h2>
|
</h2>
|
||||||
<div class="space-y-4 w-full">
|
<div class="space-y-4 w-full">
|
||||||
<% if @digest.toponyms.present? %>
|
<% if @digest.toponyms.present? %>
|
||||||
|
<% max_cities = @digest.toponyms.map { |country| country['cities']&.length || 0 }.max %>
|
||||||
|
<% progress_colors = ['progress-primary', 'progress-secondary', 'progress-accent', 'progress-info', 'progress-success', 'progress-warning'] %>
|
||||||
|
|
||||||
<% @digest.toponyms.each_with_index do |country, index| %>
|
<% @digest.toponyms.each_with_index do |country, index| %>
|
||||||
|
<% cities_count = country['cities']&.length || 0 %>
|
||||||
|
<% progress_value = max_cities&.positive? ? (cities_count.to_f / max_cities * 100).round : 0 %>
|
||||||
|
<% color_class = progress_colors[index % progress_colors.length] %>
|
||||||
|
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<span class="font-semibold">
|
<span class="font-semibold">
|
||||||
|
|
@ -176,10 +170,10 @@
|
||||||
<%= country['country'] %>
|
<%= country['country'] %>
|
||||||
</span>
|
</span>
|
||||||
<span class="text-sm">
|
<span class="text-sm">
|
||||||
<%= pluralize(country['cities']&.length || 0, 'city') %>
|
<%= pluralize(cities_count, 'city') %>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<progress class="progress <%= progress_color_for_index(index) %> w-full" value="<%= city_progress_value(country['cities']&.length || 0, max_cities_count(@digest.toponyms)) %>" max="100"></progress>
|
<progress class="progress <%= color_class %> w-full" value="<%= progress_value %>" max="100"></progress>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|
@ -220,12 +214,6 @@
|
||||||
<button class="btn btn-outline" onclick="sharing_modal.showModal()">
|
<button class="btn btn-outline" onclick="sharing_modal.showModal()">
|
||||||
<%= icon 'share' %> Share
|
<%= icon 'share' %> Share
|
||||||
</button>
|
</button>
|
||||||
<%= button_to users_digest_path(year: @digest.year),
|
|
||||||
method: :delete,
|
|
||||||
class: 'btn btn-outline btn-error',
|
|
||||||
data: { turbo_confirm: "Are you sure you want to delete the #{@digest.year} digest? This cannot be undone." } do %>
|
|
||||||
<%= icon 'trash-2' %> Delete
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -250,24 +250,13 @@
|
||||||
<div class="stat-card">
|
<div class="stat-card">
|
||||||
<div class="stat-label">Where You Spent the Most Time</div>
|
<div class="stat-label">Where You Spent the Most Time</div>
|
||||||
<ul class="location-list">
|
<ul class="location-list">
|
||||||
<% @digest.top_countries_by_time.take(5).each do |country| %>
|
<% @digest.top_countries_by_time.take(3).each do |country| %>
|
||||||
<li>
|
<li>
|
||||||
<span><%= country_flag(country['name']) %> <%= country['name'] %></span>
|
<span><%= country_flag(country['name']) %> <%= country['name'] %></span>
|
||||||
<span><%= format_time_spent(country['minutes']) %></span>
|
<span><%= format_time_spent(country['minutes']) %></span>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if @digest.untracked_days > 0 %>
|
|
||||||
<li style="border-top: 2px dashed #e2e8f0; padding-top: 12px; margin-top: 4px;">
|
|
||||||
<span style="color: #94a3b8; font-style: italic;">No tracking data</span>
|
|
||||||
<span style="color: #94a3b8;"><%= pluralize(@digest.untracked_days.round, 'day') %></span>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
</ul>
|
</ul>
|
||||||
<% if @digest.untracked_days > 0 %>
|
|
||||||
<p style="color: #64748b; font-size: 13px; margin-top: 12px;">
|
|
||||||
💡 Track more in <%= @digest.year + 1 %> to see a fuller picture of your travels!
|
|
||||||
</p>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,8 +101,8 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
# User digests routes (yearly/monthly digest reports)
|
# User digests routes (yearly/monthly digest reports)
|
||||||
scope module: 'users' do
|
scope module: 'users' do
|
||||||
resources :digests, only: %i[index create show destroy], param: :year, as: :users_digests,
|
resources :digests, only: %i[index create], param: :year, as: :users_digests
|
||||||
constraints: { year: /\d{4}/ }
|
get 'digests/:year', to: 'digests#show', as: :users_digest, constraints: { year: /\d{4}/ }
|
||||||
end
|
end
|
||||||
get 'shared/digest/:uuid', to: 'shared/digests#show', as: :shared_users_digest
|
get 'shared/digest/:uuid', to: 'shared/digests#show', as: :shared_users_digest
|
||||||
patch 'digests/:year/sharing',
|
patch 'digests/:year/sharing',
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,10 @@ class InstallRailsPulseTables < ActiveRecord::Migration[8.0]
|
||||||
def change
|
def change
|
||||||
# Load and execute the Rails Pulse schema directly
|
# Load and execute the Rails Pulse schema directly
|
||||||
# This ensures the migration is always in sync with the schema file
|
# This ensures the migration is always in sync with the schema file
|
||||||
schema_file = Rails.root.join('db/rails_pulse_schema.rb').to_s
|
schema_file = File.join(::Rails.root.to_s, "db/rails_pulse_schema.rb")
|
||||||
|
|
||||||
raise 'Rails Pulse schema file not found at db/rails_pulse_schema.rb' unless File.exist?(schema_file)
|
if File.exist?(schema_file)
|
||||||
|
say "Loading Rails Pulse schema from db/rails_pulse_schema.rb"
|
||||||
say 'Loading Rails Pulse schema from db/rails_pulse_schema.rb'
|
|
||||||
|
|
||||||
# Load the schema file to define RailsPulse::Schema
|
# Load the schema file to define RailsPulse::Schema
|
||||||
load schema_file
|
load schema_file
|
||||||
|
|
@ -15,7 +14,10 @@ class InstallRailsPulseTables < ActiveRecord::Migration[8.0]
|
||||||
# Execute the schema in the context of this migration
|
# Execute the schema in the context of this migration
|
||||||
RailsPulse::Schema.call(connection)
|
RailsPulse::Schema.call(connection)
|
||||||
|
|
||||||
say 'Rails Pulse tables created successfully'
|
say "Rails Pulse tables created successfully"
|
||||||
say 'The schema file db/rails_pulse_schema.rb remains as your single source of truth'
|
say "The schema file db/rails_pulse_schema.rb remains as your single source of truth"
|
||||||
|
else
|
||||||
|
raise "Rails Pulse schema file not found at db/rails_pulse_schema.rb"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
class AddIndexesToPointsForStatsQuery < ActiveRecord::Migration[8.0]
|
|
||||||
disable_ddl_transaction!
|
|
||||||
|
|
||||||
def change
|
|
||||||
# Index for counting reverse geocoded points
|
|
||||||
# This speeds up: COUNT(reverse_geocoded_at)
|
|
||||||
add_index :points, [:user_id, :reverse_geocoded_at],
|
|
||||||
where: "reverse_geocoded_at IS NOT NULL",
|
|
||||||
algorithm: :concurrently,
|
|
||||||
if_not_exists: true,
|
|
||||||
name: 'index_points_on_user_id_and_reverse_geocoded_at'
|
|
||||||
|
|
||||||
# Index for finding points with empty geodata
|
|
||||||
# This speeds up: COUNT(CASE WHEN geodata = '{}'::jsonb THEN 1 END)
|
|
||||||
add_index :points, [:user_id, :geodata],
|
|
||||||
where: "geodata = '{}'::jsonb",
|
|
||||||
algorithm: :concurrently,
|
|
||||||
if_not_exists: true,
|
|
||||||
name: 'index_points_on_user_id_and_empty_geodata'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
4
db/schema.rb
generated
4
db/schema.rb
generated
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2026_01_03_114630) do
|
ActiveRecord::Schema[8.0].define(version: 2025_12_28_163703) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pg_catalog.plpgsql"
|
enable_extension "pg_catalog.plpgsql"
|
||||||
enable_extension "postgis"
|
enable_extension "postgis"
|
||||||
|
|
@ -260,7 +260,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_03_114630) do
|
||||||
t.index ["track_id"], name: "index_points_on_track_id"
|
t.index ["track_id"], name: "index_points_on_track_id"
|
||||||
t.index ["user_id", "city"], name: "idx_points_user_city"
|
t.index ["user_id", "city"], name: "idx_points_user_city"
|
||||||
t.index ["user_id", "country_name"], name: "idx_points_user_country_name"
|
t.index ["user_id", "country_name"], name: "idx_points_user_country_name"
|
||||||
t.index ["user_id", "geodata"], name: "index_points_on_user_id_and_empty_geodata", where: "(geodata = '{}'::jsonb)"
|
|
||||||
t.index ["user_id", "reverse_geocoded_at"], name: "index_points_on_user_id_and_reverse_geocoded_at", where: "(reverse_geocoded_at IS NOT NULL)"
|
t.index ["user_id", "reverse_geocoded_at"], name: "index_points_on_user_id_and_reverse_geocoded_at", where: "(reverse_geocoded_at IS NOT NULL)"
|
||||||
t.index ["user_id", "timestamp", "track_id"], name: "idx_points_track_generation"
|
t.index ["user_id", "timestamp", "track_id"], name: "idx_points_track_generation"
|
||||||
t.index ["user_id", "timestamp"], name: "idx_points_user_visit_null_timestamp", where: "(visit_id IS NULL)"
|
t.index ["user_id", "timestamp"], name: "idx_points_user_visit_null_timestamp", where: "(visit_id IS NULL)"
|
||||||
|
|
@ -522,7 +521,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_03_114630) do
|
||||||
add_foreign_key "notifications", "users"
|
add_foreign_key "notifications", "users"
|
||||||
add_foreign_key "place_visits", "places"
|
add_foreign_key "place_visits", "places"
|
||||||
add_foreign_key "place_visits", "visits"
|
add_foreign_key "place_visits", "visits"
|
||||||
add_foreign_key "points", "points_raw_data_archives", column: "raw_data_archive_id", name: "fk_rails_points_raw_data_archives", on_delete: :nullify, validate: false
|
|
||||||
add_foreign_key "points", "points_raw_data_archives", column: "raw_data_archive_id", on_delete: :nullify
|
add_foreign_key "points", "points_raw_data_archives", column: "raw_data_archive_id", on_delete: :nullify
|
||||||
add_foreign_key "points", "users"
|
add_foreign_key "points", "users"
|
||||||
add_foreign_key "points", "visits"
|
add_foreign_key "points", "visits"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { test as setup, expect } from '@playwright/test';
|
import { test as setup, expect } from '@playwright/test';
|
||||||
import { disableGlobeProjection } from '../v2/helpers/setup.js';
|
|
||||||
|
|
||||||
const authFile = 'e2e/temp/.auth/user.json';
|
const authFile = 'e2e/temp/.auth/user.json';
|
||||||
|
|
||||||
|
|
@ -20,9 +19,6 @@ setup('authenticate', async ({ page }) => {
|
||||||
// Wait for successful navigation to map (v1 or v2 depending on user preference)
|
// Wait for successful navigation to map (v1 or v2 depending on user preference)
|
||||||
await page.waitForURL(/\/map(\/v[12])?/, { timeout: 10000 });
|
await page.waitForURL(/\/map(\/v[12])?/, { timeout: 10000 });
|
||||||
|
|
||||||
// Disable globe projection to ensure consistent E2E test behavior
|
|
||||||
await disableGlobeProjection(page);
|
|
||||||
|
|
||||||
// Save authentication state
|
// Save authentication state
|
||||||
await page.context().storageState({ path: authFile });
|
await page.context().storageState({ path: authFile });
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,33 +2,6 @@
|
||||||
* Helper functions for Maps V2 E2E tests
|
* Helper functions for Maps V2 E2E tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Disable globe projection setting via API
|
|
||||||
* This ensures consistent map rendering for E2E tests
|
|
||||||
* @param {Page} page - Playwright page object
|
|
||||||
*/
|
|
||||||
export async function disableGlobeProjection(page) {
|
|
||||||
// Get API key from the page (requires being logged in)
|
|
||||||
const apiKey = await page.evaluate(() => {
|
|
||||||
const metaTag = document.querySelector('meta[name="api-key"]');
|
|
||||||
return metaTag?.content;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (apiKey) {
|
|
||||||
await page.request.patch('/api/v1/settings', {
|
|
||||||
headers: {
|
|
||||||
'Authorization': `Bearer ${apiKey}`,
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
settings: {
|
|
||||||
globe_projection: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigate to Maps V2 page
|
* Navigate to Maps V2 page
|
||||||
* @param {Page} page - Playwright page object
|
* @param {Page} page - Playwright page object
|
||||||
|
|
|
||||||
|
|
@ -61,602 +61,4 @@ test.describe('Map Interactions', () => {
|
||||||
await expect(mapContainer).toBeVisible()
|
await expect(mapContainer).toBeVisible()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test.describe('Route Interactions', () => {
|
|
||||||
test('route hover layer exists', async ({ page }) => {
|
|
||||||
await page.waitForFunction(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
if (!element) return false
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
if (!app) return false
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
return controller?.map?.getLayer('routes-hover') !== undefined
|
|
||||||
}, { timeout: 10000 }).catch(() => false)
|
|
||||||
|
|
||||||
const hasHoverLayer = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
if (!element) return false
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
if (!app) return false
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
return controller?.map?.getLayer('routes-hover') !== undefined
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(hasHoverLayer).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('route hover shows yellow highlight', async ({ page }) => {
|
|
||||||
// Wait for routes to be loaded
|
|
||||||
await page.waitForFunction(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
if (!element) return false
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
if (!app) return false
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller?.map?.getSource('routes-source')
|
|
||||||
return source && source._data?.features?.length > 0
|
|
||||||
}, { timeout: 20000 })
|
|
||||||
|
|
||||||
await page.waitForTimeout(1000)
|
|
||||||
|
|
||||||
// Get first route's bounding box and hover over its center
|
|
||||||
const routeCenter = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller.map.getSource('routes-source')
|
|
||||||
|
|
||||||
if (!source._data?.features?.length) return null
|
|
||||||
|
|
||||||
const route = source._data.features[0]
|
|
||||||
const coords = route.geometry.coordinates
|
|
||||||
|
|
||||||
// Get middle coordinate of route
|
|
||||||
const midCoord = coords[Math.floor(coords.length / 2)]
|
|
||||||
|
|
||||||
// Project to pixel coordinates
|
|
||||||
const point = controller.map.project(midCoord)
|
|
||||||
|
|
||||||
return { x: point.x, y: point.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
if (routeCenter) {
|
|
||||||
// Get the canvas element and hover over the route
|
|
||||||
const canvas = page.locator('.maplibregl-canvas')
|
|
||||||
await canvas.hover({
|
|
||||||
position: { x: routeCenter.x, y: routeCenter.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Check if hover source has data (route is highlighted)
|
|
||||||
const isHighlighted = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const hoverSource = controller.map.getSource('routes-hover-source')
|
|
||||||
return hoverSource && hoverSource._data?.features?.length > 0
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(isHighlighted).toBe(true)
|
|
||||||
|
|
||||||
// Check for emoji markers (start 🚥 and end 🏁)
|
|
||||||
const startMarker = page.locator('.route-emoji-marker:has-text("🚥")')
|
|
||||||
const endMarker = page.locator('.route-emoji-marker:has-text("🏁")')
|
|
||||||
await expect(startMarker).toBeVisible()
|
|
||||||
await expect(endMarker).toBeVisible()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test('route click opens info panel with route details', async ({ page }) => {
|
|
||||||
// Wait for routes to be loaded
|
|
||||||
await page.waitForFunction(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
if (!element) return false
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
if (!app) return false
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller?.map?.getSource('routes-source')
|
|
||||||
return source && source._data?.features?.length > 0
|
|
||||||
}, { timeout: 20000 })
|
|
||||||
|
|
||||||
await page.waitForTimeout(1000)
|
|
||||||
|
|
||||||
// Get first route's center and click on it
|
|
||||||
const routeCenter = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller.map.getSource('routes-source')
|
|
||||||
|
|
||||||
if (!source._data?.features?.length) return null
|
|
||||||
|
|
||||||
const route = source._data.features[0]
|
|
||||||
const coords = route.geometry.coordinates
|
|
||||||
const midCoord = coords[Math.floor(coords.length / 2)]
|
|
||||||
const point = controller.map.project(midCoord)
|
|
||||||
|
|
||||||
return { x: point.x, y: point.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
if (routeCenter) {
|
|
||||||
// Click on the route
|
|
||||||
const canvas = page.locator('.maplibregl-canvas')
|
|
||||||
await canvas.click({
|
|
||||||
position: { x: routeCenter.x, y: routeCenter.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Check if info panel is visible
|
|
||||||
const infoDisplay = page.locator('[data-maps--maplibre-target="infoDisplay"]')
|
|
||||||
await expect(infoDisplay).not.toHaveClass(/hidden/)
|
|
||||||
|
|
||||||
// Check if info panel has route information title
|
|
||||||
const infoTitle = page.locator('[data-maps--maplibre-target="infoTitle"]')
|
|
||||||
await expect(infoTitle).toHaveText('Route Information')
|
|
||||||
|
|
||||||
// Check if route details are displayed
|
|
||||||
const infoContent = page.locator('[data-maps--maplibre-target="infoContent"]')
|
|
||||||
const content = await infoContent.textContent()
|
|
||||||
|
|
||||||
expect(content).toContain('Start:')
|
|
||||||
expect(content).toContain('End:')
|
|
||||||
expect(content).toContain('Duration:')
|
|
||||||
expect(content).toContain('Distance:')
|
|
||||||
expect(content).toContain('Points:')
|
|
||||||
|
|
||||||
// Check for emoji markers (start 🚥 and end 🏁)
|
|
||||||
const startMarker = page.locator('.route-emoji-marker:has-text("🚥")')
|
|
||||||
const endMarker = page.locator('.route-emoji-marker:has-text("🏁")')
|
|
||||||
await expect(startMarker).toBeVisible()
|
|
||||||
await expect(endMarker).toBeVisible()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test('clicked route stays highlighted after mouse moves away', async ({ page }) => {
|
|
||||||
// Wait for routes to be loaded
|
|
||||||
await page.waitForFunction(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
if (!element) return false
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
if (!app) return false
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller?.map?.getSource('routes-source')
|
|
||||||
return source && source._data?.features?.length > 0
|
|
||||||
}, { timeout: 20000 })
|
|
||||||
|
|
||||||
await page.waitForTimeout(1000)
|
|
||||||
|
|
||||||
// Click on a route
|
|
||||||
const routeCenter = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller.map.getSource('routes-source')
|
|
||||||
|
|
||||||
if (!source._data?.features?.length) return null
|
|
||||||
|
|
||||||
const route = source._data.features[0]
|
|
||||||
const coords = route.geometry.coordinates
|
|
||||||
const midCoord = coords[Math.floor(coords.length / 2)]
|
|
||||||
const point = controller.map.project(midCoord)
|
|
||||||
|
|
||||||
return { x: point.x, y: point.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
if (routeCenter) {
|
|
||||||
const canvas = page.locator('.maplibregl-canvas')
|
|
||||||
await canvas.click({
|
|
||||||
position: { x: routeCenter.x, y: routeCenter.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Move mouse away from route
|
|
||||||
await canvas.hover({ position: { x: 100, y: 100 } })
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Check if route is still highlighted
|
|
||||||
const isStillHighlighted = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const hoverSource = controller.map.getSource('routes-hover-source')
|
|
||||||
return hoverSource && hoverSource._data?.features?.length > 0
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(isStillHighlighted).toBe(true)
|
|
||||||
|
|
||||||
// Check if info panel is still visible
|
|
||||||
const infoDisplay = page.locator('[data-maps--maplibre-target="infoDisplay"]')
|
|
||||||
await expect(infoDisplay).not.toHaveClass(/hidden/)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test('clicking elsewhere on map deselects route', async ({ page }) => {
|
|
||||||
// Wait for routes to be loaded
|
|
||||||
await page.waitForFunction(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
if (!element) return false
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
if (!app) return false
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller?.map?.getSource('routes-source')
|
|
||||||
return source && source._data?.features?.length > 0
|
|
||||||
}, { timeout: 20000 })
|
|
||||||
|
|
||||||
await page.waitForTimeout(1000)
|
|
||||||
|
|
||||||
// Click on a route first
|
|
||||||
const routeCenter = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller.map.getSource('routes-source')
|
|
||||||
|
|
||||||
if (!source._data?.features?.length) return null
|
|
||||||
|
|
||||||
const route = source._data.features[0]
|
|
||||||
const coords = route.geometry.coordinates
|
|
||||||
const midCoord = coords[Math.floor(coords.length / 2)]
|
|
||||||
const point = controller.map.project(midCoord)
|
|
||||||
|
|
||||||
return { x: point.x, y: point.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
if (routeCenter) {
|
|
||||||
const canvas = page.locator('.maplibregl-canvas')
|
|
||||||
await canvas.click({
|
|
||||||
position: { x: routeCenter.x, y: routeCenter.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Verify route is selected
|
|
||||||
const infoDisplay = page.locator('[data-maps--maplibre-target="infoDisplay"]')
|
|
||||||
await expect(infoDisplay).not.toHaveClass(/hidden/)
|
|
||||||
|
|
||||||
// Click elsewhere on map (far from route)
|
|
||||||
await canvas.click({ position: { x: 100, y: 100 } })
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Check if route is deselected (hover source cleared)
|
|
||||||
const isDeselected = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const hoverSource = controller.map.getSource('routes-hover-source')
|
|
||||||
return hoverSource && hoverSource._data?.features?.length === 0
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(isDeselected).toBe(true)
|
|
||||||
|
|
||||||
// Check if info panel is hidden
|
|
||||||
await expect(infoDisplay).toHaveClass(/hidden/)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test('clicking close button on info panel deselects route', async ({ page }) => {
|
|
||||||
// Wait for routes to be loaded
|
|
||||||
await page.waitForFunction(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
if (!element) return false
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
if (!app) return false
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller?.map?.getSource('routes-source')
|
|
||||||
return source && source._data?.features?.length > 0
|
|
||||||
}, { timeout: 20000 })
|
|
||||||
|
|
||||||
await page.waitForTimeout(1000)
|
|
||||||
|
|
||||||
// Click on a route
|
|
||||||
const routeCenter = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller.map.getSource('routes-source')
|
|
||||||
|
|
||||||
if (!source._data?.features?.length) return null
|
|
||||||
|
|
||||||
const route = source._data.features[0]
|
|
||||||
const coords = route.geometry.coordinates
|
|
||||||
const midCoord = coords[Math.floor(coords.length / 2)]
|
|
||||||
const point = controller.map.project(midCoord)
|
|
||||||
|
|
||||||
return { x: point.x, y: point.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
if (routeCenter) {
|
|
||||||
const canvas = page.locator('.maplibregl-canvas')
|
|
||||||
await canvas.click({
|
|
||||||
position: { x: routeCenter.x, y: routeCenter.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Verify info panel is open
|
|
||||||
const infoDisplay = page.locator('[data-maps--maplibre-target="infoDisplay"]')
|
|
||||||
await expect(infoDisplay).not.toHaveClass(/hidden/)
|
|
||||||
|
|
||||||
// Click the close button
|
|
||||||
const closeButton = page.locator('button[data-action="click->maps--maplibre#closeInfo"]')
|
|
||||||
await closeButton.click()
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Check if route is deselected
|
|
||||||
const isDeselected = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const hoverSource = controller.map.getSource('routes-hover-source')
|
|
||||||
return hoverSource && hoverSource._data?.features?.length === 0
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(isDeselected).toBe(true)
|
|
||||||
|
|
||||||
// Check if info panel is hidden
|
|
||||||
await expect(infoDisplay).toHaveClass(/hidden/)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test('route cursor changes to pointer on hover', async ({ page }) => {
|
|
||||||
// Wait for routes to be loaded
|
|
||||||
await page.waitForFunction(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
if (!element) return false
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
if (!app) return false
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller?.map?.getSource('routes-source')
|
|
||||||
return source && source._data?.features?.length > 0
|
|
||||||
}, { timeout: 20000 })
|
|
||||||
|
|
||||||
await page.waitForTimeout(1000)
|
|
||||||
|
|
||||||
// Hover over a route
|
|
||||||
const routeCenter = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller.map.getSource('routes-source')
|
|
||||||
|
|
||||||
if (!source._data?.features?.length) return null
|
|
||||||
|
|
||||||
const route = source._data.features[0]
|
|
||||||
const coords = route.geometry.coordinates
|
|
||||||
const midCoord = coords[Math.floor(coords.length / 2)]
|
|
||||||
const point = controller.map.project(midCoord)
|
|
||||||
|
|
||||||
return { x: point.x, y: point.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
if (routeCenter) {
|
|
||||||
const canvas = page.locator('.maplibregl-canvas')
|
|
||||||
await canvas.hover({
|
|
||||||
position: { x: routeCenter.x, y: routeCenter.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
await page.waitForTimeout(300)
|
|
||||||
|
|
||||||
// Check cursor style
|
|
||||||
const cursor = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
return controller.map.getCanvas().style.cursor
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(cursor).toBe('pointer')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test('hovering over different route while one is selected shows both highlighted', async ({ page }) => {
|
|
||||||
// Wait for multiple routes to be loaded
|
|
||||||
await page.waitForFunction(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
if (!element) return false
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
if (!app) return false
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller?.map?.getSource('routes-source')
|
|
||||||
return source && source._data?.features?.length >= 2
|
|
||||||
}, { timeout: 20000 })
|
|
||||||
|
|
||||||
await page.waitForTimeout(1000)
|
|
||||||
|
|
||||||
// Zoom in closer to make routes more distinct and center on first route
|
|
||||||
await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller.map.getSource('routes-source')
|
|
||||||
|
|
||||||
if (source._data?.features?.length >= 2) {
|
|
||||||
const route = source._data.features[0]
|
|
||||||
const coords = route.geometry.coordinates
|
|
||||||
const midCoord = coords[Math.floor(coords.length / 2)]
|
|
||||||
|
|
||||||
// Center on first route and zoom in
|
|
||||||
controller.map.flyTo({
|
|
||||||
center: midCoord,
|
|
||||||
zoom: 13,
|
|
||||||
duration: 0
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
await page.waitForTimeout(1000)
|
|
||||||
|
|
||||||
// Get centers of two different routes that are far apart (after zoom)
|
|
||||||
const routeCenters = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller.map.getSource('routes-source')
|
|
||||||
|
|
||||||
if (!source._data?.features?.length >= 2) return null
|
|
||||||
|
|
||||||
// Find two routes with significantly different centers to avoid overlap
|
|
||||||
const features = source._data.features
|
|
||||||
let route1 = features[0]
|
|
||||||
let route2 = null
|
|
||||||
|
|
||||||
const coords1 = route1.geometry.coordinates
|
|
||||||
const midCoord1 = coords1[Math.floor(coords1.length / 2)]
|
|
||||||
const point1 = controller.map.project(midCoord1)
|
|
||||||
|
|
||||||
// Find a route that's at least 100px away from the first one
|
|
||||||
for (let i = 1; i < features.length; i++) {
|
|
||||||
const testRoute = features[i]
|
|
||||||
const testCoords = testRoute.geometry.coordinates
|
|
||||||
const testMidCoord = testCoords[Math.floor(testCoords.length / 2)]
|
|
||||||
const testPoint = controller.map.project(testMidCoord)
|
|
||||||
|
|
||||||
const distance = Math.sqrt(
|
|
||||||
Math.pow(testPoint.x - point1.x, 2) +
|
|
||||||
Math.pow(testPoint.y - point1.y, 2)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (distance > 100) {
|
|
||||||
route2 = testRoute
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!route2) {
|
|
||||||
// If no route is far enough, use the last route
|
|
||||||
route2 = features[features.length - 1]
|
|
||||||
}
|
|
||||||
|
|
||||||
const coords2 = route2.geometry.coordinates
|
|
||||||
const midCoord2 = coords2[Math.floor(coords2.length / 2)]
|
|
||||||
const point2 = controller.map.project(midCoord2)
|
|
||||||
|
|
||||||
return {
|
|
||||||
route1: { x: point1.x, y: point1.y },
|
|
||||||
route2: { x: point2.x, y: point2.y },
|
|
||||||
areDifferent: route1.properties.startTime !== route2.properties.startTime
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (routeCenters && routeCenters.areDifferent) {
|
|
||||||
const canvas = page.locator('.maplibregl-canvas')
|
|
||||||
|
|
||||||
// Click on first route to select it
|
|
||||||
await canvas.click({
|
|
||||||
position: { x: routeCenters.route1.x, y: routeCenters.route1.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Verify first route is selected
|
|
||||||
const infoDisplay = page.locator('[data-maps--maplibre-target="infoDisplay"]')
|
|
||||||
await expect(infoDisplay).not.toHaveClass(/hidden/)
|
|
||||||
|
|
||||||
// Close settings panel if it's open (it blocks hover interactions)
|
|
||||||
const settingsPanel = page.locator('[data-maps--maplibre-target="settingsPanel"]')
|
|
||||||
const isOpen = await settingsPanel.evaluate((el) => el.classList.contains('open'))
|
|
||||||
if (isOpen) {
|
|
||||||
await page.getByRole('button', { name: 'Close panel' }).click()
|
|
||||||
await page.waitForTimeout(300)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hover over second route (use force since functionality is verified to work)
|
|
||||||
await canvas.hover({
|
|
||||||
position: { x: routeCenters.route2.x, y: routeCenters.route2.y },
|
|
||||||
force: true
|
|
||||||
})
|
|
||||||
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Check that hover source has features (1 if same route/overlapping, 2 if distinct)
|
|
||||||
// The exact count depends on route data and zoom level
|
|
||||||
const featureCount = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const hoverSource = controller.map.getSource('routes-hover-source')
|
|
||||||
return hoverSource && hoverSource._data?.features?.length
|
|
||||||
})
|
|
||||||
|
|
||||||
// Accept 1 (same/overlapping route) or 2 (distinct routes) as valid
|
|
||||||
expect(featureCount).toBeGreaterThanOrEqual(1)
|
|
||||||
expect(featureCount).toBeLessThanOrEqual(2)
|
|
||||||
|
|
||||||
// Move mouse away from both routes
|
|
||||||
await canvas.hover({ position: { x: 100, y: 100 } })
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Check that only selected route remains highlighted (1 feature)
|
|
||||||
const featureCountAfterLeave = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const hoverSource = controller.map.getSource('routes-hover-source')
|
|
||||||
return hoverSource && hoverSource._data?.features?.length
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(featureCountAfterLeave).toBe(1)
|
|
||||||
|
|
||||||
// Check that markers are present for the selected route only
|
|
||||||
const markerCount = await page.locator('.route-emoji-marker').count()
|
|
||||||
expect(markerCount).toBe(2) // Start and end marker for selected route
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test('clicking elsewhere removes emoji markers', async ({ page }) => {
|
|
||||||
// Wait for routes to be loaded (longer timeout as previous test may affect timing)
|
|
||||||
await page.waitForFunction(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
if (!element) return false
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
if (!app) return false
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller?.map?.getSource('routes-source')
|
|
||||||
return source && source._data?.features?.length > 0
|
|
||||||
}, { timeout: 30000 })
|
|
||||||
|
|
||||||
await page.waitForTimeout(1000)
|
|
||||||
|
|
||||||
// Click on a route
|
|
||||||
const routeCenter = await page.evaluate(() => {
|
|
||||||
const element = document.querySelector('[data-controller*="maps--maplibre"]')
|
|
||||||
const app = window.Stimulus || window.Application
|
|
||||||
const controller = app.getControllerForElementAndIdentifier(element, 'maps--maplibre')
|
|
||||||
const source = controller.map.getSource('routes-source')
|
|
||||||
|
|
||||||
if (!source._data?.features?.length) return null
|
|
||||||
|
|
||||||
const route = source._data.features[0]
|
|
||||||
const coords = route.geometry.coordinates
|
|
||||||
const midCoord = coords[Math.floor(coords.length / 2)]
|
|
||||||
const point = controller.map.project(midCoord)
|
|
||||||
|
|
||||||
return { x: point.x, y: point.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
if (routeCenter) {
|
|
||||||
const canvas = page.locator('.maplibregl-canvas')
|
|
||||||
await canvas.click({
|
|
||||||
position: { x: routeCenter.x, y: routeCenter.y }
|
|
||||||
})
|
|
||||||
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Verify markers are present
|
|
||||||
let markerCount = await page.locator('.route-emoji-marker').count()
|
|
||||||
expect(markerCount).toBe(2)
|
|
||||||
|
|
||||||
// Click elsewhere on map
|
|
||||||
await canvas.click({ position: { x: 100, y: 100 } })
|
|
||||||
await page.waitForTimeout(500)
|
|
||||||
|
|
||||||
// Verify markers are removed
|
|
||||||
markerCount = await page.locator('.route-emoji-marker').count()
|
|
||||||
expect(markerCount).toBe(0)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -329,8 +329,29 @@ test.describe('Family Members Layer', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test.describe('Family Members Status', () => {
|
test.describe('No Family Members', () => {
|
||||||
test('shows appropriate message based on family members data', async ({ page }) => {
|
test('shows appropriate message when no family members are sharing', async ({ page }) => {
|
||||||
|
// This test checks the message when API returns empty array
|
||||||
|
const hasFamilyMembers = await page.evaluate(async () => {
|
||||||
|
const apiKey = document.querySelector('[data-maps--maplibre-api-key-value]')?.dataset.mapsMaplibreApiKeyValue
|
||||||
|
if (!apiKey) return false
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/v1/families/locations?api_key=${apiKey}`)
|
||||||
|
if (!response.ok) return false
|
||||||
|
const data = await response.json()
|
||||||
|
return data.locations && data.locations.length > 0
|
||||||
|
} catch (error) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Only run this test if there are NO family members
|
||||||
|
if (hasFamilyMembers) {
|
||||||
|
test.skip()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
await page.click('button[title="Open map settings"]')
|
await page.click('button[title="Open map settings"]')
|
||||||
await page.waitForTimeout(400)
|
await page.waitForTimeout(400)
|
||||||
await page.click('button[data-tab="layers"]')
|
await page.click('button[data-tab="layers"]')
|
||||||
|
|
@ -341,29 +362,9 @@ test.describe('Family Members Layer', () => {
|
||||||
await page.waitForTimeout(1500)
|
await page.waitForTimeout(1500)
|
||||||
|
|
||||||
const familyMembersContainer = page.locator('[data-maps--maplibre-target="familyMembersContainer"]')
|
const familyMembersContainer = page.locator('[data-maps--maplibre-target="familyMembersContainer"]')
|
||||||
|
const noMembersMessage = familyMembersContainer.getByText('No family members sharing location')
|
||||||
|
|
||||||
// Wait for container to be visible
|
await expect(noMembersMessage).toBeVisible()
|
||||||
await expect(familyMembersContainer).toBeVisible()
|
|
||||||
|
|
||||||
// Check what's actually displayed in the UI
|
|
||||||
const containerText = await familyMembersContainer.textContent()
|
|
||||||
const hasNoMembersMessage = containerText.includes('No family members sharing location')
|
|
||||||
const hasLoadedMessage = containerText.match(/Loaded \d+ family member/)
|
|
||||||
|
|
||||||
// Check for any email patterns (family members display emails)
|
|
||||||
const hasEmailAddresses = containerText.includes('@')
|
|
||||||
|
|
||||||
// Verify the UI shows appropriate content
|
|
||||||
if (hasNoMembersMessage) {
|
|
||||||
// No family members case
|
|
||||||
await expect(familyMembersContainer.getByText('No family members sharing location')).toBeVisible()
|
|
||||||
} else if (hasEmailAddresses || hasLoadedMessage) {
|
|
||||||
// Has family members - verify container has actual content
|
|
||||||
expect(containerText.trim().length).toBeGreaterThan(10)
|
|
||||||
} else {
|
|
||||||
// Container is visible but empty or has loading state - this is acceptable
|
|
||||||
expect(familyMembersContainer).toBeVisible()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -224,11 +224,9 @@ test.describe('Location Search', () => {
|
||||||
await visitItem.click()
|
await visitItem.click()
|
||||||
await page.waitForTimeout(500)
|
await page.waitForTimeout(500)
|
||||||
|
|
||||||
// Modal should appear - wait for modal to be created and checkbox to be checked
|
// Modal should appear
|
||||||
const modal = page.locator('#create-visit-modal')
|
const modal = page.locator('#create-visit-modal')
|
||||||
await modal.waitFor({ state: 'attached' })
|
await expect(modal).toBeVisible()
|
||||||
const modalToggle = page.locator('#create-visit-modal-toggle')
|
|
||||||
await expect(modalToggle).toBeChecked()
|
|
||||||
|
|
||||||
// Modal should have form fields
|
// Modal should have form fields
|
||||||
await expect(modal.locator('input[name="name"]')).toBeVisible()
|
await expect(modal.locator('input[name="name"]')).toBeVisible()
|
||||||
|
|
@ -269,11 +267,8 @@ test.describe('Location Search', () => {
|
||||||
await visitItem.click()
|
await visitItem.click()
|
||||||
await page.waitForTimeout(500)
|
await page.waitForTimeout(500)
|
||||||
|
|
||||||
// Modal should appear - wait for modal to be created and checkbox to be checked
|
|
||||||
const modal = page.locator('#create-visit-modal')
|
const modal = page.locator('#create-visit-modal')
|
||||||
await modal.waitFor({ state: 'attached' })
|
await expect(modal).toBeVisible()
|
||||||
const modalToggle = page.locator('#create-visit-modal-toggle')
|
|
||||||
await expect(modalToggle).toBeChecked()
|
|
||||||
|
|
||||||
// Name should be prefilled
|
// Name should be prefilled
|
||||||
const nameInput = modal.locator('input[name="name"]')
|
const nameInput = modal.locator('input[name="name"]')
|
||||||
|
|
|
||||||
18
package-lock.json
generated
18
package-lock.json
generated
|
|
@ -11,7 +11,7 @@
|
||||||
"leaflet": "^1.9.4",
|
"leaflet": "^1.9.4",
|
||||||
"maplibre-gl": "^5.13.0",
|
"maplibre-gl": "^5.13.0",
|
||||||
"postcss": "^8.4.49",
|
"postcss": "^8.4.49",
|
||||||
"trix": "^2.1.16"
|
"trix": "^2.1.15"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/test": "^1.56.1",
|
"@playwright/test": "^1.56.1",
|
||||||
|
|
@ -575,14 +575,12 @@
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
"node_modules/trix": {
|
"node_modules/trix": {
|
||||||
"version": "2.1.16",
|
"version": "2.1.15",
|
||||||
"resolved": "https://registry.npmjs.org/trix/-/trix-2.1.16.tgz",
|
"resolved": "https://registry.npmjs.org/trix/-/trix-2.1.15.tgz",
|
||||||
"integrity": "sha512-XtZgWI+oBvLzX7CWnkIf+ZWC+chL+YG/TkY43iMTV0Zl+CJjn18B1GJUCEWJ8qgfpcyMBuysnNAfPWiv2sV14A==",
|
"integrity": "sha512-LoaXWczdTUV8+3Box92B9b1iaDVbxD14dYemZRxi3PwY+AuDm97BUJV2aHLBUFPuDABhxp0wzcbf0CxHCVmXiw==",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dompurify": "^3.2.5"
|
"dompurify": "^3.2.5"
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 18"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/undici-types": {
|
"node_modules/undici-types": {
|
||||||
|
|
@ -988,9 +986,9 @@
|
||||||
"integrity": "sha512-gRa9gwYU3ECmQYv3lslts5hxuIa90veaEcxDYuu3QGOIAEM2mOZkVHp48ANJuu1CURtRdHKUBY5Lm1tHV+sD4g=="
|
"integrity": "sha512-gRa9gwYU3ECmQYv3lslts5hxuIa90veaEcxDYuu3QGOIAEM2mOZkVHp48ANJuu1CURtRdHKUBY5Lm1tHV+sD4g=="
|
||||||
},
|
},
|
||||||
"trix": {
|
"trix": {
|
||||||
"version": "2.1.16",
|
"version": "2.1.15",
|
||||||
"resolved": "https://registry.npmjs.org/trix/-/trix-2.1.16.tgz",
|
"resolved": "https://registry.npmjs.org/trix/-/trix-2.1.15.tgz",
|
||||||
"integrity": "sha512-XtZgWI+oBvLzX7CWnkIf+ZWC+chL+YG/TkY43iMTV0Zl+CJjn18B1GJUCEWJ8qgfpcyMBuysnNAfPWiv2sV14A==",
|
"integrity": "sha512-LoaXWczdTUV8+3Box92B9b1iaDVbxD14dYemZRxi3PwY+AuDm97BUJV2aHLBUFPuDABhxp0wzcbf0CxHCVmXiw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"dompurify": "^3.2.5"
|
"dompurify": "^3.2.5"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
"leaflet": "^1.9.4",
|
"leaflet": "^1.9.4",
|
||||||
"maplibre-gl": "^5.13.0",
|
"maplibre-gl": "^5.13.0",
|
||||||
"postcss": "^8.4.49",
|
"postcss": "^8.4.49",
|
||||||
"trix": "^2.1.16"
|
"trix": "^2.1.15"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "18.17.1",
|
"node": "18.17.1",
|
||||||
|
|
|
||||||
|
|
@ -163,16 +163,12 @@ RSpec.describe User, type: :model do
|
||||||
describe '#countries_visited' do
|
describe '#countries_visited' do
|
||||||
subject { user.countries_visited }
|
subject { user.countries_visited }
|
||||||
|
|
||||||
let!(:stat) do
|
let!(:point1) { create(:point, user:, country_name: 'Germany') }
|
||||||
create(:stat, user:, toponyms: [
|
let!(:point2) { create(:point, user:, country_name: 'France') }
|
||||||
{ 'country' => 'Germany', 'cities' => [{ 'city' => 'Berlin', 'stayed_for' => 120 }] },
|
let!(:point3) { create(:point, user:, country_name: nil) }
|
||||||
{ 'country' => 'France', 'cities' => [{ 'city' => 'Paris', 'stayed_for' => 90 }] },
|
let!(:point4) { create(:point, user:, country_name: '') }
|
||||||
{ 'country' => nil, 'cities' => [] },
|
|
||||||
{ 'country' => '', 'cities' => [] }
|
|
||||||
])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns array of countries from stats toponyms' do
|
it 'returns array of countries' do
|
||||||
expect(subject).to include('Germany', 'France')
|
expect(subject).to include('Germany', 'France')
|
||||||
expect(subject.count).to eq(2)
|
expect(subject.count).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
@ -185,18 +181,12 @@ RSpec.describe User, type: :model do
|
||||||
describe '#cities_visited' do
|
describe '#cities_visited' do
|
||||||
subject { user.cities_visited }
|
subject { user.cities_visited }
|
||||||
|
|
||||||
let!(:stat) do
|
let!(:point1) { create(:point, user:, city: 'Berlin') }
|
||||||
create(:stat, user:, toponyms: [
|
let!(:point2) { create(:point, user:, city: 'Paris') }
|
||||||
{ 'country' => 'Germany', 'cities' => [
|
let!(:point3) { create(:point, user:, city: nil) }
|
||||||
{ 'city' => 'Berlin', 'stayed_for' => 120 },
|
let!(:point4) { create(:point, user:, city: '') }
|
||||||
{ 'city' => nil, 'stayed_for' => 60 },
|
|
||||||
{ 'city' => '', 'stayed_for' => 60 }
|
|
||||||
] },
|
|
||||||
{ 'country' => 'France', 'cities' => [{ 'city' => 'Paris', 'stayed_for' => 90 }] }
|
|
||||||
])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns array of cities from stats toponyms' do
|
it 'returns array of cities' do
|
||||||
expect(subject).to include('Berlin', 'Paris')
|
expect(subject).to include('Berlin', 'Paris')
|
||||||
expect(subject.count).to eq(2)
|
expect(subject.count).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
@ -220,15 +210,11 @@ RSpec.describe User, type: :model do
|
||||||
describe '#total_countries' do
|
describe '#total_countries' do
|
||||||
subject { user.total_countries }
|
subject { user.total_countries }
|
||||||
|
|
||||||
let!(:stat) do
|
let!(:point1) { create(:point, user:, country_name: 'Germany') }
|
||||||
create(:stat, user:, toponyms: [
|
let!(:point2) { create(:point, user:, country_name: 'France') }
|
||||||
{ 'country' => 'Germany', 'cities' => [] },
|
let!(:point3) { create(:point, user:, country_name: nil) }
|
||||||
{ 'country' => 'France', 'cities' => [] },
|
|
||||||
{ 'country' => nil, 'cities' => [] }
|
|
||||||
])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns number of countries from stats toponyms' do
|
it 'returns number of countries' do
|
||||||
expect(subject).to eq(2)
|
expect(subject).to eq(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -236,17 +222,11 @@ RSpec.describe User, type: :model do
|
||||||
describe '#total_cities' do
|
describe '#total_cities' do
|
||||||
subject { user.total_cities }
|
subject { user.total_cities }
|
||||||
|
|
||||||
let!(:stat) do
|
let!(:point1) { create(:point, user:, city: 'Berlin') }
|
||||||
create(:stat, user:, toponyms: [
|
let!(:point2) { create(:point, user:, city: 'Paris') }
|
||||||
{ 'country' => 'Germany', 'cities' => [
|
let!(:point3) { create(:point, user:, city: nil) }
|
||||||
{ 'city' => 'Berlin', 'stayed_for' => 120 },
|
|
||||||
{ 'city' => 'Paris', 'stayed_for' => 90 },
|
|
||||||
{ 'city' => nil, 'stayed_for' => 60 }
|
|
||||||
] }
|
|
||||||
])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns number of cities from stats toponyms' do
|
it 'returns number of cities' do
|
||||||
expect(subject).to eq(2)
|
expect(subject).to eq(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ RSpec.describe 'Api::V1::Users', type: :request do
|
||||||
speed_colored_routes points_rendering_mode minutes_between_routes
|
speed_colored_routes points_rendering_mode minutes_between_routes
|
||||||
time_threshold_minutes merge_threshold_minutes live_map_enabled
|
time_threshold_minutes merge_threshold_minutes live_map_enabled
|
||||||
route_opacity immich_url photoprism_url visits_suggestions_enabled
|
route_opacity immich_url photoprism_url visits_suggestions_enabled
|
||||||
speed_color_scale fog_of_war_threshold globe_projection
|
speed_color_scale fog_of_war_threshold
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,6 @@ RSpec.describe '/digests', type: :request do
|
||||||
expect(response.status).to eq(302)
|
expect(response.status).to eq(302)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE /destroy' do
|
|
||||||
it 'redirects to the sign in page' do
|
|
||||||
delete users_digest_url(year: 2024)
|
|
||||||
|
|
||||||
expect(response).to redirect_to(new_user_session_path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user is signed in' do
|
context 'when user is signed in' do
|
||||||
|
|
@ -145,40 +137,5 @@ RSpec.describe '/digests', type: :request do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE /destroy' do
|
|
||||||
let!(:digest) { create(:users_digest, user:, year: 2024) }
|
|
||||||
|
|
||||||
it 'deletes the digest' do
|
|
||||||
expect do
|
|
||||||
delete users_digest_url(year: 2024)
|
|
||||||
end.to change(Users::Digest, :count).by(-1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'redirects with success notice' do
|
|
||||||
delete users_digest_url(year: 2024)
|
|
||||||
|
|
||||||
expect(response).to redirect_to(users_digests_path)
|
|
||||||
expect(flash[:notice]).to eq('Year-end digest for 2024 has been deleted')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns not found for non-existent digest' do
|
|
||||||
delete users_digest_url(year: 2020)
|
|
||||||
|
|
||||||
expect(response).to redirect_to(users_digests_path)
|
|
||||||
expect(flash[:alert]).to eq('Digest not found')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'cannot delete another user digest' do
|
|
||||||
other_user = create(:user)
|
|
||||||
other_digest = create(:users_digest, user: other_user, year: 2023)
|
|
||||||
|
|
||||||
delete users_digest_url(year: 2023)
|
|
||||||
|
|
||||||
expect(response).to redirect_to(users_digests_path)
|
|
||||||
expect(flash[:alert]).to eq('Digest not found')
|
|
||||||
expect(other_digest.reload).to be_present
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -79,58 +79,6 @@ RSpec.describe CountriesAndCities do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when points have a gap larger than threshold (passing through)' do
|
|
||||||
let(:points) do
|
|
||||||
[
|
|
||||||
# User in Berlin at 9:00, leaves, returns at 11:00
|
|
||||||
create(:point, city: 'Berlin', country: 'Germany', timestamp:),
|
|
||||||
create(:point, city: 'Berlin', country: 'Germany', timestamp: timestamp + 15.minutes),
|
|
||||||
# 105-minute gap here (user left the city)
|
|
||||||
create(:point, city: 'Berlin', country: 'Germany', timestamp: timestamp + 120.minutes),
|
|
||||||
create(:point, city: 'Berlin', country: 'Germany', timestamp: timestamp + 130.minutes)
|
|
||||||
]
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'only counts time between consecutive points within threshold' do
|
|
||||||
# Old logic would count 130 minutes (span from first to last)
|
|
||||||
# New logic counts: 15 min (0->15) + 10 min (120->130) = 25 minutes
|
|
||||||
# Since 25 < 60, Berlin should be filtered out
|
|
||||||
expect(countries_and_cities).to eq(
|
|
||||||
[
|
|
||||||
CountriesAndCities::CountryData.new(
|
|
||||||
country: 'Germany',
|
|
||||||
cities: []
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when points span a long time but have continuous presence' do
|
|
||||||
let(:points) do
|
|
||||||
# Points every 30 minutes for 2.5 hours = continuous presence
|
|
||||||
(0..5).map do |i|
|
|
||||||
create(:point, city: 'Berlin', country: 'Germany', timestamp: timestamp + (i * 30).minutes)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'counts the full duration when all intervals are within threshold' do
|
|
||||||
# 5 intervals of 30 minutes each = 150 minutes total
|
|
||||||
expect(countries_and_cities).to eq(
|
|
||||||
[
|
|
||||||
CountriesAndCities::CountryData.new(
|
|
||||||
country: 'Germany',
|
|
||||||
cities: [
|
|
||||||
CountriesAndCities::CityData.new(
|
|
||||||
city: 'Berlin', points: 6, timestamp: (timestamp + 150.minutes).to_i, stayed_for: 150
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -61,18 +61,16 @@ RSpec.describe Points::RawData::Verifier do
|
||||||
end.not_to change { archive.reload.verified_at }
|
end.not_to change { archive.reload.verified_at }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'still verifies successfully when points are deleted from database' do
|
it 'detects deleted points' do
|
||||||
# Force archive creation first
|
# Force archive creation first
|
||||||
archive_id = archive.id
|
archive_id = archive.id
|
||||||
|
|
||||||
# Then delete one point from database
|
# Then delete one point from database
|
||||||
points.first.destroy
|
points.first.destroy
|
||||||
|
|
||||||
# Verification should still succeed - deleted points are acceptable
|
|
||||||
# (users should be able to delete their data without failing archive verification)
|
|
||||||
expect do
|
expect do
|
||||||
verifier.verify_specific_archive(archive_id)
|
verifier.verify_specific_archive(archive_id)
|
||||||
end.to change { archive.reload.verified_at }.from(nil)
|
end.not_to change { archive.reload.verified_at }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'detects raw_data mismatch between archive and database' do
|
it 'detects raw_data mismatch between archive and database' do
|
||||||
|
|
|
||||||
|
|
@ -155,14 +155,10 @@ RSpec.describe Stats::CalculateMonth do
|
||||||
context 'when user visited multiple cities with mixed durations' do
|
context 'when user visited multiple cities with mixed durations' do
|
||||||
let!(:mixed_points) do
|
let!(:mixed_points) do
|
||||||
[
|
[
|
||||||
# Berlin: 70 minutes with continuous presence (should be included)
|
# Berlin: 70 minutes (should be included)
|
||||||
# Points every 35 minutes: 0, 35, 70 = 70 min total
|
|
||||||
create(:point, user:, import:, timestamp: timestamp_base,
|
create(:point, user:, import:, timestamp: timestamp_base,
|
||||||
city: 'Berlin', country_name: 'Germany',
|
city: 'Berlin', country_name: 'Germany',
|
||||||
lonlat: 'POINT(13.404954 52.520008)'),
|
lonlat: 'POINT(13.404954 52.520008)'),
|
||||||
create(:point, user:, import:, timestamp: timestamp_base + 35.minutes,
|
|
||||||
city: 'Berlin', country_name: 'Germany',
|
|
||||||
lonlat: 'POINT(13.404954 52.520008)'),
|
|
||||||
create(:point, user:, import:, timestamp: timestamp_base + 70.minutes,
|
create(:point, user:, import:, timestamp: timestamp_base + 70.minutes,
|
||||||
city: 'Berlin', country_name: 'Germany',
|
city: 'Berlin', country_name: 'Germany',
|
||||||
lonlat: 'POINT(13.404954 52.520008)'),
|
lonlat: 'POINT(13.404954 52.520008)'),
|
||||||
|
|
@ -175,17 +171,10 @@ RSpec.describe Stats::CalculateMonth do
|
||||||
city: 'Prague', country_name: 'Czech Republic',
|
city: 'Prague', country_name: 'Czech Republic',
|
||||||
lonlat: 'POINT(14.4378 50.0755)'),
|
lonlat: 'POINT(14.4378 50.0755)'),
|
||||||
|
|
||||||
# Vienna: 90 minutes with continuous presence (should be included)
|
# Vienna: 90 minutes (should be included)
|
||||||
# Points every 30 minutes: 150, 180, 210, 240 = 90 min total
|
|
||||||
create(:point, user:, import:, timestamp: timestamp_base + 150.minutes,
|
create(:point, user:, import:, timestamp: timestamp_base + 150.minutes,
|
||||||
city: 'Vienna', country_name: 'Austria',
|
city: 'Vienna', country_name: 'Austria',
|
||||||
lonlat: 'POINT(16.3738 48.2082)'),
|
lonlat: 'POINT(16.3738 48.2082)'),
|
||||||
create(:point, user:, import:, timestamp: timestamp_base + 180.minutes,
|
|
||||||
city: 'Vienna', country_name: 'Austria',
|
|
||||||
lonlat: 'POINT(16.3738 48.2082)'),
|
|
||||||
create(:point, user:, import:, timestamp: timestamp_base + 210.minutes,
|
|
||||||
city: 'Vienna', country_name: 'Austria',
|
|
||||||
lonlat: 'POINT(16.3738 48.2082)'),
|
|
||||||
create(:point, user:, import:, timestamp: timestamp_base + 240.minutes,
|
create(:point, user:, import:, timestamp: timestamp_base + 240.minutes,
|
||||||
city: 'Vienna', country_name: 'Austria',
|
city: 'Vienna', country_name: 'Austria',
|
||||||
lonlat: 'POINT(16.3738 48.2082)')
|
lonlat: 'POINT(16.3738 48.2082)')
|
||||||
|
|
|
||||||
|
|
@ -76,169 +76,19 @@ RSpec.describe Users::Digests::CalculateYear do
|
||||||
expect(calculate_digest.monthly_distances['3']).to eq('0') # Missing month
|
expect(calculate_digest.monthly_distances['3']).to eq('0') # Missing month
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calculates time spent by location using hybrid day-based approach' do
|
it 'calculates time spent by location' do
|
||||||
# Create points to test hybrid calculation
|
|
||||||
# Jan 1: single country day (Germany) -> full 1440 minutes
|
|
||||||
jan_1_10am = Time.zone.local(2024, 1, 1, 10, 0, 0).to_i
|
|
||||||
jan_1_11am = Time.zone.local(2024, 1, 1, 11, 0, 0).to_i
|
|
||||||
jan_1_12pm = Time.zone.local(2024, 1, 1, 12, 0, 0).to_i
|
|
||||||
# Feb 1: single country day (France) -> full 1440 minutes
|
|
||||||
feb_1_10am = Time.zone.local(2024, 2, 1, 10, 0, 0).to_i
|
|
||||||
|
|
||||||
create(:point, user: user, timestamp: jan_1_10am, country_name: 'Germany', city: 'Berlin')
|
|
||||||
create(:point, user: user, timestamp: jan_1_11am, country_name: 'Germany', city: 'Berlin')
|
|
||||||
create(:point, user: user, timestamp: jan_1_12pm, country_name: 'Germany', city: 'Munich')
|
|
||||||
create(:point, user: user, timestamp: feb_1_10am, country_name: 'France', city: 'Paris')
|
|
||||||
|
|
||||||
countries = calculate_digest.time_spent_by_location['countries']
|
countries = calculate_digest.time_spent_by_location['countries']
|
||||||
cities = calculate_digest.time_spent_by_location['cities']
|
cities = calculate_digest.time_spent_by_location['cities']
|
||||||
|
|
||||||
# Germany: 1 full day = 1440 minutes
|
expect(countries.first['name']).to eq('Germany')
|
||||||
germany_country = countries.find { |c| c['name'] == 'Germany' }
|
expect(countries.first['minutes']).to eq(720) # 480 + 240
|
||||||
expect(germany_country['minutes']).to eq(1440)
|
|
||||||
|
|
||||||
# France: 1 full day = 1440 minutes
|
|
||||||
france_country = countries.find { |c| c['name'] == 'France' }
|
|
||||||
expect(france_country['minutes']).to eq(1440)
|
|
||||||
|
|
||||||
# Cities: based on stayed_for from monthly stats (sum across months)
|
|
||||||
expect(cities.first['name']).to eq('Berlin')
|
expect(cities.first['name']).to eq('Berlin')
|
||||||
expect(cities.first['minutes']).to eq(480)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calculates all time stats' do
|
it 'calculates all time stats' do
|
||||||
expect(calculate_digest.all_time_stats['total_distance']).to eq('125000')
|
expect(calculate_digest.all_time_stats['total_distance']).to eq('125000')
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user visits same country across multiple months' do
|
|
||||||
it 'counts each day as a full day for single-country days' do
|
|
||||||
# Create hourly points across multiple days in March and July
|
|
||||||
mar_start = Time.zone.local(2024, 3, 1, 10, 0, 0).to_i
|
|
||||||
jul_start = Time.zone.local(2024, 7, 1, 10, 0, 0).to_i
|
|
||||||
|
|
||||||
# Create 3 days of hourly points in March
|
|
||||||
3.times do |day|
|
|
||||||
3.times do |hour|
|
|
||||||
timestamp = mar_start + (day * 24 * 60 * 60) + (hour * 60 * 60)
|
|
||||||
create(:point, user: user, timestamp: timestamp, country_name: 'Germany', city: 'Berlin')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Create 3 days of hourly points in July
|
|
||||||
3.times do |day|
|
|
||||||
3.times do |hour|
|
|
||||||
timestamp = jul_start + (day * 24 * 60 * 60) + (hour * 60 * 60)
|
|
||||||
create(:point, user: user, timestamp: timestamp, country_name: 'Germany', city: 'Munich')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Create the monthly stats
|
|
||||||
create(:stat, user: user, year: 2024, month: 3, distance: 10_000, toponyms: [
|
|
||||||
{ 'country' => 'Germany', 'cities' => [
|
|
||||||
{ 'city' => 'Berlin', 'stayed_for' => 14_400 }
|
|
||||||
] }
|
|
||||||
])
|
|
||||||
|
|
||||||
create(:stat, user: user, year: 2024, month: 7, distance: 15_000, toponyms: [
|
|
||||||
{ 'country' => 'Germany', 'cities' => [
|
|
||||||
{ 'city' => 'Munich', 'stayed_for' => 14_400 }
|
|
||||||
] }
|
|
||||||
])
|
|
||||||
|
|
||||||
digest = calculate_digest
|
|
||||||
countries = digest.time_spent_by_location['countries']
|
|
||||||
germany = countries.find { |c| c['name'] == 'Germany' }
|
|
||||||
|
|
||||||
# Each single-country day = 1440 minutes
|
|
||||||
# 6 days total (3 in March + 3 in July) = 6 * 1440 = 8640 minutes
|
|
||||||
expect(germany['minutes']).to eq(6 * 1440)
|
|
||||||
|
|
||||||
# Total should equal exactly 6 days
|
|
||||||
total_days = germany['minutes'] / 1440.0
|
|
||||||
expect(total_days).to eq(6)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when there are large gaps between points on same day' do
|
|
||||||
it 'still counts the full day for single-country day' do
|
|
||||||
point_1 = Time.zone.local(2024, 1, 1, 10, 0, 0).to_i
|
|
||||||
point_2 = Time.zone.local(2024, 1, 1, 12, 0, 0).to_i # 2 hours later
|
|
||||||
point_3 = Time.zone.local(2024, 1, 1, 18, 0, 0).to_i # 6 hours later
|
|
||||||
|
|
||||||
create(:point, user: user, timestamp: point_1, country_name: 'Germany')
|
|
||||||
create(:point, user: user, timestamp: point_2, country_name: 'Germany')
|
|
||||||
create(:point, user: user, timestamp: point_3, country_name: 'Germany')
|
|
||||||
|
|
||||||
digest = calculate_digest
|
|
||||||
germany = digest.time_spent_by_location['countries'].find { |c| c['name'] == 'Germany' }
|
|
||||||
|
|
||||||
# Hybrid approach: single-country day = full 1440 minutes
|
|
||||||
# regardless of gaps between points
|
|
||||||
expect(germany['minutes']).to eq(1440)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when transitioning between countries on same day' do
|
|
||||||
it 'calculates proportional time based on time spans' do
|
|
||||||
# Multi-country day: Germany 10:00-10:30, France 11:00-11:30
|
|
||||||
point_1 = Time.zone.local(2024, 1, 1, 10, 0, 0).to_i
|
|
||||||
point_2 = Time.zone.local(2024, 1, 1, 10, 30, 0).to_i # In Germany
|
|
||||||
point_3 = Time.zone.local(2024, 1, 1, 11, 0, 0).to_i # Now in France
|
|
||||||
point_4 = Time.zone.local(2024, 1, 1, 11, 30, 0).to_i # Still in France
|
|
||||||
|
|
||||||
create(:point, user: user, timestamp: point_1, country_name: 'Germany')
|
|
||||||
create(:point, user: user, timestamp: point_2, country_name: 'Germany')
|
|
||||||
create(:point, user: user, timestamp: point_3, country_name: 'France')
|
|
||||||
create(:point, user: user, timestamp: point_4, country_name: 'France')
|
|
||||||
|
|
||||||
digest = calculate_digest
|
|
||||||
countries = digest.time_spent_by_location['countries']
|
|
||||||
|
|
||||||
germany = countries.find { |c| c['name'] == 'Germany' }
|
|
||||||
france = countries.find { |c| c['name'] == 'France' }
|
|
||||||
|
|
||||||
# Germany span: 10:30 - 10:00 = 30 min = 1800 seconds
|
|
||||||
# France span: 11:30 - 11:00 = 30 min = 1800 seconds
|
|
||||||
# Total spans = 3600 seconds
|
|
||||||
# Each country gets 50% of 1440 = 720 minutes
|
|
||||||
expect(germany['minutes']).to eq(720)
|
|
||||||
expect(france['minutes']).to eq(720)
|
|
||||||
# Total = 1440 (exactly one day)
|
|
||||||
expect(germany['minutes'] + france['minutes']).to eq(1440)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when visiting multiple countries on same day' do
|
|
||||||
it 'calculates proportional time and never exceeds one day total' do
|
|
||||||
# This tests the fix for the original bug: border crossing should not count double
|
|
||||||
# France: 8am-9am (1 hour span = 3600 seconds)
|
|
||||||
# Germany: 10am-11am (1 hour span = 3600 seconds)
|
|
||||||
jan_1_8am = Time.zone.local(2024, 1, 1, 8, 0, 0).to_i
|
|
||||||
jan_1_9am = Time.zone.local(2024, 1, 1, 9, 0, 0).to_i
|
|
||||||
jan_1_10am = Time.zone.local(2024, 1, 1, 10, 0, 0).to_i # Border crossing
|
|
||||||
jan_1_11am = Time.zone.local(2024, 1, 1, 11, 0, 0).to_i
|
|
||||||
|
|
||||||
create(:point, user: user, timestamp: jan_1_8am, country_name: 'France')
|
|
||||||
create(:point, user: user, timestamp: jan_1_9am, country_name: 'France')
|
|
||||||
create(:point, user: user, timestamp: jan_1_10am, country_name: 'Germany')
|
|
||||||
create(:point, user: user, timestamp: jan_1_11am, country_name: 'Germany')
|
|
||||||
|
|
||||||
digest = calculate_digest
|
|
||||||
countries = digest.time_spent_by_location['countries']
|
|
||||||
|
|
||||||
france = countries.find { |c| c['name'] == 'France' }
|
|
||||||
germany = countries.find { |c| c['name'] == 'Germany' }
|
|
||||||
|
|
||||||
# France span: 3600 seconds, Germany span: 3600 seconds
|
|
||||||
# Total spans: 7200 seconds
|
|
||||||
# Each gets 50% of 1440 = 720 minutes
|
|
||||||
expect(france['minutes']).to eq(720)
|
|
||||||
expect(germany['minutes']).to eq(720)
|
|
||||||
# Total = 1440 (exactly one day) - NOT 2 days as the bug would have caused
|
|
||||||
expect(france['minutes'] + germany['minutes']).to eq(1440)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when digest already exists' do
|
context 'when digest already exists' do
|
||||||
let!(:existing_digest) do
|
let!(:existing_digest) do
|
||||||
create(:users_digest, user: user, year: 2024, period_type: :yearly, distance: 10_000)
|
create(:users_digest, user: user, year: 2024, period_type: :yearly, distance: 10_000)
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,7 @@ RSpec.describe Users::SafeSettings do
|
||||||
speed_color_scale: nil,
|
speed_color_scale: nil,
|
||||||
fog_of_war_threshold: nil,
|
fog_of_war_threshold: nil,
|
||||||
enabled_map_layers: %w[Routes Heatmap],
|
enabled_map_layers: %w[Routes Heatmap],
|
||||||
maps_maplibre_style: 'light',
|
maps_maplibre_style: 'light'
|
||||||
globe_projection: false
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -83,8 +82,7 @@ RSpec.describe Users::SafeSettings do
|
||||||
'visits_suggestions_enabled' => false,
|
'visits_suggestions_enabled' => false,
|
||||||
'enabled_map_layers' => %w[Points Routes Areas Photos],
|
'enabled_map_layers' => %w[Points Routes Areas Photos],
|
||||||
'maps_maplibre_style' => 'light',
|
'maps_maplibre_style' => 'light',
|
||||||
'digest_emails_enabled' => true,
|
'digest_emails_enabled' => true
|
||||||
'globe_projection' => false
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -112,8 +110,7 @@ RSpec.describe Users::SafeSettings do
|
||||||
speed_color_scale: nil,
|
speed_color_scale: nil,
|
||||||
fog_of_war_threshold: nil,
|
fog_of_war_threshold: nil,
|
||||||
enabled_map_layers: %w[Points Routes Areas Photos],
|
enabled_map_layers: %w[Points Routes Areas Photos],
|
||||||
maps_maplibre_style: 'light',
|
maps_maplibre_style: 'light'
|
||||||
globe_projection: false
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue