Preserve start_at and end_at parameters when deleting points from the Points page

This commit is contained in:
Eugene Burmakin 2024-09-28 16:43:36 +02:00
parent 911794e9ee
commit 4d743ae314
9 changed files with 47 additions and 28 deletions

View file

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- GPX export now finishes correctly and does not throw an error in the end
- Deleting points from the Points page now preserves `start_at` and `end_at` values for the routes
### Changed

View file

@ -4,14 +4,12 @@ class PointsController < ApplicationController
before_action :authenticate_user!
def index
order_by = params[:order_by] || 'desc'
@points = points
.without_raw_data
.where(timestamp: start_at..end_at)
.order(timestamp: order_by)
.page(params[:page])
.per(50)
.without_raw_data
.where(timestamp: start_at..end_at)
.order(timestamp: order_by)
.page(params[:page])
.per(50)
@start_at = Time.zone.at(start_at)
@end_at = Time.zone.at(end_at)
@ -22,7 +20,9 @@ class PointsController < ApplicationController
def bulk_destroy
current_user.tracked_points.where(id: params[:point_ids].compact).destroy_all
redirect_to points_url, notice: 'Points were successfully destroyed.', status: :see_other
redirect_to points_url(params.slice(:start_at, :end_at, :order_by, :import_id)),
notice: 'Points were successfully destroyed.',
status: :see_other
end
private
@ -54,4 +54,8 @@ class PointsController < ApplicationController
def points_from_user
current_user.tracked_points
end
def order_by
params[:order_by] || 'desc'
end
end

View file

@ -20,7 +20,7 @@ class Visits::Suggest
create_visits_notification(user)
nil unless reverse_geocoding_enabled?
return nil unless reverse_geocoding_enabled?
reverse_geocode(visits)
end

View file

@ -27,6 +27,11 @@ FactoryBot.define do
country { nil }
user
trait :with_known_location do
latitude { 55.755826 }
longitude { 37.6173 }
end
trait :with_geodata do
geodata do
{

File diff suppressed because one or more lines are too long

View file

@ -56,5 +56,12 @@ RSpec.describe '/points', type: :request do
expect(response).to redirect_to(points_url)
end
it 'preserves the start_at and end_at parameters' do
delete bulk_destroy_points_url,
params: { point_ids: [point1.id, point2.id], start_at: '2021-01-01', end_at: '2021-01-02' }
expect(response).to redirect_to(points_url(start_at: '2021-01-01', end_at: '2021-01-02'))
end
end
end

View file

@ -23,7 +23,7 @@ RSpec.describe Points::GpxSerializer do
point = points[index]
expect(waypoint.lat).to eq(point.latitude)
expect(waypoint.lon).to eq(point.longitude)
expect(waypoint.time).to eq(point.recorded_at.strftime('%FT%R:%SZ'))
expect(waypoint.time).to eq(point.recorded_at)
end
end
end

View file

@ -13,14 +13,16 @@ RSpec.describe Exports::Create do
let(:export_name) { "#{start_at.to_date}_#{end_at.to_date}" }
let(:export) { create(:export, user:, name: export_name, status: :created) }
let(:export_content) { Points::GeojsonSerializer.new(points).call }
let!(:points) { create_list(:point, 10, user:, timestamp: start_at.to_datetime.to_i) }
let!(:points) do
create_list(:point, 10, :with_known_location, user:, timestamp: start_at.to_datetime.to_i)
end
it 'writes the data to a file' do
create_export
file_path = Rails.root.join('spec/fixtures/files/geojson/export_same_points.json')
expect(File.read(file_path)).to eq(export_content)
expect(File.read(file_path).strip).to eq(export_content)
end
it 'updates the export url' do

View file

@ -10,21 +10,21 @@ RSpec.describe Visits::Suggest do
let!(:points) do
[
create(:point, user:, timestamp: start_at),
create(:point, user:, timestamp: start_at + 5.minutes),
create(:point, user:, timestamp: start_at + 10.minutes),
create(:point, user:, timestamp: start_at + 15.minutes),
create(:point, user:, timestamp: start_at + 20.minutes),
create(:point, user:, timestamp: start_at + 25.minutes),
create(:point, user:, timestamp: start_at + 30.minutes),
create(:point, user:, timestamp: start_at + 35.minutes),
create(:point, user:, timestamp: start_at + 40.minutes),
create(:point, user:, timestamp: start_at + 45.minutes),
create(:point, user:, timestamp: start_at + 50.minutes),
create(:point, user:, timestamp: start_at + 55.minutes),
create(:point, user:, timestamp: start_at + 95.minutes),
create(:point, user:, timestamp: start_at + 100.minutes),
create(:point, user:, timestamp: start_at + 105.minutes)
create(:point, :with_known_location, user:, timestamp: start_at),
create(:point, :with_known_location, user:, timestamp: start_at + 5.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 10.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 15.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 20.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 25.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 30.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 35.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 40.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 45.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 50.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 55.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 95.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 100.minutes),
create(:point, :with_known_location, user:, timestamp: start_at + 105.minutes)
]
end