]> source.dussan.org Git - redmine.git/commitdiff
"Copy link" feature for issue and issue journal (#34703).
authorGo MAEDA <maeda@farend.jp>
Thu, 18 Mar 2021 03:58:29 +0000 (03:58 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 18 Mar 2021 03:58:29 +0000 (03:58 +0000)
Patch by Mizuki ISHIKAWA.

git-svn-id: http://svn.redmine.org/redmine/trunk@20816 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
app/helpers/journals_helper.rb
app/views/issues/_action_menu.html.erb
config/locales/en.yml
public/images/copy_link.png [new file with mode: 0644]
public/javascripts/application.js
public/stylesheets/application.css
test/functional/issues_controller_test.rb
test/helpers/journals_helper_test.rb
test/system/copy_to_clipboard_test.rb [new file with mode: 0644]

index 5163ea1811269bff6b8e61c0a9da978d231f07c1..fe95eea4758ef25369c91e7aa82ebbddd30cf6b3 100644 (file)
@@ -1818,6 +1818,14 @@ module ApplicationHelper
     )
   end
 
+  def copy_object_url_link(url)
+    link_to_function(
+      l(:button_copy_link), 'copyTextToClipboard(this);',
+      class: 'icon icon-copy-link',
+      data: {'clipboard-text' => url}
+    )
+  end
+
   private
 
   def wiki_helper
index 4c3d410ecc2ed41d92fc045ac83057b9653bda12..ef649a278abc6f3983a2a5d362d2ed3d95896c80 100644 (file)
@@ -29,9 +29,11 @@ module JournalsHelper
   def render_journal_actions(issue, journal, options={})
     links = []
     dropbown_links = []
+    indice = journal.indice || @journal.issue.visible_journals_with_index.find{|j| j.id == @journal.id}.indice
+
+    dropbown_links << copy_object_url_link(issue_url(issue, anchor: "note-#{indice}", only_path: false))
     if journal.notes.present?
       if options[:reply_links]
-        indice = journal.indice || @journal.issue.visible_journals_with_index.find{|j| j.id == @journal.id}.indice
         links << link_to(l(:button_quote),
                          quoted_issue_path(issue, :journal_id => journal, :journal_indice => indice),
                          :remote => true,
index 93e5bad6335a8be2bcd5472a6d498ff34ec9c5d5..a1dcd6312f795c6c47fb9669e6d254f93ceab206 100644 (file)
@@ -6,6 +6,7 @@
             :class => 'icon icon-time-add' if User.current.allowed_to?(:log_time, @project) %>
 <%= watcher_link(@issue, User.current) %>
 <%= actions_dropdown do %>
+  <%= copy_object_url_link(issue_url(@issue, only_path: false)) %>
   <%= link_to l(:button_copy), project_copy_issue_path(@project, @issue),
               :class => 'icon icon-copy' if User.current.allowed_to?(:copy_issues, @project) && Issue.allowed_target_projects.any? %>
   <%= link_to l(:button_delete), issue_path(@issue),
index 5cbb33ffc09e5423f92bf2cadf988c1b69d25f30..2ff0ae432a83814da1eacec023a0e3324a8a5dc1 100644 (file)
@@ -1149,6 +1149,7 @@ en:
   button_change_password: Change password
   button_copy: Copy
   button_copy_and_follow: Copy and follow
+  button_copy_link: Copy link
   button_annotate: Annotate
   button_fetch_changesets: Fetch commits
   button_update: Update
diff --git a/public/images/copy_link.png b/public/images/copy_link.png
new file mode 100644 (file)
index 0000000..2a2eb09
Binary files /dev/null and b/public/images/copy_link.png differ
index 770d5900cbf683a73956cc368996fb5184e95a45..bef8f592f7de9eec074c08a411ca674c9567a4a7 100644 (file)
@@ -563,6 +563,23 @@ function randomKey(size) {
   return key;
 }
 
+function copyTextToClipboard(target) {
+  if (target) {
+    var temp = document.createElement('textarea');
+    temp.value = target.getAttribute('data-clipboard-text');
+    document.body.appendChild(temp);
+    temp.select();
+    document.execCommand('copy');
+    if (temp.parentNode) {
+      temp.parentNode.removeChild(temp);
+    }
+    if ($(target).closest('.drdn.expanded').length) {
+      $(target).closest('.drdn.expanded').removeClass("expanded");
+    }
+  }
+  return false;
+}
+
 function updateIssueFrom(url, el) {
   $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
     $(this).data('valuebeforeupdate', $(this).val());
index 1c2f76c15f9fb4a1d91c71c3f2993233ee6be887..0c4102459c0d98ba0c0c51eb0e8df2cc1acc4386 100644 (file)
@@ -1612,6 +1612,7 @@ td.gantt_selected_column .gantt_hdr,.gantt_selected_column_container {
 .icon-file.application-pdf { background-image: url(../images/files/pdf.png); }
 .icon-file.application-zip { background-image: url(../images/files/zip.png); }
 .icon-file.application-gzip { background-image: url(../images/files/zip.png); }
+.icon-copy-link { background-image: url(../images/copy_link.png); }
 
 .sort-handle.ajax-loading { background-image: url(../images/loading.gif); }
 tr.ui-sortable-helper { border:1px solid #e4e4e4; }
index 45217b6968387380838042fd2e821990ebfd1648..dd85bb5d1ac85e537a5351fb1e7818cfa7af9a46 100644 (file)
@@ -2072,12 +2072,13 @@ class IssuesControllerTest < Redmine::ControllerTest
     get(:show, :params => {:id => 1})
     assert_response :success
     assert_select 'div.issue div.description', :text => /Unable to print recipes/
-    assert_select '.contextual' do
-      assert_select 'a', {:count => 2, :text => /Edit/}
-      assert_select 'a', {:count => 0, :text => /Log time/}
-      assert_select 'a', {:count => 0, :text => /Watch/}
-      assert_select 'div.drdn-items a', {:count => 0, :text => /Copy/}
-      assert_select 'div.drdn-items a', {:count => 0, :text => /Delete/}
+    assert_select '#content>.contextual:first-child' do
+      assert_select 'a', {:count => 1, :text => 'Edit'}
+      assert_select 'a', {:count => 0, :text => 'Log time'}
+      assert_select 'a', {:count => 0, :text => 'Watch'}
+      assert_select 'div.drdn-items a', {:count => 1, :text => 'Copy link'}
+      assert_select 'div.drdn-items a', {:count => 0, :text => 'Copy'}
+      assert_select 'div.drdn-items a', {:count => 0, :text => 'Delete'}
     end
     # anonymous role is allowed to add a note
     assert_select 'form#issue-form' do
@@ -2093,12 +2094,13 @@ class IssuesControllerTest < Redmine::ControllerTest
     @request.session[:user_id] = 2
     get(:show, :params => {:id => 1})
     assert_select 'a', :text => /Quote/
-    assert_select '.contextual' do
-      assert_select 'a', {:count => 2, :text => /Edit/}
-      assert_select 'a', :text => /Log time/
-      assert_select 'a', :text => /Watch/
-      assert_select 'div.drdn-items a', :text => /Copy/
-      assert_select 'div.drdn-items a', :text => /Delete/
+    assert_select '#content>.contextual:first-child' do
+      assert_select 'a', {:count => 1, :text => 'Edit'}
+      assert_select 'a', {:count => 1, :text => 'Log time'}
+      assert_select 'a', {:count => 1, :text => 'Watch'}
+      assert_select 'div.drdn-items a', {:count => 1, :text => 'Copy link'}
+      assert_select 'div.drdn-items a', {:count => 1, :text => 'Copy'}
+      assert_select 'div.drdn-items a', {:count => 1, :text => 'Delete'}
     end
     assert_select 'form#issue-form' do
       assert_select 'fieldset' do
index a75992c41f83565cdb98f484f6554828b32a0f75..69628b0b59ca4318eec232a4d4f7b5ed5a150fa3 100644 (file)
@@ -59,6 +59,7 @@ class JournalsHelperTest < Redmine::HelperTest
     assert_select_in journal_actions, 'a[title=?][class="icon-only 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"]'
   end
 
   def test_journal_thumbnail_attachments_should_be_in_the_same_order_as_the_journal_details
diff --git a/test/system/copy_to_clipboard_test.rb b/test/system/copy_to_clipboard_test.rb
new file mode 100644 (file)
index 0000000..ffa7b79
--- /dev/null
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006-2020  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 '../application_system_test_case'
+
+class CopyToClipboardSystemTest < ApplicationSystemTestCase
+  fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
+           :trackers, :projects_trackers, :enabled_modules, :issue_statuses, :issues,
+           :enumerations, :custom_fields, :custom_values, :custom_fields_trackers,
+           :watchers, :journals, :journal_details, :versions,
+           :workflows, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
+
+  def test_copy_issue_url_to_clipboard
+    log_user('jsmith', 'jsmith')
+    visit 'issues/1'
+
+    # Copy issue url to Clipboard
+    first('.contextual span.icon-actions').click
+    find('.contextual div.drdn-items a.icon-copy-link').click
+
+    # Paste the value copied to the clipboard into the textarea to get and test
+    first('.icon-edit').click
+    find('textarea#issue_notes').send_keys([modifier_key, 'v'])
+    assert find('textarea#issue_notes').value.end_with?('/issues/1')
+  end
+
+  def test_copy_issue_journal_url_to_clipboard
+    log_user('jsmith', 'jsmith')
+    visit 'issues/1'
+
+    # Copy issue journal url to Clipboard
+    first('#note-2 .icon-actions').click
+    first('#note-2 div.drdn-items a.icon-copy-link').click
+
+    # Paste the value copied to the clipboard into the textarea to get and test
+    first('.icon-edit').click
+    find('textarea#issue_notes').send_keys([modifier_key, 'v'])
+    assert find('textarea#issue_notes').value.end_with?('/issues/1#note-2')
+  end
+
+  private
+
+  def modifier_key
+    modifier = osx? ? 'command' : 'control'
+    modifier.to_sym
+  end
+end