|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
<script lang="ts" setup> |
|
|
|
|
import type { ColumnType } from 'nocodb-sdk' |
|
|
|
|
import type { ColumnType, TableType, ViewType } from 'nocodb-sdk' |
|
|
|
|
import { UITypes, isVirtualCol } from 'nocodb-sdk' |
|
|
|
|
import { |
|
|
|
|
ActiveViewInj, |
|
|
|
@ -128,15 +128,6 @@ provide(CellUrlDisableOverlayInj, disableUrlOverlay)
|
|
|
|
|
|
|
|
|
|
const showLoading = ref(true) |
|
|
|
|
|
|
|
|
|
reloadViewDataHook?.on(async (shouldShowLoading) => { |
|
|
|
|
// set value if spinner should be hidden |
|
|
|
|
showLoading.value = !!shouldShowLoading |
|
|
|
|
await loadData() |
|
|
|
|
|
|
|
|
|
// reset to default (showing spinner on load) |
|
|
|
|
showLoading.value = true |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const skipRowRemovalOnCancel = ref(false) |
|
|
|
|
|
|
|
|
|
const expandForm = (row: Row, state?: Record<string, any>, fromToolbar = false) => { |
|
|
|
@ -157,11 +148,6 @@ const expandForm = (row: Row, state?: Record<string, any>, fromToolbar = false)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
openNewRecordFormHook?.on(async () => { |
|
|
|
|
const newRow = await addEmptyRow() |
|
|
|
|
expandForm(newRow, undefined, true) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const onresize = (colID: string, event: any) => { |
|
|
|
|
updateWidth(colID, event.detail) |
|
|
|
|
} |
|
|
|
@ -272,30 +258,54 @@ const showContextMenu = (e: MouseEvent, target?: { row: number; col: number }) =
|
|
|
|
|
|
|
|
|
|
const rowRefs = $ref<any[]>() |
|
|
|
|
|
|
|
|
|
/** save/update records before unmounting the component */ |
|
|
|
|
onBeforeUnmount(async () => { |
|
|
|
|
const saveOrUpdateRecords = async (args: { metaValue?: TableType; viewMetaValue?: ViewType; data?: any } = {}) => { |
|
|
|
|
let index = -1 |
|
|
|
|
for (const currentRow of data.value) { |
|
|
|
|
for (const currentRow of args.data || data.value) { |
|
|
|
|
index++ |
|
|
|
|
/** if new record save row and save the LTAR cells */ |
|
|
|
|
if (currentRow.rowMeta.new) { |
|
|
|
|
const syncLTARRefs = rowRefs[index]!.syncLTARRefs |
|
|
|
|
const savedRow = await updateOrSaveRow(currentRow, '') |
|
|
|
|
await syncLTARRefs(savedRow) |
|
|
|
|
const savedRow = await updateOrSaveRow(currentRow, '', {}, args) |
|
|
|
|
await syncLTARRefs(savedRow, args) |
|
|
|
|
currentRow.rowMeta.changed = false |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
/** if existing row check updated cell and invoke update method */ |
|
|
|
|
if (currentRow.rowMeta.changed) { |
|
|
|
|
currentRow.rowMeta.changed = false |
|
|
|
|
for (const field of meta.value?.columns ?? []) { |
|
|
|
|
for (const field of (args.metaValue || meta.value)?.columns ?? []) { |
|
|
|
|
if (isVirtualCol(field)) continue |
|
|
|
|
if (currentRow.row[field.title!] !== currentRow.oldRow[field.title!]) { |
|
|
|
|
await updateOrSaveRow(currentRow, field.title!) |
|
|
|
|
await updateOrSaveRow(currentRow, field.title!, args) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function reloadViewDataHandler(shouldShowLoading: boolean | void) { |
|
|
|
|
// set value if spinner should be hidden |
|
|
|
|
showLoading.value = !!shouldShowLoading |
|
|
|
|
await loadData() |
|
|
|
|
// reset to default (showing spinner on load) |
|
|
|
|
showLoading.value = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function openNewRecordHandler() { |
|
|
|
|
const newRow = await addEmptyRow() |
|
|
|
|
expandForm(newRow, undefined, true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
reloadViewDataHook?.on(reloadViewDataHandler) |
|
|
|
|
openNewRecordFormHook?.on(openNewRecordHandler) |
|
|
|
|
|
|
|
|
|
onBeforeUnmount(() => { |
|
|
|
|
/** save/update records before unmounting the component */ |
|
|
|
|
saveOrUpdateRecords() |
|
|
|
|
|
|
|
|
|
// reset hooks |
|
|
|
|
reloadViewDataHook?.off(reloadViewDataHandler) |
|
|
|
|
openNewRecordFormHook?.off(openNewRecordHandler) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const expandedFormOnRowIdDlg = computed({ |
|
|
|
@ -320,9 +330,21 @@ provide(ReloadRowDataHookInj, reloadViewDataHook)
|
|
|
|
|
// reloadViewDataHook.trigger() |
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
|
() => view.value?.id, |
|
|
|
|
view, |
|
|
|
|
async (next, old) => { |
|
|
|
|
if (next && next !== old) { |
|
|
|
|
if (next && next.id !== old?.id) { |
|
|
|
|
// whenever tab changes or view changes save any unsaved data |
|
|
|
|
if (old?.id) { |
|
|
|
|
const { getMeta } = useMetas() |
|
|
|
|
const oldMeta = await getMeta(old.fk_model_id!) |
|
|
|
|
if (oldMeta) { |
|
|
|
|
await saveOrUpdateRecords({ |
|
|
|
|
viewMetaValue: old, |
|
|
|
|
metaValue: oldMeta as TableType, |
|
|
|
|
data: data.value, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
await loadData() |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|