mirror of
https://github.com/internetee/registry.git
synced 2025-06-03 19:27:29 +02:00
added registrar status filter
This commit is contained in:
parent
b5b263f4b2
commit
83d896ec17
4 changed files with 60 additions and 9 deletions
|
@ -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
|
||||
|
|
29
app/views/admin/registrars/_search_form.html.erb
Normal file
29
app/views/admin/registrars/_search_form.html.erb
Normal file
|
@ -0,0 +1,29 @@
|
|||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<%= search_form_for @q, url: [:admin, :registrars], html: { style: 'margin-bottom: 0;' } do |f| %>
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<%= 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'} %>
|
||||
</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-3 text-right" style="padding-top: 25px;float: right;padding-right: 15px;">
|
||||
<button class="btn btn-default search">
|
||||
|
||||
<span class="glyphicon glyphicon-search"></span>
|
||||
|
||||
</button>
|
||||
<%= link_to(t('.reset_btn'), admin_registrars_path, class: 'btn btn-default') %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
|
@ -10,7 +10,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<%= render 'application/pagination' %>
|
||||
<%= render 'search_form', search: @search %>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
@ -44,9 +44,11 @@
|
|||
<td>
|
||||
<%= x.reg_no %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to "#{x.balance}", edit_admin_account_path(x.cash_account) %>
|
||||
</td>
|
||||
<% if x.cash_account.present? %>
|
||||
<td>
|
||||
<%= link_to "#{x.balance}", edit_admin_account_path(x.cash_account) %>
|
||||
</td>
|
||||
<% end %>
|
||||
<td>
|
||||
<%= "#{x.test_registrar}" %>
|
||||
</td>
|
||||
|
@ -69,7 +71,7 @@
|
|||
</div>
|
||||
<div class="col-md-6 text-right">
|
||||
<div class="pagination">
|
||||
<%= t(:result_count, count: @q.result.count) %>
|
||||
<%= t(:result_count, count: @registrars.total_count) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -70,3 +70,7 @@ en:
|
|||
|
||||
preferences:
|
||||
header: Preferences
|
||||
|
||||
search_form:
|
||||
download_btn: Download CSV
|
||||
reset_btn: Reset
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue