Feature #41294 » 0003-Add-the-ability-to-quote-partial-text.patch
| app/assets/javascripts/application.js | ||
|---|---|---|
|
tribute.attach(element);
|
||
|
}
|
||
|
function quoteReply(path) {
|
||
|
function quoteReply(path, selectorForContentElement) {
|
||
|
const contentElement = $(selectorForContentElement).get(0);
|
||
|
const quote = QuoteExtractor.extract(contentElement);
|
||
|
$.ajax({
|
||
|
url: path,
|
||
|
type: 'post'
|
||
|
type: 'post',
|
||
|
data: { quote: quote }
|
||
|
});
|
||
|
}
|
||
|
class QuoteExtractor {
|
||
|
static extract(targetElement) {
|
||
|
return new QuoteExtractor(targetElement).extract();
|
||
|
}
|
||
|
constructor(targetElement) {
|
||
|
this.targetElement = targetElement;
|
||
|
this.selection = window.getSelection();
|
||
|
}
|
||
|
extract() {
|
||
|
const range = this.selectedRange;
|
||
|
if (!range) {
|
||
|
return null;
|
||
|
}
|
||
|
if (!this.targetElement.contains(range.startContainer)) {
|
||
|
range.setStartBefore(this.targetElement);
|
||
|
}
|
||
|
if (!this.targetElement.contains(range.endContainer)) {
|
||
|
range.setEndAfter(this.targetElement);
|
||
|
}
|
||
|
return this.formatRange(range);
|
||
|
}
|
||
|
formatRange(range) {
|
||
|
return range.toString().trim();
|
||
|
}
|
||
|
get selectedRange() {
|
||
|
if (!this.isSelected) {
|
||
|
return null;
|
||
|
}
|
||
|
// Retrive the first range that intersects with the target element.
|
||
|
// NOTE: Firefox allows to select multiple ranges in the document.
|
||
|
for (let i = 0; i < this.selection.rangeCount; i++) {
|
||
|
let range = this.selection.getRangeAt(i);
|
||
|
if (range.intersectsNode(this.targetElement)) {
|
||
|
return range;
|
||
|
}
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
get isSelected() {
|
||
|
return this.selection.containsNode(this.targetElement, true);
|
||
|
}
|
||
|
}
|
||
|
$(document).ready(setupAjaxIndicator);
|
||
|
$(document).ready(hideOnLoad);
|
||
|
$(document).ready(addFormObserversForDoubleSubmit);
|
||
| app/controllers/journals_controller.rb | ||
|---|---|---|
|
@content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
|
||
|
end
|
||
|
# Replaces pre blocks with [...]
|
||
|
text = text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
|
||
|
text = params[:quote].presence || text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
|
||
|
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||
|
rescue ActiveRecord::RecordNotFound
|
||
|
render_404
|
||
| app/controllers/messages_controller.rb | ||
|---|---|---|
|
else
|
||
|
@content = "#{ll(Setting.default_language, :text_user_wrote_in, {:value => @message.author, :link => "message##{@message.id}"})}\n> "
|
||
|
end
|
||
|
@content << @message.content.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||
|
quote_text = params[:quote].presence || @message.content.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
|
||
|
@content << quote_text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||
|
respond_to do |format|
|
||
|
format.html { render_404 }
|
||
| app/helpers/journals_helper.rb | ||
|---|---|---|
|
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 quoted_issue_path(issue, :journal_id => journal, :journal_indice => indice)}')",
|
||
|
"quoteReply('#{j url}', '#journal-#{j journal.id}-notes')",
|
||
|
:title => l(:button_quote),
|
||
|
:class => 'icon-only icon-comment'
|
||
|
)
|
||
| app/views/issues/show.html.erb | ||
|---|---|---|
|
<hr />
|
||
|
<div class="description">
|
||
|
<div class="contextual">
|
||
|
<%= link_to_function icon_with_label('comment', l(:button_quote)), "quoteReply('#{j quoted_issue_path(@issue)}')",:class => 'icon icon-comment ' if @issue.notes_addable? %>
|
||
|
<%= 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? %>
|
||
|
</div>
|
||
|
<p><strong><%=l(:field_description)%></strong></p>
|
||
|
<div class="wiki">
|
||
|
<div id="issue_description_wiki" class="wiki">
|
||
|
<%= textilizable @issue, :description, :attachments => @issue.attachments %>
|
||
|
</div>
|
||
|
</div>
|
||
| app/views/messages/show.html.erb | ||
|---|---|---|
|
<%= 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')}')",
|
||
|
"quoteReply('#{j url_for(:action => 'quote', :id => @topic, :format => 'js')}', '#message_topic_wiki')",
|
||
|
:class => 'icon icon-comment') if !@topic.locked? && authorize_for('messages', 'reply') %>
|
||
|
<%= link_to(
|
||
|
icon_with_label('edit', l(:button_edit)),
|
||
| ... | ... | |
|
<div class="message">
|
||
|
<p><span class="author"><%= authoring @topic.created_on, @topic.author %></span></p>
|
||
|
<div class="wiki">
|
||
|
<div id="message_topic_wiki" class="wiki">
|
||
|
<%= textilizable(@topic, :content) %>
|
||
|
</div>
|
||
|
<%= link_to_attachments @topic, :author => false, :thumbnails => true %>
|
||
| ... | ... | |
|
<div class="contextual">
|
||
|
<%= link_to_function(
|
||
|
icon_with_label('comment', l(:button_quote), icon_only: true),
|
||
|
"quoteReply('#{j url_for(:action => 'quote', :id => message, :format => 'js')}')",
|
||
|
"quoteReply('#{j url_for(:action => 'quote', :id => message, :format => 'js')}', '#message-#{j message.id} .wiki')",
|
||
|
:title => l(:button_quote),
|
||
|
:class => 'icon icon-comment'
|
||
|
) if !@topic.locked? && authorize_for('messages', 'reply') %>
|
||
| test/functional/journals_controller_test.rb | ||
|---|---|---|
|
assert_response :not_found
|
||
|
end
|
||
|
def test_reply_to_issue_with_partial_quote
|
||
|
@request.session[:user_id] = 2
|
||
|
params = { id: 6, quote: 'a private subproject of cookbook' }
|
||
|
post :new, params: params, xhr: true
|
||
|
assert_response :success
|
||
|
assert_equal 'text/javascript', response.media_type
|
||
|
assert_include 'John Smith wrote:', response.body
|
||
|
assert_include '> a private subproject of cookbook', response.body
|
||
|
end
|
||
|
def test_reply_to_note_with_partial_quote
|
||
|
@request.session[:user_id] = 2
|
||
|
params = { id: 6, journal_id: 4, journal_indice: 1, quote: 'a private version' }
|
||
|
post :new, params: params, xhr: true
|
||
|
assert_response :success
|
||
|
assert_equal 'text/javascript', response.media_type
|
||
|
assert_include 'Redmine Admin wrote in #note-1:', response.body
|
||
|
assert_include '> a private version', response.body
|
||
|
end
|
||
|
def test_edit_xhr
|
||
|
@request.session[:user_id] = 1
|
||
|
get(:edit, :params => {:id => 2}, :xhr => true)
|
||
| test/functional/messages_controller_test.rb | ||
|---|---|---|
|
assert_include '> An other reply', response.body
|
||
|
end
|
||
|
def test_quote_with_partial_quote_if_message_is_root
|
||
|
@request.session[:user_id] = 2
|
||
|
params = { board_id: 1, id: 1,
|
||
|
quote: "the very first post\nin the forum" }
|
||
|
post :quote, params: params, xhr: true
|
||
|
assert_response :success
|
||
|
assert_equal 'text/javascript', response.media_type
|
||
|
assert_include 'RE: First post', response.body
|
||
|
assert_include "Redmine Admin wrote:", response.body
|
||
|
assert_include '> the very first post\n> in the forum', response.body
|
||
|
end
|
||
|
def test_quote_with_partial_quote_if_message_is_not_root
|
||
|
@request.session[:user_id] = 2
|
||
|
params = { board_id: 1, id: 3, quote: 'other reply' }
|
||
|
post :quote, params: params, xhr: true
|
||
|
assert_response :success
|
||
|
assert_equal 'text/javascript', response.media_type
|
||
|
assert_include 'RE: First post', response.body
|
||
|
assert_include 'John Smith wrote in message#3:', response.body
|
||
|
assert_include '> other reply', response.body
|
||
|
end
|
||
|
def test_quote_as_html_should_respond_with_404
|
||
|
@request.session[:user_id] = 2
|
||
|
post(
|
||
| test/system/issues_reply_test.rb | ||
|---|---|---|
|
click_link 'Quote'
|
||
|
end
|
||
|
# Select the other than the issue description element.
|
||
|
page.execute_script <<-JS
|
||
|
const range = document.createRange();
|
||
|
// Select "Description" text.
|
||
|
range.selectNodeContents(document.querySelector('.description > p'))
|
||
|
window.getSelection().addRange(range);
|
||
|
JS
|
||
|
assert_field 'issue_notes', with: <<~TEXT
|
||
|
John Smith wrote:
|
||
|
> Unable to print recipes
|
||
| ... | ... | |
|
TEXT
|
||
|
assert_selector :css, '#issue_notes:focus'
|
||
|
end
|
||
|
def test_reply_to_issue_with_partial_quote
|
||
|
assert_text 'Unable to print recipes'
|
||
|
# Select only the "print" text from the text "Unable to print recipes" in the description.
|
||
|
page.execute_script <<-JS
|
||
|
const range = document.createRange();
|
||
|
const wiki = document.querySelector('#issue_description_wiki > p').childNodes[0];
|
||
|
range.setStart(wiki, 10);
|
||
|
range.setEnd(wiki, 15);
|
||
|
window.getSelection().addRange(range);
|
||
|
JS
|
||
|
within '.issue.details' do
|
||
|
click_link 'Quote'
|
||
|
end
|
||
|
assert_field 'issue_notes', with: <<~TEXT
|
||
|
John Smith wrote:
|
||
|
> print
|
||
|
TEXT
|
||
|
assert_selector :css, '#issue_notes:focus'
|
||
|
end
|
||
|
def test_reply_to_note_with_partial_quote
|
||
|
assert_text 'Journal notes'
|
||
|
# Select the entire details of the note#1 and the part of the note#1's text.
|
||
|
page.execute_script <<-JS
|
||
|
const range = document.createRange();
|
||
|
range.setStartBefore(document.querySelector('#change-1 .details'));
|
||
|
// Select only the text "Journal" from the text "Journal notes" in the note-1.
|
||
|
range.setEnd(document.querySelector('#change-1 .wiki > p').childNodes[0], 7);
|
||
|
window.getSelection().addRange(range);
|
||
|
JS
|
||
|
within '#change-1' do
|
||
|
click_link 'Quote'
|
||
|
end
|
||
|
assert_field 'issue_notes', with: <<~TEXT
|
||
|
Redmine Admin wrote in #note-1:
|
||
|
> Journal
|
||
|
TEXT
|
||
|
assert_selector :css, '#issue_notes:focus'
|
||
|
end
|
||
|
end
|
||
| test/system/messages_test.rb | ||
|---|---|---|
|
TEXT
|
||
|
end
|
||
|
def test_reply_to_topic_message_with_partial_quote
|
||
|
assert_text /This is the very first post/
|
||
|
# Select the part of the topic message through the entire text of the attachment below it.
|
||
|
page.execute_script <<-'JS'
|
||
|
const range = document.createRange();
|
||
|
const message = document.querySelector('#message_topic_wiki');
|
||
|
// Select only the text "in the forum" from the text "This is the very first post\nin the forum".
|
||
|
range.setStartBefore(message.querySelector('p').childNodes[2]);
|
||
|
range.setEndAfter(message.parentNode.querySelector('.attachments'));
|
||
|
window.getSelection().addRange(range);
|
||
|
JS
|
||
|
within '#content > .contextual' do
|
||
|
click_link 'Quote'
|
||
|
end
|
||
|
assert_field 'message_content', with: <<~TEXT
|
||
|
Redmine Admin wrote:
|
||
|
> in the forum
|
||
|
TEXT
|
||
|
end
|
||
|
def test_reply_to_message_with_partial_quote
|
||
|
assert_text 'Reply to the first post'
|
||
|
# Select the entire message, including the subject and headers of messages #2 and #3.
|
||
|
page.execute_script <<-JS
|
||
|
const range = document.createRange();
|
||
|
range.setStartBefore(document.querySelector('#message-2'));
|
||
|
range.setEndAfter(document.querySelector('#message-3'));
|
||
|
window.getSelection().addRange(range);
|
||
|
JS
|
||
|
within '#message-2' do
|
||
|
click_link 'Quote'
|
||
|
end
|
||
|
assert_field 'message_content', with: <<~TEXT
|
||
|
Redmine Admin wrote in message#2:
|
||
|
> Reply to the first post
|
||
|
TEXT
|
||
|
end
|
||
|
end
|
||