From cdb42aad6675c59a5e5cdc088ec0d59d11a8a319 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 7 Jan 2020 01:16:37 -0600 Subject: [PATCH] /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). --- app/logical/table_builder.rb | 17 +++------- app/views/post_events/index.html.erb | 46 ++++++++++------------------ 2 files changed, 21 insertions(+), 42 deletions(-) diff --git a/app/logical/table_builder.rb b/app/logical/table_builder.rb index ccda7e0b3..c5a2398bb 100644 --- a/app/logical/table_builder.rb +++ b/app/logical/table_builder.rb @@ -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 diff --git a/app/views/post_events/index.html.erb b/app/views/post_events/index.html.erb index ef8a24f22..57effc0af 100644 --- a/app/views/post_events/index.html.erb +++ b/app/views/post_events/index.html.erb @@ -2,36 +2,22 @@

Post Events

- - - - - - - - - - - <% @events.each do |event| %> - - - - - - + <%= 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 %> + hidden <% end %> - -
TypeUserDescriptionResolved?
<%= event.type_name %> - <% if event.is_creator_visible? %> - <%= link_to_user event.creator %> - <% else %> - hidden - <% end %> -
<%= time_ago_in_words_tagged event.created_at %> -
-
- <%= format_text event.reason %> -
-
<%= event.is_resolved %>
+
<%= time_ago_in_words_tagged event.created_at %> + <% end %> + <% t.column "Description", {}, { class: "col-expand" } do |event| %> +
+ <%= format_text event.reason %> +
+ <% end %> + <% t.column :is_resolved, {}, name: "Resolved" %> + <% end %>