Use bootstrap table striping to replace hand-cycled table stripes

This cuts down on the complexity of having to use the `cycle` function
and makes the templates easier to read. CSS-based striping has been
around for many years.

The CSS is in order to keep our custom colour for striped tables.
This commit is contained in:
Andy Allan 2020-03-18 11:27:36 +01:00
parent b0c50ab344
commit 5fdada204c
9 changed files with 22 additions and 33 deletions

View file

@ -2048,16 +2048,11 @@ a.button {
} }
} }
/* Rules for doing distinct colour of alternate table rows */ /* Customise the background colour of striped tables */
.table0, .table-striped > tbody > tr:nth-child(2n+1) > td,
.item0 { .table-striped > tbody > tr:nth-child(2n+1) > th {
background: $offwhite; background-color: $offwhite;
}
.table1,
.item1 {
background: #fff;
} }
/* Rules for OpenID logo */ /* Rules for OpenID logo */

View file

@ -2,7 +2,7 @@
<h1><%= t(".has_commented_on", :display_name => @user.display_name) %></h1> <h1><%= t(".has_commented_on", :display_name => @user.display_name) %></h1>
<% end %> <% end %>
<table class="messages" width="100%"> <table class="table table-striped" width="100%">
<thead> <thead>
<tr> <tr>
<th width="25%"><%= t ".post" %></th> <th width="25%"><%= t ".post" %></th>
@ -11,8 +11,7 @@
</tr> </tr>
</thead> </thead>
<% @comments.each do |comment| -%> <% @comments.each do |comment| -%>
<% cl = cycle("table0", "table1") %> <tr class="<%= "deemphasize" unless comment.visible? %>">
<tr class="<%= cl %><%= " deemphasize" unless comment.visible? %>">
<td width="25%"><%= link_to comment.diary_entry.title, diary_entry_path(comment.diary_entry.user, comment.diary_entry) %></td> <td width="25%"><%= link_to comment.diary_entry.title, diary_entry_path(comment.diary_entry.user, comment.diary_entry) %></td>
<td width="25%"><span title="<%= l comment.created_at, :format => :friendly %>"><%= time_ago_in_words(comment.created_at, :scope => :'datetime.distance_in_words_ago') %></span></td> <td width="25%"><span title="<%= l comment.created_at, :format => :friendly %>"><%= time_ago_in_words(comment.created_at, :scope => :'datetime.distance_in_words_ago') %></span></td>
<td width="50%" class="richtext"><%= comment.body.to_html %></td> <td width="50%" class="richtext"><%= comment.body.to_html %></td>

View file

@ -1,6 +1,5 @@
<tr> <tr>
<% cl = cycle("table0", "table1") %> <td>
<td class="<%= cl %>">
<% if Settings.status != "gpx_offline" %> <% if Settings.status != "gpx_offline" %>
<% if trace.inserted %> <% if trace.inserted %>
<a href="<%= url_for :controller => "traces", :action => "show", :id => trace.id, :display_name => trace.user.display_name %>"><img src="<%= url_for :controller => "traces", :action => "icon", :id => trace.id, :display_name => trace.user.display_name %>" border="0" alt="" /></a> <a href="<%= url_for :controller => "traces", :action => "show", :id => trace.id, :display_name => trace.user.display_name %>"><img src="<%= url_for :controller => "traces", :action => "icon", :id => trace.id, :display_name => trace.user.display_name %>" border="0" alt="" /></a>
@ -9,7 +8,7 @@
<% end %> <% end %>
<% end %> <% end %>
</td> </td>
<td class="<%= cl %>"><%= link_to trace.name, :controller => "traces", :action => "show", :display_name => trace.user.display_name, :id => trace.id %> <td><%= link_to trace.name, :controller => "traces", :action => "show", :display_name => trace.user.display_name, :id => trace.id %>
<span class="trace_summary" title="<%= trace.timestamp %>"> ... <span class="trace_summary" title="<%= trace.timestamp %>"> ...
<% if trace.inserted %> <% if trace.inserted %>
(<%= t ".count_points", :count => trace.size %>) (<%= t ".count_points", :count => trace.size %>)

View file

@ -25,7 +25,7 @@
<% if @traces.size > 0 %> <% if @traces.size > 0 %>
<%= render :partial => "trace_paging_nav" %> <%= render :partial => "trace_paging_nav" %>
<table id="trace_list" cellpadding="3"> <table id="trace_list" class="table table-borderless table-striped">
<thead> <thead>
<tr> <tr>
<th></th> <th></th>

