added auction list to admin panel

This commit is contained in:
olegphenomenon 2022-04-08 18:39:47 +03:00
parent faf87aec7a
commit 2aa1100305
12 changed files with 359 additions and 4 deletions

View file

@ -0,0 +1,41 @@
module Admin
class AuctionsController < BaseController
load_and_authorize_resource
def index
params[:q] ||= {}
@auctions = Auction.with_status(params[:statuses_contains])
normalize_search_parameters do
@q = @auctions.ransack(PartialSearchFormatter.format(params[:q]))
@auctions = @q.result.page(params[:page])
end
@auctions = @auctions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
render_by_format('admin/auctions/index', 'auctions')
end
def update
redirect_to admin_auctions_path
end
private
def normalize_search_parameters
ca_cache = params[:q][:valid_to_lteq]
begin
end_time = params[:q][:valid_to_lteq].try(:to_date)
params[:q][:valid_to_lteq] = end_time.try(:end_of_day)
rescue
logger.warn('Invalid date')
end
yield
params[:q][:valid_to_lteq] = ca_cache
end
end
end

View file

@ -51,8 +51,26 @@ module Admin
redirect_to admin_reserved_domains_path
end
def release_to_auction
redirect_to admin_reserved_domains_path and return if params[:reserved_elements].nil?
reserved_domains_ids = params[:reserved_elements][:domain_ids]
reserved_domains = ReservedDomain.where(id: reserved_domains_ids)
reserved_domains.each do |domain|
Auction.create!(domain: domain.name, status: Auction.statuses[:started])
domain.destroy!
end
redirect_to admin_reserved_domains_path
end
private
def reserved_checked_elements
# params.require(:reserved_elements).permit(:name, :password)
end
def reserved_domain_params
params.require(:reserved_domain).permit(:name, :password)
end

View file

@ -0,0 +1,21 @@
module AuctionHelper
include ActionView::Helpers::TagHelper
extend self
def colorize_auction(auction)
case auction.status
when 'started' then render_status_black(auction.domain)
when 'awaiting_payment' then render_status_black(auction.domain)
else render_status_green(auction.domain)
end
end
def render_status_black(name)
content_tag(:span, name.to_s, style: 'color: black;')
end
def render_status_green(name)
content_tag(:span, name.to_s , style: 'color: green;')
end
end

View file

@ -95,6 +95,7 @@ class Ability
can :manage, User
can :manage, ApiUser
can :manage, AdminUser
can :manage, Auction
can :manage, Certificate
can :manage, LegalDocument
can :manage, BankStatement

View file

@ -12,8 +12,13 @@ class Auction < ApplicationRecord
PENDING_STATUSES = [statuses[:started],
statuses[:awaiting_payment],
statuses[:payment_received]].freeze
private_constant :PENDING_STATUSES
scope :with_status, -> (status) {
where(status: status) if status.present?
}
def self.pending(domain_name)
find_by(domain: domain_name.to_s, status: PENDING_STATUSES)
end

View file

@ -0,0 +1,17 @@
<%= search_form_for [:admin, @q], html: { class: 'search-form', autocomplete: 'off' } do |f| %>
<div class="row">
<div class="col-md-5"></div>
<div class="col-md-3"></div>
<div class="col-md-4"></div>
<div class="col-md-12 text-right">
<%= link_to t('.download_csv_btn'), admin_domains_path(format: :csv, params: params.permit!),
"data-toggle" => "tooltip", "data-placement" => "bottom", "title" => t('.download_csv_btn'),
class: 'btn btn-primary' %>
</div>
</div>
<div class="row form-group"></div>
<% end %>

View file

@ -0,0 +1,101 @@
<div class="page-header">
<h1>Auctions</h1>
</div>
<div class="row">
<div class="col-md-12">
<%= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<%= f.label :domain %>
<%= f.search_field :domain_matches, value: params[:q][:domain_matches], class: 'form-control', placeholder: t(:name) %>
</div>
<div class="form-group">
<%= f.label :status %>
<%= select_tag :statuses_contains, options_for_select(Auction.statuses.map { |x| [x[0], x[1]] }, params[:q][:status]), { include_blank:true, class: 'form-control' } %>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<%= f.label t(:created_at_from) %>
<%= f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control js-datepicker', placeholder: t(:created_at_from) %>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<%= f.label t(:created_at_until) %>
<%= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_at_until) %>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<%= label_tag t(:results_per_page) %>
<%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %>
</div>
</div>
<div class="col-md-4" style="padding-top: 25px;">
<button class="btn btn-primary">
&nbsp;
<span class="glyphicon glyphicon-search"></span>
&nbsp;
</button>
<%= link_to(t('.reset_btn'), admin_auctions_path, class: 'btn btn-default') %>
</div>
</div>
<% end %>
</div>
</div>
<hr/>
<div class="row">
<div class="col-md-12">
<div class="col-md-12 text-right" style='margin: 0 0 10px 0;'>
<%= link_to 'Download auction list', admin_auctions_path(format: :csv, params: params.permit!),
"data-toggle" => "tooltip", "data-placement" => "bottom", "title" => t('.download_csv_btn'),
class: 'btn btn-primary' %>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-hover table-bordered table-condensed">
<thead>
<tr>
<th class="col-xs-2">
<%= sort_link(@q, 'domain') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'status') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'created_at') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'registration_code') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'registration_deadline') %>
</th>
</tr>
</thead>
<tbody>
<% @auctions.each do |auction| %>
<tr>
<td><%= AuctionHelper.colorize_auction(auction) %></td>
<td><%= auction.status %></td>
<td><%= auction.created_at %></td>
<td><%= auction.registration_code %></td>
<td><%= auction.registration_deadline %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>

