|
|
@ -1,6 +1,7 @@ |
|
|
|
import { UITypes, ViewTypes } from 'nocodb-sdk' |
|
|
|
import { UITypes, ViewTypes } from 'nocodb-sdk' |
|
|
|
import type { Api, ColumnType, FormColumnType, FormType, GalleryType, PaginatedType, TableType, ViewType } from 'nocodb-sdk' |
|
|
|
import type { Api, ColumnType, FormColumnType, FormType, GalleryType, PaginatedType, TableType, ViewType } from 'nocodb-sdk' |
|
|
|
import type { ComputedRef, Ref } from 'vue' |
|
|
|
import type { ComputedRef, Ref } from 'vue' |
|
|
|
|
|
|
|
import type { CellRange } from '#imports' |
|
|
|
import { |
|
|
|
import { |
|
|
|
IsPublicInj, |
|
|
|
IsPublicInj, |
|
|
|
NOCO, |
|
|
|
NOCO, |
|
|
@ -615,6 +616,82 @@ export function useViewData( |
|
|
|
await syncPagination() |
|
|
|
await syncPagination() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function deleteRangeOfRows(cellRange: CellRange) { |
|
|
|
|
|
|
|
if (!cellRange._start || !cellRange._end) return |
|
|
|
|
|
|
|
const start = Math.max(cellRange._start.row, cellRange._end.row) |
|
|
|
|
|
|
|
const end = Math.min(cellRange._start.row, cellRange._end.row) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// plus one because we want to include the end row
|
|
|
|
|
|
|
|
let row = start + 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const removedRowsData: { id?: string; row: Row; rowIndex: number }[] = [] |
|
|
|
|
|
|
|
while (row--) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const { row: rowObj, rowMeta } = formattedData.value[row] as Record<string, any> |
|
|
|
|
|
|
|
if (!rowMeta.new) { |
|
|
|
|
|
|
|
const id = meta?.value?.columns |
|
|
|
|
|
|
|
?.filter((c) => c.pk) |
|
|
|
|
|
|
|
.map((c) => rowObj[c.title as string]) |
|
|
|
|
|
|
|
.join('___') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const successfulDeletion = await deleteRowById(id as string) |
|
|
|
|
|
|
|
if (!successfulDeletion) { |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
removedRowsData.push({ id, row: clone(formattedData.value[row]), rowIndex: row }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
formattedData.value.splice(row, 1) |
|
|
|
|
|
|
|
} catch (e: any) { |
|
|
|
|
|
|
|
return message.error(`${t('msg.error.deleteRowFailed')}: ${await extractSdkResponseErrorMsg(e)}`) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (row === end) break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addUndo({ |
|
|
|
|
|
|
|
redo: { |
|
|
|
|
|
|
|
fn: async function redo(this: UndoRedoAction, removedRowsData: { id?: string; row: Row; rowIndex: number }[]) { |
|
|
|
|
|
|
|
for (const { id, row } of removedRowsData) { |
|
|
|
|
|
|
|
await deleteRowById(id as string) |
|
|
|
|
|
|
|
const pk: Record<string, string> = rowPkData(row.row, meta?.value?.columns as ColumnType[]) |
|
|
|
|
|
|
|
const rowIndex = findIndexByPk(pk) |
|
|
|
|
|
|
|
if (rowIndex !== -1) formattedData.value.splice(rowIndex, 1) |
|
|
|
|
|
|
|
paginationData.value.totalRows = paginationData.value.totalRows! - 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
await syncPagination() |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
args: [removedRowsData], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
undo: { |
|
|
|
|
|
|
|
fn: async function undo( |
|
|
|
|
|
|
|
this: UndoRedoAction, |
|
|
|
|
|
|
|
removedRowsData: { id?: string; row: Row; rowIndex: number }[], |
|
|
|
|
|
|
|
pg: { page: number; pageSize: number }, |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
for (const { row, rowIndex } of removedRowsData.slice().reverse()) { |
|
|
|
|
|
|
|
const pkData = rowPkData(row.row, meta.value?.columns as ColumnType[]) |
|
|
|
|
|
|
|
row.row = { ...pkData, ...row.row } |
|
|
|
|
|
|
|
await insertRow(row, {}, {}, true) |
|
|
|
|
|
|
|
if (rowIndex !== -1 && pg.pageSize === paginationData.value.pageSize) { |
|
|
|
|
|
|
|
if (pg.page === paginationData.value.page) { |
|
|
|
|
|
|
|
formattedData.value.splice(rowIndex, 0, row) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
await changePage(pg.page) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
await loadData() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
args: [removedRowsData, { page: paginationData.value.page, pageSize: paginationData.value.pageSize }], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
scope: defineViewScope({ view: viewMeta.value }), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await syncCount() |
|
|
|
|
|
|
|
await syncPagination() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function loadFormView() { |
|
|
|
async function loadFormView() { |
|
|
|
if (!viewMeta?.value?.id) return |
|
|
|
if (!viewMeta?.value?.id) return |
|
|
|
try { |
|
|
|
try { |
|
|
@ -728,6 +805,7 @@ export function useViewData( |
|
|
|
deleteRow, |
|
|
|
deleteRow, |
|
|
|
deleteRowById, |
|
|
|
deleteRowById, |
|
|
|
deleteSelectedRows, |
|
|
|
deleteSelectedRows, |
|
|
|
|
|
|
|
deleteRangeOfRows, |
|
|
|
updateOrSaveRow, |
|
|
|
updateOrSaveRow, |
|
|
|
selectedAllRecords, |
|
|
|
selectedAllRecords, |
|
|
|
syncCount, |
|
|
|
syncCount, |
|
|
|