From c6df9ed10b3703863d7c601ed383704d83df3c3f Mon Sep 17 00:00:00 2001 From: ishikawa999 Date: Tue, 16 Mar 2021 01:34:47 +0000 Subject: [PATCH] Add link to copy object's url to the clipboard --- app/helpers/application_helper.rb | 8 +++++ app/helpers/journals_helper.rb | 4 ++- app/views/issues/_action_menu.html.erb | 1 + config/locales/en.yml | 1 + public/images/copy_link.png | Bin 0 -> 1731 bytes public/javascripts/application.js | 17 +++++++++ public/stylesheets/application.css | 1 + test/functional/issues_controller_test.rb | 26 +++++++------- test/helpers/journals_helper_test.rb | 1 + test/system/copy_to_clipboard_test.rb | 56 ++++++++++++++++++++++++++++++ 10 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 public/images/copy_link.png create mode 100644 test/system/copy_to_clipboard_test.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5163ea181..c4693dc8d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb index 4c3d410ec..ef649a278 100644 --- a/app/helpers/journals_helper.rb +++ b/app/helpers/journals_helper.rb @@ -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, diff --git a/app/views/issues/_action_menu.html.erb b/app/views/issues/_action_menu.html.erb index 93e5bad63..a1dcd6312 100644 --- a/app/views/issues/_action_menu.html.erb +++ b/app/views/issues/_action_menu.html.erb @@ -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), diff --git a/config/locales/en.yml b/config/locales/en.yml index 5cbb33ffc..2ff0ae432 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 index 0000000000000000000000000000000000000000..2a2eb09ff87e0a7f43258ef1c7fbeebe5552247c GIT binary patch literal 1731 zcmbVNe@q)y96w+Ln3lS@C4}I-9hqZc?fvKv=t*JF!lf|IDTc`2{#0?lG& zy8`yLSNr+)Any=}l486l$|8a=&^SCA4oNB-brLaN7OnMdlE7mSE$Adlb%A)j*N3~H z0&u&TGVv5;#|s>0+HNhdS$5$J#n2?hkhIN2)2xkQX$u~I2qaAr8rfQRMO+s8auUs& zCbJ|NiA2m1iy10SB<*lGbPk3wA%sb7lQb@BlGNN)1~*W7MU*uWO1RF*1z?NjB#@>n zCWPe#t)#}?gd9djIhmx*lx|WCDDVlK+@geH!UdiLArJvY2R_pSH4$onycEAlX&29I|<|$vnUFzU=0AP1=vg!0}4$vZw;6nmO{J9 zR!|566wLz%ZC$lNT6cs=w$AmZENBYR+lHqs0b>3^ie3QUEKT7*+TX%q6+LsO1K%9DDnuGm5T z)5O@>nz~+vqh_Hm6I}{@B>EhXP;*mI7ZZlS6ow_$d)%e|yw|`9XXODdtNY9!6LrHQ z>8(9Cwi&vPeNl7c!}QF|Oeu5zWa+`2XL}~_PU3Xx!42=sWS$%ByEE7|`x;wv3*y z>i;-@@WR=@?o&C?Mwdgsp%SHO8@DBZMU;uGNcscY~A$hpN8Gb-A4|;>-eE7WA^0G%lQqx zV^<0V$Byz|%k#a=E5lcxarRYoW&M2Uz_IEHaAom$lCt@|TPah!zRRUTrT3SHc6)xA zcc(2~7)gF=p1+os@%EvQP7Qy$x#reZ`g-2wS2K=$Hn)GW {: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 diff --git a/test/helpers/journals_helper_test.rb b/test/helpers/journals_helper_test.rb index a75992c41..69628b0b5 100644 --- a/test/helpers/journals_helper_test.rb +++ b/test/helpers/journals_helper_test.rb @@ -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 index 000000000..c54508fea --- /dev/null +++ b/test/system/copy_to_clipboard_test.rb @@ -0,0 +1,56 @@ +# 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 File.expand_path('../../application_system_test_case', __FILE__) + +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([:control, '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([:control, 'v']) + assert find('textarea#issue_notes').value.end_with?('/issues/1#note-2') + end +end -- 2.11.0