Add row copy action and improve table bottom spacing
This commit is contained in:
@@ -455,6 +455,8 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
padding-bottom: 16px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -504,6 +506,7 @@
|
||||
<div id="appContent" style="display: none;">
|
||||
<div id="toolbar">
|
||||
<button id="btnInsert">➕ Вставить</button>
|
||||
<button id="btnCopy">📄 Копировать строку</button>
|
||||
<button id="btnEdit">✏️ Изменить</button>
|
||||
<button id="btnDelete">🗑️ Удалить</button>
|
||||
<div class="toolbar-divider"></div>
|
||||
|
||||
@@ -150,6 +150,68 @@ function initOperationsHandlers() {
|
||||
}
|
||||
});
|
||||
|
||||
// Копировать строку
|
||||
document.getElementById('btnCopy').addEventListener('click', async () => {
|
||||
if (!table || !currentSchema || !currentTable || !currentMeta) {
|
||||
alert('Сначала выберите таблицу');
|
||||
return;
|
||||
}
|
||||
|
||||
const tabulatorSelected = table.getSelectedData();
|
||||
const allSelectedData = new Map();
|
||||
|
||||
tabulatorSelected.forEach(rowData => {
|
||||
const key = getRowKey(rowData);
|
||||
allSelectedData.set(key, rowData);
|
||||
});
|
||||
|
||||
selectedRowsDataGlobal.forEach((rowData, key) => {
|
||||
allSelectedData.set(key, rowData);
|
||||
});
|
||||
|
||||
const selectedRows = Array.from(allSelectedData.values());
|
||||
if (selectedRows.length === 0) {
|
||||
alert('Выберите строку для копирования');
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedRows.length > 1) {
|
||||
const proceed = confirm(`Выбрано ${selectedRows.length} строк. Скопировать только первую?`);
|
||||
if (!proceed) return;
|
||||
}
|
||||
|
||||
const sourceRow = selectedRows[0];
|
||||
const rowToInsert = {};
|
||||
const primaryKeySet = new Set(currentMeta.primaryKey || []);
|
||||
|
||||
currentMeta.columns.forEach(col => {
|
||||
const name = col.COLUMN_NAME;
|
||||
if (col.IS_AUTO_INCREMENT) return;
|
||||
if (primaryKeySet.has(name)) return;
|
||||
if (Object.prototype.hasOwnProperty.call(sourceRow, name)) {
|
||||
rowToInsert[name] = sourceRow[name];
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await api('/api/table/insert', 'POST', {
|
||||
schema: currentSchema,
|
||||
table: currentTable,
|
||||
row: rowToInsert
|
||||
});
|
||||
|
||||
await table.replaceData();
|
||||
const lastPage = table.getPageMax ? table.getPageMax() : 1;
|
||||
if (lastPage > 1) {
|
||||
await table.setPage(lastPage);
|
||||
}
|
||||
alert('✓ Строка скопирована');
|
||||
} catch (e) {
|
||||
console.error('Ошибка копирования строки:', e);
|
||||
alert('Ошибка копирования: ' + e.message);
|
||||
}
|
||||
});
|
||||
|
||||
// Удалить
|
||||
document.getElementById('btnDelete').addEventListener('click', async () => {
|
||||
if (!table || !currentSchema || !currentTable) {
|
||||
|
||||
Reference in New Issue
Block a user