From e0c60cbb0a47882b6edcb0d4958c6645cb086c0e Mon Sep 17 00:00:00 2001 From: Katsuya Hidaka Date: Mon, 16 Sep 2024 16:34:03 +0900 Subject: [PATCH 5/7] Separate helpers for the quote reply into the Redmine::QuoteReply --- app/helpers/journals_helper.rb | 8 ++-- app/helpers/messages_helper.rb | 1 + app/views/issues/show.html.erb | 7 +--- app/views/messages/show.html.erb | 19 ++++----- lib/redmine/quote_reply.rb | 41 +++++++++++++++++++ test/helpers/journals_helper_test.rb | 2 +- .../lib/redmine/quote_reply_helper_test.rb | 40 ++++++++++++++++++ 7 files changed, 97 insertions(+), 21 deletions(-) create mode 100644 lib/redmine/quote_reply.rb create mode 100644 test/unit/lib/redmine/quote_reply_helper_test.rb diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb index 983644b63..e4c23995e 100644 --- a/app/helpers/journals_helper.rb +++ b/app/helpers/journals_helper.rb @@ -18,6 +18,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module JournalsHelper + include Redmine::QuoteReply::Helper + # Returns the attachments of a journal that are displayed as thumbnails def journal_thumbnail_attachments(journal) journal.attachments.select(&:thumbnailable?) @@ -41,11 +43,7 @@ module JournalsHelper if journal.notes.present? if options[:reply_links] url = quoted_issue_path(issue, :journal_id => journal, :journal_indice => indice) - links << link_to_function(icon_with_label('comment', l(:button_quote)), - "quoteReply('#{j url}', '#journal-#{j journal.id}-notes')", - :title => l(:button_quote), - :class => 'icon-only icon-comment' - ) + links << quote_reply(url, "#journal-#{journal.id}-notes", icon_only: true) end if journal.editable_by?(User.current) links << link_to(icon_with_label('edit', l(:button_edit)), diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb index 24218e46e..fd9ba3bcb 100644 --- a/app/helpers/messages_helper.rb +++ b/app/helpers/messages_helper.rb @@ -18,4 +18,5 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module MessagesHelper + include Redmine::QuoteReply::Helper end diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index 2a6e6448f..be6898746 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -1,5 +1,5 @@ <% content_for :header_tags do %> - <%= javascript_include_tag 'quote_reply' %> + <%= javascript_for_quote_reply_include_tag %> <% end %> <%= render :partial => 'action_menu' %> @@ -88,10 +88,7 @@ end %>
- <%= link_to_function(icon_with_label('comment', l(:button_quote)), - "quoteReply('#{j quoted_issue_path(@issue)}', '#issue_description_wiki')", - :class => 'icon icon-comment ' - ) if @issue.notes_addable? %> + <%= quote_reply(quoted_issue_path(@issue), '#issue_description_wiki') if @issue.notes_addable? %>

<%=l(:field_description)%>

diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index 5ac083cc0..e21d1686c 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -1,15 +1,15 @@ <% content_for :header_tags do %> - <%= javascript_include_tag 'quote_reply' %> + <%= javascript_for_quote_reply_include_tag %> <% end %> <%= board_breadcrumb(@message) %>
<%= watcher_link(@topic, User.current) %> - <%= link_to_function( - icon_with_label('comment', l(:button_quote)), - "quoteReply('#{j url_for(:action => 'quote', :id => @topic, :format => 'js')}', '#message_topic_wiki')", - :class => 'icon icon-comment') if !@topic.locked? && authorize_for('messages', 'reply') %> + <%= quote_reply( + url_for(:action => 'quote', :id => @topic, :format => 'js'), + '#message_topic_wiki' + ) if !@topic.locked? && authorize_for('messages', 'reply') %> <%= link_to( icon_with_label('edit', l(:button_edit)), {:action => 'edit', :id => @topic}, @@ -44,11 +44,10 @@ <% @replies.each do |message| %>
">
- <%= link_to_function( - icon_with_label('comment', l(:button_quote), icon_only: true), - "quoteReply('#{j url_for(:action => 'quote', :id => message, :format => 'js')}', '#message-#{j message.id} .wiki')", - :title => l(:button_quote), - :class => 'icon icon-comment' + <%= quote_reply( + url_for(:action => 'quote', :id => message, :format => 'js'), + "#message-#{message.id} .wiki", + icon_only: true ) if !@topic.locked? && authorize_for('messages', 'reply') %> <%= link_to( icon_with_label('edit', l(:button_edit), icon_only: true), diff --git a/lib/redmine/quote_reply.rb b/lib/redmine/quote_reply.rb new file mode 100644 index 000000000..18a13eb6f --- /dev/null +++ b/lib/redmine/quote_reply.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006- Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module Redmine + module QuoteReply + module Helper + def javascript_for_quote_reply_include_tag + javascript_include_tag 'quote_reply' + end + + def quote_reply(url, selector_for_content, icon_only: false) + quote_reply_function = "quoteReply('#{j url}', '#{j selector_for_content}')" + + html_options = { class: 'icon icon-comment' } + html_options[:title] = l(:button_quote) if icon_only + + link_to_function( + icon_with_label('comment', l(:button_quote), icon_only: icon_only), + quote_reply_function, + html_options + ) + end + end + end +end diff --git a/test/helpers/journals_helper_test.rb b/test/helpers/journals_helper_test.rb index 55fb1260a..b9d73ef64 100644 --- a/test/helpers/journals_helper_test.rb +++ b/test/helpers/journals_helper_test.rb @@ -57,7 +57,7 @@ class JournalsHelperTest < Redmine::HelperTest journals = issue.visible_journals_with_index # add indice journal_actions = render_journal_actions(issue, journals.first, {reply_links: true}) - assert_select_in journal_actions, 'a[title=?][class="icon-only icon-comment"]', 'Quote' + assert_select_in journal_actions, 'a[title=?][class="icon icon-comment"]', 'Quote' assert_select_in journal_actions, 'a[title=?][class="icon-only icon-edit"]', 'Edit' assert_select_in journal_actions, 'div[class="drdn-items"] a[class="icon icon-del"]' assert_select_in journal_actions, 'div[class="drdn-items"] a[class="icon icon-copy-link"]' diff --git a/test/unit/lib/redmine/quote_reply_helper_test.rb b/test/unit/lib/redmine/quote_reply_helper_test.rb new file mode 100644 index 000000000..6c643c045 --- /dev/null +++ b/test/unit/lib/redmine/quote_reply_helper_test.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006- Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require_relative '../../../test_helper' + +class QuoteReplyHelperTest < ActionView::TestCase + include ERB::Util + include Redmine::QuoteReply::Helper + + fixtures :issues + + def test_quote_reply + url = quoted_issue_path(issues(:issues_001)) + + a_tag = quote_reply(url, '#issue_description_wiki') + assert_includes a_tag, %|onclick="#{h "quoteReply('/issues/1/quoted', '#issue_description_wiki'); return false;"}"| + assert_includes a_tag, %|class="icon icon-comment"| + assert_not_includes a_tag, 'title=' + + # When icon_only is true + a_tag = quote_reply(url, '#issue_description_wiki', icon_only: true) + assert_includes a_tag, %|title="Quote"| + end +end -- 2.44.0