From: Andy Allan Date: Wed, 28 Apr 2021 09:36:09 +0000 (+0100) Subject: Merge pull request #3169 from harry-wood/empty-lists X-Git-Tag: live~1603 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/7158426ebb50d990445f475af7f6c31212d9dd03?hp=7cafc6206300921530ced03e2a5c6d48a2cec73c Merge pull request #3169 from harry-wood/empty-lists Display message when the there are no notes/comments to display --- diff --git a/app/views/diary_entries/comments.html.erb b/app/views/diary_entries/comments.html.erb index 78f16eb8c..290fba35e 100644 --- a/app/views/diary_entries/comments.html.erb +++ b/app/views/diary_entries/comments.html.erb @@ -2,24 +2,30 @@

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

<% end %> - - - - - - +<% if @comments.empty? %> +

<%= t ".no_comments" %>

+ +<% else %> +
<%= t ".post" %><%= t ".when" %><%= t ".comment" %>
+ + + + + + + + <% @comments.each do |comment| -%> + "> + + + - - <% @comments.each do |comment| -%> - "> - - - - - <% end -%> -
<%= t ".post" %><%= t ".when" %><%= t ".comment" %>
<%= 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 %>
<%= 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 %>
+ <% end -%> + + +
+ <%= link_to t(".older_comments"), :page => @comment_pages.current.next if @comment_pages.current.next %> + <%= link_to t(".newer_comments"), :page => @comment_pages.current.previous if @comment_pages.current.previous %> +
-
- <%= link_to t(".older_comments"), :page => @comment_pages.current.next if @comment_pages.current.next %> - <%= link_to t(".newer_comments"), :page => @comment_pages.current.previous if @comment_pages.current.previous %> -
+<% end -%> diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb index 50059625d..b5af25321 100644 --- a/app/views/notes/index.html.erb +++ b/app/views/notes/index.html.erb @@ -3,35 +3,41 @@

<%= t ".subheading_html", :user => link_to(@user.display_name, user_path(@user)) %>

<% end %> -<%= render :partial => "notes_paging_nav" %> +<% if @notes.empty? %> +

<%= t ".no_notes" %>

- - - - - - - - - +<% else %> + <%= render :partial => "notes_paging_nav" %> + +
<%= t ".id" %><%= t ".creator" %><%= t ".description" %><%= t ".created_at" %><%= t ".last_changed" %>
+ + + + + + + + + + + <% @notes.each do |note| -%> + class="creator"<% end %>> + + + + + + - -<% @notes.each do |note| -%> - class="creator"<% end %>> - - - - - - - -<% end -%> -
<%= t ".id" %><%= t ".creator" %><%= t ".description" %><%= t ".created_at" %><%= t ".last_changed" %>
+ <% if note.closed? %> + <%= image_tag("closed_note_marker.png", :alt => "closed", :size => "25x40") %> + <% else %> + <%= image_tag("open_note_marker.png", :alt => "open", :size => "25x40") %> + <% end %> + <%= link_to note.id, browse_note_path(note) %><%= note_author(note.author) %><%= note.comments.first.body.to_html %><%= friendly_date_ago(note.created_at) %><%= friendly_date_ago(note.updated_at) %>
- <% if note.closed? %> - <%= image_tag("closed_note_marker.png", :alt => "closed", :size => "25x40") %> - <% else %> - <%= image_tag("open_note_marker.png", :alt => "open", :size => "25x40") %> - <% end %> - <%= link_to note.id, browse_note_path(note) %><%= note_author(note.author) %><%= note.comments.first.body.to_html %><%= friendly_date_ago(note.created_at) %><%= friendly_date_ago(note.updated_at) %>
+ <% end -%> + -<%= render :partial => "notes_paging_nav" %> + <%= render :partial => "notes_paging_nav" %> + +<% end -%> diff --git a/config/locales/en.yml b/config/locales/en.yml index 4cfdf5754..b07536c27 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -474,6 +474,7 @@ en: description: "Recent diary entries from users of OpenStreetMap" comments: has_commented_on: "%{display_name} has commented on the following diary entries" + no_comments: "No diary comments" post: Post when: When comment: Comment @@ -2638,6 +2639,7 @@ en: title: "Notes submitted or commented on by %{user}" heading: "%{user}'s notes" subheading_html: "Notes submitted or commented on by %{user}" + no_notes: No notes id: "Id" creator: "Creator" description: "Description" diff --git a/test/controllers/diary_entries_controller_test.rb b/test/controllers/diary_entries_controller_test.rb index 45fe4add1..255b43997 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -848,9 +848,7 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest get diary_comments_path(:display_name => user.display_name) assert_response :success assert_template :comments - assert_select "table.table-striped" do - assert_select "tr", :count => 1 # header, no comments - end + assert_select "h4", :html => "No diary comments" # Test a user with a comment create(:diary_comment, :user => other_user) diff --git a/test/controllers/notes_controller_test.rb b/test/controllers/notes_controller_test.rb index 1450aced8..50e7ae833 100644 --- a/test/controllers/notes_controller_test.rb +++ b/test/controllers/notes_controller_test.rb @@ -73,4 +73,11 @@ class NotesControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_select "table.note_list tr", :count => 11 end + + def test_empty_page + user = create(:user) + get user_notes_path(:display_name => user.display_name) + assert_response :success + assert_select "h4", :html => "No notes" + end end