paste using grider implementation

This commit is contained in:
Jan Prochazka
2020-10-24 21:27:56 +02:00
parent 45d172d0b1
commit f9f2a501ab
3 changed files with 74 additions and 72 deletions

View File

@@ -99,10 +99,20 @@ export default class ChangeSetGrider extends Grider {
this.applyModification((chs) => deleteChangeSetRows(chs, this.rowDefinitionsCache[index])); this.applyModification((chs) => deleteChangeSetRows(chs, this.rowDefinitionsCache[index]));
} }
insertRow(): number { get rowCountInUpdate() {
this.applyModification((chs) => changeSetInsertNewRow(chs, this.display.baseTable)); if (this.batchChangeSet) {
const newRows = getChangeSetInsertedRows(this.batchChangeSet, this.display.baseTable);
return this.sourceRows.length + newRows.length;
} else {
return this.rowCount; return this.rowCount;
} }
}
insertRow(): number {
const res = this.rowCountInUpdate;
this.applyModification((chs) => changeSetInsertNewRow(chs, this.display.baseTable));
return res;
}
beginUpdate() { beginUpdate() {
this.batchChangeSet = this.changeSet; this.batchChangeSet = this.changeSet;

View File

@@ -448,46 +448,38 @@ 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(
@@ -497,24 +489,26 @@ export default function DataGridCore(props) {
// ), // ),
// 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];
setCellValue(cell, pasteCell);
// chs = setCellValue(chs, 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();

View File

@@ -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;
} }