AMBARI-20420. 'Link to copy' on background ops doesnt copy stderr/stdout to clipboard (alexantonenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/369057a8 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/369057a8 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/369057a8 Branch: refs/heads/branch-feature-AMBARI-12556 Commit: 369057a8b890cd320c0b9394f6168f9d58df5c20 Parents: 9b52ce5 Author: Alex Antonenko <[email protected]> Authored: Mon Mar 13 17:09:16 2017 +0200 Committer: Alex Antonenko <[email protected]> Committed: Mon Mar 13 18:56:31 2017 +0200 ---------------------------------------------------------------------- .../templates/common/host_progress_popup.hbs | 2 +- .../common/host_progress_popup_body_view.js | 20 ++++++++++++ .../host_progress_popup_body_view_test.js | 34 ++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/369057a8/ambari-web/app/templates/common/host_progress_popup.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/common/host_progress_popup.hbs b/ambari-web/app/templates/common/host_progress_popup.hbs index c9d344c..03c014c 100644 --- a/ambari-web/app/templates/common/host_progress_popup.hbs +++ b/ambari-web/app/templates/common/host_progress_popup.hbs @@ -276,7 +276,7 @@ <button type="button" class="btn btn-link pull-right" {{translateAttr title="common.openNewWindow"}} {{action openTaskLogInDialog}}> <i class="icon icon-external-link"></i> {{t common.open}} </button> - <button type="button" class="btn btn-link pull-right" {{translateAttr title="common.fullLogPopup.clickToCopy"}} {{action "textTrigger" taskInfo target="view"}}> + <button type="button" class="btn btn-link pull-right copy-clipboard" {{translateAttr title="common.fullLogPopup.clickToCopy"}} {{action "textTrigger" taskInfo target="view"}}> <i class="glyphicon glyphicon-copy"></i> {{t common.copy}} </button> <button type="button" class="btn btn-link pull-right" {{action backToTaskList}}> http://git-wip-us.apache.org/repos/asf/ambari/blob/369057a8/ambari-web/app/views/common/host_progress_popup_body_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/host_progress_popup_body_view.js b/ambari-web/app/views/common/host_progress_popup_body_view.js index 25be849..5cce8e7 100644 --- a/ambari-web/app/views/common/host_progress_popup_body_view.js +++ b/ambari-web/app/views/common/host_progress_popup_body_view.js @@ -105,6 +105,15 @@ App.HostProgressPopupBodyView = App.TableView.extend({ hostInfoLoaded: true, /** + * Clipboard for task logs + * Used when user click "Copy" and textarea with task stderr and stdout is shown + * Should be destroyed (call `destroy`) when used is moved out from task logs level or when BG-ops modal is closed + * + * @type {?Clipboard} + */ + taskLogsClipboard: null, + + /** * Alias for <code>controller.hosts</code> * * @type {wrappedHost[]} @@ -933,6 +942,13 @@ App.HostProgressPopupBodyView = App.TableView.extend({ toggleTaskLog: function (event) { var taskInfo = event.context; this.set("parentView.isLogWrapHidden", false); + const self = this; + var taskLogsClipboard = new Clipboard('.btn.copy-clipboard', { + text: function() { + return self.get('textAreaValue'); + } + }); + this.set('taskLogsClipboard', taskLogsClipboard); if (this.get('isClipBoardActive')) { this.destroyClipBoard(); } @@ -978,6 +994,10 @@ App.HostProgressPopupBodyView = App.TableView.extend({ var logElement = this.get('isLogComponentActive') ? $('.log-component-tab.active .log-tail-content'): $(".task-detail-log-maintext"); logElement.css('display', 'block'); this.set('isClipBoardActive', false); + const taskLogsClipboard = this.get('taskLogsClipboard'); + if (taskLogsClipboard) { + Em.tryInvoke(taskLogsClipboard, 'destroy'); + } }, /** http://git-wip-us.apache.org/repos/asf/ambari/blob/369057a8/ambari-web/test/views/common/host_progress_popup_body_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/common/host_progress_popup_body_view_test.js b/ambari-web/test/views/common/host_progress_popup_body_view_test.js index 370f75a..5ccc024 100644 --- a/ambari-web/test/views/common/host_progress_popup_body_view_test.js +++ b/ambari-web/test/views/common/host_progress_popup_body_view_test.js @@ -24,6 +24,7 @@ describe('App.HostProgressPopupBodyView', function () { beforeEach(function () { view = App.HostProgressPopupBodyView.create({ controller: Em.Object.create({ + setSelectCount: Em.K, dataSourceController: Em.Object.create({}), setBackgroundOperationHeader: Em.K, hosts: [] @@ -303,4 +304,37 @@ describe('App.HostProgressPopupBodyView', function () { expect(view.rerender.calledOnce).to.be.true; }); }); + + describe('#toggleTaskLog', function () { + + var task = {}; + + beforeEach(function() { + view.toggleTaskLog({context: task}); + }); + + it('clipboard created', function () { + expect(view.get('taskLogsClipboard')).to.be.instanceOf(Clipboard); + }); + + }); + + describe('#destroyClipBoard', function () { + + beforeEach(function () { + view.toggleTaskLog({context: {}}); + sinon.spy(view.get('taskLogsClipboard'), 'destroy'); + view.destroyClipBoard(); + }); + + afterEach(function () { + view.get('taskLogsClipboard').destroy.restore(); + }); + + it('should destroy clipboard', function () { + expect(view.get('taskLogsClipboard').destroy.calledOnce).to.be.true; + }); + + }); + });
