Project

General

Profile

Feature #41294 » 0005-Separate-helpers-for-the-quote-reply-into-the-Redmine-QuoteReply.patch

Katsuya HIDAKA, 2024-09-22 13:01

View differences:

app/helpers/journals_helper.rb
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 19

  
20 20
module JournalsHelper
21
  include Redmine::QuoteReply::Helper
22

  
21 23
  # Returns the attachments of a journal that are displayed as thumbnails
22 24
  def journal_thumbnail_attachments(journal)
23 25
    journal.attachments.select(&:thumbnailable?)
......
41 43
    if journal.notes.present?
42 44
      if options[:reply_links]
43 45
        url = quoted_issue_path(issue, :journal_id => journal, :journal_indice => indice)
44
        links << link_to_function(icon_with_label('comment', l(:button_quote)),
45
                                  "quoteReply('#{j url}', '#journal-#{j journal.id}-notes')",
46
                                  :title => l(:button_quote),
47
                                  :class => 'icon-only icon-comment'
48
                                 )
46
        links << quote_reply(url, "#journal-#{journal.id}-notes", icon_only: true)
49 47
      end
50 48
      if journal.editable_by?(User.current)
51 49
        links << link_to(icon_with_label('edit', l(:button_edit)),
app/helpers/messages_helper.rb
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 19

  
20 20
module MessagesHelper
21
  include Redmine::QuoteReply::Helper
21 22
end
app/views/issues/show.html.erb
1 1
<% content_for :header_tags do %>
2
  <%= javascript_include_tag 'quote_reply' %>
2
  <%= javascript_for_quote_reply_include_tag %>
3 3
<% end %>
4 4

  
5 5
<%= render :partial => 'action_menu' %>
......
88 88
<hr />
89 89
<div class="description">
90 90
  <div class="contextual">
91
  <%= link_to_function(icon_with_label('comment', l(:button_quote)),
92
                       "quoteReply('#{j quoted_issue_path(@issue)}', '#issue_description_wiki')",
93
                       :class => 'icon icon-comment '
94
                      ) if @issue.notes_addable? %>
91
  <%= quote_reply(quoted_issue_path(@issue), '#issue_description_wiki') if @issue.notes_addable? %>
95 92
  </div>
96 93

  
97 94
  <p><strong><%=l(:field_description)%></strong></p>
app/views/messages/show.html.erb
1 1
<% content_for :header_tags do %>
2
  <%= javascript_include_tag 'quote_reply' %>
2
  <%= javascript_for_quote_reply_include_tag %>
3 3
<% end %>
4 4

  
5 5
<%= board_breadcrumb(@message) %>
6 6

  
7 7
<div class="contextual">
8 8
    <%= watcher_link(@topic, User.current) %>
9
    <%= link_to_function(
10
          icon_with_label('comment', l(:button_quote)),
11
          "quoteReply('#{j url_for(:action => 'quote', :id => @topic, :format => 'js')}', '#message_topic_wiki')",
12
          :class => 'icon icon-comment') if !@topic.locked? && authorize_for('messages', 'reply') %>
9
    <%= quote_reply(
10
          url_for(:action => 'quote', :id => @topic, :format => 'js'),
11
          '#message_topic_wiki'
12
        ) if !@topic.locked? && authorize_for('messages', 'reply') %>
13 13
    <%= link_to(
14 14
          icon_with_label('edit', l(:button_edit)),
15 15
          {:action => 'edit', :id => @topic},
......
44 44
<% @replies.each do |message| %>
45 45
  <div class="message reply" id="<%= "message-#{message.id}" %>">
46 46
    <div class="contextual">
47
      <%= link_to_function(
48
            icon_with_label('comment', l(:button_quote), icon_only: true),
49
            "quoteReply('#{j url_for(:action => 'quote', :id => message, :format => 'js')}', '#message-#{j message.id} .wiki')",
50
            :title => l(:button_quote),
51
            :class => 'icon icon-comment'
47
      <%= quote_reply(
48
            url_for(:action => 'quote', :id => message, :format => 'js'),
49
            "#message-#{message.id} .wiki",
50
            icon_only: true
52 51
          ) if !@topic.locked? && authorize_for('messages', 'reply') %>
53 52
      <%= link_to(
54 53
            icon_with_label('edit', l(:button_edit), icon_only: true),
lib/redmine/quote_reply.rb
1
# frozen_string_literal: true
2

  
3
# Redmine - project management software
4
# Copyright (C) 2006-  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

  
20
module Redmine
21
  module QuoteReply
22
    module Helper
23
      def javascript_for_quote_reply_include_tag
24
        javascript_include_tag 'quote_reply'
25
      end
26

  
27
      def quote_reply(url, selector_for_content, icon_only: false)
28
        quote_reply_function = "quoteReply('#{j url}', '#{j selector_for_content}')"
29

  
30
        html_options = { class: 'icon icon-comment' }
31
        html_options[:title] = l(:button_quote) if icon_only
32

  
33
        link_to_function(
34
          icon_with_label('comment', l(:button_quote), icon_only: icon_only),
35
          quote_reply_function,
36
          html_options
37
        )
38
      end
39
    end
40
  end
41
end
test/helpers/journals_helper_test.rb
57 57
    journals = issue.visible_journals_with_index # add indice
58 58
    journal_actions = render_journal_actions(issue, journals.first, {reply_links: true})
59 59

  
60
    assert_select_in journal_actions, 'a[title=?][class="icon-only icon-comment"]', 'Quote'
60
    assert_select_in journal_actions, 'a[title=?][class="icon icon-comment"]', 'Quote'
61 61
    assert_select_in journal_actions, 'a[title=?][class="icon-only icon-edit"]', 'Edit'
62 62
    assert_select_in journal_actions, 'div[class="drdn-items"] a[class="icon icon-del"]'
63 63
    assert_select_in journal_actions, 'div[class="drdn-items"] a[class="icon icon-copy-link"]'
test/unit/lib/redmine/quote_reply_helper_test.rb
1
# frozen_string_literal: true
2

  
3
# Redmine - project management software
4
# Copyright (C) 2006-  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

  
20
require_relative '../../../test_helper'
21

  
22
class QuoteReplyHelperTest < ActionView::TestCase
23
  include ERB::Util
24
  include Redmine::QuoteReply::Helper
25

  
26
  fixtures :issues
27

  
28
  def test_quote_reply
29
    url = quoted_issue_path(issues(:issues_001))
30

  
31
    a_tag = quote_reply(url, '#issue_description_wiki')
32
    assert_includes a_tag, %|onclick="#{h "quoteReply('/issues/1/quoted', '#issue_description_wiki'); return false;"}"|
33
    assert_includes a_tag, %|class="icon icon-comment"|
34
    assert_not_includes a_tag, 'title='
35

  
36
    # When icon_only is true
37
    a_tag = quote_reply(url, '#issue_description_wiki', icon_only: true)
38
    assert_includes a_tag, %|title="Quote"|
39
  end
40
end
(11-11/17)