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
|
2025-12-14 06:05:59 -05:00
|
|
|
include SafeTimestampParser
|
|
|
|
|
|
2024-03-15 18:45:48 -04:00
|
|
|
before_action :authenticate_user!
|
|
|
|
|
|
2024-03-15 18:27:31 -04:00
|
|
|
def index
|
2024-09-08 11:25:35 -04:00
|
|
|
@points = points
|
2024-09-28 10:43:36 -04:00
|
|
|
.without_raw_data
|
|
|
|
|
.where(timestamp: start_at..end_at)
|
|
|
|
|
.order(timestamp: order_by)
|
|
|
|
|
.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
|
2025-07-26 08:46:53 -04:00
|
|
|
point_ids = params[:point_ids]&.compact&.reject(&:blank?)
|
|
|
|
|
|
2025-07-26 08:41:03 -04:00
|
|
|
redirect_to points_url(preserved_params),
|
|
|
|
|
alert: 'No points selected.',
|
2025-07-26 08:46:53 -04:00
|
|
|
status: :see_other and return if point_ids.blank?
|
|
|
|
|
|
2025-08-21 16:32:29 -04:00
|
|
|
current_user.points.where(id: point_ids).destroy_all
|
2025-07-26 08:41:03 -04:00
|
|
|
|
2024-09-28 10:50:49 -04:00
|
|
|
redirect_to points_url(preserved_params),
|
2024-09-28 10:43:36 -04:00
|
|
|
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?
|
|
|
|
|
|
2025-12-14 06:05:59 -05:00
|
|
|
safe_timestamp(params[:start_at])
|
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
|
|
|
|
2025-12-14 06:05:59 -05:00
|
|
|
safe_timestamp(params[:end_at])
|
2024-03-16 18:15:44 -04:00
|
|
|
end
|
2024-09-08 11:25:35 -04:00
|
|
|
|
|
|
|
|
def points
|
2024-09-28 11:29:56 -04:00
|
|
|
params[:import_id].present? ? import_points : user_points
|
2024-09-08 11:25:35 -04:00
|
|
|
end
|
|
|
|
|
|
2024-09-28 11:29:56 -04:00
|
|
|
def import_points
|
2024-09-08 11:25:35 -04:00
|
|
|
current_user.imports.find(params[:import_id]).points
|
|
|
|
|
end
|
|
|
|
|
|
2024-09-28 11:29:56 -04:00
|
|
|
def user_points
|
2025-08-21 16:32:29 -04:00
|
|
|
current_user.points
|
2024-09-08 11:25:35 -04:00
|
|
|
end
|
2024-09-28 10:43:36 -04:00
|
|
|
|
|
|
|
|
def order_by
|
|
|
|
|
params[:order_by] || 'desc'
|
|
|
|
|
end
|
2024-09-28 10:50:49 -04:00
|
|
|
|
|
|
|
|
def preserved_params
|
|
|
|
|
params.to_enum.to_h.with_indifferent_access.slice(:start_at, :end_at, :order_by, :import_id)
|
|
|
|
|
end
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|