Class: Admino::Query::SortingPresenter
- Inherits:
-
Showcase::Presenter
- Object
- Showcase::Presenter
- Admino::Query::SortingPresenter
- Defined in:
- lib/admino/query/sorting_presenter.rb
Instance Method Summary collapse
- #scope_link(scope, *args) ⇒ Object
- #scope_name(scope) ⇒ Object
- #scope_params(scope) ⇒ Object
- #scope_path(scope) ⇒ Object
- #scopes ⇒ Object
Instance Method Details
#scope_link(scope, *args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/admino/query/sorting_presenter.rb', line 7 def scope_link(scope, *args) = args. label = args.first || scope_name(scope) desc_class = .delete(:desc_class) { 'is-desc' } asc_class = .delete(:asc_class) { 'is-asc' } = Showcase::Helpers::HtmlOptions.new() if is_scope_active?(scope) .add_class!(ascending? ? asc_class : desc_class) end h.link_to label, scope_path(scope), .to_h end |
#scope_name(scope) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/admino/query/sorting_presenter.rb', line 50 def scope_name(scope) I18n.t( :"#{query_i18n_key}.#{scope}", scope: 'query.sorting_scopes', default: scope.to_s.titleize.capitalize ) end |
#scope_params(scope) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/admino/query/sorting_presenter.rb', line 34 def scope_params(scope) params = ActiveSupport::HashWithIndifferentAccess.new( h.request.query_parameters.deep_dup ) if is_scope_active?(scope) params.merge!(sorting: scope.to_s, sort_order: ascending? ? 'desc' : 'asc') elsif default_scope == scope params.merge!(sorting: scope.to_s, sort_order: default_direction.to_s) else params.merge!(sorting: scope.to_s, sort_order: 'asc') end params end |
#scope_path(scope) ⇒ Object
24 25 26 |
# File 'lib/admino/query/sorting_presenter.rb', line 24 def scope_path(scope) h.request.path + "?" + scope_params(scope).to_query end |
#scopes ⇒ Object
28 29 30 31 32 |
# File 'lib/admino/query/sorting_presenter.rb', line 28 def scopes @scopes ||= super.map do |scope| ScopePresenter.new(scope, self, view_context) end end |