Module: Admin::ApplicationHelper

Defined in:
app/helpers/admin/application_helper.rb

Constant Summary collapse

WHITE_LIST_PARAMS =

The following params will automatically be white listed for tabbed navigation

[:tab, :sort, :direction, :dir, :search, :id].freeze

Instance Method Summary collapse

Instance Method Details

#determine_fancy_timestmap(datetime) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/admin/application_helper.rb', line 11

def determine_fancy_timestmap(datetime)
  if Time.now() > datetime # in the past
    if Time.now() - datetime > 604800
      datetime.strftime('%B %d, %Y') + ' at ' + datetime.strftime('%I:%M %p')
    else
      time_ago_in_words(datetime) + ' ago'
    end
  elsif Time.now() < datetime # in the future
    datetime.strftime('%B %d, %Y') + ' at ' + datetime.strftime('%I:%M %p')
  else
    'Right now'
  end
end

#table_nesting_indicator(depth) ⇒ Object

Build an icon with left padding to indicate nesting below the previous table row



35
36
37
38
39
40
41
42
# File 'app/helpers/admin/application_helper.rb', line 35

def table_nesting_indicator(depth)
  if depth.positive?
    depth.times do
      concat (:span, '', class: 'nesting-spacer')
    end
    (:span, '', class: 'glyphicon glyphicon-chevron-right')
  end
end

#tb_core_tabbed_navigation(url_helper, tabs, white_list: []) ⇒ Object

Build a Bootstrap nav-tabs element

  • url_helper: A symbol representing the url helper method. ie: admin_widgets_path

  • tabs: An array of tab hashes with :title and :value keys

  • white_list: An array of param keys that should be allowed in the tabs. Optional.

Example:

<%= tb_core_tabbed_navigation(:admin_vehicles_path, [
  {:title => 'All'},
  {:title => 'New', :value => 'new'},
  {:title => 'Used', :value => 'used'}
], white_list: [:category_id]) %>

This would generate:

<ul class=“nav nav-tabs”>

<li class="active"><a href="/admin/vehicles">All</a></li>
<li class=""><a href="/admin/vehicles?tab=new">New</a></li>
<li class=""><a href="/admin/vehicles?tab=used">Used</a></li>

</ul>



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/admin/application_helper.rb', line 70

def tb_core_tabbed_navigation(url_helper, tabs, white_list: [])
  key = :tab
   :ul, class: 'nav nav-tabs' do
    tabs.each do |tab|
      cls = params[key] == tab[:value] ? 'active' : ''
      url = tab.delete(:url)
      if url.blank?
        link_args = params.permit(white_list.concat(WHITE_LIST_PARAMS)).merge(key => tab[:value])
        url = self.send(url_helper, link_args)
      end
      concat((:li, class: cls){ link_to tab[:title], url })
    end
  end
end

#timestamp(datetime = nil) ⇒ Object



3
4
5
6
7
8
9
# File 'app/helpers/admin/application_helper.rb', line 3

def timestamp(datetime=nil)
  return 'Never' if datetime.blank?

   :span,
    determine_fancy_timestmap(datetime),
    title: datetime
end

#url_for_admin_dashboard_application(url) ⇒ Object



25
26
27
28
29
30
31
# File 'app/helpers/admin/application_helper.rb', line 25

def url_for_admin_dashboard_application(url)
  if Rails.configuration.relative_url_root.blank?
    return url
  else
    return [Rails.configuration.relative_url_root, url].join('/').gsub(/(\/+)/, '/')
  end
end