Skip to content

Commit

Permalink
Merge branch 'master' into countries-and-cities-revised
Browse files Browse the repository at this point in the history
  • Loading branch information
Freika committed Jun 25, 2024
2 parents 7844bf1 + b735b17 commit 591eeb2
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .app_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.0
0.7.1
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.7.1] — 2024-06-20

In new Settings page you can now change the following settings:

- Maximum distance between two points to consider them as one route
- Maximum time between two points to consider them as one route

### Added

- New Settings page to change Dawarich settings.

### Changed

- Settings link in user menu now redirects to the new Settings page.
- Old settings page is now available undeer Account link in user menu.

---
## [0.7.0] — 2024-06-19

## The GPX MVP Release
Expand Down
38 changes: 19 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ GEM
down (5.4.2)
addressable (~> 2.8)
drb (2.2.1)
erubi (1.12.0)
erubi (1.13.0)
et-orbi (1.2.11)
tzinfo
factory_bot (6.4.6)
Expand All @@ -145,7 +145,7 @@ GEM
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.7.2)
irb (1.13.1)
irb (1.13.2)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.7.2)
Expand All @@ -161,9 +161,9 @@ GEM
net-pop
net-smtp
marcel (1.0.4)
method_source (1.0.0)
method_source (1.1.0)
mini_mime (1.1.5)
minitest (5.23.1)
minitest (5.24.0)
msgpack (1.7.2)
mutex_m (0.2.0)
net-imap (0.4.12)
Expand All @@ -176,17 +176,17 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.3)
nokogiri (1.16.5-aarch64-linux)
nokogiri (1.16.6-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.5-arm-linux)
nokogiri (1.16.6-arm-linux)
racc (~> 1.4)
nokogiri (1.16.5-arm64-darwin)
nokogiri (1.16.6-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.5-x86-linux)
nokogiri (1.16.6-x86-linux)
racc (~> 1.4)
nokogiri (1.16.5-x86_64-darwin)
nokogiri (1.16.6-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.5-x86_64-linux)
nokogiri (1.16.6-x86_64-linux)
racc (~> 1.4)
oj (3.16.4)
bigdecimal (>= 3.0)
Expand All @@ -205,8 +205,8 @@ GEM
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
pry-rails (0.3.9)
pry (>= 0.10.4)
pry-rails (0.3.11)
pry (>= 0.13.0)
psych (5.1.2)
stringio
public_suffix (5.0.5)
Expand All @@ -216,7 +216,7 @@ GEM
activesupport (>= 3.0.0)
raabro (1.4.0)
racc (1.8.0)
rack (3.0.11)
rack (3.1.4)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
Expand Down Expand Up @@ -262,7 +262,7 @@ GEM
redis-client (0.22.1)
connection_pool
regexp_parser (2.9.2)
reline (0.5.8)
reline (0.5.9)
io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
Expand All @@ -271,13 +271,13 @@ GEM
strscan (>= 3.0.9)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
rspec-expectations (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (6.1.2)
rspec-rails (6.1.3)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
Expand Down Expand Up @@ -345,7 +345,7 @@ GEM
sprockets (>= 3.0.0)
stimulus-rails (1.3.3)
railties (>= 6.0.0)
stringio (3.1.0)
stringio (3.1.1)
strscan (3.1.0)
super_diff (0.12.1)
attr_extras (>= 6.2.4)
Expand Down Expand Up @@ -383,7 +383,7 @@ GEM
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
will_paginate (4.0.1)
zeitwerk (2.6.15)
zeitwerk (2.6.16)

PLATFORMS
aarch64-linux
Expand Down
2 changes: 1 addition & 1 deletion app/assets/builds/tailwind.css

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
class SettingsController < ApplicationController
before_action :authenticate_user!

def index
end

def update
current_user.update(settings: settings_params)

flash.now[:notice] = 'Settings updated'

redirect_to settings_path, notice: 'Settings updated'
end

def theme
current_user.update(theme: params[:theme])

Expand All @@ -14,4 +25,10 @@ def generate_api_key

redirect_back(fallback_location: root_path)
end

private

def settings_params
params.require(:settings).permit(:meters_between_routes, :minutes_between_routes)
end
end
4 changes: 2 additions & 2 deletions app/javascript/controllers/maps_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ export default class extends Controller {
createPolylinesLayer(markers, map, timezone) {
const splitPolylines = [];
let currentPolyline = [];
const distanceThresholdMeters = parseInt(this.getUrlParameter("meters_between_routes")) || 500;
const timeThresholdMinutes = parseInt(this.getUrlParameter("minutes_between_routes")) || 60;
const distanceThresholdMeters = parseInt(this.element.dataset.meters_between_routes) || 500;
const timeThresholdMinutes = parseInt(this.element.dataset.minutes_between_routes) || 60;

for (let i = 0, len = markers.length; i < len; i++) {
if (currentPolyline.length === 0) {
Expand Down
2 changes: 2 additions & 0 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% content_for :title, 'Account' %>

<div class="hero min-h-content bg-base-200">
<div class="hero-content flex-col lg:flex-row-reverse w-full my-10">
<div class="text-center lg:text-left">
Expand Down
4 changes: 3 additions & 1 deletion app/views/map/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
data-controller="maps"
data-coordinates="<%= @coordinates %>"
data-center="<%= MAP_CENTER %>"
data-timezone="<%= Rails.configuration.time_zone %>">
data-timezone="<%= Rails.configuration.time_zone %>"
data-meters_between_routes="<%= current_user.settings['meters_between_routes'] %>"
data-minutes_between_routes="<%= current_user.settings['minutes_between_routes'] %>">
<div data-maps-target="container" class="h-[25rem] w-auto min-h-screen"></div>
</div>
</div>
Expand Down
65 changes: 65 additions & 0 deletions app/views/settings/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<% content_for :title, 'Settings' %>

<div class="hero min-h-content bg-base-200">
<div class="hero-content flex-col lg:flex-row-reverse w-full my-10">
<div class="text-center lg:text-left">
<h1 class="text-5xl font-bold">Edit your Dawarich settings!</h1>
</div>
<div class="card flex-shrink-0 w-full max-w-sm shadow-2xl bg-base-100 px-5 py-5">
<%= form_for :settings, url: settings_path, method: :patch, data: { turbo_method: :patch, turbo: false } do |f| %>
<div class="form-control my-2">
<%= f.label :meters_between_routes do %>
Meters between routes

<!-- The button to open modal -->
<label for="meters_between_routes_info" class="btn">?</label>

<!-- Put this part before </body> tag -->
<input type="checkbox" id="meters_between_routes_info" class="modal-toggle" />
<div class="modal" role="dialog">
<div class="modal-box">
<h3 class="text-lg font-bold">Meters between routes</h3>
<p class="py-4">
Value in meters.
</p>
<p class="py-4">
Points on the map are connected by lines. This value is the maximum distance between two points to be connected by a line. If the distance between two points is greater than this value, they will not be connected, and the line will not be drawn. This allows to split the route into smaller segments, and to avoid drawing lines between two points that are far from each other.
</p>
</div>
<label class="modal-backdrop" for="meters_between_routes_info">Close</label>
</div>
<% end %>
<%= f.number_field :meters_between_routes, value: current_user.settings['meters_between_routes'], class: "input input-bordered" %>
</div>

<div class="form-control my-2">
<%= f.label :minutes_between_routes do %>
Minutes between routes

<!-- The button to open modal -->
<label for="minutes_between_routes_info" class="btn">?</label>

<!-- Put this part before </body> tag -->
<input type="checkbox" id="minutes_between_routes_info" class="modal-toggle" />
<div class="modal" role="dialog">
<div class="modal-box">
<h3 class="text-lg font-bold">Minutes between routes</h3>
<p class="py-4">
Value in minutes.
</p>
<p class="py-4">
Points on the map are connected by lines. This value is the maximum time between two points to be connected by a line. If the time between two points is greater than this value, they will not be connected. This allows to split the route into smaller segments, and to avoid drawing lines between two points that are far in time from each other.
</p>
</div>
<label class="modal-backdrop" for="minutes_between_routes_info">Close</label>
</div>
<% end %>
<%= f.number_field :minutes_between_routes, value: current_user.settings['minutes_between_routes'], class: "input input-bordered" %>
</div>
<div class="form-control my-2">
<%= f.submit "Update", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
</div>
3 changes: 2 additions & 1 deletion app/views/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
<%= "#{current_user.email}" %>
</summary>
<ul class="p-2 bg-base-100 rounded-t-none z-10">
<li><%= link_to 'Settings', edit_user_registration_path %></li>
<li><%= link_to 'Account', edit_user_registration_path %></li>
<li><%= link_to 'Settings', settings_path %></li>
<li><%= link_to 'Logout', destroy_user_session_path, method: :delete, data: { turbo_method: :delete } %></li>
</ul>
</details>
Expand Down
6 changes: 4 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
mount Rswag::Ui::Engine => '/api-docs'
mount Sidekiq::Web => '/sidekiq'

resources :settings, only: :index

patch 'settings', to: 'settings#update'
get 'settings/theme', to: 'settings#theme'
post 'settings/generate_api_key', to: 'settings#generate_api_key', as: :generate_api_key

resources :imports
resources :exports, only: %i[index create destroy]
Expand All @@ -26,8 +30,6 @@
root to: 'home#index'
devise_for :users

post 'settings/generate_api_key', to: 'settings#generate_api_key', as: :generate_api_key

get 'map', to: 'map#index'

namespace :api do
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20240620205120_add_settings_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class AddSettingsToUsers < ActiveRecord::Migration[7.1]
def change
add_column :users, :settings, :jsonb, default: {
meters_between_routes: 500,
minutes_between_routes: 60
}
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions spec/requests/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,19 @@
end
end
end

describe 'PATCH /settings' do
let(:user) { create(:user) }
let(:params) { { settings: { 'meters_between_routes' => '1000', 'minutes_between_routes' => '10' } } }

before do
sign_in user
end

it 'updates the user settings' do
patch '/settings', params: params

expect(user.reload.settings).to eq(params[:settings])
end
end
end

0 comments on commit 591eeb2

Please sign in to comment.