Use optional parameter to set column class
- Fixes the extremely long class name on the post versions view - Can now use one value instead of having to set th and td - Added missing column classes on all tables
This commit is contained in:
@@ -2,8 +2,9 @@ class TableBuilder
|
||||
class Column
|
||||
attr_reader :attribute, :name, :block, :header_attributes, :body_attributes
|
||||
|
||||
def initialize(attribute = nil, th: {}, td: {}, width: nil, name: nil, &block)
|
||||
def initialize(attribute = nil, column: nil, th: {}, td: {}, width: nil, name: nil, &block)
|
||||
@attribute = attribute
|
||||
@column = column
|
||||
@header_attributes = { width: width, **th }
|
||||
@body_attributes = td
|
||||
@block = block
|
||||
@@ -11,8 +12,12 @@ class TableBuilder
|
||||
@name = name || attribute
|
||||
@name = @name.to_s.titleize unless @name.is_a?(String)
|
||||
|
||||
if @name.present?
|
||||
column_class = "#{@name.parameterize.dasherize}-column"
|
||||
if @name.present? || @column.present?
|
||||
if @column.present?
|
||||
column_class = "#{@column}-column"
|
||||
else
|
||||
column_class = "#{@name.parameterize.dasherize}-column"
|
||||
end
|
||||
@header_attributes[:class] = "#{column_class} #{@header_attributes[:class]}".strip
|
||||
@body_attributes[:class] = "#{column_class} #{@body_attributes[:class]}".strip
|
||||
end
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<%= compact_time commentary_version.updated_at %>
|
||||
<% end %>
|
||||
<% if artist_commentary_versions_listing_type == :revert %>
|
||||
<% t.column width: "7%" do |commentary_version| %>
|
||||
<% t.column column: "control", width: "7%" do |commentary_version| %>
|
||||
<%= link_to "Revert to", revert_artist_commentary_path(commentary_version.post_id, :version_id => commentary_version.id), :remote => true, :method => :put, :data => {:confirm => "Are you sure you want to revert to this version?"} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
</p>
|
||||
<% end %>
|
||||
<% if artist_versions_listing_type == :revert %>
|
||||
<% t.column do |artist_version| %>
|
||||
<% t.column column: "control" do |artist_version| %>
|
||||
<%= link_to "Revert to", revert_artist_path(artist_version.artist_id, version_id: artist_version.id), method: :put, "data-confirm": "Are you sure you want to revert to this version?" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<% t.column "Updated" do |artist| %>
|
||||
<%= time_ago_in_words_tagged(artist.updated_at) %>
|
||||
<% end %>
|
||||
<% t.column do |artist| %>
|
||||
<% t.column column: "control" do |artist| %>
|
||||
<% if CurrentUser.is_member? %>
|
||||
<%= link_to "Edit", edit_artist_path(artist) %>
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<%= link_to "»", bans_path(search: { banner_name: ban.banner.name }) %>
|
||||
<div><%= time_ago_in_words_tagged(ban.created_at) %></div>
|
||||
<% end %>
|
||||
<% t.column do |ban| %>
|
||||
<% t.column column: "control" do |ban| %>
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<%= link_to "Edit", edit_ban_path(ban) %>
|
||||
| <%= link_to "Delete", ban_path(ban), :method => :delete, :remote => true %>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<%= link_to "»", bulk_update_requests_path(search: { user_name: request.user.name }) %>
|
||||
<div><%= time_ago_in_words_tagged(request.created_at) %></div>
|
||||
<% end %>
|
||||
<% t.column do |request| %>
|
||||
<% t.column column: "control" do |request| %>
|
||||
<%= link_to "Show", bulk_update_request_path(request) %> |
|
||||
<%= render "bulk_update_requests/bur_edit_links", bur: request %>
|
||||
<% end %>
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<%= link_to "»", comment_votes_path(search: { user_name: vote.user.name }) %>
|
||||
<div><%= time_ago_in_words_tagged(vote.created_at) %></div>
|
||||
<% end %>
|
||||
<% t.column do |vote| %>
|
||||
<% t.column column: "control" do |vote| %>
|
||||
<% if vote.user == CurrentUser.user %>
|
||||
<%= link_to "unvote", comment_comment_votes_path(vote.comment), remote: true, method: :delete %>
|
||||
<% end %>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<% t.column "Run at" do |job| %>
|
||||
<%= time_ago_in_words_tagged(job.run_at) %>
|
||||
<% end %>
|
||||
<% t.column do |job| %>
|
||||
<% t.column column: "control" do |job| %>
|
||||
<% if CurrentUser.is_admin? %>
|
||||
<% if job.locked_at? %>
|
||||
Running
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<%= link_to "»", forum_post_votes_path(search: { creator_name: forum_post_vote.creator.name }) %>
|
||||
<div><%= time_ago_in_words_tagged(forum_post_vote.created_at) %></div>
|
||||
<% end %>
|
||||
<% t.column do |forum_post_vote| %>
|
||||
<% t.column column: "control" do |forum_post_vote| %>
|
||||
<% if forum_post_vote.creator == CurrentUser.user %>
|
||||
<%= link_to "unvote", forum_post_vote_path(forum_post_vote, format: "js"), remote: true, method: :delete %>
|
||||
<% end %>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<% t.column "Date" do |ip| %>
|
||||
<%= time_ago_in_words_tagged ip.created_at %>
|
||||
<% end %>
|
||||
<% t.column do |ip| %>
|
||||
<% t.column column: "ip-info" do |ip| %>
|
||||
<%= link_to "IP info", "https://ipinfo.io/#{ip.ip_addr}" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<% t.column "Uses" do |ip| %>
|
||||
<%= link_to ip.count_all, ip_addresses_path(search: { ip_addr: ip.to_s }) %>
|
||||
<% end %>
|
||||
<% t.column "" do |ip| %>
|
||||
<% t.column column: "ip-info" do |ip| %>
|
||||
<%= link_to "IP info", "https://ipinfo.io/#{ip.ip_addr}" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<%= link_to_user ip_ban.creator %>
|
||||
<% end %>
|
||||
<% t.column :reason %>
|
||||
<% t.column do |ip_ban| %>
|
||||
<% t.column column: "control" do |ip_ban| %>
|
||||
<%= link_to "Unban", ip_ban_path(ip_ban), :remote => true, :method => :delete, :data => {:confirm => "Do your really want to unban #{ip_ban.ip_addr}?"} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<%= link_to_user news_update.creator %>
|
||||
<% end %>
|
||||
<% t.column :message %>
|
||||
<% t.column do |news_update| %>
|
||||
<% t.column column: "control" do |news_update| %>
|
||||
<%= link_to "Edit", edit_news_update_path(news_update) %>
|
||||
| <%= link_to "Delete", news_update_path(news_update), :method => :delete %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div id="p-<%= note_versions_listing_type %>-listing">
|
||||
|
||||
<%= table_for @note_versions, {class: "striped autofit", width: "100%"} do |t| %>
|
||||
<% t.column %>
|
||||
<% t.column column: "empty" %>
|
||||
<% t.column "Post", {width: "5%"} do |note_version| %>
|
||||
<%= link_to note_version.post_id, post_path(note_version.post_id) %>
|
||||
<% if params.dig(:search, :note_id).present? %>
|
||||
@@ -31,7 +31,7 @@
|
||||
<%= compact_time note_version.updated_at %>
|
||||
<% end %>
|
||||
<% if note_versions_listing_type == :revert %>
|
||||
<% t.column "", {width: "7%"} do |note_version| %>
|
||||
<% t.column column: "control", width: "7%" do |note_version| %>
|
||||
<%= link_to "Revert to", revert_note_path(note_version.note_id, :version_id => note_version.id), :remote => true, :method => :put, :data => {:confirm => "Are you sure you want to revert to this version?"} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div id="p-<%= pool_versions_listing_type %>-listing">
|
||||
|
||||
<%= table_for @pool_versions, {class: "striped autofit", width: "100%"} do |t| %>
|
||||
<% t.column th: {width: "3%"} do |pool_version| %>
|
||||
<% t.column column: "diff", width: "3%" do |pool_version| %>
|
||||
<%= link_to_if pool_version.previous.present?, "diff", diff_pool_version_path(pool_version.id) %>
|
||||
<% end %>
|
||||
<% t.column "Pool" do |pool_version| %>
|
||||
@@ -27,7 +27,7 @@
|
||||
<%= compact_time pool_version.updated_at %>
|
||||
<% end %>
|
||||
<% if pool_versions_listing_type == :revert %>
|
||||
<% t.column do |pool_version| %>
|
||||
<% t.column column: "control" do |pool_version| %>
|
||||
<%= link_to "Revert to", revert_pool_path(pool_version.pool_id, :version_id => pool_version.id), :method => :put, :remote => true %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<%= table_for @post_versions, {id: "post-versions-table", class: "striped autofit"} do |t| %>
|
||||
<% if CurrentUser.user.is_builder? %>
|
||||
<% t.column tag.label(tag.input type: :checkbox, id: "post-version-select-all-checkbox", class: "post-version-select-checkbox"), th: { class: "post-version-select-column" }, td: { class: "post-version-select-column" } do |post_version| %>
|
||||
<% t.column tag.label(tag.input type: :checkbox, id: "post-version-select-all-checkbox", class: "post-version-select-checkbox"), column: "post-version-select" do |post_version| %>
|
||||
<input type="checkbox" class="post-version-select-checkbox" <%= "disabled" unless post_version.can_undo?(CurrentUser.user) %>>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<%= link_to "»", post_votes_path(search: { user_name: vote.user.name }) %>
|
||||
<div><%= time_ago_in_words_tagged(vote.created_at) %></div>
|
||||
<% end %>
|
||||
<% t.column do |vote| %>
|
||||
<% t.column column: "control" do |vote| %>
|
||||
<% if vote.user == CurrentUser.user %>
|
||||
<%= link_to "unvote", post_post_votes_path(vote.post), remote: true, method: :delete %>
|
||||
<% end %>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<% t.column "Status", {width: "5%"} do |tag_alias| %>
|
||||
<span id="tag-alias-status-for-<%= tag_alias.id %>"><%= tag_alias.status %></span>
|
||||
<% end %>
|
||||
<% t.column width: "15%" do |tag_alias| %>
|
||||
<% t.column column: "control", width: "15%" do |tag_alias| %>
|
||||
<%= link_to "Show", tag_alias_path(tag_alias) %>
|
||||
|
||||
<% if tag_alias.is_pending? && tag_alias.editable_by?(CurrentUser.user) %>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<% t.column "Status", {width: "5%"} do |tag_implication| %>
|
||||
<span id="tag-implication-status-for-<%= tag_implication.id %>"><%= tag_implication.status %></span>
|
||||
<% end %>
|
||||
<% t.column width: "15%" do |tag_implication| %>
|
||||
<% t.column column: "control", width: "15%" do |tag_implication| %>
|
||||
<%= link_to "Show", tag_implication_path(tag_implication) %>
|
||||
|
||||
<% if tag_implication.is_pending? && tag_implication.editable_by?(CurrentUser.user) %>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<%= link_to_wiki "?", tag.name, class: "tag-type-#{tag.category}" %>
|
||||
<%= link_to tag.name, posts_path(tags: tag.name), class: "tag-type-#{tag.category}" %>
|
||||
<% end %>
|
||||
<% t.column do |tag| %>
|
||||
<% t.column column: "control" do |tag| %>
|
||||
<%= link_to_if tag.editable_by?(CurrentUser.user), "Edit", edit_tag_path(tag) %> |
|
||||
<%= link_to "History", post_versions_path(search: { changed_tags: tag.name }) %> |
|
||||
<%= link_to "Related", related_tag_path(search: { query: tag.name }) %> |
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<%= link_to "»", user_feedbacks_path(search: { creator_name: feedback.creator.name }) %>
|
||||
<div><%= time_ago_in_words_tagged(feedback.created_at) %></div>
|
||||
<% end %>
|
||||
<% t.column do |feedback| %>
|
||||
<% t.column column: "control" do |feedback| %>
|
||||
<% if feedback.editable_by?(CurrentUser.user) %>
|
||||
<%= link_to "edit", edit_user_feedback_path(feedback) %>
|
||||
<% if feedback.deletable_by?(CurrentUser.user) && !feedback.is_deleted? %>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<% t.column "Date" do |change_request| %>
|
||||
<%= compact_time change_request.created_at %>
|
||||
<% end %>
|
||||
<% t.column do |change_request| %>
|
||||
<% t.column column: "control" do |change_request| %>
|
||||
<%= link_to "view", user_name_change_request_path(change_request) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<h1>Users</h1>
|
||||
|
||||
<%= table_for @users, width: "100%" do |t| %>
|
||||
<% t.column do |user| %>
|
||||
<% t.column column: "control" do |user| %>
|
||||
<% if CurrentUser.is_admin? %>
|
||||
<%= link_to "Edit", edit_admin_user_path(user) %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<div id="p-<%= wiki_page_versions_listing_type %>-listing">
|
||||
<%= form_tag(diff_wiki_page_versions_path, :method => :get) do %>
|
||||
<%= table_for @wiki_page_versions, width: "100%" do |t| %>
|
||||
<% t.column width: "3%" do |wiki_page_version, i| %>
|
||||
<% t.column column: "diff", width: "3%" do |wiki_page_version, i| %>
|
||||
<%= link_to_if wiki_page_version.previous.present?, "diff", diff_wiki_page_versions_path(otherpage: wiki_page_version.previous.try(:id), thispage: wiki_page_version.id) %>
|
||||
<% end %>
|
||||
|
||||
<% if wiki_page_versions_listing_type == :page %>
|
||||
<% t.column width: "2%" do |wiki_page_version, i| %>
|
||||
<% t.column column: "this-page", width: "2%" do |wiki_page_version, i| %>
|
||||
<%= radio_button_tag "thispage", wiki_page_version.id, (i == 1) %>
|
||||
<% end %>
|
||||
<% t.column width: "2%" do |wiki_page_version, i| %>
|
||||
<% t.column column: "other-page", width: "2%" do |wiki_page_version, i| %>
|
||||
<%= radio_button_tag "otherpage", wiki_page_version.id, (i == 0) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user