Add links to view import points on the map and on the Points page on the Imports page

This commit is contained in:
Eugene Burmakin 2024-09-08 17:25:35 +02:00
parent d2a8180a7f
commit 0f3268e6b6
9 changed files with 61 additions and 21 deletions

View file

@ -5,4 +5,4 @@ DATABASE_NAME=dawarich_development
DATABASE_PORT=5432 DATABASE_PORT=5432
REDIS_URL=redis://localhost:6379/1 REDIS_URL=redis://localhost:6379/1
PHOTON_API_HOST='photon.komoot.io' PHOTON_API_HOST='photon.komoot.io'
DISTANCE_UNIT='mi' DISTANCE_UNIT='km'

View file

@ -7,14 +7,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.13.5] — 2024-09-08 ## [0.13.5] — 2024-09-08
### Added
- Links to view import points on the map and on the Points page on the Imports page.
### Fixed
- The Imports page now loading faster.
### Changed ### Changed
- Default value for `RAILS_MAX_THREADS` was changed to 10. - Default value for `RAILS_MAX_THREADS` was changed to 10.
- Visit suggestions background job was moved to its own low priority queue to prevent it from blocking other jobs. - Visit suggestions background job was moved to its own low priority queue to prevent it from blocking other jobs.
### Fixed
- The Imports page now loading faster.
## [0.13.4] — 2024-09-06 ## [0.13.4] — 2024-09-06

File diff suppressed because one or more lines are too long

View file

@ -4,8 +4,10 @@ class MapController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
def index def index
@points = current_user.tracked_points.without_raw_data.where('timestamp >= ? AND timestamp <= ?', start_at, @points = points
end_at).order(timestamp: :asc) .without_raw_data
.where('timestamp >= ? AND timestamp <= ?', start_at, end_at)
.order(timestamp: :asc)
@countries_and_cities = CountriesAndCities.new(@points).call @countries_and_cities = CountriesAndCities.new(@points).call
@coordinates = @coordinates =
@ -42,4 +44,16 @@ class MapController < ApplicationController
@distance.round(1) @distance.round(1)
end end
def points
params[:import_id] ? points_from_import : points_from_user
end
def points_from_import
current_user.imports.find(params[:import_id]).points
end
def points_from_user
current_user.tracked_points
end
end end

View file

@ -6,9 +6,7 @@ class PointsController < ApplicationController
def index def index
order_by = params[:order_by] || 'desc' order_by = params[:order_by] || 'desc'
@points = @points = points
current_user
.tracked_points
.without_raw_data .without_raw_data
.where(timestamp: start_at..end_at) .where(timestamp: start_at..end_at)
.order(timestamp: order_by) .order(timestamp: order_by)
@ -19,6 +17,7 @@ class PointsController < ApplicationController
@end_at = Time.zone.at(end_at) @end_at = Time.zone.at(end_at)
@points_number = @points.except(:limit, :offset).size @points_number = @points.except(:limit, :offset).size
@imports = current_user.imports.order(created_at: :desc)
end end
def bulk_destroy def bulk_destroy
@ -44,4 +43,16 @@ class PointsController < ApplicationController
Time.zone.parse(params[:end_at]).to_i Time.zone.parse(params[:end_at]).to_i
end end
def points
params[:import_id] ? points_from_import : points_from_user
end
def points_from_import
current_user.imports.find(params[:import_id]).points
end
def points_from_user
current_user.tracked_points
end
end end

View file

@ -44,6 +44,10 @@
<tr> <tr>
<td> <td>
<%= link_to import.name, import, class: 'underline hover:no-underline' %> (<%= import.source %>) <%= link_to import.name, import, class: 'underline hover:no-underline' %> (<%= import.source %>)
&nbsp
<%= link_to '🗺️', map_path(import_id: import.id) %>
&nbsp
<%= link_to '📋', points_path(import_id: import.id) %>
</td> </td>
<td> <td>
<%= "#{number_with_delimiter import.points_count}" %> <%= "#{number_with_delimiter import.points_count}" %>

View file

