Class: Admino::Query::GroupPresenter

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

Instance Method Summary collapse

Instance Method Details

#nameObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/admino/query/group_presenter.rb', line 54

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


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

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



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/admino/query/group_presenter.rb', line 42

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

#scope_params(scope) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/admino/query/group_presenter.rb', line 30

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

  if scope
    params.merge!(param_name => scope.to_s)
  else
    params.delete(param_name)
  end

  params
end

#scope_path(scope) ⇒ Object



26
27
28
# File 'lib/admino/query/group_presenter.rb', line 26

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