From 15c8c5c056d79c0b255cdfe4bf9223d07b876d97 Mon Sep 17 00:00:00 2001 From: Varun Sharma Date: Wed, 13 Sep 2017 16:03:34 +0530 Subject: [PATCH 1/3] Implements #8263, Adds a re-usable Clipboard Copying service. --- .../public/doc_table/components/table_row.js | 9 ++++- .../components/table_row/details.html | 7 ++++ src/ui/public/share/index.js | 1 + .../public/share/services/copyToClipboard.js | 34 +++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/ui/public/share/services/copyToClipboard.js diff --git a/src/ui/public/doc_table/components/table_row.js b/src/ui/public/doc_table/components/table_row.js index dcf9c45787ccaf..1bb024eeb85805 100644 --- a/src/ui/public/doc_table/components/table_row.js +++ b/src/ui/public/doc_table/components/table_row.js @@ -26,7 +26,7 @@ const MIN_LINE_LENGTH = 20; * * ``` */ -module.directive('kbnTableRow', function ($compile, $httpParamSerializer, kbnUrl) { +module.directive('kbnTableRow', function ($compile, $httpParamSerializer, kbnUrl, copyToClipboardService) { const cellTemplate = _.template(noWhiteSpace(require('ui/doc_table/components/table_row/cell.html'))); const truncateByHeightTemplate = _.template(noWhiteSpace(require('ui/partials/truncate_by_height.html'))); @@ -51,6 +51,13 @@ module.directive('kbnTableRow', function ($compile, $httpParamSerializer, kbnUrl // when we compile the toggle button in the summary, we use this $scope let $toggleScope; + $scope.copyToClipboard = (uriescape) => { + let text = window.location.origin + window.location.pathname; + text += '#/doc/' + $scope.indexPattern.id + '/' + $scope.row._index + '/' + + $scope.row._type + '/?id=' + ($scope.row._id || uriescape); + copyToClipboardService.copyText(text); + }; + // toggle display of the rows details, a full list of the fields from each row $scope.toggleRow = function () { const $detailsTr = $el.next(); diff --git a/src/ui/public/doc_table/components/table_row/details.html b/src/ui/public/doc_table/components/table_row/details.html index 46e52b7caa4f1f..cba4991be10bdf 100644 --- a/src/ui/public/doc_table/components/table_row/details.html +++ b/src/ui/public/doc_table/components/table_row/details.html @@ -15,6 +15,13 @@ > View single document + + Copy Link + { + const notify = new Notifier({ + location: `Copy To Clipboard`, + }); + return { + copyText: text => { + const temp = document.createElement('textarea'); + temp.value = text; + temp.cols = 1; + temp.rows = 1; + temp.style.color = 'transparent'; + temp.style.border = 'none'; + document.body.appendChild(temp); + temp.select(); + let isCopied = false; + try { + isCopied = document.execCommand('copy'); + if (isCopied) { + notify.info('URL copied to clipboard.'); + } else { + notify.error('Failed to Copy to Clipboard.'); + } + } catch (err) { + notify.error('Failed to Copy to Clipboard.'); + } + document.body.removeChild(temp); + } + }; +}); \ No newline at end of file From d96233f37c0c681b413724ece890702a6668167b Mon Sep 17 00:00:00 2001 From: Varun Sharma Date: Wed, 13 Sep 2017 20:11:37 +0530 Subject: [PATCH 2/3] Makes action Keyboard accessible. --- src/ui/public/doc_table/components/table_row/details.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/public/doc_table/components/table_row/details.html b/src/ui/public/doc_table/components/table_row/details.html index cba4991be10bdf..280107b12debbe 100644 --- a/src/ui/public/doc_table/components/table_row/details.html +++ b/src/ui/public/doc_table/components/table_row/details.html @@ -15,13 +15,13 @@ > View single document - Copy Link - + Date: Fri, 22 Sep 2017 14:01:57 +0530 Subject: [PATCH 3/3] Using template strings instead of String Concatination. --- src/ui/public/doc_table/components/table_row.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ui/public/doc_table/components/table_row.js b/src/ui/public/doc_table/components/table_row.js index 1bb024eeb85805..bc2ce03b5f0926 100644 --- a/src/ui/public/doc_table/components/table_row.js +++ b/src/ui/public/doc_table/components/table_row.js @@ -52,9 +52,8 @@ module.directive('kbnTableRow', function ($compile, $httpParamSerializer, kbnUrl let $toggleScope; $scope.copyToClipboard = (uriescape) => { - let text = window.location.origin + window.location.pathname; - text += '#/doc/' + $scope.indexPattern.id + '/' + $scope.row._index + '/' + - $scope.row._type + '/?id=' + ($scope.row._id || uriescape); + let text = `${window.location.origin}${window.location.pathname}`; + text += `#/doc/${$scope.indexPattern.id}/${$scope.row._index}/${$scope.row._type}/?id=${$scope.row._id || uriescape}`; copyToClipboardService.copyText(text); };