Module: AdminHelper

Defined in:
app/helpers/admin_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin_area?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'app/helpers/admin_helper.rb', line 54

def admin_area?
  request_parts.first == 'admin'
end

#admin_header_tag(record, &block) ⇒ Object



71
72
73
74
75
76
77
# File 'app/helpers/admin_helper.rb', line 71

def admin_header_tag(record, &block)
  record = record.first if record.respond_to?(:join)
   :div, capture(&block), class: "admin-header", data: {
    record_type: record&.class&.model_name&.singular,
    record_id: record.try(:id)
  }
end

#admin_navbar_active_class(nav_item_path) ⇒ Object



50
51
52
# File 'app/helpers/admin_helper.rb', line 50

def admin_navbar_active_class(nav_item_path)
  'active' if nav_item_path == request.path
end

#admin_navbar_classObject



38
39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/admin_helper.rb', line 38

def admin_navbar_class
  return unless (@page && @page.statusable?)

  # if @page.scheduled?
  #   'bg-info'
  # elsif [email protected]?
  #   'bg-warning'
  # end

  !@page.published?
end

#admin_page_level_indicator(level) ⇒ Object



34
35
36
# File 'app/helpers/admin_helper.rb', line 34

def admin_page_level_indicator(level)
  (level + 1).times.collect{}.join('— ').html_safe
end

#back_button(default_url) ⇒ Object



79
80
81
82
83
84
85
# File 'app/helpers/admin_helper.rb', line 79

def back_button(default_url)
  if request.referer.present?
    request.referer
  else
    default_url
  end
end

#forest_date(datetime) ⇒ Object



28
29
30
31
32
# File 'app/helpers/admin_helper.rb', line 28

def forest_date(datetime)
  return if datetime.blank?
  datetime_format = datetime.is_a?(Date) ? '%m‑%d‑%Y' : '%m‑%d‑%Y %l:%M %p'
  datetime.strftime(datetime_format).html_safe
end

#jquery_include_tagObject



87
88
89
90
91
92
93
94
# File 'app/helpers/admin_helper.rb', line 87

def jquery_include_tag
  if Rails.env.production?
    jquery_url = 'https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'
  else
    jquery_url = 'forest/lib/jquery-3.3.1.min'
  end
  javascript_include_tag jquery_url, data: { turbolinks_eval: false, turbolinks_suppress_warning: true }
end

#public_area?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/helpers/admin_helper.rb', line 58

def public_area?
  !admin_area?
end

#record_name(record) ⇒ Object



66
67
68
69
# File 'app/helpers/admin_helper.rb', line 66

def record_name(record)
  return unless record.present?
  record.try(:display_name).presence || record.try(:title).presence || record.try(:name).presence || "#{record.model_name.human} #{record.id}"
end

#request_partsObject



62
63
64
# File 'app/helpers/admin_helper.rb', line 62

def request_parts
  request.path.split('/').reject(&:blank?)
end

#table_color_representation(color) ⇒ Object



24
25
26
# File 'app/helpers/admin_helper.rb', line 24

def table_color_representation(color)
   :div, '', class: 'table-color-representation', style: "background-color: #{color};"
end

#table_sorter(options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/admin_helper.rb', line 2

def table_sorter(options = {})
  title = options.fetch :title
  path = options.fetch :path
  scope = options.fetch :scope
  default_order = options.fetch :default_order, :asc
  opposite_order = default_order == :asc ? :desc : :asc
  is_default_order = params[scope]&.to_sym == default_order
  active_class = params[scope].present? ? 'active ' : ''

  link_to title,
    send(path, "#{scope}": (is_default_order ? opposite_order : default_order)),
    class: "#{active_class}#{(is_default_order ? 'order--default' : 'order--reverse')}"
end

#table_thumbnail(image) ⇒ Object



16
17
18
19
20
21
22
# File 'app/helpers/admin_helper.rb', line 16

def table_thumbnail(image)
  if image&.attachment.present?
     :div, class: 'table-thumbnail' do
      image_tag image.attachment.url(:thumb)
    end
  end
end