View file

@ -21,6 +21,7 @@
%li= link_to t('.prices'), admin_prices_path
%li= link_to t(:bank_statements), admin_bank_statements_path
%li= link_to t(:invoices), admin_invoices_path
%li= link_to t(:auctions), admin_auctions_path
%li= link_to t(:accounts), admin_accounts_path
%li= link_to t(:account_activities), admin_account_activities_path(created_after: 'today')
%li.divider

View file

@ -0,0 +1,134 @@
<% content_for :actions do %>
<%= link_to(t('.new_btn'), new_admin_reserved_domain_path, class: 'btn btn-primary') %>
<% end %>
<%= render 'shared/title', name: t('.title') %>
<div class="row">
<div class="col-md-12">
<%= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<%= f.label :name %>
<%= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name) %>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<%= f.label t(:created_at_from) %>
<%= f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control js-datepicker', placeholder: t(:created_at_from) %>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<%= f.label t(:created_at_until) %>
<%= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_at_until) %>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<%= label_tag t(:results_per_page) %>
<%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %>
</div>
</div>
<div class="col-md-4" style="padding-top: 25px;">
<button class="btn btn-primary">
&nbsp;
<span class="glyphicon glyphicon-search"></span>
&nbsp;
</button>
<%= link_to(t('.csv_btn'), admin_reserved_domains_path(format: :csv, params: params.permit!), class: 'btn btn-default') %>
<%= link_to(t('.reset_btn'), admin_reserved_domains_path, class: 'btn btn-default') %>
</div>
</div>
<% end %>
</div>
</div>
<hr/>
<%= form_for :reserved_elements, url: release_to_auction_admin_reserved_domains_path, html: { class: 'form-horizontal', autocomplete: 'off' } do |f| %>
<%= f.submit 'Send to the auction list', class: 'btn btn-primary', style: 'margin: 10px 0 20px 0;' %>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-hover table-bordered table-condensed">
<thead>
<tr>
<th class="col-xs-1 text-center">
<%= check_box_tag :check_all %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'name') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'password') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'created_at', t(:created_at)) %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'updated_at', t(:updated_at)) %>
</th>
<th class="col-xs-2">
<%= t(:actions) %>
</th>
</tr>
</thead>
<tbody>
<% @domains.each do |x| %>
<tr>
<td class="text-center">
<%= f.check_box :domain_ids, { multiple: true }, x.id, nil %>
</td>
<td>
<%= x.name %>
</td>
<td>
<%= x.password %>
</td>
<td>
<%= l(x.created_at, format: :short) %>
</td>
<td>
<%= l(x.updated_at, format: :short) %>
</td>
<td>
<%= link_to(t(:edit_pw), edit_admin_reserved_domain_path(id: x.id), class: 'btn btn-primary btn-xs') %>
<%= link_to(t(:delete), delete_admin_reserved_domain_path(id: x.id), data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs') %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
<% end %>
<div class="row">
<div class="col-md-6">
<%= paginate @domains %>
</div>
<div class="col-md-6 text-right">
<div class="pagination">
<%= t(:result_count, count: @domains.total_count) %>
</div>
</div>
</div>
<script>
(function() {
const checkAll = document.getElementById('check_all');
checkAll.addEventListener('click', (source) => {
var checkboxes = document.querySelectorAll('[id^="reserved_elements_domain_ids"]');
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].checked = !checkboxes[i].checked;
}
});
})();
</script>

View file

@ -30,6 +30,7 @@
&nbsp;
= link_to(t('.csv_btn'), admin_reserved_domains_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_reserved_domains_path, class: 'btn btn-default')
= link_to 'Send to auction',release_to_auction_admin_reserved_domains_path, method: :post, class: 'btn btn-default', style: 'margin-top: 5px;'
%hr
.row
.col-md-12
@ -37,6 +38,7 @@
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-1'}
%th{class: 'col-xs-2'}
= sort_link(@q, 'name')
%th{class: 'col-xs-2'}
@ -50,6 +52,8 @@
%tbody
- @domains.each do |x|
%tr
%td{class: 'text-center'}
= check_box_tag "reserved_domains[domain_ids][]", x.id, false
%td= x.name
%td= x.password
%td= l(x.created_at, format: :short)

View file

@ -266,6 +266,11 @@ Rails.application.routes.draw do
resources :accounts
resources :account_activities
resources :auctions, only: [ :index ] do
collection do
patch :update
end
end
resources :bank_statements do
resources :bank_transactions
@ -335,6 +340,10 @@ Rails.application.routes.draw do
member do
get 'delete'
end
collection do
post 'release_to_auction', to: 'reserved_domains#release_to_auction', as: 'release_to_auction'
end
end
resources :disputes do
member do

View file

@ -813,7 +813,8 @@ CREATE TABLE public.dnskeys (
updator_str character varying,
legacy_domain_id integer,
updated_at timestamp without time zone,
validation_datetime timestamp without time zone
validation_datetime timestamp without time zone,
failed_validation_reason character varying
);
@ -1089,6 +1090,7 @@ CREATE TABLE public.invoices (
buyer_vat_no character varying,
issue_date date NOT NULL,
e_invoice_sent_at timestamp without time zone,
payment_link character varying,
CONSTRAINT invoices_due_date_is_not_before_issue_date CHECK ((due_date >= issue_date))
);
@ -5084,6 +5086,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220406085500'),
('20220413073315'),
('20220413084536'),
('20220413084748');
('20220413084748'),
('20220124105717'),
('20220216113112'),
('20220228093211');