Class: Admino::Query::FilterGroupPresenter

Inherits:
Showcase::Presenter
  • Object
show all
Defined in:
lib/admino/query/filter_group_presenter.rb

Instance Method Summary collapse

Instance Method Details

#each_scope(&block) ⇒ Object



33
34
35
# File 'lib/admino/query/filter_group_presenter.rb', line 33

def each_scope(&block)
  scopes.each(&block)
end

#nameObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/admino/query/filter_group_presenter.rb', line 72

def name
  I18n.t(
    :"#{query_i18n_key}.#{i18n_key}.name",
    scope: 'query.filter_groups',
    default: [
      :"#{i18n_key}.name",
      i18n_key.to_s.titleize.capitalize
    ]
  )
end


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/admino/query/filter_group_presenter.rb', line 12

def scope_link(scope, *args)
  options = args.extract_options!

  label = args.first || scope_name(scope)

  active_class = options.delete(:active_class) { 'is-active' }
  options = Showcase::Helpers::HtmlOptions.new(options)

  if is_scope_active?(scope)
    options.add_class!(active_class)
  end

  h.link_to label, scope_path(scope), options.to_h
end

#scope_name(scope) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/admino/query/filter_group_presenter.rb', line 61

def scope_name(scope)
  I18n.t(
    :"#{query_i18n_key}.#{i18n_key}.scopes.#{scope}",
    scope: 'query.filter_groups',
    default: [
      :"#{i18n_key}.scopes.#{scope}",
      scope.to_s.titleize
    ]
  )
end

#scope_params(scope) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/admino/query/filter_group_presenter.rb', line 41

def scope_params(scope)
  params = ActiveSupport::HashWithIndifferentAccess.new(
    h.request.query_parameters.deep_dup
  )

  params[:query] ||= {}

  if is_scope_active?(scope)
    params[:query].delete(param_name)
  else
    params[:query].merge!(param_name => scope.to_s)
  end

  if params[:query].empty?
    params.delete(:query)
  end

  params
end

#scope_path(scope) ⇒ Object



37
38
39
# File 'lib/admino/query/filter_group_presenter.rb', line 37

def scope_path(scope)
  h.request.path + "?" + scope_params(scope).to_query
end

#scopesObject



27
28
29
30
31
# File 'lib/admino/query/filter_group_presenter.rb', line 27

def scopes
  @scopes ||= super.map do |scope|
    ScopePresenter.new(scope, self, view_context)
  end
end