Module: EasyAdminUi::EasyAdminUiHelper
- Defined in:
- app/helpers/easy_admin_ui/easy_admin_ui_helper.rb
Instance Method Summary collapse
-
#admin_delete_link_with_confirmation(item, url_options = {}, options = {}) ⇒ Object
Use if below /admin/.
- #admin_edit_link(item, url_options = {}, html_options = {}) ⇒ Object
- #admin_new_link(url_options = {}, html_options = {}) ⇒ Object
- #admin_show_link(item, url_options = {}, html_options = {}) ⇒ Object
- #delete_icon_image_tag ⇒ Object
- #edit_icon_image_tag ⇒ Object
- #filename_from_partial(partial) ⇒ Object
- #items_to_url(item) ⇒ Object
- #my_table_end ⇒ Object
- #partial_exists?(filename) ⇒ Boolean
-
#render_optional(partial) ⇒ Object
Render partial if it exists.
-
#render_optional_either(*partials) ⇒ Object
Render the first partial it finds.
- #right_align(content) ⇒ Object
- #show_icon_image_tag ⇒ Object
- #table(items, columns, actions, options = {}, &block) ⇒ Object
- #table_head(columns, actions, options = {}) ⇒ Object
- #table_row(options = {}) ⇒ Object
Instance Method Details
#admin_delete_link_with_confirmation(item, url_options = {}, options = {}) ⇒ Object
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, = {}, = {}) 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' => [:hide_id]) end |
#admin_edit_link(item, url_options = {}, html_options = {}) ⇒ Object
79 80 81 |
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 79 def admin_edit_link(item, = {}, = {}) link_to(edit_icon_image_tag, eval("edit_#{items_to_url(item)}(*item, url_options)"), ) end |
#admin_new_link(url_options = {}, html_options = {}) ⇒ Object
74 75 76 77 |
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 74 def admin_new_link( = {}, = {}) content_tag(:span, raw(' - ') + link_to('New', {action: 'new'}.merge(), )) end |
#admin_show_link(item, url_options = {}, html_options = {}) ⇒ Object
70 71 72 |
# File 'app/helpers/easy_admin_ui/easy_admin_ui_helper.rb', line 70 def admin_show_link(item, = {}, = {}) link_to(show_icon_image_tag, eval("#{items_to_url(item)}(*item, url_options)"), ) end |
#delete_icon_image_tag ⇒ Object
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_tag ⇒ Object
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_end ⇒ Object
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
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_tag ⇒ Object
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, = {}, &block) ||= {} html = ''.html_safe html << table_head(columns, actions, ) html << render(:collection => items, :partial => [: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, = {}) [:class] ||= 'easy' html = ''.html_safe html << "<table class='#{[:class]}' id='#{[:id]}'>".html_safe html << content_tag(:thead, content_tag(:tr, ( columns.map do |title, th_class| th_class ||= [] content_tag(:th, [ if th_class.include?('sortable') content_tag(: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 ? content_tag(:th, '', :class => 'actions') : '') ) ) html << [:body_id] ? "<tbody id=\"#{[: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( = {}) [:actions] ||= [] content_tag(:tr, [ # Could pass: # # [category.created_at, {:class => '', :onmouseover => "javascript: blah"}] # [category.created_at, 'my_class_name'] # [:cells].map do |txt, cell_opts| cell_opts = {:class => cell_opts} if cell_opts.is_a?(String) cell_opts ||= {} content_tag(:td, txt, cell_opts) end, [:actions].blank? ? '' : content_tag(:td, [:actions].join(' ').html_safe, :class => "act") ].join(' ').html_safe, :id => [:id], :class => ["#{cyc = cycle("even", "odd")}", [:class]].join(' ')).html_safe end |