diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index 36a8f76dc..4e2a7cb15 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -2,12 +2,14 @@ module Admin class RegistrarsController < BaseController load_and_authorize_resource before_action :set_registrar, only: [:show, :edit, :update, :destroy] + before_action :set_registrar_status_filter, only: [:index] helper_method :registry_vat_rate helper_method :iban_max_length def index - @q = Registrar.joins(:accounts).ordered.search(params[:q]) - @registrars = @q.result.page(params[:page]) + registrars = filter_by_status + @q = registrars.ransack(params[:q]) + @registrars = @q.result(distinct: true).page(params[:page]) @registrars = @registrars.per(params[:results_per_page]) if paginate? end @@ -31,8 +33,7 @@ module Admin end end - def edit; - end + def edit; end def update if @registrar.update(registrar_params) @@ -54,6 +55,21 @@ module Admin private + def filter_by_status + case params[:status] + when 'Active' + Registrar.includes(:accounts, :api_users).where.not(api_users: { id: nil }).ordered + when 'Inactive' + Registrar.includes(:accounts, :api_users).where(api_users: { id: nil }).ordered + else + Registrar.includes(:accounts, :api_users).ordered + end + end + + def set_registrar_status_filter + params[:status] ||= 'Active' + end + def set_registrar @registrar = Registrar.find(params[:id]) end diff --git a/app/views/admin/registrars/_search_form.html.erb b/app/views/admin/registrars/_search_form.html.erb new file mode 100644 index 000000000..4cfc447b2 --- /dev/null +++ b/app/views/admin/registrars/_search_form.html.erb @@ -0,0 +1,29 @@ +
+
+ <%= search_form_for @q, url: [:admin, :registrars], html: { style: 'margin-bottom: 0;' } do |f| %> +
+
+
+ <%= label_tag t(:status) %> + <%= select_tag :status, options_for_select(%w(Active Inactive), params[:status]), + { multiple: false, include_blank: true, selected: params[:status], class: 'form-control selectize'} %> +
+
+
+
+ <%= 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_registrars_path, class: 'btn btn-default') %> +
+
+ <% end %> +
+
diff --git a/app/views/admin/registrars/index.html.erb b/app/views/admin/registrars/index.html.erb index 23f29115c..610da71b9 100644 --- a/app/views/admin/registrars/index.html.erb +++ b/app/views/admin/registrars/index.html.erb @@ -10,7 +10,7 @@ -<%= render 'application/pagination' %> +<%= render 'search_form', search: @search %>
@@ -44,9 +44,11 @@ <%= x.reg_no %> - - <%= link_to "#{x.balance}", edit_admin_account_path(x.cash_account) %> - + <% if x.cash_account.present? %> + + <%= link_to "#{x.balance}", edit_admin_account_path(x.cash_account) %> + + <% end %> <%= "#{x.test_registrar}" %> @@ -69,7 +71,7 @@
diff --git a/config/locales/admin/registrars.en.yml b/config/locales/admin/registrars.en.yml index 59a999bd2..2f281a3b7 100644 --- a/config/locales/admin/registrars.en.yml +++ b/config/locales/admin/registrars.en.yml @@ -70,3 +70,7 @@ en: preferences: header: Preferences + + search_form: + download_btn: Download CSV + reset_btn: Reset