diff --git a/app/controllers/admin/results_controller.rb b/app/controllers/admin/results_controller.rb index d433b1ced..4d48bc1d7 100644 --- a/app/controllers/admin/results_controller.rb +++ b/app/controllers/admin/results_controller.rb @@ -2,20 +2,10 @@ module Admin class ResultsController < BaseController # GET /admin/results def index - sort_column = params[:sort].presence_in(%w[auctions.domain_name - auctions.ends_at - registration_due_date - status - users.id]) || 'auctions.ends_at' - sort_direction = params[:direction].presence_in(%w[asc desc]) || 'desc' + order_string = "#{allowed_sort_columns[sort_column]} #{allowed_sort_directions}" - @results = Result.includes(:auction, offer: [:billing_profile]) - .search(params) - .includes(:user) - .includes(:auction) - .order("#{sort_column} #{sort_direction}") - - @pagy, @results = pagy(@results, items: params[:per_page] ||= 15) + @results = result_query.order(Arel.sql(order_string)) + @pagy, @results = pagy(@results, items: params[:per_page] ||= 15, link_extra: 'data-turbo-action="advance"') @auctions_needing_results = Auction.without_result.search(params) end @@ -43,6 +33,23 @@ def show private + def result_query = Result.includes(:auction, offer: [:billing_profile]) + .references(:auction, :offer) + .search(params) + .includes(:user) + + def sort_column = params[:sort_by].presence_in(allowed_sort_columns.keys) || 'auctions.ends_at' + + def allowed_sort_directions = params[:sort_direction].presence_in(%w[asc desc]) || 'desc' + + def allowed_sort_columns = { + 'auctions.domain_name' => 'auctions.domain_name', + 'auctions.ends_at' => 'auctions.ends_at', + 'results.registration_due_date' => 'results.registration_due_date', + 'status' => 'results.status', + 'billing_profile_id' => 'offers.billing_profile_id' + } + def buyer_name return @result.offer.billing_profile.name if @result.offer.billing_profile.present? diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb index 5a61eabb0..f5dc54906 100644 --- a/app/views/admin/auctions/index.html.erb +++ b/app/views/admin/auctions/index.html.erb @@ -114,7 +114,6 @@ <%= component 'common/table', header_collection:, options: { class: 'js-table-dt dataTable no-footer' } do %> <%= tag.tbody id: "auctions-table-body", class: 'contents' do %> - <%#= render partial: 'auctions', locals: { auctions: @auctions, form: @form_auction_table } %> <%= render @auctions, form: @form_auction_table %> <% end %> <% end %> diff --git a/app/views/admin/results/_result.html.erb b/app/views/admin/results/_result.html.erb new file mode 100644 index 000000000..9f1679730 --- /dev/null +++ b/app/views/admin/results/_result.html.erb @@ -0,0 +1,16 @@ +