dawarich/app/controllers/points_controller.rb

48 lines
1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2024-05-23 14:12:23 -04:00
2024-03-15 18:27:31 -04:00
class PointsController < ApplicationController
before_action :authenticate_user!
2024-03-15 18:27:31 -04:00
def index
order_by = params[:order_by] || 'desc'
2024-05-23 14:12:23 -04:00
@points =
2024-05-25 07:26:56 -04:00
current_user
.tracked_points
2024-05-23 14:12:23 -04:00
.without_raw_data
.where(timestamp: start_at..end_at)
.order(timestamp: order_by)
2024-07-24 14:25:16 -04:00
.page(params[:page])
.per(50)
2024-03-15 18:27:31 -04:00
2024-03-24 13:55:35 -04:00
@start_at = Time.zone.at(start_at)
@end_at = Time.zone.at(end_at)
@points_number = @points.except(:limit, :offset).size
2024-05-23 14:12:23 -04:00
end
def bulk_destroy
2024-05-25 07:26:56 -04:00
current_user.tracked_points.where(id: params[:point_ids].compact).destroy_all
2024-05-23 14:12:23 -04:00
2024-05-25 07:26:56 -04:00
redirect_to points_url, notice: 'Points were successfully destroyed.', status: :see_other
2024-03-15 18:27:31 -04:00
end
private
2024-05-23 14:12:23 -04:00
def point_params
params.fetch(:point, {})
end
def start_at
return 1.month.ago.beginning_of_day.to_i if params[:start_at].nil?
2024-04-21 12:12:07 -04:00
Time.zone.parse(params[:start_at]).to_i
end
def end_at
2024-03-24 13:55:35 -04:00
return Time.zone.today.end_of_day.to_i if params[:end_at].nil?
2024-04-21 12:12:07 -04:00
Time.zone.parse(params[:end_at]).to_i
end
2024-03-15 18:27:31 -04:00
end