View file

@ -1,24 +1,22 @@
<tr> <tr>
<% c1 = cycle("table0", "table1") %>
<% if show_user_name %> <% if show_user_name %>
<td class="<%= c1 %>"><%= link_to h(block.user.display_name), user_path(block.user) %></td> <td><%= link_to h(block.user.display_name), user_path(block.user) %></td>
<% end %> <% end %>
<% if show_creator_name %> <% if show_creator_name %>
<td class="<%= c1 %>"><%= link_to h(block.creator.display_name), user_path(block.creator) %></td> <td><%= link_to h(block.creator.display_name), user_path(block.creator) %></td>
<% end %> <% end %>
<td class="<%= c1 %>"><%= h truncate(block.reason) %></td> <td><%= h truncate(block.reason) %></td>
<td class="<%= c1 %>"><%= h block_status(block) %></td> <td><%= h block_status(block) %></td>
<td class="<%= c1 %>"> <td>
<% if block.revoker_id.nil? %> <% if block.revoker_id.nil? %>
<%= t(".not_revoked") %> <%= t(".not_revoked") %>
<% else %> <% else %>
<%= link_to h(block.revoker.display_name), user_path(block.revoker) %> <%= link_to h(block.revoker.display_name), user_path(block.revoker) %>
<% end %> <% end %>
</td> </td>
<td class="<%= c1 %>"><%= link_to t(".show"), block %></td> <td><%= link_to t(".show"), block %></td>
<td class="<%= c1 %>"><% if current_user and current_user.id == block.creator_id and block.active? %><%= link_to t(".edit"), edit_user_block_path(block) %><% end %></td> <td><% if current_user and current_user.id == block.creator_id and block.active? %><%= link_to t(".edit"), edit_user_block_path(block) %><% end %></td>
<% if show_revoke_link %> <% if show_revoke_link %>
<td class="<%= c1 %>"><% if block.active? %><%= link_to t(".revoke"), :controller => "user_blocks", :action => "revoke", :id => block.id %><% end %></td> <td><% if block.active? %><%= link_to t(".revoke"), :controller => "user_blocks", :action => "revoke", :id => block.id %><% end %></td>
<% end %> <% end %>
</tr> </tr>

View file

@ -1,4 +1,4 @@
<table id="block_list" cellpadding="3"> <table id="block_list" class="table table-borderless table-striped table-sm">
<thead> <thead>
<tr> <tr>
<% if show_user_name %> <% if show_user_name %>

View file

@ -1,6 +1,4 @@
<% cl = cycle("table0", "table1") %> <tr>
<tr class="<%= cl %>">
<td> <td>
<%= user_thumbnail(user) %> <%= user_thumbnail(user) %>
</td> </td>

View file

@ -13,7 +13,7 @@
<%= hidden_field_tag :status, params[:status] if params[:status] %> <%= hidden_field_tag :status, params[:status] if params[:status] %>
<%= hidden_field_tag :ip, params[:ip] if params[:ip] %> <%= hidden_field_tag :ip, params[:ip] if params[:ip] %>
<%= hidden_field_tag :page, params[:page] if params[:page] %> <%= hidden_field_tag :page, params[:page] if params[:page] %>
<table id="user_list"> <table id="user_list" class="table table-borderless table-striped">
<thead> <thead>
<tr> <tr>
<td colspan="2"> <td colspan="2">

View file

@ -873,7 +873,7 @@ class DiaryEntriesControllerTest < ActionController::TestCase
get :comments, :params => { :display_name => user.display_name } get :comments, :params => { :display_name => user.display_name }
assert_response :success assert_response :success
assert_template :comments assert_template :comments
assert_select "table.messages" do assert_select "table.table-striped" do
assert_select "tr", :count => 1 # header, no comments assert_select "tr", :count => 1 # header, no comments
end end
@ -883,7 +883,7 @@ class DiaryEntriesControllerTest < ActionController::TestCase
get :comments, :params => { :display_name => other_user.display_name } get :comments, :params => { :display_name => other_user.display_name }
assert_response :success assert_response :success
assert_template :comments assert_template :comments
assert_select "table.messages" do assert_select "table.table-striped" do
assert_select "tr", :count => 2 # header and one comment assert_select "tr", :count => 2 # header and one comment
end end