dawarich/app/services/users/safe_settings.rb

143 lines
3.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class Users::SafeSettings
attr_reader :settings
2025-05-19 17:28:33 -04:00
DEFAULT_VALUES = {
'fog_of_war_meters' => 50,
'meters_between_routes' => 500,
'preferred_map_layer' => 'OpenStreetMap',
'speed_colored_routes' => false,
'points_rendering_mode' => 'raw',
'minutes_between_routes' => 30,
'time_threshold_minutes' => 30,
'merge_threshold_minutes' => 15,
'live_map_enabled' => true,
2025-05-22 13:09:43 -04:00
'route_opacity' => 60,
2025-05-19 17:28:33 -04:00
'immich_url' => nil,
'immich_api_key' => nil,
'photoprism_url' => nil,
'photoprism_api_key' => nil,
2025-07-02 17:50:32 -04:00
'maps' => { 'distance_unit' => 'km' },
2025-10-20 14:11:28 -04:00
'visits_suggestions_enabled' => 'true',
0.36.2 (#2007) * fix: move foreman to global gems to fix startup crash (#1971) * Update exporting code to stream points data to file in batches to red… (#1980) * Update exporting code to stream points data to file in batches to reduce memory usage * Update changelog * Update changelog * Feature/maplibre frontend (#1953) * Add a plan to use MapLibre GL JS for the frontend map rendering, replacing Leaflet * Implement phase 1 * Phases 1-3 + part of 4 * Fix e2e tests * Phase 6 * Implement fog of war * Phase 7 * Next step: fix specs, phase 7 done * Use our own map tiles * Extract v2 map logic to separate manager classes * Update settings panel on v2 map * Update v2 e2e tests structure * Reimplement location search in maps v2 * Update speed routes * Implement visits and places creation in v2 * Fix last failing test * Implement visits merging * Fix a routes e2e test and simplify the routes layer styling. * Extract js to modules from maps_v2_controller.js * Implement area creation * Fix spec problem * Fix some e2e tests * Implement live mode in v2 map * Update icons and panel * Extract some styles * Remove unused file * Start adding dark theme to popups on MapLibre maps * Make popups respect dark theme * Move v2 maps to maplibre namespace * Update v2 references to maplibre * Put place, area and visit info into side panel * Update API to use safe settings config method * Fix specs * Fix method name to config in SafeSettings and update usages accordingly * Add missing public files * Add handling for real time points * Fix remembering enabled/disabled layers of the v2 map * Fix lots of e2e tests * Add settings to select map version * Use maps/v2 as main path for MapLibre maps * Update routing * Update live mode * Update maplibre controller * Update changelog * Remove some console.log statements --------- Co-authored-by: Robin Tuszik <mail@robin.gg>
2025-12-06 14:54:49 -05:00
'enabled_map_layers' => ['Routes', 'Heatmap'],
'maps_maplibre_style' => 'light'
2025-05-19 17:28:33 -04:00
}.freeze
def initialize(settings = {})
@settings = DEFAULT_VALUES.dup.merge(settings)
end
# rubocop:disable Metrics/MethodLength
0.36.2 (#2007) * fix: move foreman to global gems to fix startup crash (#1971) * Update exporting code to stream points data to file in batches to red… (#1980) * Update exporting code to stream points data to file in batches to reduce memory usage * Update changelog * Update changelog * Feature/maplibre frontend (#1953) * Add a plan to use MapLibre GL JS for the frontend map rendering, replacing Leaflet * Implement phase 1 * Phases 1-3 + part of 4 * Fix e2e tests * Phase 6 * Implement fog of war * Phase 7 * Next step: fix specs, phase 7 done * Use our own map tiles * Extract v2 map logic to separate manager classes * Update settings panel on v2 map * Update v2 e2e tests structure * Reimplement location search in maps v2 * Update speed routes * Implement visits and places creation in v2 * Fix last failing test * Implement visits merging * Fix a routes e2e test and simplify the routes layer styling. * Extract js to modules from maps_v2_controller.js * Implement area creation * Fix spec problem * Fix some e2e tests * Implement live mode in v2 map * Update icons and panel * Extract some styles * Remove unused file * Start adding dark theme to popups on MapLibre maps * Make popups respect dark theme * Move v2 maps to maplibre namespace * Update v2 references to maplibre * Put place, area and visit info into side panel * Update API to use safe settings config method * Fix specs * Fix method name to config in SafeSettings and update usages accordingly * Add missing public files * Add handling for real time points * Fix remembering enabled/disabled layers of the v2 map * Fix lots of e2e tests * Add settings to select map version * Use maps/v2 as main path for MapLibre maps * Update routing * Update live mode * Update maplibre controller * Update changelog * Remove some console.log statements --------- Co-authored-by: Robin Tuszik <mail@robin.gg>
2025-12-06 14:54:49 -05:00
def config
{
fog_of_war_meters: fog_of_war_meters,
meters_between_routes: meters_between_routes,
preferred_map_layer: preferred_map_layer,
speed_colored_routes: speed_colored_routes,
points_rendering_mode: points_rendering_mode,
minutes_between_routes: minutes_between_routes,
time_threshold_minutes: time_threshold_minutes,
merge_threshold_minutes: merge_threshold_minutes,
live_map_enabled: live_map_enabled,
route_opacity: route_opacity,
immich_url: immich_url,
immich_api_key: immich_api_key,
photoprism_url: photoprism_url,
photoprism_api_key: photoprism_api_key,
maps: maps,
2025-07-02 17:50:32 -04:00
distance_unit: distance_unit,
visits_suggestions_enabled: visits_suggestions_enabled?,
speed_color_scale: speed_color_scale,
2025-10-20 14:11:28 -04:00
fog_of_war_threshold: fog_of_war_threshold,
0.36.2 (#2007) * fix: move foreman to global gems to fix startup crash (#1971) * Update exporting code to stream points data to file in batches to red… (#1980) * Update exporting code to stream points data to file in batches to reduce memory usage * Update changelog * Update changelog * Feature/maplibre frontend (#1953) * Add a plan to use MapLibre GL JS for the frontend map rendering, replacing Leaflet * Implement phase 1 * Phases 1-3 + part of 4 * Fix e2e tests * Phase 6 * Implement fog of war * Phase 7 * Next step: fix specs, phase 7 done * Use our own map tiles * Extract v2 map logic to separate manager classes * Update settings panel on v2 map * Update v2 e2e tests structure * Reimplement location search in maps v2 * Update speed routes * Implement visits and places creation in v2 * Fix last failing test * Implement visits merging * Fix a routes e2e test and simplify the routes layer styling. * Extract js to modules from maps_v2_controller.js * Implement area creation * Fix spec problem * Fix some e2e tests * Implement live mode in v2 map * Update icons and panel * Extract some styles * Remove unused file * Start adding dark theme to popups on MapLibre maps * Make popups respect dark theme * Move v2 maps to maplibre namespace * Update v2 references to maplibre * Put place, area and visit info into side panel * Update API to use safe settings config method * Fix specs * Fix method name to config in SafeSettings and update usages accordingly * Add missing public files * Add handling for real time points * Fix remembering enabled/disabled layers of the v2 map * Fix lots of e2e tests * Add settings to select map version * Use maps/v2 as main path for MapLibre maps * Update routing * Update live mode * Update maplibre controller * Update changelog * Remove some console.log statements --------- Co-authored-by: Robin Tuszik <mail@robin.gg>
2025-12-06 14:54:49 -05:00
enabled_map_layers: enabled_map_layers,
maps_maplibre_style: maps_maplibre_style
}
end
# rubocop:enable Metrics/MethodLength
def fog_of_war_meters
2025-05-19 17:28:33 -04:00
settings['fog_of_war_meters']
end
def meters_between_routes
2025-05-19 17:28:33 -04:00
settings['meters_between_routes']
end
def preferred_map_layer
2025-05-19 17:28:33 -04:00
settings['preferred_map_layer']
end
def speed_colored_routes
2025-05-19 17:28:33 -04:00
settings['speed_colored_routes']
end
def points_rendering_mode
2025-05-19 17:28:33 -04:00
settings['points_rendering_mode']
end
def minutes_between_routes
2025-05-19 17:28:33 -04:00
settings['minutes_between_routes']
end
def time_threshold_minutes
2025-05-19 17:28:33 -04:00
settings['time_threshold_minutes']
end
def merge_threshold_minutes
2025-05-19 17:28:33 -04:00
settings['merge_threshold_minutes']
end
def live_map_enabled
2025-05-19 17:28:33 -04:00
settings['live_map_enabled']
end
def route_opacity
2025-05-19 17:28:33 -04:00
settings['route_opacity']
end
def immich_url
settings['immich_url']
end
def immich_api_key
settings['immich_api_key']
end
def photoprism_url
settings['photoprism_url']
end
def photoprism_api_key
settings['photoprism_api_key']
end
def maps
2025-05-19 17:28:33 -04:00
settings['maps']
end
def distance_unit
2025-05-19 17:28:33 -04:00
settings.dig('maps', 'distance_unit')
end
2025-07-02 17:50:32 -04:00
def visits_suggestions_enabled?
settings['visits_suggestions_enabled'] == 'true'
end
def speed_color_scale
settings['speed_color_scale']
end
def fog_of_war_threshold
settings['fog_of_war_threshold']
end
2025-10-20 14:11:28 -04:00
def enabled_map_layers
settings['enabled_map_layers']
end
0.36.2 (#2007) * fix: move foreman to global gems to fix startup crash (#1971) * Update exporting code to stream points data to file in batches to red… (#1980) * Update exporting code to stream points data to file in batches to reduce memory usage * Update changelog * Update changelog * Feature/maplibre frontend (#1953) * Add a plan to use MapLibre GL JS for the frontend map rendering, replacing Leaflet * Implement phase 1 * Phases 1-3 + part of 4 * Fix e2e tests * Phase 6 * Implement fog of war * Phase 7 * Next step: fix specs, phase 7 done * Use our own map tiles * Extract v2 map logic to separate manager classes * Update settings panel on v2 map * Update v2 e2e tests structure * Reimplement location search in maps v2 * Update speed routes * Implement visits and places creation in v2 * Fix last failing test * Implement visits merging * Fix a routes e2e test and simplify the routes layer styling. * Extract js to modules from maps_v2_controller.js * Implement area creation * Fix spec problem * Fix some e2e tests * Implement live mode in v2 map * Update icons and panel * Extract some styles * Remove unused file * Start adding dark theme to popups on MapLibre maps * Make popups respect dark theme * Move v2 maps to maplibre namespace * Update v2 references to maplibre * Put place, area and visit info into side panel * Update API to use safe settings config method * Fix specs * Fix method name to config in SafeSettings and update usages accordingly * Add missing public files * Add handling for real time points * Fix remembering enabled/disabled layers of the v2 map * Fix lots of e2e tests * Add settings to select map version * Use maps/v2 as main path for MapLibre maps * Update routing * Update live mode * Update maplibre controller * Update changelog * Remove some console.log statements --------- Co-authored-by: Robin Tuszik <mail@robin.gg>
2025-12-06 14:54:49 -05:00
def maps_maplibre_style
settings['maps_maplibre_style']
end
end