]> git.openstreetmap.org Git - rails.git/commitdiff
Use bootstrap table striping to replace hand-cycled table stripes
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 18 Mar 2020 10:27:36 +0000 (11:27 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 18 Mar 2020 11:14:24 +0000 (12:14 +0100)
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.

app/assets/stylesheets/common.scss
app/views/diary_entries/comments.html.erb
app/views/traces/_trace.html.erb
app/views/traces/index.html.erb
app/views/user_blocks/_block.html.erb
app/views/user_blocks/_blocks.html.erb
app/views/users/_user.html.erb
app/views/users/index.html.erb
test/controllers/diary_entries_controller_test.rb

index df0b072e0fbf5617d2c0ad8eb15c8c386d513b83..9b6b69db797673f2cdd1a338d7c95e32d01fe9a8 100644 (file)
@@ -2048,16 +2048,11 @@ a.button {
   }
 }
 
-/* Rules for doing distinct colour of alternate table rows */
+/* Customise the background colour of striped tables */
 
-.table0,
-.item0 {
-  background: $offwhite;
-}
-
-.table1,
-.item1 {
-  background: #fff;
+.table-striped > tbody > tr:nth-child(2n+1) > td,
+.table-striped > tbody > tr:nth-child(2n+1) > th {
+   background-color: $offwhite;
 }
 
 /* Rules for OpenID logo */
index 00045efc08f992058930b2d18417c29fcc232b16..ec8c3dfda8e7535ac419171d0910171bd96abd51 100644 (file)
@@ -2,7 +2,7 @@
   <h1><%= t(".has_commented_on", :display_name => @user.display_name) %></h1>
 <% end %>
 
-<table class="messages" width="100%">
+<table class="table table-striped" width="100%">
   <thead>
     <tr>
       <th width="25%"><%= t ".post" %></th>
@@ -11,8 +11,7 @@
     </tr>
   </thead>
   <% @comments.each do |comment| -%>
-  <% cl = cycle("table0", "table1") %>
-  <tr class="<%= cl %><%= " deemphasize" unless comment.visible? %>">
+  <tr class="<%= "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%"><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>
index 47860d50d4284dfeedf1b7f825beea665f3a9dfb..473d0aa39e614fdabe35c577200fa0377cbbb68e 100644 (file)
@@ -1,6 +1,5 @@
 <tr>
-  <% cl = cycle("table0", "table1") %>
-  <td class="<%= cl %>">
+  <td>
     <% if Settings.status != "gpx_offline" %>
       <% 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>
@@ -9,7 +8,7 @@
       <% end %>
     <% end %>
   </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 %>"> ...
       <% if trace.inserted %>
         (<%= t ".count_points", :count => trace.size %>)
index fff62ba551ee00d61f31164ebbdad3148edefa9e..d2f22c0695ee0e17e25e6e196560c4a27b578550 100644 (file)
@@ -25,7 +25,7 @@
 <% if @traces.size > 0 %>
   <%= render :partial => "trace_paging_nav" %>
 
-  <table id="trace_list" cellpadding="3">
+  <table id="trace_list" class="table table-borderless table-striped">
     <thead>
       <tr>
         <th></th>
index ec04c79b7e897f04c337113070f0d8471d3e6259..49619a9c1c03cf7bd16d9175621417a45f2d2be5 100644 (file)
@@ -1,24 +1,22 @@
 <tr>
-  <% c1 = cycle("table0", "table1") %>
-
   <% 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 %>
   <% 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 %>
-  <td class="<%= c1 %>"><%= h truncate(block.reason) %></td>
-  <td class="<%= c1 %>"><%= h block_status(block) %></td>
-  <td class="<%= c1 %>">
+  <td><%= h truncate(block.reason) %></td>
+  <td><%= h block_status(block) %></td>
+  <td>
     <% if block.revoker_id.nil? %>
       <%= t(".not_revoked") %>
     <% else %>
       <%= link_to h(block.revoker.display_name), user_path(block.revoker) %>
     <% end %>
   </td>
-  <td class="<%= c1 %>"><%= 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><%= link_to t(".show"), block %></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 %>
-  <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 %>
 </tr>
index 03ee7ae8e0163f61b1374b602c02a3dd373e080b..8955852c1a818f2219194ad05869a0702aad9e38 100644 (file)
@@ -1,4 +1,4 @@
-<table id="block_list" cellpadding="3">
+<table id="block_list" class="table table-borderless table-striped table-sm">
   <thead>
     <tr>
       <% if show_user_name %>
index c8fd4ac9e8718a7e9a265f58c99708c6b05904b5..801755556b69df054198c203b13aa9967bfd9db0 100644 (file)
@@ -1,6 +1,4 @@
-<% cl = cycle("table0", "table1") %>
-
-<tr class="<%= cl %>">
+<tr>
   <td>
     <%= user_thumbnail(user) %>
   </td>
index 01b7c60aa11bbbae82a013d8f7ae1a63c4b30fb6..cc71702222121efcdde10c9b3f88656baabd1532 100644 (file)
@@ -13,7 +13,7 @@
     <%= hidden_field_tag :status, params[:status] if params[:status] %>
     <%= hidden_field_tag :ip, params[:ip] if params[:ip] %>
     <%= hidden_field_tag :page, params[:page] if params[:page] %>
-    <table id="user_list">
+    <table id="user_list" class="table table-borderless table-striped">
       <thead>
         <tr>
           <td colspan="2">
index e959133a0afb7c5ee44c829c5764528cfaf0ed69..0f071914e08190418a1a7180aec6ce677f9af3ff 100644 (file)
@@ -873,7 +873,7 @@ class DiaryEntriesControllerTest < ActionController::TestCase
     get :comments, :params => { :display_name => user.display_name }
     assert_response :success
     assert_template :comments
-    assert_select "table.messages" do
+    assert_select "table.table-striped" do
       assert_select "tr", :count => 1 # header, no comments
     end
 
@@ -883,7 +883,7 @@ class DiaryEntriesControllerTest < ActionController::TestCase
     get :comments, :params => { :display_name => other_user.display_name }
     assert_response :success
     assert_template :comments
-    assert_select "table.messages" do
+    assert_select "table.table-striped" do
       assert_select "tr", :count => 2 # header and one comment
     end