From: Andy Allan Date: Wed, 18 Mar 2020 10:27:36 +0000 (+0100) Subject: Use bootstrap table striping to replace hand-cycled table stripes X-Git-Tag: live~2179^2 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/5fdada204cf92d8ca99300927713724aaaf1b2bd 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. --- diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index df0b072e0..9b6b69db7 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -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 */ diff --git a/app/views/diary_entries/comments.html.erb b/app/views/diary_entries/comments.html.erb index 00045efc0..ec8c3dfda 100644 --- a/app/views/diary_entries/comments.html.erb +++ b/app/views/diary_entries/comments.html.erb @@ -2,7 +2,7 @@

<%= t(".has_commented_on", :display_name => @user.display_name) %>

<% end %> - +
@@ -11,8 +11,7 @@ <% @comments.each do |comment| -%> - <% cl = cycle("table0", "table1") %> - "> + "> diff --git a/app/views/traces/_trace.html.erb b/app/views/traces/_trace.html.erb index 47860d50d..473d0aa39 100644 --- a/app/views/traces/_trace.html.erb +++ b/app/views/traces/_trace.html.erb @@ -1,6 +1,5 @@ - <% cl = cycle("table0", "table1") %> - -
<%= t ".post" %>
<%= link_to comment.diary_entry.title, diary_entry_path(comment.diary_entry.user, comment.diary_entry) %> <%= time_ago_in_words(comment.created_at, :scope => :'datetime.distance_in_words_ago') %> <%= comment.body.to_html %>
+ <% if Settings.status != "gpx_offline" %> <% if trace.inserted %> "show", :id => trace.id, :display_name => trace.user.display_name %>"> "icon", :id => trace.id, :display_name => trace.user.display_name %>" border="0" alt="" /> @@ -9,7 +8,7 @@ <% end %> <% end %> <%= link_to trace.name, :controller => "traces", :action => "show", :display_name => trace.user.display_name, :id => trace.id %> + <%= link_to trace.name, :controller => "traces", :action => "show", :display_name => trace.user.display_name, :id => trace.id %> ... <% if trace.inserted %> (<%= t ".count_points", :count => trace.size %>) diff --git a/app/views/traces/index.html.erb b/app/views/traces/index.html.erb index fff62ba55..d2f22c069 100644 --- a/app/views/traces/index.html.erb +++ b/app/views/traces/index.html.erb @@ -25,7 +25,7 @@ <% if @traces.size > 0 %> <%= render :partial => "trace_paging_nav" %> - +
diff --git a/app/views/user_blocks/_block.html.erb b/app/views/user_blocks/_block.html.erb index ec04c79b7..49619a9c1 100644 --- a/app/views/user_blocks/_block.html.erb +++ b/app/views/user_blocks/_block.html.erb @@ -1,24 +1,22 @@ - <% c1 = cycle("table0", "table1") %> - <% if show_user_name %> - + <% end %> <% if show_creator_name %> - + <% end %> - - - + + - - + + <% if show_revoke_link %> - + <% end %> diff --git a/app/views/user_blocks/_blocks.html.erb b/app/views/user_blocks/_blocks.html.erb index 03ee7ae8e..8955852c1 100644 --- a/app/views/user_blocks/_blocks.html.erb +++ b/app/views/user_blocks/_blocks.html.erb @@ -1,4 +1,4 @@ -
<%= link_to h(block.user.display_name), user_path(block.user) %><%= link_to h(block.user.display_name), user_path(block.user) %><%= link_to h(block.creator.display_name), user_path(block.creator) %><%= link_to h(block.creator.display_name), user_path(block.creator) %><%= h truncate(block.reason) %><%= h block_status(block) %> + <%= h truncate(block.reason) %><%= h block_status(block) %> <% if block.revoker_id.nil? %> <%= t(".not_revoked") %> <% else %> <%= link_to h(block.revoker.display_name), user_path(block.revoker) %> <% end %> <%= link_to t(".show"), block %><% if current_user and current_user.id == block.creator_id and block.active? %><%= link_to t(".edit"), edit_user_block_path(block) %><% end %><%= link_to t(".show"), block %><% if current_user and current_user.id == block.creator_id and block.active? %><%= link_to t(".edit"), edit_user_block_path(block) %><% end %><% if block.active? %><%= link_to t(".revoke"), :controller => "user_blocks", :action => "revoke", :id => block.id %><% end %><% if block.active? %><%= link_to t(".revoke"), :controller => "user_blocks", :action => "revoke", :id => block.id %><% end %>
+
<% if show_user_name %> diff --git a/app/views/users/_user.html.erb b/app/views/users/_user.html.erb index c8fd4ac9e..801755556 100644 --- a/app/views/users/_user.html.erb +++ b/app/views/users/_user.html.erb @@ -1,6 +1,4 @@ -<% cl = cycle("table0", "table1") %> - - + diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 01b7c60aa..cc7170222 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -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] %> -
<%= user_thumbnail(user) %>
+
diff --git a/test/controllers/diary_entries_controller_test.rb b/test/controllers/diary_entries_controller_test.rb index e959133a0..0f071914e 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -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