mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 20:16:00 +00:00
paste using grider implementation
This commit is contained in:
@@ -99,9 +99,19 @@ export default class ChangeSetGrider extends Grider {
|
|||||||
this.applyModification((chs) => deleteChangeSetRows(chs, this.rowDefinitionsCache[index]));
|
this.applyModification((chs) => deleteChangeSetRows(chs, this.rowDefinitionsCache[index]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get rowCountInUpdate() {
|
||||||
|
if (this.batchChangeSet) {
|
||||||
|
const newRows = getChangeSetInsertedRows(this.batchChangeSet, this.display.baseTable);
|
||||||
|
return this.sourceRows.length + newRows.length;
|
||||||
|
} else {
|
||||||
|
return this.rowCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
insertRow(): number {
|
insertRow(): number {
|
||||||
|
const res = this.rowCountInUpdate;
|
||||||
this.applyModification((chs) => changeSetInsertNewRow(chs, this.display.baseTable));
|
this.applyModification((chs) => changeSetInsertNewRow(chs, this.display.baseTable));
|
||||||
return this.rowCount;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
beginUpdate() {
|
beginUpdate() {
|
||||||
|
|||||||
@@ -448,73 +448,67 @@ export default function DataGridCore(props) {
|
|||||||
|
|
||||||
function setCellValue(cell, value) {
|
function setCellValue(cell, value) {
|
||||||
grider.setCellValue(cell[0], realColumnUniqueNames[cell[1]], value);
|
grider.setCellValue(cell[0], realColumnUniqueNames[cell[1]], value);
|
||||||
// return setChangeSetValue(
|
|
||||||
// chs,
|
|
||||||
// display.getChangeSetField(
|
|
||||||
// rows[cell[0]],
|
|
||||||
// realColumnUniqueNames[cell[1]],
|
|
||||||
// cell[0] >= rows.length ? cell[0] - rows.length : null
|
|
||||||
// ),
|
|
||||||
// value
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePaste(event) {
|
function handlePaste(event) {
|
||||||
// var pastedText = undefined;
|
var pastedText = undefined;
|
||||||
// // @ts-ignore
|
// @ts-ignore
|
||||||
// if (window.clipboardData && window.clipboardData.getData) {
|
if (window.clipboardData && window.clipboardData.getData) {
|
||||||
// // IE
|
// IE
|
||||||
// // @ts-ignore
|
// @ts-ignore
|
||||||
// pastedText = window.clipboardData.getData('Text');
|
pastedText = window.clipboardData.getData('Text');
|
||||||
// } else if (event.clipboardData && event.clipboardData.getData) {
|
} else if (event.clipboardData && event.clipboardData.getData) {
|
||||||
// pastedText = event.clipboardData.getData('text/plain');
|
pastedText = event.clipboardData.getData('text/plain');
|
||||||
// }
|
}
|
||||||
// event.preventDefault();
|
event.preventDefault();
|
||||||
// const pasteRows = pastedText
|
grider.beginUpdate();
|
||||||
// .replace(/\r/g, '')
|
const pasteRows = pastedText
|
||||||
// .split('\n')
|
.replace(/\r/g, '')
|
||||||
// .map((row) => row.split('\t'));
|
.split('\n')
|
||||||
|
.map((row) => row.split('\t'));
|
||||||
// let chs = changeSet;
|
// let chs = changeSet;
|
||||||
// let allRows = loadedAndInsertedRows;
|
// let allRows = loadedAndInsertedRows;
|
||||||
// if (selectedCells.length <= 1) {
|
if (selectedCells.length <= 1) {
|
||||||
// const startRow = isRegularCell(currentCell) ? currentCell[0] : loadedAndInsertedRows.length;
|
const startRow = isRegularCell(currentCell) ? currentCell[0] : grider.rowCount;
|
||||||
// const startCol = isRegularCell(currentCell) ? currentCell[1] : 0;
|
const startCol = isRegularCell(currentCell) ? currentCell[1] : 0;
|
||||||
// let rowIndex = startRow;
|
let rowIndex = startRow;
|
||||||
// for (const rowData of pasteRows) {
|
for (const rowData of pasteRows) {
|
||||||
// if (rowIndex >= allRows.length) {
|
if (rowIndex >= grider.rowCountInUpdate) {
|
||||||
// chs = changeSetInsertNewRow(chs, display.baseTable);
|
grider.insertRow();
|
||||||
// allRows = [...loadedRows, ...getChangeSetInsertedRows(chs, display.baseTable)];
|
}
|
||||||
// }
|
let colIndex = startCol;
|
||||||
// let colIndex = startCol;
|
// const row = allRows[rowIndex];
|
||||||
// const row = allRows[rowIndex];
|
for (const cell of rowData) {
|
||||||
// for (const cell of rowData) {
|
setCellValue([rowIndex, colIndex], cell == '(NULL)' ? null : cell);
|
||||||
// chs = setChangeSetValue(
|
// chs = setChangeSetValue(
|
||||||
// chs,
|
// chs,
|
||||||
// display.getChangeSetField(
|
// display.getChangeSetField(
|
||||||
// row,
|
// row,
|
||||||
// realColumnUniqueNames[colIndex],
|
// realColumnUniqueNames[colIndex],
|
||||||
// rowIndex >= loadedRows.length ? rowIndex - loadedRows.length : null
|
// rowIndex >= loadedRows.length ? rowIndex - loadedRows.length : null
|
||||||
// ),
|
// ),
|
||||||
// cell == '(NULL)' ? null : cell
|
// cell == '(NULL)' ? null : cell
|
||||||
// );
|
// );
|
||||||
// colIndex += 1;
|
colIndex += 1;
|
||||||
// }
|
}
|
||||||
// rowIndex += 1;
|
rowIndex += 1;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// if (selectedCells.length > 1) {
|
if (selectedCells.length > 1) {
|
||||||
// const regularSelected = selectedCells.filter(isRegularCell);
|
const regularSelected = selectedCells.filter(isRegularCell);
|
||||||
// const startRow = _.min(regularSelected.map((x) => x[0]));
|
const startRow = _.min(regularSelected.map((x) => x[0]));
|
||||||
// const startCol = _.min(regularSelected.map((x) => x[1]));
|
const startCol = _.min(regularSelected.map((x) => x[1]));
|
||||||
// for (const cell of regularSelected) {
|
for (const cell of regularSelected) {
|
||||||
// const [rowIndex, colIndex] = cell;
|
const [rowIndex, colIndex] = cell;
|
||||||
// const selectionRow = rowIndex - startRow;
|
const selectionRow = rowIndex - startRow;
|
||||||
// const selectionCol = colIndex - startCol;
|
const selectionCol = colIndex - startCol;
|
||||||
// const pasteRow = pasteRows[selectionRow % pasteRows.length];
|
const pasteRow = pasteRows[selectionRow % pasteRows.length];
|
||||||
// const pasteCell = pasteRow[selectionCol % pasteRow.length];
|
const pasteCell = pasteRow[selectionCol % pasteRow.length];
|
||||||
// chs = setCellValue(chs, cell, pasteCell);
|
setCellValue(cell, pasteCell);
|
||||||
// }
|
// chs = setCellValue(chs, cell, pasteCell);
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
grider.endUpdate();
|
||||||
// setChangeSet(chs);
|
// setChangeSet(chs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,11 +518,6 @@ export default function DataGridCore(props) {
|
|||||||
setCellValue(cell, null);
|
setCellValue(cell, null);
|
||||||
});
|
});
|
||||||
grider.endUpdate();
|
grider.endUpdate();
|
||||||
// let chs = changeSet;
|
|
||||||
// selectedCells.filter(isRegularCell).forEach((cell) => {
|
|
||||||
// chs = setCellValue(chs, cell, null);
|
|
||||||
// });
|
|
||||||
// setChangeSet(chs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cellsToRegularCells(cells) {
|
function cellsToRegularCells(cells) {
|
||||||
@@ -659,10 +648,10 @@ export default function DataGridCore(props) {
|
|||||||
display.setFilters(flts);
|
display.setFilters(flts);
|
||||||
}
|
}
|
||||||
|
|
||||||
function revertAllChanges() {
|
// function revertAllChanges() {
|
||||||
grider.revertAllChanges();
|
// grider.revertAllChanges();
|
||||||
// setChangeSet(createChangeSet());
|
// // setChangeSet(createChangeSet());
|
||||||
}
|
// }
|
||||||
|
|
||||||
function deleteSelectedRows() {
|
function deleteSelectedRows() {
|
||||||
grider.beginUpdate();
|
grider.beginUpdate();
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ export default abstract class Grider {
|
|||||||
revertAllChanges() {}
|
revertAllChanges() {}
|
||||||
undo() {}
|
undo() {}
|
||||||
redo() {}
|
redo() {}
|
||||||
|
get rowCountInUpdate() {
|
||||||
|
return this.rowCount;
|
||||||
|
}
|
||||||
get canUndo() {
|
get canUndo() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user