Verified Commit cfb130e5 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

use ransack for filtering by models scopes

parent 2b6b8c27
......@@ -11,7 +11,6 @@ class ClientsController < ApplicationController
@q = policy_scope(Client).ransack(params[:q])
@q.sorts = ['created_at desc'] if @q.sorts.empty?
@clients = @q.result
activity_filter
respond_to do |format|
format.xlsx
format.html do
......@@ -81,9 +80,6 @@ class ClientsController < ApplicationController
private
def activity_filter
return unless params[:q] && params[:q][:active_eq]
@clients = params[:q][:active_eq] == 'true' ? @clients.active : @clients.inactive
end
def set_client
......
......@@ -5,6 +5,8 @@ class Client < ApplicationRecord
include ZuerichScopes
include ImportRelation
ransackable_scopes [:active, :inactive]
before_update :record_acceptance_change, if: :going_to_change_to_resigned?
enum acceptance: { accepted: 0, rejected: 1, resigned: 2 }
......@@ -109,6 +111,11 @@ class Client < ApplicationRecord
private
# allow ransack to use the scopes
def self.ransackable_scopes(auth_object = nil)
['active', 'inactive']
end
def going_to_change_to_resigned?
will_save_change_to_acceptance?(to: 'resigned')
end
......
......@@ -15,7 +15,7 @@ nav.navbar.navbar-top.hidden-print
- if policy(User).index?
li= link_to 'Benutzer/innen', users_path
- if policy(Client).index?
li= link_to 'Klienten/innen', clients_path(q: { acceptance_not_eq: 2 })
li= link_to 'Klienten/innen', clients_path
- if policy(Volunteer).index?
li= link_to 'Freiwillige', volunteers_path
- if policy(Department).manager_with_department?
......
......@@ -12,7 +12,9 @@ nav.navbar.section-navigation.hidden-print
= list_filter_dropdown(:salutation, Client::SALUTATIONS)
- if policy(Client).superadmin_privileges?
= enum_filter_dropdown(:acceptance, Client.acceptances)
= boolean_toggler_filter_dropdown(:active, 'Tandem', 'Aktiv', 'Inaktiv')
= custom_filter_dropdown('Tandem',
{ q: :active, text: 'Aktiv', value: 'true' },
{ q: :inactive, text: 'Inktiv', value: 'true' })
li= button_link t('clear_filters'), clients_path, dimension: :sm
li= button_link navigation_fa_icon(:xlsx), url_for(format: :xlsx, q: search_parameters), dimension: :sm
li= link_to navigation_glyph(:print), url_for(print: :true, q: search_parameters), { class: 'btn btn-default btn-sm', target: '_blank' }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment