/post_events: convert to table builder.

Also fix TableBuilder#all_row_attributes to work with objects that don't
inherit from ApplicationRecord (and therefore don't have an id or model name).
This commit is contained in:
evazion
2020-01-07 01:16:37 -06:00
parent ab4af3c410
commit cdb42aad66
2 changed files with 21 additions and 42 deletions

View File

@@ -36,18 +36,11 @@ class TableBuilder
end end
def all_row_attributes(item, i) def all_row_attributes(item, i)
if !item.id.nil? return {} if !item.is_a?(ApplicationRecord)
standard_attributes = { id: "#{item.model_name.singular.dasherize}-#{item.id}", "data-id": item.id }
else
standard_attributes = {}
end
if item.html_data_attributes.length > 0 {
class_attributes = ApplicationController.helpers.data_attributes_for(item, "data", item.html_data_attributes) id: "#{item.model_name.singular.dasherize}-#{item.id}",
else **ApplicationController.helpers.data_attributes_for(item, "data", item.html_data_attributes)
class_attributes = {} }
end
standard_attributes.merge(class_attributes)
end end
end end

View File

@@ -2,36 +2,22 @@
<div id="a-index"> <div id="a-index">
<h1>Post Events</h1> <h1>Post Events</h1>
<table width="100%" class="striped autofit"> <%= table_for @events, class: "striped autofit", width: "100%" do |t| %>
<thead> <% t.column :type_name, nil, { name: "Type" } %>
<tr> <% t.column "User" do |event| %>
<th>Type</th> <% if event.is_creator_visible? %>
<th>User</th> <%= link_to_user event.creator %>
<th>Description</th> <% else %>
<th>Resolved?</th> <i>hidden</i>
</tr>
</thead>
<tbody>
<% @events.each do |event| %>
<tr class="resolved-<%= event.is_resolved %>">
<td><%= event.type_name %></td>
<td>
<% if event.is_creator_visible? %>
<%= link_to_user event.creator %>
<% else %>
<i>hidden</i>
<% end %>
<br><%= time_ago_in_words_tagged event.created_at %>
</td>
<td class="col-expand">
<div class="prose">
<%= format_text event.reason %>
</div>
</td>
<td><%= event.is_resolved %></td>
</tr>
<% end %> <% end %>
</tbody> <br><%= time_ago_in_words_tagged event.created_at %>
</table> <% end %>
<% t.column "Description", {}, { class: "col-expand" } do |event| %>
<div class="prose">
<%= format_text event.reason %>
</div>
<% end %>
<% t.column :is_resolved, {}, name: "Resolved" %>
<% end %>
</div> </div>
</div> </div>