/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
def all_row_attributes(item, i)
if !item.id.nil?
standard_attributes = { id: "#{item.model_name.singular.dasherize}-#{item.id}", "data-id": item.id }
else
standard_attributes = {}
end
return {} if !item.is_a?(ApplicationRecord)
if item.html_data_attributes.length > 0
class_attributes = ApplicationController.helpers.data_attributes_for(item, "data", item.html_data_attributes)
else
class_attributes = {}
end
standard_attributes.merge(class_attributes)
{
id: "#{item.model_name.singular.dasherize}-#{item.id}",
**ApplicationController.helpers.data_attributes_for(item, "data", item.html_data_attributes)
}
end
end

View File

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