From 8bcdeb25ee92bf7f5ee6cac4314b574b67559200 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 12 Oct 2019 15:59:33 +0300 Subject: [PATCH 1/7] Convert HAML to ERB --- app/views/registrar/contacts/index.haml | 120 ------------ app/views/registrar/contacts/index.html.erb | 193 ++++++++++++++++++++ 2 files changed, 193 insertions(+), 120 deletions(-) delete mode 100644 app/views/registrar/contacts/index.haml create mode 100644 app/views/registrar/contacts/index.html.erb diff --git a/app/views/registrar/contacts/index.haml b/app/views/registrar/contacts/index.haml deleted file mode 100644 index 518e6eccf..000000000 --- a/app/views/registrar/contacts/index.haml +++ /dev/null @@ -1,120 +0,0 @@ -- content_for :actions do - = link_to(t(:new), new_registrar_contact_path, class: 'btn btn-primary') -= render 'shared/title', name: t(:contacts) - -.row - .col-md-12 - = search_form_for [:registrar, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| - .row - .col-md-3 - .form-group - = f.label :name - = f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name) - .col-md-3 - .form-group - = f.label t(:id) - = f.search_field :code_eq, class: 'form-control', placeholder: t(:id) - .col-md-3 - .form-group - = f.label t(:ident) - = f.search_field :ident_matches, class: 'form-control', placeholder: t(:ident) - .col-md-3 - .form-group - = label_tag t(:ident_type) - = select_tag '[q][ident_type_eq]', options_for_select(ident_types, params[:q][:ident_type_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } - .row - .col-md-3 - .form-group - = f.label t(:email) - = f.search_field :email_matches, class: 'form-control', placeholder: t(:email) - .col-md-3 - .form-group - = label_tag t(:country) - = select_tag '[q][country_code_eq]', SortedCountry.all_options(params[:q][:country_code_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } - .col-md-6 - .form-group - = label_tag t(:contact_type) - = select_tag '[q][domain_contacts_type_in]', options_for_select([['admin', 'AdminDomainContact'], ['tech', 'TechDomainContact'], ['registrant', 'registrant']], params[:q][:domain_contacts_type_in]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' } - .row - .col-md-3 - .form-group - = f.label t(:registrar_name) - = f.select :registrar_id_eq, Registrar.all.map { |x| [x, x.id] }, { include_blank: true }, class: 'form-control selectize', placeholder: t(:choose) - .col-md-3 - .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) - .col-md-3 - .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) - .col-md-3 - .form-group - = f.label t(:updated_at) - = f.search_field :updated_at_gteq, value: params[:q][:updated_at_gteq], class: 'form-control js-datepicker', placeholder: t(:updated_at) - .row - .col-md-6 - .form-group - = label_tag t(:status) - = select_tag :statuses_contains, options_for_select(Contact::STATUSES, params[:statuses_contains]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' } - .col-md-3 - .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) - .col-md-3{style: 'padding-top: 25px;'} - %button.btn.btn-primary -   - %span.glyphicon.glyphicon-search -   - = link_to(t('.reset_btn'), registrar_contacts_path, class: 'btn btn-default') - .row - .col-md-3 - .btn-group{:role => "group"} - %button.btn.btn-default.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", :type => "button"} - Download - %span.caret - %ul.dropdown-menu - %li= link_to 'PDF', download_list_registrar_contacts_path(q: params[:q], format: "pdf") - %li= link_to 'CSV', download_list_registrar_contacts_path(q: params[:q], format: "csv") - .col-md-3 - .col-md-3 - .col-md-3 - -%hr -.row - .col-md-12 - .table-responsive - %table.table.table-hover.table-bordered.table-condensed.contacts - %thead - %tr - %th{class: 'col-xs-2'} - = sort_link(@q, 'name', t(:name)) - %th{class: 'col-xs-2'} - = sort_link(@q, 'code', t(:id)) - %th{class: 'col-xs-2'} - = sort_link(@q, 'ident', t(:ident)) - %th{class: 'col-xs-2'} - = sort_link(@q, 'email', t(:created_at)) - %th{class: 'col-xs-2'} - = sort_link(@q, 'registrar_name', t(:registrar_name)) - %th{class: 'col-xs-2'}= t(:actions) - %tbody - - @contacts.each do |contact| - %tr - %td= link_to(contact.name, registrar_contact_path(id: contact.code)) - %td= contact.code - %td= ident_for(contact) - %td= l(contact.created_at, format: :short) - %td - - if contact.registrar - = contact.registrar - %td - = link_to(t(:edit), edit_registrar_contact_path(contact.code), class: 'btn btn-primary btn-xs') - = link_to(t(:delete), delete_registrar_contact_path(contact.code), class: 'btn btn-default btn-xs') - -.row - .col-md-6 - = paginate @contacts - .col-md-6.text-right - .pagination - = t(:result_count, count: @contacts.total_count) diff --git a/app/views/registrar/contacts/index.html.erb b/app/views/registrar/contacts/index.html.erb new file mode 100644 index 000000000..5fc7ce09c --- /dev/null +++ b/app/views/registrar/contacts/index.html.erb @@ -0,0 +1,193 @@ +<% content_for :actions do %> + <%= link_to(t(:new), new_registrar_contact_path, class: 'btn btn-primary') %> +<% end %> +<%= render 'shared/title', name: t(:contacts) %> +
+
+ <%= search_form_for [:registrar, @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(:id) %> + <%= f.search_field :code_eq, class: 'form-control', placeholder: t(:id) %> +
+
+
+
+ <%= f.label t(:ident) %> + <%= f.search_field :ident_matches, class: 'form-control', placeholder: t(:ident) %> +
+
+
+
+ <%= label_tag t(:ident_type) %> + <%= select_tag '[q][ident_type_eq]', options_for_select(ident_types, params[:q][:ident_type_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } %> +
+
+
+
+
+
+ <%= f.label t(:email) %> + <%= f.search_field :email_matches, class: 'form-control', placeholder: t(:email) %> +
+
+
+
+ <%= label_tag t(:country) %> + <%= select_tag '[q][country_code_eq]', SortedCountry.all_options(params[:q][:country_code_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } %> +
+
+
+
+ <%= label_tag t(:contact_type) %> + <%= select_tag '[q][domain_contacts_type_in]', options_for_select([['admin', 'AdminDomainContact'], ['tech', 'TechDomainContact'], ['registrant', 'registrant']], params[:q][:domain_contacts_type_in]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' } %> +
+
+
+
+
+
+ <%= f.label t(:registrar_name) %> + <%= f.select :registrar_id_eq, Registrar.all.map { |x| [x, x.id] }, { include_blank: true }, class: 'form-control selectize', placeholder: t(:choose) %> +
+
+
+
+ <%= 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) %> +
+
+
+
+ <%= f.label t(:updated_at) %> + <%= f.search_field :updated_at_gteq, value: params[:q][:updated_at_gteq], class: 'form-control js-datepicker', placeholder: t(:updated_at) %> +
+
+
+
+
+
+ <%= label_tag t(:status) %> + <%= select_tag :statuses_contains, options_for_select(Contact::STATUSES, params[:statuses_contains]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' } %> +
+
+
+
+ <%= 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'), registrar_contacts_path, class: 'btn btn-default') %> +
+
+
+
+
+ + +
+
+
+
+
+
+ <% end %> +
+
+
+
+
+
+ + + + + + + + + + + + + <% @contacts.each do |contact| %> + + + + + + + + + <% end %> + +
+ <%= sort_link(@q, 'name', t(:name)) %> + + <%= sort_link(@q, 'code', t(:id)) %> + + <%= sort_link(@q, 'ident', t(:ident)) %> + + <%= sort_link(@q, 'email', t(:created_at)) %> + + <%= sort_link(@q, 'registrar_name', t(:registrar_name)) %> + + <%= t(:actions) %> +
+ <%= link_to(contact.name, registrar_contact_path(id: contact.code)) %> + + <%= contact.code %> + + <%= ident_for(contact) %> + + <%= l(contact.created_at, format: :short) %> + + <% if contact.registrar %> + <%= contact.registrar %> + <% end %> + + <%= link_to(t(:edit), edit_registrar_contact_path(contact.code), class: 'btn btn-primary btn-xs') %> + <%= link_to(t(:delete), delete_registrar_contact_path(contact.code), class: 'btn btn-default btn-xs') %> +
+
+
+
+
+
+ <%= paginate @contacts %> +
+
+ +
+
From f8765eca4d66dfb0cb194632205fb2c561bb3d89 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 12 Oct 2019 16:02:42 +0300 Subject: [PATCH 2/7] Extract partial --- .../registrar/contacts/_search_form.html.erb | 131 ++++++++++++++++++ app/views/registrar/contacts/index.html.erb | 118 +--------------- config/locales/registrar/contacts.en.yml | 2 +- 3 files changed, 133 insertions(+), 118 deletions(-) create mode 100644 app/views/registrar/contacts/_search_form.html.erb diff --git a/app/views/registrar/contacts/_search_form.html.erb b/app/views/registrar/contacts/_search_form.html.erb new file mode 100644 index 000000000..66bb263bd --- /dev/null +++ b/app/views/registrar/contacts/_search_form.html.erb @@ -0,0 +1,131 @@ +<%= search_form_for [:registrar, @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(:id) %> + <%= f.search_field :code_eq, class: 'form-control', placeholder: t(:id) %> +
+
+ +
+
+ <%= f.label t(:ident) %> + <%= f.search_field :ident_matches, class: 'form-control', placeholder: t(:ident) %> +
+
+ +
+
+ <%= label_tag t(:ident_type) %> + <%= select_tag '[q][ident_type_eq]', options_for_select(ident_types, params[:q][:ident_type_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } %> +
+
+
+ +
+
+
+ <%= f.label t(:email) %> + <%= f.search_field :email_matches, class: 'form-control', placeholder: t(:email) %> +
+
+ +
+
+ <%= label_tag t(:country) %> + <%= select_tag '[q][country_code_eq]', SortedCountry.all_options(params[:q][:country_code_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } %> +
+
+ +
+
+ <%= label_tag t(:contact_type) %> + <%= select_tag '[q][domain_contacts_type_in]', options_for_select([['admin', 'AdminDomainContact'], ['tech', 'TechDomainContact'], ['registrant', 'registrant']], params[:q][:domain_contacts_type_in]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' } %> +
+
+
+ +
+
+
+ <%= f.label t(:registrar_name) %> + <%= f.select :registrar_id_eq, Registrar.all.map { |x| [x, x.id] }, { include_blank: true }, class: 'form-control selectize', placeholder: t(:choose) %> +
+
+ +
+
+ <%= 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) %> +
+
+ +
+
+ <%= f.label t(:updated_at) %> + <%= f.search_field :updated_at_gteq, value: params[:q][:updated_at_gteq], class: 'form-control js-datepicker', placeholder: t(:updated_at) %> +
+
+
+ +
+
+
+ <%= label_tag t(:status) %> + <%= select_tag :statuses_contains, options_for_select(Contact::STATUSES, params[:statuses_contains]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' } %> +
+
+ +
+
+ <%= 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'), registrar_contacts_path, class: 'btn btn-default') %> +
+
+ +
+
+
+ + +
+
+
+
+
+
+<% end %> diff --git a/app/views/registrar/contacts/index.html.erb b/app/views/registrar/contacts/index.html.erb index 5fc7ce09c..4a7e8759a 100644 --- a/app/views/registrar/contacts/index.html.erb +++ b/app/views/registrar/contacts/index.html.erb @@ -4,123 +4,7 @@ <%= render 'shared/title', name: t(:contacts) %>
- <%= search_form_for [:registrar, @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(:id) %> - <%= f.search_field :code_eq, class: 'form-control', placeholder: t(:id) %> -
-
-
-
- <%= f.label t(:ident) %> - <%= f.search_field :ident_matches, class: 'form-control', placeholder: t(:ident) %> -
-
-
-
- <%= label_tag t(:ident_type) %> - <%= select_tag '[q][ident_type_eq]', options_for_select(ident_types, params[:q][:ident_type_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } %> -
-
-
-
-
-
- <%= f.label t(:email) %> - <%= f.search_field :email_matches, class: 'form-control', placeholder: t(:email) %> -
-
-
-
- <%= label_tag t(:country) %> - <%= select_tag '[q][country_code_eq]', SortedCountry.all_options(params[:q][:country_code_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' } %> -
-
-
-
- <%= label_tag t(:contact_type) %> - <%= select_tag '[q][domain_contacts_type_in]', options_for_select([['admin', 'AdminDomainContact'], ['tech', 'TechDomainContact'], ['registrant', 'registrant']], params[:q][:domain_contacts_type_in]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' } %> -
-
-
-
-
-
- <%= f.label t(:registrar_name) %> - <%= f.select :registrar_id_eq, Registrar.all.map { |x| [x, x.id] }, { include_blank: true }, class: 'form-control selectize', placeholder: t(:choose) %> -
-
-
-
- <%= 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) %> -
-
-
-
- <%= f.label t(:updated_at) %> - <%= f.search_field :updated_at_gteq, value: params[:q][:updated_at_gteq], class: 'form-control js-datepicker', placeholder: t(:updated_at) %> -
-
-
-
-
-
- <%= label_tag t(:status) %> - <%= select_tag :statuses_contains, options_for_select(Contact::STATUSES, params[:statuses_contains]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' } %> -
-
-
-
- <%= 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'), registrar_contacts_path, class: 'btn btn-default') %> -
-
-
-
-
- - -
-
-
-
-
-
- <% end %> + <%= render 'search_form' %>

diff --git a/config/locales/registrar/contacts.en.yml b/config/locales/registrar/contacts.en.yml index 84afd481d..7eeb3c518 100644 --- a/config/locales/registrar/contacts.en.yml +++ b/config/locales/registrar/contacts.en.yml @@ -1,7 +1,7 @@ en: registrar: contacts: - index: + search_form: reset_btn: Reset partials: From 199085f8ac0ec3894e5117e5f906fa58c49ab960 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 12 Oct 2019 17:06:35 +0300 Subject: [PATCH 3/7] Use resourceful routes https://github.com/rails/rails/pull/23980 --- .../registrant/domains_controller.rb | 44 ++++++++-------- .../registrar/contacts_controller.rb | 37 +++++--------- .../registrar/domains_controller.rb | 5 +- .../registrant/domains/download_list.haml | 2 +- app/views/registrant/domains/index.html.erb | 51 ++++++++----------- .../registrar/contacts/_search_form.html.erb | 36 ++++--------- .../registrar/domains/_search_form.html.erb | 6 +-- config/locales/registrant/domains.en.yml | 2 + config/locales/registrar/contacts.en.yml | 2 + config/locales/registrar/domains.en.yml | 2 +- config/routes.rb | 6 --- .../registrant_area/domains_test.rb | 25 +++++++++ .../registrar_area/contacts_test.rb | 25 +++++++++ .../registrar_area/domains_test.rb | 20 ++++++++ test/system/registrar_area/domains_test.rb | 2 +- 15 files changed, 152 insertions(+), 113 deletions(-) create mode 100644 test/integration/registrant_area/domains_test.rb create mode 100644 test/integration/registrar_area/contacts_test.rb create mode 100644 test/integration/registrar_area/domains_test.rb diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index b8cd8f37a..15d38ad7f 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -4,11 +4,27 @@ class Registrant::DomainsController < RegistrantController params[:q] ||= {} normalize_search_parameters do - @q = current_user_domains.search(params[:q]) - @domains = @q.result.page(params[:page]) + @q = current_user_domains.search(search_params) end - @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? + domains = @q.result + + respond_to do |format| + format.html do + @domains = domains.page(params[:page]) + domains_per_page = params[:results_per_page].to_i + @domains = @domains.per(domains_per_page) if domains_per_page.positive? + end + format.csv do + raw_csv = @q.result.to_csv + send_data raw_csv, filename: 'domains.csv', type: "#{Mime[:csv]}; charset=utf-8" + end + format.pdf do + @domains = domains + raw_pdf = domains.pdf(render_to_string('registrant/domains/download_list', layout: false)) + send_data raw_pdf, filename: 'domains.pdf' + end + end end def show @@ -32,23 +48,6 @@ class Registrant::DomainsController < RegistrantController end end - def download_list - authorize! :view, :registrant_domains - params[:q] ||= {} - normalize_search_parameters do - @q = current_user_domains.search(params[:q]) - @domains = @q - end - - respond_to do |format| - format.csv { render text: @domains.result.to_csv } - format.pdf do - pdf = @domains.result.pdf(render_to_string('registrant/domains/download_list', layout: false)) - send_data pdf, filename: 'domains.pdf' - end - end - end - private def normalize_search_parameters @@ -70,4 +69,9 @@ class Registrant::DomainsController < RegistrantController registrant_domain_delete_confirm_url(token: domain.registrant_verification_token) end end + + def search_params + params.require(:q).permit(:name_matches, :registrant_ident_eq, :valid_to_gteq, :valid_to_lteq, + :results_per_page) + end end \ No newline at end of file diff --git a/app/controllers/registrar/contacts_controller.rb b/app/controllers/registrar/contacts_controller.rb index f343f9bfb..2bc15fd9c 100644 --- a/app/controllers/registrar/contacts_controller.rb +++ b/app/controllers/registrar/contacts_controller.rb @@ -30,37 +30,26 @@ class Registrar normalize_search_parameters do @q = contacts.search(search_params) - @contacts = @q.result(distinct: :true).page(params[:page]) end - @contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? - end - - def download_list - authorize! :view, Depp::Contact - - params[:q] ||= {} - params[:q].delete_if { |_k, v| v.blank? } - if params[:q].length == 1 && params[:q][:name_matches].present? - @contacts = Contact.find_by(name: params[:q][:name_matches]) - end - - contacts = current_registrar_user.registrar.contacts.includes(:registrar) - contacts = contacts.filter_by_states(params[:statuses_contains]) if params[:statuses_contains] - - normalize_search_parameters do - @q = contacts.search(params[:q]) - @contacts = @q.result - end + contacts = @q.result respond_to do |format| - format.csv { render text: @contacts.to_csv } + format.html do + contacts_per_page = params[:results_per_page].to_i + @contacts = contacts.page(params[:page]) + @contacts = @contacts.per(contacts_per_page) if contacts_per_page.positive? + end + format.csv do + raw_csv = contacts.to_csv + send_data raw_csv, filename: 'contacts.csv', type: "#{Mime[:csv]}; charset=utf-8" + end format.pdf do - pdf = @contacts.pdf(render_to_string('registrar/contacts/download_list', layout: false)) - send_data pdf, filename: 'contacts.pdf' + @contacts = contacts + raw_pdf = contacts.pdf(render_to_string('registrar/contacts/download_list', layout: false)) + send_data raw_pdf, filename: 'contacts.pdf' end end - end def new diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index d2969bb69..bdab2eefc 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -47,9 +47,10 @@ class Registrar domain_presenters << ::DomainPresenter.new(domain: domain, view: view_context) end - csv = Registrar::DomainListCSVPresenter.new(domains: domain_presenters, view: view_context).to_s + raw_csv = Registrar::DomainListCSVPresenter.new(domains: domain_presenters, + view: view_context).to_s filename = "Domains_#{l(Time.zone.now, format: :filename)}.csv" - send_data(csv, filename: filename) + send_data raw_csv, filename: filename, type: "#{Mime[:csv]}; charset=utf-8" end end end diff --git a/app/views/registrant/domains/download_list.haml b/app/views/registrant/domains/download_list.haml index f0af344cd..b37e3a42a 100644 --- a/app/views/registrant/domains/download_list.haml +++ b/app/views/registrant/domains/download_list.haml @@ -18,7 +18,7 @@ %th{class: 'col-xs-2'} =t(:registrar_name) %tbody - - @domains.result.each do |x| + - @domains.each do |x| %tr %td= x.name %td= x.registrant diff --git a/app/views/registrant/domains/index.html.erb b/app/views/registrant/domains/index.html.erb index acb9afcff..1254bfbc8 100644 --- a/app/views/registrant/domains/index.html.erb +++ b/app/views/registrant/domains/index.html.erb @@ -18,6 +18,13 @@ <%= f.search_field :registrant_ident_eq, class: 'form-control', placeholder: t(:registrant_ident) %> + +
+
+ <%= label_tag t(:results_per_page) %> + <%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %> +
+
@@ -32,43 +39,27 @@ <%= f.search_field :valid_to_lteq, value: params[:q][:valid_to_lteq], class: 'form-control js-datepicker', placeholder: t(:valid_to_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'), registrant_domains_path, class: 'btn btn-default') %> + <%= button_tag t('.download_pdf_btn'), + formaction: registrant_domains_path(format: :pdf), + name: nil, + class: 'btn btn-default' %> + <%= button_tag t('.download_csv_btn'), + formaction: registrant_domains_path(format: :csv), + name: nil, + class: 'btn btn-default' %> + <%= link_to t('.reset_btn'), registrant_domains_path, + class: 'btn btn-default' %>
-
-
-
- - -
-
-
-
-
-
<% end %> diff --git a/app/views/registrar/contacts/_search_form.html.erb b/app/views/registrar/contacts/_search_form.html.erb index 66bb263bd..e15ff1880 100644 --- a/app/views/registrar/contacts/_search_form.html.erb +++ b/app/views/registrar/contacts/_search_form.html.erb @@ -83,49 +83,35 @@
-
+
<%= label_tag t(:status) %> <%= select_tag :statuses_contains, options_for_select(Contact::STATUSES, params[:statuses_contains]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' } %>
-
+
<%= label_tag t(:results_per_page) %> <%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %>
-
+
+ <%= button_tag t('.download_pdf_btn'), + formaction: registrar_contacts_path(format: :pdf), + name: nil, + class: 'btn btn-default' %> + <%= button_tag t('.download_csv_btn'), + formaction: registrar_contacts_path(format: :csv), + name: nil, + class: 'btn btn-default' %> <%= link_to(t('.reset_btn'), registrar_contacts_path, class: 'btn btn-default') %>
- -
-
-
- - -
-
-
-
-
-
<% end %> diff --git a/app/views/registrar/domains/_search_form.html.erb b/app/views/registrar/domains/_search_form.html.erb index b494e0d8d..743f8de60 100644 --- a/app/views/registrar/domains/_search_form.html.erb +++ b/app/views/registrar/domains/_search_form.html.erb @@ -74,14 +74,14 @@
-
+
- <%= button_tag t('.download_btn'), class: 'btn btn-primary export-domains-csv-btn', - formaction: registrar_domains_path(format: 'csv') %> + <%= button_tag t('.download_btn'), formaction: registrar_domains_path(format: 'csv'), + class: 'btn btn-default' %> <%= link_to t('.reset_btn'), registrar_domains_path, class: 'btn btn-default' %>
diff --git a/config/locales/registrant/domains.en.yml b/config/locales/registrant/domains.en.yml index 2dbdce79a..a56d10b69 100644 --- a/config/locales/registrant/domains.en.yml +++ b/config/locales/registrant/domains.en.yml @@ -4,6 +4,8 @@ en: index: header: Domains registrant: Registrant + download_pdf_btn: Download PDF + download_csv_btn: Download CSV reset_btn: Reset download_list: diff --git a/config/locales/registrar/contacts.en.yml b/config/locales/registrar/contacts.en.yml index 7eeb3c518..590e419d2 100644 --- a/config/locales/registrar/contacts.en.yml +++ b/config/locales/registrar/contacts.en.yml @@ -2,6 +2,8 @@ en: registrar: contacts: search_form: + download_pdf_btn: Download PDF + download_csv_btn: Download CSV reset_btn: Reset partials: diff --git a/config/locales/registrar/domains.en.yml b/config/locales/registrar/domains.en.yml index 31380074f..c98002b8f 100644 --- a/config/locales/registrar/domains.en.yml +++ b/config/locales/registrar/domains.en.yml @@ -17,7 +17,7 @@ en: transfer_btn: Transfer search_form: - download_btn: Download as CSV + download_btn: Download CSV reset_btn: Reset domain: diff --git a/config/routes.rb b/config/routes.rb index 4b65087b5..4c1e25864 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -87,7 +87,6 @@ Rails.application.routes.draw do collection do get 'check' - get 'download_list' end end @@ -151,11 +150,6 @@ Rails.application.routes.draw do resources :registrars, only: :show resources :domains, only: %i[index show] do resources :contacts, only: %i[show edit update] - - collection do - get :download_list - end - member do get 'confirmation' end diff --git a/test/integration/registrant_area/domains_test.rb b/test/integration/registrant_area/domains_test.rb new file mode 100644 index 000000000..11709dd5b --- /dev/null +++ b/test/integration/registrant_area/domains_test.rb @@ -0,0 +1,25 @@ +require 'test_helper' + +class RegistrantAreaDomainsIntegrationTest < ApplicationIntegrationTest + setup do + sign_in users(:registrant) + end + + def test_downloads_list_as_csv + get registrant_domains_path(format: :csv) + + assert_response :ok + assert_equal "#{Mime[:csv]}; charset=utf-8", response.headers['Content-Type'] + assert_equal 'attachment; filename="domains.csv"', response.headers['Content-Disposition'] + assert_not_empty response.body + end + + def test_downloads_list_as_pdf + get registrant_domains_path(format: :pdf) + + assert_response :ok + assert_equal Mime[:pdf], response.headers['Content-Type'] + assert_equal 'attachment; filename="domains.pdf"', response.headers['Content-Disposition'] + assert_not_empty response.body + end +end diff --git a/test/integration/registrar_area/contacts_test.rb b/test/integration/registrar_area/contacts_test.rb new file mode 100644 index 000000000..2597518b1 --- /dev/null +++ b/test/integration/registrar_area/contacts_test.rb @@ -0,0 +1,25 @@ +require 'test_helper' + +class RegistrarAreaContactsIntegrationTest < ApplicationIntegrationTest + setup do + sign_in users(:api_bestnames) + end + + def test_downloads_list_as_csv + get registrar_contacts_path(format: :csv) + + assert_response :ok + assert_equal "#{Mime[:csv]}; charset=utf-8", response.headers['Content-Type'] + assert_equal 'attachment; filename="contacts.csv"', response.headers['Content-Disposition'] + assert_not_empty response.body + end + + def test_downloads_list_as_pdf + get registrar_contacts_path(format: :pdf) + + assert_response :ok + assert_equal Mime[:pdf], response.headers['Content-Type'] + assert_equal 'attachment; filename="contacts.pdf"', response.headers['Content-Disposition'] + assert_not_empty response.body + end +end diff --git a/test/integration/registrar_area/domains_test.rb b/test/integration/registrar_area/domains_test.rb new file mode 100644 index 000000000..eaa43e674 --- /dev/null +++ b/test/integration/registrar_area/domains_test.rb @@ -0,0 +1,20 @@ +require 'test_helper' + +class RegistrarAreaDomainsIntegrationTest < ApplicationIntegrationTest + setup do + sign_in users(:api_bestnames) + end + + def test_downloads_list_as_csv + now = Time.zone.parse('2010-07-05 08:00') + travel_to now + + get registrar_domains_path(format: :csv) + + assert_response :ok + assert_equal "#{Mime[:csv]}; charset=utf-8", response.headers['Content-Type'] + assert_equal %(attachment; filename="Domains_#{l(now, format: :filename)}.csv"), + response.headers['Content-Disposition'] + assert_not_empty response.body + end +end diff --git a/test/system/registrar_area/domains_test.rb b/test/system/registrar_area/domains_test.rb index 00d5c9e43..db51d7096 100644 --- a/test/system/registrar_area/domains_test.rb +++ b/test/system/registrar_area/domains_test.rb @@ -14,7 +14,7 @@ class RegistrarDomainsTest < ApplicationSystemTestCase CSV visit registrar_domains_url - click_button 'Download as CSV' + click_button 'Download CSV' assert_equal 'attachment; filename="Domains_2010-07-05_10.30.csv"', response_headers['Content-Disposition'] assert_equal expected_csv, page.body end From 7fbf21daf8ae82ad034220e09a6aad16d9eb30bd Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 12 Oct 2019 17:45:28 +0300 Subject: [PATCH 4/7] Convert HAML to ERB --- .../registrant/domains_controller.rb | 6 ++-- .../registrar/contacts_controller.rb | 7 ++-- .../registrant/domains/download_list.haml | 28 --------------- .../registrant/domains/download_list.html.erb | 32 +++++++++++++++++ .../registrar/contacts/download_list.haml | 30 ---------------- .../registrar/contacts/download_list.html.erb | 34 +++++++++++++++++++ 6 files changed, 75 insertions(+), 62 deletions(-) delete mode 100644 app/views/registrant/domains/download_list.haml create mode 100644 app/views/registrant/domains/download_list.html.erb delete mode 100644 app/views/registrar/contacts/download_list.haml create mode 100644 app/views/registrar/contacts/download_list.html.erb diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 15d38ad7f..9dda025b5 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -20,8 +20,10 @@ class Registrant::DomainsController < RegistrantController send_data raw_csv, filename: 'domains.csv', type: "#{Mime[:csv]}; charset=utf-8" end format.pdf do - @domains = domains - raw_pdf = domains.pdf(render_to_string('registrant/domains/download_list', layout: false)) + view = ActionView::Base.new(ActionController::Base.view_paths, domains: domains) + raw_html = view.render(file: 'registrant/domains/download_list', layout: false) + raw_pdf = domains.pdf(raw_html) + send_data raw_pdf, filename: 'domains.pdf' end end diff --git a/app/controllers/registrar/contacts_controller.rb b/app/controllers/registrar/contacts_controller.rb index 2bc15fd9c..f418a672b 100644 --- a/app/controllers/registrar/contacts_controller.rb +++ b/app/controllers/registrar/contacts_controller.rb @@ -45,8 +45,11 @@ class Registrar send_data raw_csv, filename: 'contacts.csv', type: "#{Mime[:csv]}; charset=utf-8" end format.pdf do - @contacts = contacts - raw_pdf = contacts.pdf(render_to_string('registrar/contacts/download_list', layout: false)) + view = ActionView::Base.new(ActionController::Base.view_paths, contacts: contacts) + view.class_eval { include ::ApplicationHelper } + raw_html = view.render(file: 'registrar/contacts/download_list', layout: false) + raw_pdf = contacts.pdf(raw_html) + send_data raw_pdf, filename: 'contacts.pdf' end end diff --git a/app/views/registrant/domains/download_list.haml b/app/views/registrant/domains/download_list.haml deleted file mode 100644 index b37e3a42a..000000000 --- a/app/views/registrant/domains/download_list.haml +++ /dev/null @@ -1,28 +0,0 @@ -!!! -%html - %head - %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"} - %title Contacts - %body - .col-md-12 - .table-responsive - %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-2'} - =t(:name) - %th{class: 'col-xs-2'} - =t('.registrant') - %th{class: 'col-xs-2'} - =t(:valid_to) - %th{class: 'col-xs-2'} - =t(:registrar_name) - %tbody - - @domains.each do |x| - %tr - %td= x.name - %td= x.registrant - %td= l(x.valid_to, format: :short) - %td= x.registrar - .row - .col-md-6 diff --git a/app/views/registrant/domains/download_list.html.erb b/app/views/registrant/domains/download_list.html.erb new file mode 100644 index 000000000..9e1d39339 --- /dev/null +++ b/app/views/registrant/domains/download_list.html.erb @@ -0,0 +1,32 @@ + + + +
+
+
+ + + + + + + + + + + + <% @domains.each do |x| %> + + + + + + + <% end %> + +
<%= t(:name) %><%= t('.registrant') %><%= t(:valid_to) %><%= t(:registrar_name) %>
<%= x.name %><%= x.registrant %><%= l(x.valid_to, format: :short) %><%= x.registrar %>
+
+
+
+ + diff --git a/app/views/registrar/contacts/download_list.haml b/app/views/registrar/contacts/download_list.haml deleted file mode 100644 index 51423a3f2..000000000 --- a/app/views/registrar/contacts/download_list.haml +++ /dev/null @@ -1,30 +0,0 @@ -!!! -%html - %head - %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"} - %title Contacts - %body - .row - .col-md-12 - .table-responsive - %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-2'} - =t(:name) - %th{class: 'col-xs-2'} - =t(:id) - %th{class: 'col-xs-2'} - =t(:ident) - %th{class: 'col-xs-2'} - =t(:created_at) - %th{class: 'col-xs-2'} - =t(:registrar_name) - %tbody - - @contacts.each do |contact| - %tr - %td= contact - %td= contact.code - %td= ident_for(contact) - %td= l(contact.created_at, format: :short) - %td= contact.registrar diff --git a/app/views/registrar/contacts/download_list.html.erb b/app/views/registrar/contacts/download_list.html.erb new file mode 100644 index 000000000..63ba9205c --- /dev/null +++ b/app/views/registrar/contacts/download_list.html.erb @@ -0,0 +1,34 @@ + + + +
+
+
+ + + + + + + + + + + + + <% @contacts.each do |contact| %> + + + + + + + + <% end %> + +
<%= t(:name) %><%= t(:id) %><%= t(:ident) %><%= t(:created_at) %><%= t(:registrar_name) %>
<%= contact %><%= contact.code %><%= ident_for(contact) %><%= l(contact.created_at, format: :short) %><%= contact.registrar %>
+
+
+
+ + From 59a6f9d21eaa1d7d28093aeec0ee1c574c5af31f Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 12 Oct 2019 17:47:00 +0300 Subject: [PATCH 5/7] Improve readability --- app/controllers/registrant/domains_controller.rb | 2 +- app/controllers/registrar/contacts_controller.rb | 2 +- .../{download_list.html.erb => list_pdf.html.erb} | 10 +++++----- .../{download_list.html.erb => list_pdf.html.erb} | 0 config/locales/registrant/domains.en.yml | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) rename app/views/registrant/domains/{download_list.html.erb => list_pdf.html.erb} (74%) rename app/views/registrar/contacts/{download_list.html.erb => list_pdf.html.erb} (100%) diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 9dda025b5..fc66806e2 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -21,7 +21,7 @@ class Registrant::DomainsController < RegistrantController end format.pdf do view = ActionView::Base.new(ActionController::Base.view_paths, domains: domains) - raw_html = view.render(file: 'registrant/domains/download_list', layout: false) + raw_html = view.render(file: 'registrant/domains/list_pdf', layout: false) raw_pdf = domains.pdf(raw_html) send_data raw_pdf, filename: 'domains.pdf' diff --git a/app/controllers/registrar/contacts_controller.rb b/app/controllers/registrar/contacts_controller.rb index f418a672b..ec280a46c 100644 --- a/app/controllers/registrar/contacts_controller.rb +++ b/app/controllers/registrar/contacts_controller.rb @@ -47,7 +47,7 @@ class Registrar format.pdf do view = ActionView::Base.new(ActionController::Base.view_paths, contacts: contacts) view.class_eval { include ::ApplicationHelper } - raw_html = view.render(file: 'registrar/contacts/download_list', layout: false) + raw_html = view.render(file: 'registrar/contacts/list_pdf', layout: false) raw_pdf = contacts.pdf(raw_html) send_data raw_pdf, filename: 'contacts.pdf' diff --git a/app/views/registrant/domains/download_list.html.erb b/app/views/registrant/domains/list_pdf.html.erb similarity index 74% rename from app/views/registrant/domains/download_list.html.erb rename to app/views/registrant/domains/list_pdf.html.erb index 9e1d39339..44a293493 100644 --- a/app/views/registrant/domains/download_list.html.erb +++ b/app/views/registrant/domains/list_pdf.html.erb @@ -15,12 +15,12 @@ - <% @domains.each do |x| %> + <% @domains.each do |domain| %> - <%= x.name %> - <%= x.registrant %> - <%= l(x.valid_to, format: :short) %> - <%= x.registrar %> + <%= domain.name %> + <%= domain.registrant %> + <%= l(domain.valid_to, format: :short) %> + <%= domain.registrar %> <% end %> diff --git a/app/views/registrar/contacts/download_list.html.erb b/app/views/registrar/contacts/list_pdf.html.erb similarity index 100% rename from app/views/registrar/contacts/download_list.html.erb rename to app/views/registrar/contacts/list_pdf.html.erb diff --git a/config/locales/registrant/domains.en.yml b/config/locales/registrant/domains.en.yml index a56d10b69..f59697915 100644 --- a/config/locales/registrant/domains.en.yml +++ b/config/locales/registrant/domains.en.yml @@ -8,7 +8,7 @@ en: download_csv_btn: Download CSV reset_btn: Reset - download_list: + list_pdf: registrant: Registrant partials: From 1374de89fed7384e63eebdbc7727aa966748c0d4 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 12 Oct 2019 18:01:48 +0300 Subject: [PATCH 6/7] Use default translations --- app/views/registrant/domains/list_pdf.html.erb | 8 ++++---- app/views/registrar/contacts/list_pdf.html.erb | 10 +++++----- config/locales/registrant/domains.en.yml | 3 --- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/views/registrant/domains/list_pdf.html.erb b/app/views/registrant/domains/list_pdf.html.erb index 44a293493..4ce4f5ed0 100644 --- a/app/views/registrant/domains/list_pdf.html.erb +++ b/app/views/registrant/domains/list_pdf.html.erb @@ -7,10 +7,10 @@ - - - - + + + + diff --git a/app/views/registrar/contacts/list_pdf.html.erb b/app/views/registrar/contacts/list_pdf.html.erb index 63ba9205c..b9bbb1c0e 100644 --- a/app/views/registrar/contacts/list_pdf.html.erb +++ b/app/views/registrar/contacts/list_pdf.html.erb @@ -7,11 +7,11 @@
<%= t(:name) %><%= t('.registrant') %><%= t(:valid_to) %><%= t(:registrar_name) %><%= Domain.human_attribute_name :name %><%= Registrant.model_name.human %><%= Domain.human_attribute_name :valid_to %><%= Registrar.model_name.human %>
- - - - - + + + + + diff --git a/config/locales/registrant/domains.en.yml b/config/locales/registrant/domains.en.yml index f59697915..1e02d00e1 100644 --- a/config/locales/registrant/domains.en.yml +++ b/config/locales/registrant/domains.en.yml @@ -8,9 +8,6 @@ en: download_csv_btn: Download CSV reset_btn: Reset - list_pdf: - registrant: Registrant - partials: registrant: header: Registrant From 90a90f335d5bfcd79cae267ab62d608733c6c83d Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 15 Oct 2019 19:02:04 +0300 Subject: [PATCH 7/7] Configure `pdfkit` gem --- config/initializers/pdfkit.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/initializers/pdfkit.rb b/config/initializers/pdfkit.rb index d7bbc64b8..eb0828729 100644 --- a/config/initializers/pdfkit.rb +++ b/config/initializers/pdfkit.rb @@ -6,7 +6,8 @@ PDFKit.configure do |config| config.wkhtmltopdf = installed config.default_options = { page_size: 'A4', - quiet: true + quiet: true, + encoding: 'utf-8', # :print_media_type => true } end
<%= t(:name) %><%= t(:id) %><%= t(:ident) %><%= t(:created_at) %><%= t(:registrar_name) %><%= Contact.human_attribute_name :name %><%= Contact.human_attribute_name :code %><%= Contact.human_attribute_name :ident %><%= Contact.human_attribute_name :created_at %><%= Registrar.model_name.human %>