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

Marius BALTEANU, 2017-09-10 14:18

Download (6.7 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
1025 1025
  label_font_monospace: Monospaced font
1026 1026
  label_font_proportional: Proportional font
1027 1027
  label_last_notes: Last notes
1028
  label_issue_history_properties: Property changes
1029
  label_issue_history_notes: Notes
1028 1030

  
1029 1031
  button_login: Login
1030 1032
  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.parent().find('.tab-content').hide();
350
  tab_content.show();
351
  tab_content.parent().find('div.tabs a').removeClass('selected');
352

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

  
355
  replaceInHistory(url)
356

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

  
370
  return false;
371
}
372

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

  
349 381
function moveTabRight(el) {
test/functional/issues_controller_test.rb
2280 2280
    assert_select 'a', :text => 'Delete', :count => 0
2281 2281
  end
2282 2282

  
2283
  def test_show_should_not_display_history_tabs_for_issue_without_journals
2284
    @request.session[:user_id] = 1
2285

  
2286
    get :show, :params => {:id => 5}
2287
    assert_response :success
2288
    assert_select '#history div.tabs', 0
2289
    assert_select '#history p.nodata', :text => 'No data to display'
2290
  end
2291

  
2292
  def test_show_display_only_all_and_notes_tabs_for_issue_with_notes_only
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', 2
2299
      assert_select 'div.tabs a[id=?]', 'tab-history', :text => 'History'
2300
      assert_select 'div.tabs a[id=?]', 'tab-notes', :text => 'Notes'
2301
    end
2302
  end
2303

  
2304
  def test_show_display_only_all_and_history_tabs_for_issue_with_history_changes_only
2305
    journal = Journal.create!(:journalized => Issue.find(5), :user_id => 1)
2306
    detail = JournalDetail.create!(:journal => journal, :property => 'attr', :prop_key => 'description',
2307
      :old_value => 'Foo', :value => 'Bar')
2308

  
2309
    @request.session[:user_id] = 1
2310

  
2311
    get :show, :params => {:id => 5}
2312
    assert_response :success
2313
    assert_select '#history' do
2314
      assert_select 'div.tabs ul a', 2
2315
      assert_select 'div.tabs a[id=?]', 'tab-history', :text => 'History'
2316
      assert_select 'div.tabs a[id=?]', 'tab-properties', :text => 'Property changes'
2317
    end
2318
  end
2319

  
2320
  def test_show_display_all_notes_and_history_tabs_for_issue_with_notes_and_history_changes
2321
    journal = Journal.create!(:journalized => Issue.find(6), :user_id => 1)
2322
    detail = JournalDetail.create!(:journal => journal, :property => 'attr', :prop_key => 'description',
2323
      :old_value => 'Foo', :value => 'Bar')
2324

  
2325
    @request.session[:user_id] = 1
2326

  
2327
    get :show, :params => {:id => 6}
2328
    assert_response :success
2329
    assert_select '#history' do
2330
      assert_select 'div.tabs ul a', 3
2331
      assert_select 'div.tabs a[id=?]', 'tab-history', :text => 'History'
2332
      assert_select 'div.tabs a[id=?]', 'tab-notes', :text => 'Notes'
2333
      assert_select 'div.tabs a[id=?]', 'tab-properties', :text => 'Property changes'
2334
    end
2335
  end
2336

  
2283 2337
  def test_get_new
2284 2338
    @request.session[:user_id] = 2
2285 2339
    get :new, :params => {