04_add-time-entries-tab-to-issue-history-tabs_r16963.patch

Marius BALTEANU, 2017-09-10 14:18

Download (4.55 KB)

View differences:

app/controllers/issues_controller.rb
101 101
        @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
102 102
        @priorities = IssuePriority.active
103 103
        @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
104
        @time_entries = @issue.time_entries.visible.preload(:activity, :user)
104 105
        @relation = IssueRelation.new
105 106
        retrieve_previous_and_next_issue_ids
106 107
        render :template => 'issues/show'
app/helpers/issues_helper.rb
552 552
      tabs << {:name => 'notes', :label => :label_issue_history_notes, :onclick => 'showIssueHistory("notes", this.href)'} if journals_with_notes.any?
553 553
      tabs << {:name => 'properties', :label => :label_issue_history_properties, :onclick => 'showIssueHistory("properties", this.href)'} if journals_without_notes.any?
554 554
    end
555
    tabs << {:name => 'time_entries', :label => :label_time_entry_plural, :partial => 'issues/tabs/time_entries', :locals => {:time_entries => @time_entries}} if User.current.allowed_to?(:view_time_entries, @project) && @issue.spent_hours > 0
555 556
    tabs << {:name => 'changesets', :label => :label_associated_revisions, :partial => 'issues/tabs/changesets', :locals => {:changesets => @changesets}} if @changesets.present?
556 557
    tabs
557 558
  end
app/views/issues/tabs/_time_entries.html.erb
1
<% for time_entry in tab[:locals][:time_entries] %>
2
  <div id="time-entry-<%= time_entry.id %>" class="time_entry journal">
3
    <% if time_entry.editable_by?(User.current) -%>
4
      <div class="contextual">
5
        <%= link_to l(:button_edit), edit_time_entry_path(time_entry),
6
                    :title => l(:button_edit),
7
                    :class => 'icon-only icon-edit' %>
8
        <%= link_to l(:button_delete), time_entry_path(time_entry),
9
                    :data => {:confirm => l(:text_are_you_sure)},
10
                    :method => :delete,
11
                    :title => l(:button_delete),
12
                    :class => 'icon-only icon-del' %>
13
      </div>
14
    <% end -%>
15
    <h4>
16
      <%= avatar(time_entry.user, :size => "24") %>
17
      <%= authoring time_entry.created_on, time_entry.user, :label => :label_added_time_by %>
18
    </h4>
19
    <ul class="details">
20
      <li>
21
        <strong><%= l(:label_time_entry_plural) %></strong>:
22
        <%= l_hours_short time_entry.hours %>
23
      </li>
24
    </ul>
25
    <p><%= time_entry.comments %></p>
26
  </div>
27
  <%= call_hook(:view_issues_history_time_entry_bottom, { :time_entry => time_entry }) %>
28
<% end %>
test/functional/issues_controller_test.rb
2336 2336

  
2337 2337
  def test_show_display_changesets_tab_for_issue_with_changesets
2338 2338
    project = Project.find(2)
2339
    issue = Issue.find(3)
2339
    issue = Issue.find(9)
2340 2340
    issue.changeset_ids = [102]
2341 2341
    issue.save!
2342 2342

  
2343 2343
    @request.session[:user_id] = 2
2344
    get :show, :params => {:id => 3}
2344
    get :show, :params => {:id => issue.id}
2345 2345

  
2346 2346
    assert_select '#history' do
2347 2347
      assert_select 'div.tabs ul a', 1
......
2349 2349
    end
2350 2350
  end
2351 2351

  
2352
  def test_show_should_display_spent_time_tab_for_issue_with_time_entries
2353
    @request.session[:user_id] = 1
2354
    get :show, :params => {:id => 3}
2355
    assert_response :success
2356

  
2357
    assert_select '#history' do
2358
      assert_select 'div.tabs ul a', 1
2359
      assert_select 'div.tabs a[id=?]', 'tab-time_entries', :text => 'Spent time'
2360
    end
2361

  
2362
    assert_select 'div[id=?]', 'time-entry-3' do
2363
      assert_select 'a[title=?][href=?]', 'Edit', '/time_entries/3/edit'
2364
      assert_select 'a[title=?][href=?]', 'Delete', '/time_entries/3'
2365

  
2366
      assert_select 'ul[class=?]', 'details', :text => /1.00 h/
2367
    end
2368
  end
2369

  
2352 2370
  def test_get_new
2353 2371
    @request.session[:user_id] = 2
2354 2372
    get :new, :params => {