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

Marius BALTEANU, 2017-07-02 10:56

Download (4.54 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
2304 2304

  
2305 2305
  def test_show_display_changesets_tab_for_issue_with_changesets
2306 2306
    project = Project.find(2)
2307
    issue = Issue.find(3)
2307
    issue = Issue.find(9)
2308 2308
    issue.changeset_ids = [102]
2309 2309
    issue.save!
2310 2310

  
2311 2311
    @request.session[:user_id] = 2
2312
    get :show, :params => {:id => 3}
2312
    get :show, :params => {:id => issue.id}
2313 2313

  
2314 2314
    assert_select '#history' do
2315 2315
      assert_select 'div.tabs ul a', 1
......
2317 2317
    end
2318 2318
  end
2319 2319

  
2320
  def test_show_should_display_spent_time_tab_for_issue_with_time_entries
2321
    @request.session[:user_id] = 1
2322
    get :show, :params => {:id => 3}
2323
    assert_response :success
2324

  
2325
    assert_select '#history' do
2326
      assert_select 'div.tabs ul a', 1
2327
      assert_select 'div.tabs a[id=?]', 'tab-time_entries', :text => 'Spent time'
2328
    end
2329

  
2330
    assert_select 'div[id=?]', 'time-entry-3' do
2331
      assert_select 'a[title=?][href=?]', 'Edit', '/time_entries/3/edit'
2332
      assert_select 'a[title=?][href=?]', 'Delete', '/time_entries/3'
2333

  
2334
      assert_select 'ul[class=?]', 'details', :text => /1.00 h/
2335
    end
2336
  end
2337

  
2320 2338
  def test_get_new
2321 2339
    @request.session[:user_id] = 2
2322 2340
    get :new, :params => {