Project

General

Profile

Feature #34336 » 34336.patch

Takenori TAKAKI, 2021-01-29 08:14

View differences:

app/controllers/boards_controller.rb
32 32
    if @boards.size == 1
33 33
      @board = @boards.first
34 34
      show
35
    else
36
      @messages = Message.joins(:board).where(boards: {project_id: @project.id}).order('created_on desc').limit(10)
35 37
    end
36 38
  end
37 39

  
app/views/boards/index.html.erb
33 33
  </tbody>
34 34
</table>
35 35

  
36
<% if @messages && @messages.any? %>
37
  <h3><%= l(:label_latest_message_plural) %></h3>
38
  <table class="list messages">
39
    <thead><tr>
40
      <th><%= l(:label_board) %></th>
41
      <th><%= l(:field_subject) %></th>
42
      <th><%= l(:field_content) %></th>
43
      <th><%= l(:field_author) %></th>
44
      <th><%= l(:field_created_on) %></th>
45
    </tr></thead>
46
    <tbody>
47
    <% @messages.each do |message| %>
48
      <tr id="message-<%= message.id %>" class="message">
49
        <td class="board"><%= link_to message.board.name, project_board_path(message.board.project, message.board), :class => "board" %>
50
        <td class="subject"><%= link_to message.subject, board_message_path(message.board, message) %></td>
51
        <td class="content"><%=  message.content %></td>
52
        <td class="author"><%= link_to_user(message.author) %></td>
53
        <td class="created_on"><%= format_time(message.created_on) %></td>
54
      </tr>
55
    <% end %>
56
    </tbody>
57
  </table>
58
<% end %>
59

  
36 60
<% other_formats_links do |f| %>
37 61
  <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_messages => 1, :key => User.current.rss_key} %>
38 62
<% end %>
config/locales/en.yml
1102 1102
  label_display_type_board: Board
1103 1103
  label_my_bookmarks: My bookmarks
1104 1104
  label_assign_to_me: Assign to me
1105
  label_latest_message_plural: Latest messages
1105 1106

  
1106 1107
  button_login: Login
1107 1108
  button_submit: Submit
public/stylesheets/application.css
316 316
table.members td.roles, table.memberships td.roles { width: 45%; }
317 317

  
318 318
table.messages td.last_message {text-align:left;}
319
table.messages td.content {text-align:left;}
319 320
tr.message { height: 2.6em; }
320 321
tr.message td.created_on { white-space: nowrap; }
321 322
tr.message td.last_message { font-size: 80%; white-space: nowrap; }
test/functional/boards_controller_test.rb
62 62
    assert_select 'table.messages'
63 63
  end
64 64

  
65
  def test_index_should_latest_messages
66
    old_message = Message.create(:board_id => 1, :subject => "Old Message", :content => "Old Message", :author_id => 2)
67
    latest_10_messages = 10.times.collect do |i|
68
      Message.create(:board_id => 1, :subject => "New Message #{i}", :content => "New Message #{i}", :author_id => 2)
69
    end
70

  
71
    get(
72
      :index,
73
      :params => {
74
        :project_id => 1
75
      }
76
    )
77
    assert_response :success
78

  
79
    assert_select 'div#content h3', :text => 'Latest messages'
80
    assert_select 'table.messages tbody' do
81
      assert_select 'tr', 10
82
      assert_select latest_10_messages.reverse.collect { |m| "tr#message-#{m.id}" }.join(' + ')
83
      assert_select "tr#message-#{old_message.id}", false
84
    end
85
  end
86

  
65 87
  def test_show
66 88
    get(
67 89
      :show,
(2-2/2)