From 2aa1100305ac3b6d01b590b9576ba5aeb08de78c Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 8 Apr 2022 18:39:47 +0300 Subject: [PATCH 01/11] added auction list to admin panel --- app/controllers/admin/auctions_controller.rb | 41 ++++++ .../admin/reserved_domains_controller.rb | 18 +++ app/helpers/auction_helper.rb | 21 +++ app/models/ability.rb | 1 + app/models/auction.rb | 5 + .../admin/auctions/_search_form.html.erb | 17 +++ app/views/admin/auctions/index.html.erb | 101 +++++++++++++ app/views/admin/base/_menu.haml | 1 + .../admin/reserved_domains/index.html.erb | 134 ++++++++++++++++++ .../{index.haml => index2.haml} | 4 + config/routes.rb | 9 ++ db/structure.sql | 11 +- 12 files changed, 359 insertions(+), 4 deletions(-) create mode 100644 app/controllers/admin/auctions_controller.rb create mode 100644 app/helpers/auction_helper.rb create mode 100644 app/views/admin/auctions/_search_form.html.erb create mode 100644 app/views/admin/auctions/index.html.erb create mode 100644 app/views/admin/reserved_domains/index.html.erb rename app/views/admin/reserved_domains/{index.haml => index2.haml} (90%) diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb new file mode 100644 index 000000000..39834ac54 --- /dev/null +++ b/app/controllers/admin/auctions_controller.rb @@ -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 diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 1bfade83e..aeebe8906 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -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 diff --git a/app/helpers/auction_helper.rb b/app/helpers/auction_helper.rb new file mode 100644 index 000000000..e4ef44736 --- /dev/null +++ b/app/helpers/auction_helper.rb @@ -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 diff --git a/app/models/ability.rb b/app/models/ability.rb index caca24524..bc2caa6ba 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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 diff --git a/app/models/auction.rb b/app/models/auction.rb index 791184d60..fd48c22f2 100644 --- a/app/models/auction.rb +++ b/app/models/auction.rb @@ -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 diff --git a/app/views/admin/auctions/_search_form.html.erb b/app/views/admin/auctions/_search_form.html.erb new file mode 100644 index 000000000..d675a70ca --- /dev/null +++ b/app/views/admin/auctions/_search_form.html.erb @@ -0,0 +1,17 @@ +<%= search_form_for [:admin, @q], html: { class: 'search-form', autocomplete: 'off' } do |f| %> + +
+
+
+
+ +
+ <%= 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' %> + +
+
+ +
+<% end %> diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb new file mode 100644 index 000000000..a9a708755 --- /dev/null +++ b/app/views/admin/auctions/index.html.erb @@ -0,0 +1,101 @@ + + +
+
+ <%= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %> +
+
+
+ <%= f.label :domain %> + <%= f.search_field :domain_matches, value: params[:q][:domain_matches], class: 'form-control', placeholder: t(:name) %> +
+
+ <%= 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' } %> +
+
+
+
+ <%= 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) %> +
+
+
+
+ <%= 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) %> +
+
+
+
+ <%= label_tag t(:results_per_page) %> + <%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %> +
+
+
+ + <%= link_to(t('.reset_btn'), admin_auctions_path, class: 'btn btn-default') %> +
+
+ <% end %> +
+
+ +
+ +
+
+
+ <%= 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' %> +
+
+
+ +
+
+
+ + + + + + + + + + + + + + <% @auctions.each do |auction| %> + + + + + + + + <% end %> + +
+ <%= sort_link(@q, 'domain') %> + + <%= sort_link(@q, 'status') %> + + <%= sort_link(@q, 'created_at') %> + + <%= sort_link(@q, 'registration_code') %> + + <%= sort_link(@q, 'registration_deadline') %> +
<%= AuctionHelper.colorize_auction(auction) %><%= auction.status %><%= auction.created_at %><%= auction.registration_code %><%= auction.registration_deadline %>
+
+
+
diff --git a/app/views/admin/base/_menu.haml b/app/views/admin/base/_menu.haml index c5edd4708..d233ad34d 100644 --- a/app/views/admin/base/_menu.haml +++ b/app/views/admin/base/_menu.haml @@ -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 diff --git a/app/views/admin/reserved_domains/index.html.erb b/app/views/admin/reserved_domains/index.html.erb new file mode 100644 index 000000000..6f1018875 --- /dev/null +++ b/app/views/admin/reserved_domains/index.html.erb @@ -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') %> +
+
+ <%= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %> +
+
+
+ <%= f.label :name %> + <%= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name) %> +
+
+
+
+ <%= 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) %> +
+
+
+
+ <%= 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) %> +
+
+
+
+
+
+ <%= label_tag t(:results_per_page) %> + <%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %> +
+
+
+ + <%= 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') %> +
+
+ <% end %> +
+
+ +
+ +<%= 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;' %> + +
+
+
+ + + + + + + + + + + + + <% @domains.each do |x| %> + + + + + + + + + <% end %> + +
+ <%= check_box_tag :check_all %> + + <%= sort_link(@q, 'name') %> + + <%= sort_link(@q, 'password') %> + + <%= sort_link(@q, 'created_at', t(:created_at)) %> + + <%= sort_link(@q, 'updated_at', t(:updated_at)) %> + + <%= t(:actions) %> +
+ <%= f.check_box :domain_ids, { multiple: true }, x.id, nil %> + + <%= x.name %> + + <%= x.password %> + + <%= l(x.created_at, format: :short) %> + + <%= l(x.updated_at, format: :short) %> + + <%= 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') %> +
+
+
+
+<% end %> + +
+
+ <%= paginate @domains %> +
+
+ +
+
+ + \ No newline at end of file diff --git a/app/views/admin/reserved_domains/index.haml b/app/views/admin/reserved_domains/index2.haml similarity index 90% rename from app/views/admin/reserved_domains/index.haml rename to app/views/admin/reserved_domains/index2.haml index 5444ba34d..a3b49e0b0 100644 --- a/app/views/admin/reserved_domains/index.haml +++ b/app/views/admin/reserved_domains/index2.haml @@ -30,6 +30,7 @@   = 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) diff --git a/config/routes.rb b/config/routes.rb index a2a4556f7..38e263c94 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/structure.sql b/db/structure.sql index 2c4723dce..4c22970d3 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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'); From 77249629bb96cf5a0629508f83c17459ad1e693a Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Tue, 12 Apr 2022 14:28:09 +0300 Subject: [PATCH 02/11] added modal window --- app/controllers/admin/auctions_controller.rb | 34 ++++++++++- .../admin/reserved_domains_controller.rb | 2 +- app/views/admin/auctions/_modal.html.erb | 15 +++++ .../admin/auctions/_search_form.html.erb | 17 ------ app/views/admin/auctions/index.html.erb | 58 ++++++++++++++++--- config/routes.rb | 6 +- 6 files changed, 102 insertions(+), 30 deletions(-) create mode 100644 app/views/admin/auctions/_modal.html.erb delete mode 100644 app/views/admin/auctions/_search_form.html.erb diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index 39834ac54..22c186b17 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -6,6 +6,7 @@ module Admin params[:q] ||= {} @auctions = Auction.with_status(params[:statuses_contains]) + @auction = Auction.new normalize_search_parameters do @q = @auctions.ransack(PartialSearchFormatter.format(params[:q])) @@ -14,16 +15,47 @@ module Admin @auctions = @auctions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? + domains = ReservedDomain.all.order(:name) + q = domains.ransack(PartialSearchFormatter.format(params[:q])) + @domains = q.result.page(params[:page]) + @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? + render_by_format('admin/auctions/index', 'auctions') end - def update + def create + auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started]) + + if auction.save + remove_from_reserved(auction) + flash[:notice] = "Auction #{params[:domain]} created" + else + flash[:alert] = "Something goes wrong" + end + + redirect_to admin_auctions_path + end + + def upload_spreadsheet + table = CSV.parse(File.read(params[:q][:file]), headers: true) + + table.each do |row| + record = row.to_h + auction = Auction.new(domain: record['name'], status: Auction.statuses[:started]) + remove_from_reserved(auction) if auction.save! + end redirect_to admin_auctions_path end private + def remove_from_reserved(auction) + domain = ReservedDomain.find_by(name: auction.domain) + + domain.destroy if domain.present? + end + def normalize_search_parameters ca_cache = params[:q][:valid_to_lteq] begin diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index aeebe8906..dc9ff9d15 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -62,7 +62,7 @@ module Admin domain.destroy! end - redirect_to admin_reserved_domains_path + redirect_to admin_auctions_path end private diff --git a/app/views/admin/auctions/_modal.html.erb b/app/views/admin/auctions/_modal.html.erb new file mode 100644 index 000000000..e57d2139d --- /dev/null +++ b/app/views/admin/auctions/_modal.html.erb @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/app/views/admin/auctions/_search_form.html.erb b/app/views/admin/auctions/_search_form.html.erb deleted file mode 100644 index d675a70ca..000000000 --- a/app/views/admin/auctions/_search_form.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -<%= search_form_for [:admin, @q], html: { class: 'search-form', autocomplete: 'off' } do |f| %> - -
-
-
-
- -
- <%= 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' %> - -
-
- -
-<% end %> diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb index a9a708755..d3f9f7745 100644 --- a/app/views/admin/auctions/index.html.erb +++ b/app/views/admin/auctions/index.html.erb @@ -34,28 +34,62 @@ <%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %> -
- - <%= link_to(t('.reset_btn'), admin_auctions_path, class: 'btn btn-default') %> +
+ <%= link_to(t('.reset_btn'), admin_auctions_path, class: 'btn btn-default') %> +
+
+ <%= 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' %> +
+
+ <%= link_to "#", class: "btn btn-warning edit", + data: { + toggle: "modal", + url: admin_reserved_domains_path, + target: "#user-form-edit"} do %> + + Get reserved domains + <% end %> + + <%= render 'modal' %> + +
<% end %> +
+ + <%= search_form_for [:admin, @q], method: :post, html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %> + <%= label_tag :new_auction %> + +
+ <%= text_field_tag :domain, params[:domain], class: 'form-control', placeholder: 'domain name' %> + <%= f.submit 'Create', class: 'btn btn-primary', style: 'margin-left: .4rem;' %> +
+ <% end %> +
-
-
- <%= 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' %> -
+
+ <%= search_form_for @q, url: upload_spreadsheet_admin_auctions_path, method: :post, html: { style: 'margin-bottom: 0; display: flex; flex-direction: row; align-items: center;', class: 'js-form', autocomplete: 'off' } do |f| %> + <%= f.file_field :file, + accept: ".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel", + direct_upload: true, + style: 'width: 200px;' %> + <%= f.submit 'Upload csv', class: 'btn btn-primary' %> + <% end %> +
@@ -99,3 +133,9 @@
+ + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 38e263c94..4ba44300d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -266,11 +266,13 @@ Rails.application.routes.draw do resources :accounts resources :account_activities - resources :auctions, only: [ :index ] do + resources :auctions, only: [ :index, :create ] do collection do - patch :update + post 'upload_spreadsheet', to: 'auctions#upload_spreadsheet', as: :upload_spreadsheet end end + # post 'admi/upload_spreadsheet', to: 'customers#upload_spreadsheet', as: :customers_upload_spreadsheet + resources :bank_statements do resources :bank_transactions From d8c0ba24320390083d4a96f3f11a0017e1994276 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 13 Apr 2022 09:25:44 +0300 Subject: [PATCH 03/11] add new column --- app/controllers/admin/auctions_controller.rb | 4 ++-- app/controllers/admin/reserved_domains_controller.rb | 2 +- app/models/auction.rb | 2 ++ app/models/dns/domain_name.rb | 1 + app/views/admin/auctions/index.html.erb | 4 ++++ db/migrate/20220412130856_add_type_to_auction.rb | 5 +++++ db/structure.sql | 1 + 7 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20220412130856_add_type_to_auction.rb diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index 22c186b17..ca3065108 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -24,7 +24,7 @@ module Admin end def create - auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started]) + auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: :english) if auction.save remove_from_reserved(auction) @@ -41,7 +41,7 @@ module Admin table.each do |row| record = row.to_h - auction = Auction.new(domain: record['name'], status: Auction.statuses[:started]) + auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: :english) remove_from_reserved(auction) if auction.save! end diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index dc9ff9d15..2e5cff63c 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -58,7 +58,7 @@ module Admin reserved_domains = ReservedDomain.where(id: reserved_domains_ids) reserved_domains.each do |domain| - Auction.create!(domain: domain.name, status: Auction.statuses[:started]) + Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: :english) domain.destroy! end diff --git a/app/models/auction.rb b/app/models/auction.rb index fd48c22f2..208425f4d 100644 --- a/app/models/auction.rb +++ b/app/models/auction.rb @@ -9,6 +9,8 @@ class Auction < ApplicationRecord domain_not_registered: 'domain_not_registered', } + enum type: %i[blind english] + PENDING_STATUSES = [statuses[:started], statuses[:awaiting_payment], statuses[:payment_received]].freeze diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index bceb4433b..3fe4760ac 100644 --- a/app/models/dns/domain_name.rb +++ b/app/models/dns/domain_name.rb @@ -35,6 +35,7 @@ module DNS def sell_at_auction auction = Auction.new auction.domain = name + auction.platform = :blind auction.start ToStdout.msg "Created the auction: #{auction.inspect}" update_whois_from_auction(auction) diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb index d3f9f7745..2ea206671 100644 --- a/app/views/admin/auctions/index.html.erb +++ b/app/views/admin/auctions/index.html.erb @@ -114,6 +114,9 @@ <%= sort_link(@q, 'registration_deadline') %> + + <%= sort_link(@q, 'type') %> + @@ -126,6 +129,7 @@ <%= auction.created_at %> <%= auction.registration_code %> <%= auction.registration_deadline %> + <%= auction.platform %> <% end %> diff --git a/db/migrate/20220412130856_add_type_to_auction.rb b/db/migrate/20220412130856_add_type_to_auction.rb new file mode 100644 index 000000000..a48ca5ed9 --- /dev/null +++ b/db/migrate/20220412130856_add_type_to_auction.rb @@ -0,0 +1,5 @@ +class AddTypeToAuction < ActiveRecord::Migration[6.1] + def change + # add_column :auctions, :type, :integer, null: true + end +end diff --git a/db/structure.sql b/db/structure.sql index 4c22970d3..74d2802bb 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -5090,3 +5090,4 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220124105717'), ('20220216113112'), ('20220228093211'); +('20220412130856'); From 9766650ae4370a15fda7a8ed9e9cdc83ac44f1c9 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 13 Apr 2022 10:54:49 +0300 Subject: [PATCH 04/11] renamed column in auction from type to platform --- app/controllers/admin/auctions_controller.rb | 9 +++++---- app/controllers/admin/reserved_domains_controller.rb | 2 +- app/helpers/auction_helper.rb | 6 ++---- app/models/auction.rb | 4 ++-- app/models/dns/domain_name.rb | 2 +- app/views/admin/auctions/index.html.erb | 2 +- config/locales/en.yml | 1 + db/migrate/20220412130856_add_type_to_auction.rb | 2 +- db/structure.sql | 3 ++- 9 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index ca3065108..fc89c01f7 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -24,24 +24,25 @@ module Admin end def create - auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: :english) + auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: 'english') if auction.save remove_from_reserved(auction) flash[:notice] = "Auction #{params[:domain]} created" else - flash[:alert] = "Something goes wrong" + flash[:alert] = 'Something goes wrong' end redirect_to admin_auctions_path end def upload_spreadsheet - table = CSV.parse(File.read(params[:q][:file]), headers: true) + filename = params[:q][:file] + table = CSV.parse(File.read(filename), headers: true) table.each do |row| record = row.to_h - auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: :english) + auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: 'english') remove_from_reserved(auction) if auction.save! end diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 2e5cff63c..2daa6e068 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -58,7 +58,7 @@ module Admin reserved_domains = ReservedDomain.where(id: reserved_domains_ids) reserved_domains.each do |domain| - Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: :english) + Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: 'english') domain.destroy! end diff --git a/app/helpers/auction_helper.rb b/app/helpers/auction_helper.rb index e4ef44736..25cf463af 100644 --- a/app/helpers/auction_helper.rb +++ b/app/helpers/auction_helper.rb @@ -1,7 +1,5 @@ module AuctionHelper include ActionView::Helpers::TagHelper - - extend self def colorize_auction(auction) case auction.status @@ -12,10 +10,10 @@ module AuctionHelper end def render_status_black(name) - content_tag(:span, name.to_s, style: 'color: black;') + tag.span name.to_s, style: 'color: black;' end def render_status_green(name) - content_tag(:span, name.to_s , style: 'color: green;') + tag.span name.to_s, style: 'color: green;' end end diff --git a/app/models/auction.rb b/app/models/auction.rb index 208425f4d..56acba7c6 100644 --- a/app/models/auction.rb +++ b/app/models/auction.rb @@ -9,7 +9,7 @@ class Auction < ApplicationRecord domain_not_registered: 'domain_not_registered', } - enum type: %i[blind english] + enum platform: %i[blind english] PENDING_STATUSES = [statuses[:started], statuses[:awaiting_payment], @@ -17,7 +17,7 @@ class Auction < ApplicationRecord private_constant :PENDING_STATUSES - scope :with_status, -> (status) { + scope :with_status, ->(status) { where(status: status) if status.present? } diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index 3fe4760ac..f914e3439 100644 --- a/app/models/dns/domain_name.rb +++ b/app/models/dns/domain_name.rb @@ -35,7 +35,7 @@ module DNS def sell_at_auction auction = Auction.new auction.domain = name - auction.platform = :blind + auction.platform = 'blind' auction.start ToStdout.msg "Created the auction: #{auction.inspect}" update_whois_from_auction(auction) diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb index 2ea206671..52472e7fa 100644 --- a/app/views/admin/auctions/index.html.erb +++ b/app/views/admin/auctions/index.html.erb @@ -124,7 +124,7 @@ <% @auctions.each do |auction| %> - <%= AuctionHelper.colorize_auction(auction) %> + <%= colorize_auction(auction) %> <%= auction.status %> <%= auction.created_at %> <%= auction.registration_code %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 28d2d0281..c36dcadeb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -189,6 +189,7 @@ en: log_out: 'Log out (%{user})' system: 'System' domains: 'Domains' + auctions: 'Auctions' registrars: 'Registrars' valid_to: 'Valid to' name: 'Name' diff --git a/db/migrate/20220412130856_add_type_to_auction.rb b/db/migrate/20220412130856_add_type_to_auction.rb index a48ca5ed9..14714e868 100644 --- a/db/migrate/20220412130856_add_type_to_auction.rb +++ b/db/migrate/20220412130856_add_type_to_auction.rb @@ -1,5 +1,5 @@ class AddTypeToAuction < ActiveRecord::Migration[6.1] def change - # add_column :auctions, :type, :integer, null: true + add_column :auctions, :platform, :integer, null: true end end diff --git a/db/structure.sql b/db/structure.sql index 74d2802bb..8512da48e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -337,7 +337,8 @@ CREATE TABLE public.auctions ( uuid uuid DEFAULT public.gen_random_uuid() NOT NULL, created_at timestamp without time zone NOT NULL, registration_code character varying, - registration_deadline timestamp without time zone + registration_deadline timestamp without time zone, + platform integer ); From 3b9ff74bd24210798e94acb08d8434c7e72eff46 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 22 Apr 2022 14:04:29 +0300 Subject: [PATCH 05/11] fix issues --- app/controllers/admin/auctions_controller.rb | 35 +++++++++++++++---- .../admin/reserved_domains_controller.rb | 2 +- app/models/auction.rb | 10 +++++- app/models/dns/domain_name.rb | 2 +- app/views/admin/auctions/index.html.erb | 26 +++++++++++--- app/views/admin/base/_menu.haml | 2 +- config/routes.rb | 3 ++ 7 files changed, 66 insertions(+), 14 deletions(-) diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index fc89c01f7..8e3e0ce3d 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -24,7 +24,7 @@ module Admin end def create - auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: 'english') + auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: 'manually') if auction.save remove_from_reserved(auction) @@ -40,17 +40,40 @@ module Admin filename = params[:q][:file] table = CSV.parse(File.read(filename), headers: true) - table.each do |row| - record = row.to_h - auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: 'english') - remove_from_reserved(auction) if auction.save! + if validate_table(table) + table.each do |row| + record = row.to_h + auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: 'manually') + remove_from_reserved(auction) if auction.save! + end + flash[:notice] = "Domains added" + redirect_to admin_auctions_path + else + flash[:alert] = "Invalid CSV format." + redirect_to admin_auctions_path end + end - redirect_to admin_auctions_path + def send_to_auction + auction = Auction.find(params[:id]) + + p ">>>>>.." + p auction + p ">>>>>>" end private + def validate_table(table) + first_row = table.headers + first_row[0] == 'id' && + first_row[1] == 'created_at' && + first_row[2] == 'updated_at' && + first_row[3] == 'creator_str' && + first_row[4] == 'updator_str' && + first_row[5] == 'name' + end + def remove_from_reserved(auction) domain = ReservedDomain.find_by(name: auction.domain) diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 2daa6e068..3812a2394 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -58,7 +58,7 @@ module Admin reserved_domains = ReservedDomain.where(id: reserved_domains_ids) reserved_domains.each do |domain| - Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: 'english') + Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: 'manually') domain.destroy! end diff --git a/app/models/auction.rb b/app/models/auction.rb index 56acba7c6..cb0e9916d 100644 --- a/app/models/auction.rb +++ b/app/models/auction.rb @@ -9,7 +9,7 @@ class Auction < ApplicationRecord domain_not_registered: 'domain_not_registered', } - enum platform: %i[blind english] + enum platform: %i[automatically manually] PENDING_STATUSES = [statuses[:started], statuses[:awaiting_payment], @@ -21,6 +21,14 @@ class Auction < ApplicationRecord where(status: status) if status.present? } + scope :with_start_created_at_date, -> (start_created_at) { + where("created_at >= ?", start_created_at) if start_created_at.present? + } + + scope :with_end_created_at_date, -> (end_created_at) { + where("created_at <= ?", end_created_at) if end_created_at.present? + } + def self.pending(domain_name) find_by(domain: domain_name.to_s, status: PENDING_STATUSES) end diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index f914e3439..5d89868ff 100644 --- a/app/models/dns/domain_name.rb +++ b/app/models/dns/domain_name.rb @@ -35,7 +35,7 @@ module DNS def sell_at_auction auction = Auction.new auction.domain = name - auction.platform = 'blind' + auction.platform = 'automatically' auction.start ToStdout.msg "Created the auction: #{auction.inspect}" update_whois_from_auction(auction) diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb index 52472e7fa..bae4a2239 100644 --- a/app/views/admin/auctions/index.html.erb +++ b/app/views/admin/auctions/index.html.erb @@ -41,11 +41,11 @@  
- <%= link_to(t('.reset_btn'), admin_auctions_path, class: 'btn btn-default') %> + <%= link_to('Clear', admin_auctions_path, class: 'btn btn-default') %>
<%= link_to 'Download auction list', admin_auctions_path(format: :csv, params: params.permit!), - "data-toggle" => "tooltip", "data-placement" => "bottom", "title" => t('.download_csv_btn'), + "data-toggle" => "tooltip", "data-placement" => "bottom", "title" => 'Download CSV', class: 'btn btn-primary' %>
@@ -114,10 +114,12 @@ <%= sort_link(@q, 'registration_deadline') %> - + <%= sort_link(@q, 'type') %> - + + Action + @@ -130,6 +132,11 @@ <%= auction.registration_code %> <%= auction.registration_deadline %> <%= auction.platform %> + + <%= button_tag type: 'button', data: { confirm: "Are you sure?" }, class: 'btn btn-primary' do %> + <% link_to 'Send to auction', send_to_auction_admin_auction_path(auction), method: :post, style: "color: white;" %> + <% end %> + <% end %> @@ -138,6 +145,17 @@
+
+
+ <%= paginate @auctions %> +
+
+ +
+
+