Class: Para::Markup::ResourcesTable
- Defined in:
- lib/para/markup/resources_table.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#orderable ⇒ Object
readonly
Returns the value of attribute orderable.
Attributes inherited from Component
Instance Method Summary collapse
- #actions_cell(resource) ⇒ Object
- #clone_button(resource) ⇒ Object
- #container(options = {}, &block) ⇒ Object
-
#data_for(*args, &block) ⇒ Object
Data for can accept 2 versions of arguments :.
- #delete_button(resource) ⇒ Object
- #edit_button(resource) ⇒ Object
- #header(&block) ⇒ Object
- #header_for(field_name = nil, options = {}, &block) ⇒ Object
- #order_cell(resource) ⇒ Object
- #row(resource, &block) ⇒ Object
- #rows(resources, &block) ⇒ Object
Methods inherited from Component
Constructor Details
This class inherits a constructor from Para::Markup::Component
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
7 8 9 |
# File 'lib/para/markup/resources_table.rb', line 7 def actions @actions end |
#component ⇒ Object (readonly)
Returns the value of attribute component.
7 8 9 |
# File 'lib/para/markup/resources_table.rb', line 7 def component @component end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/para/markup/resources_table.rb', line 7 def model @model end |
#orderable ⇒ Object (readonly)
Returns the value of attribute orderable.
7 8 9 |
# File 'lib/para/markup/resources_table.rb', line 7 def orderable @orderable end |
Instance Method Details
#actions_cell(resource) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/para/markup/resources_table.rb', line 133 def actions_cell(resource) content_tag(:td, class: 'table-row-actions') do actions.map do |type| send(:"#{ type }_button", resource) end.compact.join.html_safe end end |
#clone_button(resource) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/para/markup/resources_table.rb', line 141 def (resource) return unless resource.class.cloneable? path = component.relation_path( resource, action: :clone, return_to: view.request.fullpath ) = { method: :post, class: 'btn btn-sm btn-icon-info btn-shadow hint--left', aria: { label: ::I18n.t('para.shared.copy') } } view.link_to(path, ) do content_tag(:i, '', class: 'fa fa-copy') end end |
#container(options = {}, &block) ⇒ Object
9 10 11 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 |
# File 'lib/para/markup/resources_table.rb', line 9 def container( = {}, &block) @model = .delete(:model) @component = .delete(:component) if !.key?(:orderable) || .delete(:orderable) @orderable = model.orderable? end @actions = build_actions(.delete(:actions)) merge_class!(, 'table') merge_class!(, 'para-component-relation-table') merge_class!(, 'table-hover') if .fetch(:hover, true) if orderable merge_class!(, 'orderable') [:data] ||= {} [:data][:'order-url'] = component.relation_path(model.model_name.route_key, action: :order) end table = content_tag(:table, ) do capture { block.call(self) } end if .fetch(:responsive, true) content_tag(:div, table, class: 'table-responsive') else table end end |
#data_for(*args, &block) ⇒ Object
Data for can accept 2 versions of arguments :
- resource, field_name, type : cell value will be retrieved from
the field_value_for helper
- a single value : The value to display in the cell directly
which will be processed to be shorter than 100 chars
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/para/markup/resources_table.rb', line 109 def data_for(*args, &block) value = if args.length >= 2 resource, field_name, type = args view.field_value_for(resource, field_name, type).to_s elsif block capture { block.call } else view.excerpt_value_for(args.first) end content_tag(:td) do value end end |
#delete_button(resource) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/para/markup/resources_table.rb', line 171 def (resource) path = component.relation_path(resource) = { method: :delete, data: { confirm: ::I18n.t('para.list.delete_confirmation') }, class: 'btn btn-sm btn-icon-danger btn-shadow hint--left', aria: { label: ::I18n.t('para.shared.destroy') } } view.link_to(path, ) do content_tag(:i, '', class: 'fa fa-times') end end |
#edit_button(resource) ⇒ Object
161 162 163 164 165 166 167 168 169 |
# File 'lib/para/markup/resources_table.rb', line 161 def (resource) path = component.relation_path( resource, action: :edit, return_to: view.request.fullpath ) view.link_to(path, class: 'btn btn-sm btn-icon-primary btn-shadow hint--left', aria: { label: ::I18n.t('para.shared.edit') }) do content_tag(:i, '', class: 'fa fa-pencil') end end |
#header(&block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/para/markup/resources_table.rb', line 40 def header(&block) cells = [] # Add orderable empty header cells << content_tag(:th, '') if orderable # Append cells cells << capture { block.call } # Append actions empty cell cells << content_tag(:th, '', class: 'table-row-actions') if actions # Output full header content_tag(:thead) do content_tag(:tr, cells.join("\n").html_safe) end end |
#header_for(field_name = nil, options = {}, &block) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/para/markup/resources_table.rb', line 76 def header_for(field_name = nil, = {}, &block) if Hash === field_name = field_name field_name = nil end label = if Symbol === field_name model.human_attribute_name(field_name) elsif block capture { block.call } else field_name end content_tag(:th, ) do if (sort = .delete(:sort)) view.sort_link(search, *sort, label, hide_indicator: true) elsif searchable?(field_name) view.sort_link(search, field_name, label, hide_indicator: true) else label end end end |
#order_cell(resource) ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/para/markup/resources_table.rb', line 124 def order_cell(resource) order_cell = content_tag(:td) do view.reorder_anchor( value: resource.position, data: { id: resource.id } ) end end |
#row(resource, &block) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/para/markup/resources_table.rb', line 64 def row(resource, &block) cells = [] # Add orderable cell with "move" thumb cells << order_cell(resource) if orderable # Add data cells cells << capture { block.call(resource) } # Add actions links to the last cell cells << actions_cell(resource) if actions cells.join("\n").html_safe end |
#rows(resources, &block) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/para/markup/resources_table.rb', line 55 def rows(resources, &block) rows = resources.each_with_object(ActiveSupport::SafeBuffer.new('')) do |resource, buffer| buffer << content_tag(:tr, row(resource, &block)) end # Output full header content_tag(:tbody, rows) end |