Module: EasyAdminUi::EasyAdminUiHelper

Defined in:
app/helpers/easy_admin_ui/easy_admin_ui_helper.rb

Instance Method Summary collapse

Instance Method Details

Use if below /admin/.



84
85
86
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 84

def admin_delete_link_with_confirmation(item, url_options = {}, options = {})
  link_to(delete_icon_image_tag, eval("#{items_to_url(item)}(*item, url_options)"), class: "admin_delete", 'data-id' => item.to_param.gsub('/', '_'), 'data-hide-id' => options[:hide_id])
end


79
80
81
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 79

def admin_edit_link(item, url_options = {}, html_options = {})
  link_to(edit_icon_image_tag, eval("edit_#{items_to_url(item)}(*item, url_options)"), html_options)
end


74
75
76
77
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 74

def admin_new_link(url_options = {}, html_options = {})
  (:span, raw(' - ') +
    link_to('New', {action: 'new'}.merge(url_options), html_options))
end


70
71
72
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 70

def admin_show_link(item, url_options = {}, html_options = {})
  link_to(show_icon_image_tag, eval("#{items_to_url(item)}(*item, url_options)"), html_options)
end

#delete_icon_image_tagObject



138
139
140
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 138

def delete_icon_image_tag
  image_tag('easy_admin_ui/delete.png')
end

#edit_icon_image_tagObject



134
135
136
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 134

def edit_icon_image_tag
  image_tag("easy_admin_ui/pencil.png")
end

#filename_from_partial(partial) ⇒ Object



108
109
110
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 108

def filename_from_partial(partial)
  "_#{partial}.html.erb"
end

#items_to_url(item) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 88

def items_to_url(item)
  "admin_" +
  if item.is_a?(Array)
    item.map { |obj|
      if obj.new_record?
        obj.class.to_s.pluralize.underscore
      else
        obj.class.to_s.singularize.underscore
      end
    }.join('_')
  else
    item.class.to_s.underscore.singularize.to_s
  end +
  "_path"
end

#my_table_endObject



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

def my_table_end
  '</tbody></table>'.html_safe
end

#partial_exists?(filename) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 104

def partial_exists?(filename)
  ActionController::Base.view_paths.any? {|path| File.exists?(File.join(path, self.controller_path, filename)) }
end

#render_optional(partial) ⇒ Object

Render partial if it exists.



113
114
115
116
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 113

def render_optional(partial)
  return '' unless partial_exists?(filename_from_partial(partial))
  render partial: partial
end

#render_optional_either(*partials) ⇒ Object

Render the first partial it finds.



119
120
121
122
123
124
125
126
127
128
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 119

def render_optional_either(*partials)
  ''.tap do |html|
    partials.each do |partial|
      if partial_exists?(filename_from_partial(partial))
        html << render(partial: partial)
        break
      end
    end
  end.html_safe
end

#right_align(content) ⇒ Object



66
67
68
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 66

def right_align(content)
  [content, 'aright']
end

#show_icon_image_tagObject



130
131
132
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 130

def show_icon_image_tag
  image_tag("easy_admin_ui/show.png")
end

#table(items, columns, actions, options = {}, &block) ⇒ Object



3
4
5
6
7
8
9
10
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 3

def table(items, columns, actions, options = {}, &block)
  options ||= {}
  html = ''.html_safe
  html << table_head(columns, actions, options)
  html << render(:collection => items, :partial => options[:partial])
  html << my_table_end
  html
end

#table_head(columns, actions, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 12

def table_head(columns, actions, options = {})
  options[:class] ||= 'easy'
  html = ''.html_safe
  html << "<table class='#{options[:class]}' id='#{options[:id]}'>".html_safe
  html <<
    (:thead,
      (:tr, (
          columns.map do |title, th_class|
            th_class ||= []
            (:th,
              [
                if th_class.include?('sortable')
                  (:div,
                    link_to('', '#', :class => 'sort_up') +
                    link_to('', '#', :class => 'sort_down'),
                    {:class => 'sort'})
                else
                  nil
                end,
                title
              ].compact.join('').html_safe,
              :class => th_class)
          end
        ).join('').html_safe + (actions ? (:th, '', :class => 'actions') : '')
      )
    )
  html << options[:body_id] ? "<tbody id=\"#{options[:body_id]}\">" : '<tbody>'
  html
end

#table_row(options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 42

def table_row(options = {})
  options[:actions] ||= []

  (:tr,
    [
      # Could pass:
      #
      # [category.created_at, {:class => '', :onmouseover => "javascript: blah"}]
      # [category.created_at, 'my_class_name']
      #
      options[:cells].map do |txt, cell_opts|
        cell_opts = {:class => cell_opts} if cell_opts.is_a?(String)
        cell_opts ||= {}
        (:td, txt, cell_opts)
      end,
      options[:actions].blank? ? '' : (:td, options[:actions].join(' ').html_safe, :class => "act")
    ].join(' ').html_safe,
    :id => options[:id], :class => ["#{cyc = cycle("even", "odd")}", options[:class]].join(' ')).html_safe
end