02_show-issue-history-in-tabs_v2.patch

Marius BALTEANU, 2017-07-02 10:56

Download (6.63 KB)

View differences:

app/helpers/issues_helper.rb
540 540
      end
541 541
    end
542 542
  end
543

  
544
  # Issue history tabs
545
  def issue_history_tabs()
546
    tabs = []
547
    if @journals.present?
548
      journals_without_notes = @journals.select{|value| value.notes.blank?}
549
      journals_with_notes = @journals.reject{|value| value.notes.blank?}
550

  
551
      tabs << {:name => 'history', :label => :label_history, :onclick => 'showIssueHistory("history", this.href)', :partial => 'history', :locals => {:issue => @issue, :journals => @journals}}
552
      tabs << {:name => 'notes', :label => :label_issue_history_notes, :onclick => 'showIssueHistory("notes", this.href)'} if journals_with_notes.any?
553
      tabs << {:name => 'properties', :label => :label_issue_history_properties, :onclick => 'showIssueHistory("properties", this.href)'} if journals_without_notes.any?
554
    end
555
    tabs
556
  end
543 557
end
app/views/issues/_history.html.erb
1
<%
2
  issue = tab[:locals][:issue]
3
  journals = tab[:locals][:journals]
4
%>
5

  
1 6
<% reply_links = issue.notes_addable? -%>
2 7
<% for journal in journals %>
3 8
  <div id="change-<%= journal.id %>" class="<%= journal.css_classes %>">
app/views/issues/show.html.erb
125 125
</div>
126 126
<% end %>
127 127

  
128
<% if @journals.present? %>
129 128
<div id="history">
130 129
<h3><%=l(:label_history)%></h3>
131
<%= render :partial => 'history', :locals => { :issue => @issue, :journals => @journals } %>
130
<%= render_tabs issue_history_tabs, params[:tab] ? params[:tab] : 'notes' %>
132 131
</div>
133
<% end %>
134

  
135 132

  
136 133
<div style="clear: both;"></div>
137 134
<%= render :partial => 'action_menu' %>
config/locales/en.yml
1020 1020
  label_font_monospace: Monospaced font
1021 1021
  label_font_proportional: Proportional font
1022 1022
  label_last_notes: Last notes
1023
  label_issue_history_properties: Property changes
1024
  label_issue_history_notes: Notes
1023 1025

  
1024 1026
  button_login: Login
1025 1027
  button_submit: Submit
public/javascripts/application.js
338 338
  $('#tab-content-' + name).parent().find('div.tabs a').removeClass('selected');
339 339
  $('#tab-content-' + name).show();
340 340
  $('#tab-' + name).addClass('selected');
341
  //replaces current URL with the "href" attribute of the current link
342
  //(only triggered if supported by browser)
341

  
342
  replaceInHistory(url)
343

  
344
  return false;
345
}
346

  
347
function showIssueHistory(journal, url) {
348
  tab_content = $('#tab-content-history');
349
  tab_content.show();
350
  tab_content.parent().find('div.tabs a').removeClass('selected');
351

  
352
  $('#tab-' + journal).addClass('selected');
353

  
354
  replaceInHistory(url)
355

  
356
  switch(journal) {
357
    case 'notes':
358
      tab_content.find('.journal:not(.has-notes)').hide();
359
      tab_content.find('.journal.has-notes').show();
360
      break;
361
    case 'properties':
362
      tab_content.find('.journal.has-notes').hide();
363
      tab_content.find('.journal:not(.has-notes)').show();
364
      break;
365
    default:
366
      tab_content.find('.journal').show();
367
  }
368

  
369
  return false;
370
}
371

  
372
//replaces current URL with the "href" attribute of the current link
373
//(only triggered if supported by browser)
374
function replaceInHistory(url) {
343 375
  if ("replaceState" in window.history) {
344 376
    window.history.replaceState(null, document.title, url);
345 377
  }
346
  return false;
347 378
}
348 379

  
349 380
function moveTabRight(el) {
test/functional/issues_controller_test.rb
2248 2248
    assert_select 'a', :text => 'Delete', :count => 0
2249 2249
  end
2250 2250

  
2251
  def test_show_should_not_display_history_tabs_for_issue_without_journals
2252
    @request.session[:user_id] = 1
2253

  
2254
    get :show, :params => {:id => 5}
2255
    assert_response :success
2256
    assert_select '#history div.tabs', 0
2257
    assert_select '#history p.nodata', :text => 'No data to display'
2258
  end
2259

  
2260
  def test_show_display_only_all_and_notes_tabs_for_issue_with_notes_only
2261
    @request.session[:user_id] = 1
2262

  
2263
    get :show, :params => {:id => 6}
2264
    assert_response :success
2265
    assert_select '#history' do
2266
      assert_select 'div.tabs ul a', 2
2267
      assert_select 'div.tabs a[id=?]', 'tab-history', :text => 'History'
2268
      assert_select 'div.tabs a[id=?]', 'tab-notes', :text => 'Notes'
2269
    end
2270
  end
2271

  
2272
  def test_show_display_only_all_and_history_tabs_for_issue_with_history_changes_only
2273
    journal = Journal.create!(:journalized => Issue.find(5), :user_id => 1)
2274
    detail = JournalDetail.create!(:journal => journal, :property => 'attr', :prop_key => 'description',
2275
      :old_value => 'Foo', :value => 'Bar')
2276

  
2277
    @request.session[:user_id] = 1
2278

  
2279
    get :show, :params => {:id => 5}
2280
    assert_response :success
2281
    assert_select '#history' do
2282
      assert_select 'div.tabs ul a', 2
2283
      assert_select 'div.tabs a[id=?]', 'tab-history', :text => 'History'
2284
      assert_select 'div.tabs a[id=?]', 'tab-properties', :text => 'Property changes'
2285
    end
2286
  end
2287

  
2288
  def test_show_display_all_notes_and_history_tabs_for_issue_with_notes_and_history_changes
2289
    journal = Journal.create!(:journalized => Issue.find(6), :user_id => 1)
2290
    detail = JournalDetail.create!(:journal => journal, :property => 'attr', :prop_key => 'description',
2291
      :old_value => 'Foo', :value => 'Bar')
2292

  
2293
    @request.session[:user_id] = 1
2294

  
2295
    get :show, :params => {:id => 6}
2296
    assert_response :success
2297
    assert_select '#history' do
2298
      assert_select 'div.tabs ul a', 3
2299
      assert_select 'div.tabs a[id=?]', 'tab-history', :text => 'History'
2300
      assert_select 'div.tabs a[id=?]', 'tab-notes', :text => 'Notes'
2301
      assert_select 'div.tabs a[id=?]', 'tab-properties', :text => 'Property changes'
2302
    end
2303
  end
2304

  
2251 2305
  def test_get_new
2252 2306
    @request.session[:user_id] = 2
2253 2307
    get :new, :params => {