Skip to content

Commit

Permalink
refactor public position page
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-xiong committed Mar 23, 2024
1 parent 37db7df commit 44cfe60
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/controllers/page_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ 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
parts = histories.partition {|h| h.send("#{sort}").nil? || h.send("#{sort}") == 'N/A'}
@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})
@last_summary = snapshots.last_summary(data: @total_summary)
snapshots = SnapshotInfo.where(source_type: 'synced', user_id: nil, event_date: compare_date).first&.snapshot_positions
@last_summary = snapshots.last_summary(data: @total_summary) rescue {}
@snapshots = snapshots.to_a
flash[:alert] = "找不到相应的快照" if params[:compare_date].present? && @snapshots.blank?
end
Expand Down
1 change: 1 addition & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ def get_roi(total_summary)
end

def last_summary_display(data, is_percent = false)
data = data.to_f
c = data > 0 ? 'pos-num' : 'neg-num'
if is_percent
"(<span class='#{c}'>#{data.round(2)}%</span>)".html_safe
Expand Down
6 changes: 3 additions & 3 deletions features/user_positions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ Feature: User Positions pages
Background:
Given I am a new, authenticated user
Given I have 10 user positions with user id
Given I have uploaded snapshot with user id
Given I have synced snapshot with user id

@javascript
Scenario: Visit User positions page
When I visit the '/user_positions' page
Then I see '总投入' text
Then I see '(-124.8)' text
Then I see '(307.2)' text
Then I see '绝对收益' text
Then I see '(392.55)' text
Then I see '(157.22)' text
Then I see 'EOS' text
When I select2 "BTCUSDT" from "#search" filter
And I click on the button "确定"
Expand Down

0 comments on commit 44cfe60

Please sign in to comment.