mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Add home location based on "Home" tagged place
This commit is contained in:
parent
e1013b1ae1
commit
a33373ae7c
5 changed files with 30 additions and 2 deletions
|
|
@ -25,6 +25,7 @@ OIDC_REDIRECT_URI=https://your-dawarich-url.com/users/auth/openid_connect/callba
|
||||||
- User can create and manage tags for places.
|
- User can create and manage tags for places.
|
||||||
- User can enable or disable places layers on the map to show/hide all or just some of their visited places based on tags.
|
- User can enable or disable places layers on the map to show/hide all or just some of their visited places based on tags.
|
||||||
- User can define privacy zones around places with specific tags to hide map data within a certain radius.
|
- User can define privacy zones around places with specific tags to hide map data within a certain radius.
|
||||||
|
- If user has a place tagged with a tag named "Home" (case insensitive), and this place doesn't have a privacy zone defined, this place will be used as home location for days with no tracked data.
|
||||||
|
|
||||||
## Fixed
|
## Fixed
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ class MapController < ApplicationController
|
||||||
@years = years_range
|
@years = years_range
|
||||||
@points_number = points_count
|
@points_number = points_count
|
||||||
@features = DawarichSettings.features
|
@features = DawarichSettings.features
|
||||||
|
@home_coordinates = current_user.home_place_coordinates
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -117,8 +117,22 @@ export default class extends BaseController {
|
||||||
this.markers = [];
|
this.markers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set default center (Berlin) if no markers available
|
// Set default center based on priority: Home place > last marker > Berlin
|
||||||
this.center = this.markers.length > 0 ? this.markers[this.markers.length - 1] : [52.514568, 13.350111];
|
let defaultCenter = [52.514568, 13.350111]; // Berlin as final fallback
|
||||||
|
|
||||||
|
// Try to get Home place coordinates
|
||||||
|
try {
|
||||||
|
const homeCoords = this.element.dataset.home_coordinates ?
|
||||||
|
JSON.parse(this.element.dataset.home_coordinates) : null;
|
||||||
|
if (homeCoords && Array.isArray(homeCoords) && homeCoords.length === 2) {
|
||||||
|
defaultCenter = homeCoords;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Error parsing home coordinates:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use last marker if available, otherwise use default center (Home or Berlin)
|
||||||
|
this.center = this.markers.length > 0 ? this.markers[this.markers.length - 1] : defaultCenter;
|
||||||
|
|
||||||
this.map = L.map(this.containerTarget).setView([this.center[0], this.center[1]], 14);
|
this.map = L.map(this.containerTarget).setView([this.center[0], this.center[1]], 14);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -187,4 +187,15 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
|
||||||
Users::MailerSendingJob.set(wait: 9.days).perform_later(id, 'post_trial_reminder_early')
|
Users::MailerSendingJob.set(wait: 9.days).perform_later(id, 'post_trial_reminder_early')
|
||||||
Users::MailerSendingJob.set(wait: 14.days).perform_later(id, 'post_trial_reminder_late')
|
Users::MailerSendingJob.set(wait: 14.days).perform_later(id, 'post_trial_reminder_late')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def home_place_coordinates
|
||||||
|
home_tag = tags.find_by('LOWER(name) = ?', 'home')
|
||||||
|
return nil unless home_tag
|
||||||
|
return nil if home_tag.privacy_zone?
|
||||||
|
|
||||||
|
home_place = home_tag.places.first
|
||||||
|
return nil unless home_place
|
||||||
|
|
||||||
|
[home_place.latitude, home_place.longitude]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@
|
||||||
data-timezone="<%= Rails.configuration.time_zone %>"
|
data-timezone="<%= Rails.configuration.time_zone %>"
|
||||||
data-features='<%= @features.to_json.html_safe %>'
|
data-features='<%= @features.to_json.html_safe %>'
|
||||||
data-user_tags='<%= current_user.tags.ordered.select(:id, :name, :icon, :color).as_json.to_json.html_safe %>'
|
data-user_tags='<%= current_user.tags.ordered.select(:id, :name, :icon, :color).as_json.to_json.html_safe %>'
|
||||||
|
data-home_coordinates='<%= @home_coordinates.to_json.html_safe %>'
|
||||||
data-family-members-features-value='<%= @features.to_json.html_safe %>'
|
data-family-members-features-value='<%= @features.to_json.html_safe %>'
|
||||||
data-family-members-user-theme-value="<%= current_user&.theme || 'dark' %>">
|
data-family-members-user-theme-value="<%= current_user&.theme || 'dark' %>">
|
||||||
<div data-maps-target="container" class="w-full h-full">
|
<div data-maps-target="container" class="w-full h-full">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue