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 @@ + + + <%= link_to result.auction.domain_name, admin_result_path(result) %> + + <%= I18n.l(result.auction.ends_at) %> + <%= I18n.l(result.registration_due_date) %> + <%= result.status.humanize %> + + <%- unless result.no_bids? %> + <%- unless result.offer.nil? %> + <%= result.offer.billing_profile&.name %> + <% end %> + <% end %> + + + diff --git a/app/views/admin/results/index.html.erb b/app/views/admin/results/index.html.erb index 186fec17a..26825441b 100644 --- a/app/views/admin/results/index.html.erb +++ b/app/views/admin/results/index.html.erb @@ -18,6 +18,7 @@ <% end %> + <% header_collection = [{ column: '', caption: t('auctions.domain_name'), options: { class: "" } }, { column: '', caption: t('auctions.finished_at'), options: { class: "" } }] %>
@@ -37,35 +38,24 @@ <% end %> <% end %> - <% result_header_collection = [{ column: '', caption: t('auctions.domain_name'), options: { class: "" } }, - { column: '', caption: t('auctions.finished_at'), options: { class: "" } }, - { column: '', caption: t('results.registration_due_date'), options: { class: "" } }, - { column: '', caption: t('status'), options: { class: "" } }, - { column: '', caption: t('billing_profiles.name'), options: { class: "" } }] %> + <% result_header_collection = [{ column: 'auctions.domain_name', caption: t('auctions.domain_name'), options: { class: "sorting" } }, + { column: 'auctions.finished_at', caption: t('auctions.finished_at'), options: { class: "sorting" } }, + { column: 'results.registration_due_date', caption: t('results.registration_due_date'), options: { class: "sorting" } }, + { column: 'status', caption: t('status'), options: { class: "sorting" } }, + { column: 'billing_profile_id', caption: t('billing_profiles.name'), options: { class: "sorting" } }] %>

<%= t('.results') %>

- <%= component 'common/table', header_collection: result_header_collection, options: { class: 'js-table-dt' } do %> + + <%= turbo_frame_tag "results" do %> + <%= component 'common/table', header_collection: result_header_collection, options: { class: 'js-table-dt dataTable no-footer' } do %> <%= tag.tbody class: 'contents' do %> - <% @results.each do |result| %> - - - <%= link_to result.auction.domain_name, admin_result_path(result) %> - - <%= I18n.l(result.auction.ends_at) %> - <%= I18n.l(result.registration_due_date) %> - <%= result.status.humanize %> - - <%- unless result.no_bids? %> - <%- unless result.offer.nil? %> - <%= result.offer.billing_profile&.name %> - <% end %> - <% end %> - - - - <% end %> + <%= render @results %> <% end %> <% end %> + + <%= component 'common/pagy', pagy: @pagy %> + <% end %> +