From 49c988af9c201c23123db50839c0d8a8c4079fa4 Mon Sep 17 00:00:00 2001 From: Pan Xiong Date: Sat, 23 Mar 2024 10:47:19 +1100 Subject: [PATCH] refactor public position page --- app/controllers/page_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/page_controller.rb b/app/controllers/page_controller.rb index ce3938e..7d47d05 100644 --- a/app/controllers/page_controller.rb +++ b/app/controllers/page_controller.rb @@ -8,6 +8,7 @@ def user_positions sort_type = params[:sort_type].presence || "desc" @symbol = params[:search] histories = UserPosition.available.where(user_id: nil) + @total_summary = histories.total_summary histories = histories.where(origin_symbol: @symbol) if @symbol.present? histories = histories.where(level: params[:level]) if params[:level].present? histories = histories.select{|h| h.amount < @max_amount} if @flag && @max_amount > 0 @@ -15,9 +16,8 @@ def user_positions @histories = parts.last.sort_by{|h| h.send("#{sort}")} + parts.first @histories = @histories.reverse if sort_type == "desc" @histories = Kaminari.paginate_array(@histories).page(params[:page]).per(15) - @total_summary = UserPosition.available.total_summary compare_date = params[:compare_date].presence || Date.yesterday - snapshots = SnapshotPosition.joins(:snapshot_info).where(snapshot_info: {source_type: 'synced', user_id: nil, event_date: compare_date}) + snapshots = SnapshotInfo.where(source_type: 'synced', user_id: nil, event_date: compare_date).first.snapshot_positions @last_summary = snapshots.last_summary(data: @total_summary) @snapshots = snapshots.to_a flash[:alert] = "找不到相应的快照" if params[:compare_date].present? && @snapshots.blank?