mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
1) Copy table rows across two or more active query tool sessions. 2) Copied rows can be pasted multiple times without selecting a row in the query tool grid. 3) Adds an empty row at the end in the query tool grid after pasting rows.
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
/////////////////////////////////////////////////////////////
|
|
//
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
//
|
|
// Copyright (C) 2013 - 2020, The pgAdmin Development Team
|
|
// This software is released under the PostgreSQL Licence
|
|
//
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
define([
|
|
'jquery',
|
|
'underscore',
|
|
'sources/selection/clipboard',
|
|
'sources/selection/range_selection_helper',
|
|
'sources/selection/range_boundary_navigator',
|
|
],
|
|
function ($, _, clipboard, RangeSelectionHelper, rangeBoundaryNavigator) {
|
|
var copyData = function () {
|
|
var self = this || window;
|
|
|
|
var grid = self.slickgrid;
|
|
var columnDefinitions = grid.getColumns();
|
|
var selectedRanges = grid.getSelectionModel().getSelectedRanges();
|
|
var dataView = grid.getData();
|
|
var rows = grid.getSelectedRows();
|
|
var CSVOptions = grid.CSVOptions;
|
|
|
|
if (RangeSelectionHelper.areAllRangesCompleteRows(grid, selectedRanges)) {
|
|
self.copied_rows = rows.map(function (rowIndex) {
|
|
return grid.getDataItem(rowIndex);
|
|
});
|
|
setPasteRowButtonEnablement(self.can_edit, true);
|
|
} else {
|
|
self.copied_rows = [];
|
|
setPasteRowButtonEnablement(self.can_edit, false);
|
|
}
|
|
var csvText = rangeBoundaryNavigator.rangesToCsv(dataView.getItems(), columnDefinitions,
|
|
selectedRanges, CSVOptions, copyWithHeader());
|
|
if (csvText) {
|
|
clipboard.copyTextToClipboard(csvText);
|
|
}
|
|
};
|
|
|
|
var copyWithHeader = function () {
|
|
return !$('.copy-with-header').hasClass('visibility-hidden');
|
|
};
|
|
|
|
var setPasteRowButtonEnablement = function (canEditFlag, isEnabled) {
|
|
if (canEditFlag) {
|
|
$('#btn-paste-row').prop('disabled', !isEnabled);
|
|
if(isEnabled && window.parent.$) {
|
|
// trigger copied event to all sessions
|
|
window.parent.$(window.parent.document).trigger('pgadmin-sqleditor:rows-copied', copyWithHeader());
|
|
}
|
|
}
|
|
};
|
|
return copyData;
|
|
});
|