From 8f38f4602ea1347137381874eee13b5693968014 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Sun, 9 Sep 2018 11:07:12 +0000 Subject: [PATCH 2/7] show issue history in tabs --- app/helpers/issues_helper.rb | 14 ++++++++ app/views/issues/_history.html.erb | 5 +++ app/views/issues/show.html.erb | 4 +-- config/locales/en.yml | 2 ++ public/javascripts/application.js | 38 ++++++++++++++++++++-- test/functional/issues_controller_test.rb | 54 +++++++++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 6 deletions(-) mode change 100644 => 100755 app/helpers/issues_helper.rb mode change 100644 => 100755 app/views/issues/_history.html.erb mode change 100644 => 100755 app/views/issues/show.html.erb mode change 100644 => 100755 config/locales/en.yml mode change 100644 => 100755 public/javascripts/application.js mode change 100644 => 100755 test/functional/issues_controller_test.rb diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb old mode 100644 new mode 100755 index 66d3e1f..388b7bb --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -542,4 +542,18 @@ module IssuesHelper end end end + + # Issue history tabs + def issue_history_tabs() + tabs = [] + if @journals.present? + journals_without_notes = @journals.select{|value| value.notes.blank?} + journals_with_notes = @journals.reject{|value| value.notes.blank?} + + tabs << {:name => 'history', :label => :label_history, :onclick => 'showIssueHistory("history", this.href)', :partial => 'history', :locals => {:issue => @issue, :journals => @journals}} + tabs << {:name => 'notes', :label => :label_issue_history_notes, :onclick => 'showIssueHistory("notes", this.href)'} if journals_with_notes.any? + tabs << {:name => 'properties', :label => :label_issue_history_properties, :onclick => 'showIssueHistory("properties", this.href)'} if journals_without_notes.any? + end + tabs + end end diff --git a/app/views/issues/_history.html.erb b/app/views/issues/_history.html.erb old mode 100644 new mode 100755 index aa8ecbf..d08c745 --- a/app/views/issues/_history.html.erb +++ b/app/views/issues/_history.html.erb @@ -1,3 +1,8 @@ +<% + issue = tab[:locals][:issue] + journals = tab[:locals][:journals] +%> + <% reply_links = issue.notes_addable? -%> <% for journal in journals %>
diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb old mode 100644 new mode 100755 index 5a1cc85..5290d86 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -129,12 +129,10 @@ end %> <%= render partial: 'action_menu_edit' if User.current.wants_comments_in_reverse_order? %> -<% if @journals.present? %>

<%=l(:label_history)%>

-<%= render :partial => 'history', :locals => { :issue => @issue, :journals => @journals } %> +<%= render_tabs issue_history_tabs, params[:tab] ? params[:tab] : 'notes' %>
-<% end %> <%= render partial: 'action_menu_edit' unless User.current.wants_comments_in_reverse_order? %> diff --git a/config/locales/en.yml b/config/locales/en.yml old mode 100644 new mode 100755 index 2eb5361..799d180 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1035,6 +1035,8 @@ en: label_font_proportional: Proportional font label_last_notes: Last notes label_nothing_to_preview: Nothing to preview + label_issue_history_properties: Property changes + label_issue_history_notes: Notes button_login: Login button_submit: Submit diff --git a/public/javascripts/application.js b/public/javascripts/application.js old mode 100644 new mode 100755 index 75848dd..9869dd9 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -345,12 +345,44 @@ function showTab(name, url) { $('#tab-content-' + name).show(); $('#tab-' + name).closest('.tabs').find('a').removeClass('selected'); $('#tab-' + name).addClass('selected'); - //replaces current URL with the "href" attribute of the current link - //(only triggered if supported by browser) + + replaceInHistory(url) + + return false; +} + +function showIssueHistory(journal, url) { + tab_content = $('#tab-content-history'); + tab_content.parent().find('.tab-content').hide(); + tab_content.show(); + tab_content.parent().find('div.tabs a').removeClass('selected'); + + $('#tab-' + journal).addClass('selected'); + + replaceInHistory(url) + + switch(journal) { + case 'notes': + tab_content.find('.journal:not(.has-notes)').hide(); + tab_content.find('.journal.has-notes').show(); + break; + case 'properties': + tab_content.find('.journal.has-notes').hide(); + tab_content.find('.journal:not(.has-notes)').show(); + break; + default: + tab_content.find('.journal').show(); + } + + return false; +} + +//replaces current URL with the "href" attribute of the current link +//(only triggered if supported by browser) +function replaceInHistory(url) { if ("replaceState" in window.history) { window.history.replaceState(null, document.title, url); } - return false; } function moveTabRight(el) { diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb old mode 100644 new mode 100755 index 08a2187..30ed68f --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -2424,6 +2424,60 @@ class IssuesControllerTest < Redmine::ControllerTest assert_select 'a', :text => 'Delete', :count => 0 end + def test_show_should_not_display_history_tabs_for_issue_without_journals + @request.session[:user_id] = 1 + + get :show, :params => {:id => 5} + assert_response :success + assert_select '#history div.tabs', 0 + assert_select '#history p.nodata', :text => 'No data to display' + end + + def test_show_display_only_all_and_notes_tabs_for_issue_with_notes_only + @request.session[:user_id] = 1 + + get :show, :params => {:id => 6} + assert_response :success + assert_select '#history' do + assert_select 'div.tabs ul a', 2 + assert_select 'div.tabs a[id=?]', 'tab-history', :text => 'History' + assert_select 'div.tabs a[id=?]', 'tab-notes', :text => 'Notes' + end + end + + def test_show_display_only_all_and_history_tabs_for_issue_with_history_changes_only + journal = Journal.create!(:journalized => Issue.find(5), :user_id => 1) + detail = JournalDetail.create!(:journal => journal, :property => 'attr', :prop_key => 'description', + :old_value => 'Foo', :value => 'Bar') + + @request.session[:user_id] = 1 + + get :show, :params => {:id => 5} + assert_response :success + assert_select '#history' do + assert_select 'div.tabs ul a', 2 + assert_select 'div.tabs a[id=?]', 'tab-history', :text => 'History' + assert_select 'div.tabs a[id=?]', 'tab-properties', :text => 'Property changes' + end + end + + def test_show_display_all_notes_and_history_tabs_for_issue_with_notes_and_history_changes + journal = Journal.create!(:journalized => Issue.find(6), :user_id => 1) + detail = JournalDetail.create!(:journal => journal, :property => 'attr', :prop_key => 'description', + :old_value => 'Foo', :value => 'Bar') + + @request.session[:user_id] = 1 + + get :show, :params => {:id => 6} + assert_response :success + assert_select '#history' do + assert_select 'div.tabs ul a', 3 + assert_select 'div.tabs a[id=?]', 'tab-history', :text => 'History' + assert_select 'div.tabs a[id=?]', 'tab-notes', :text => 'Notes' + assert_select 'div.tabs a[id=?]', 'tab-properties', :text => 'Property changes' + end + end + def test_get_new @request.session[:user_id] = 2 get :new, :params => { -- 2.1.4