@ -2,7 +2,7 @@
<div class='w-4/5 mt-8'> <div class='w-4/5 mt-8'>
<div class="flex flex-col space-y-4 mb-4 w-full"> <div class="flex flex-col space-y-4 mb-4 w-full">
<%= form_with url: map_path, method: :get do |f| %> <%= form_with url: map_path(import_id: params[:import_id]), method: :get do |f| %>
<div class="flex flex-col md:flex-row md:space-x-4 md:items-end"> <div class="flex flex-col md:flex-row md:space-x-4 md:items-end">
<div class="w-full md:w-2/12"> <div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2"> <div class="flex flex-col space-y-2">
@ -23,17 +23,17 @@
</div> </div>
<div class="w-full md:w-2/12"> <div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2 text-center"> <div class="flex flex-col space-y-2 text-center">
<%= link_to "Yesterday", map_path(start_at: Date.yesterday.beginning_of_day, end_at: Date.yesterday.end_of_day), class: "px-4 py-2 bg-gray-500 text-white rounded-md" %> <%= link_to "Yesterday", map_path(start_at: Date.yesterday.beginning_of_day, end_at: Date.yesterday.end_of_day, import_id: params[:import_id]), class: "px-4 py-2 bg-gray-500 text-white rounded-md" %>
</div> </div>
</div> </div>
<div class="w-full md:w-2/12"> <div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2 text-center"> <div class="flex flex-col space-y-2 text-center">
<%= link_to "Last 7 days", map_path(start_at: 1.week.ago.beginning_of_day, end_at: Time.current.end_of_day), class: "px-4 py-2 bg-gray-500 text-white rounded-md" %> <%= link_to "Last 7 days", map_path(start_at: 1.week.ago.beginning_of_day, end_at: Time.current.end_of_day, import_id: params[:import_id]), class: "px-4 py-2 bg-gray-500 text-white rounded-md" %>
</div> </div>
</div> </div>
<div class="w-full md:w-2/12"> <div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2 text-center"> <div class="flex flex-col space-y-2 text-center">
<%= link_to "Last month", map_path(start_at: 1.month.ago.beginning_of_day, end_at: Time.current.end_of_day), class: "px-4 py-2 bg-gray-500 text-white rounded-md" %> <%= link_to "Last month", map_path(start_at: 1.month.ago.beginning_of_day, end_at: Time.current.end_of_day, import_id: params[:import_id]), class: "px-4 py-2 bg-gray-500 text-white rounded-md" %>
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,20 +1,26 @@
<% content_for :title, 'Points' %> <% content_for :title, 'Points' %>
<div class="w-full"> <div class="w-full">
<%= form_with url: points_path, method: :get do |f| %> <%= form_with url: points_path(import_id: params[:import_id]), method: :get do |f| %>
<div class="flex flex-col md:flex-row md:space-x-4 md:items-end"> <div class="flex flex-col md:flex-row md:space-x-4 md:items-end">
<div class="w-full md:w-3/12"> <div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2"> <div class="flex flex-col space-y-2">
<%= f.label :start_at, class: "text-sm font-semibold" %> <%= f.label :start_at, class: "text-sm font-semibold" %>
<%= f.datetime_local_field :start_at, class: "rounded-md w-full", value: @start_at %> <%= f.datetime_local_field :start_at, class: "rounded-md w-full", value: @start_at %>
</div> </div>
</div> </div>
<div class="w-full md:w-3/12"> <div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2"> <div class="flex flex-col space-y-2">
<%= f.label :end_at, class: "text-sm font-semibold" %> <%= f.label :end_at, class: "text-sm font-semibold" %>
<%= f.datetime_local_field :end_at, class: "rounded-md w-full", value: @end_at %> <%= f.datetime_local_field :end_at, class: "rounded-md w-full", value: @end_at %>
</div> </div>
</div> </div>
<div class="w-full md:w-2/12">
<div class="flex flex-col space-y-2">
<%= f.label :import, class: "text-sm font-semibold" %>
<%= f.select :import_id, options_for_select(@imports.map { |i| [i.name, i.id] }, params[:import_id]), { include_blank: true }, class: "rounded-md w-full" %>
</div>
</div>
<div class="w-full md:w-1/12"> <div class="w-full md:w-1/12">
<div class="flex flex-col space-y-2"> <div class="flex flex-col space-y-2">
<%= f.submit "Search", class: "px-4 py-2 bg-blue-500 text-white rounded-md" %> <%= f.submit "Search", class: "px-4 py-2 bg-blue-500 text-white rounded-md" %>
@ -48,8 +54,8 @@
</div> </div>
<div class="flex justify-end"> <div class="flex justify-end">
<span class="mr-2">Order by:</span> <span class="mr-2">Order by:</span>
<%= link_to 'Newest', points_path(order_by: :desc), class: 'btn btn-xs btn-primary mx-1' %> <%= link_to 'Newest', points_path(order_by: :desc, import_id: params[:import_id]), class: 'btn btn-xs btn-primary mx-1' %>
<%= link_to 'Oldest', points_path(order_by: :asc), class: 'btn btn-xs btn-primary mx-1' %> <%= link_to 'Oldest', points_path(order_by: :asc, import_id: params[:import_id]), class: 'btn btn-xs btn-primary mx-1' %>
</div> </div>
</div> </div>

View file

@ -5,7 +5,7 @@
<div tabindex="0" role="button" class="btn m-1">Select year</div> <div tabindex="0" role="button" class="btn m-1">Select year</div>
<ul tabindex="0" class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52"> <ul tabindex="0" class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52">
<% current_user.stats.years.each do |year| %> <% current_user.stats.years.each do |year| %>
<li><%= link_to year, map_url(year_timespan(year).merge(year: year)) %></li> <li><%= link_to year, map_url(year_timespan(year).merge(year: year, import_id: params[:import_id])) %></li>
<% end %> <% end %>
</ul> </ul>
</div> </div>
@ -19,7 +19,7 @@
<% (1..12).to_a.each_slice(3) do |months| %> <% (1..12).to_a.each_slice(3) do |months| %>
<% months.each do |month_number| %> <% months.each do |month_number| %>
<% if past?(year, month_number) && points_exist?(year, month_number, current_user) %> <% if past?(year, month_number) && points_exist?(year, month_number, current_user) %>
<%= link_to Date::ABBR_MONTHNAMES[month_number], map_url(timespan(month_number, year)), class: 'btn btn-default' %> <%= link_to Date::ABBR_MONTHNAMES[month_number], map_url(timespan(month_number, year).merge(import_id: params[:import_id])), class: 'btn btn-default' %>
<% else %> <% else %>
<div class='btn btn-disabled'><%= Date::ABBR_MONTHNAMES[month_number] %></div> <div class='btn btn-disabled'><%= Date::ABBR_MONTHNAMES[month_number] %></div>
<% end %> <% end %>