2024-05-18 05:48:22 -04:00
|
|
|
# frozen_string_literal: true
|
2024-05-23 14:12:23 -04:00
|
|
|
|
2024-03-15 18:27:31 -04:00
|
|
|
class PointsController < ApplicationController
|
2024-03-15 18:45:48 -04:00
|
|
|
before_action :authenticate_user!
|
|
|
|
|
|
2024-03-15 18:27:31 -04:00
|
|
|
def index
|
2024-07-31 13:35:35 -04:00
|
|
|
order_by = params[:order_by] || 'desc'
|
|
|
|
|
|
2024-09-08 11:25:35 -04:00
|
|
|
@points = points
|
2024-05-23 14:12:23 -04:00
|
|
|
.without_raw_data
|
2024-05-30 17:36:12 -04:00
|
|
|
.where(timestamp: start_at..end_at)
|
2024-07-31 13:35:35 -04:00
|
|
|
.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)
|
2024-09-05 18:19:53 -04:00
|
|
|
|
2024-09-08 11:25:35 -04:00
|
|
|
@imports = current_user.imports.order(created_at: :desc)
|
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
|
2024-03-16 18:15:44 -04:00
|
|
|
|
2024-03-17 12:58:09 -04:00
|
|
|
private
|
|
|
|
|
|
2024-05-23 14:12:23 -04:00
|
|
|
def point_params
|
|
|
|
|
params.fetch(:point, {})
|
|
|
|
|
end
|
|
|
|
|
|
2024-03-16 18:15:44 -04:00
|
|
|
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
|
2024-03-16 18:15:44 -04:00
|
|
|
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-03-16 18:15:44 -04:00
|
|
|
|
2024-04-21 12:12:07 -04:00
|
|
|
Time.zone.parse(params[:end_at]).to_i
|
2024-03-16 18:15:44 -04:00
|
|
|
end
|
2024-09-08 11:25:35 -04:00
|
|
|
|
|
|
|
|
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
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|