|
|
@ -1,5 +1,5 @@ |
|
|
|
<script lang="ts" setup> |
|
|
|
<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 { UITypes, isVirtualCol } from 'nocodb-sdk' |
|
|
|
import { |
|
|
|
import { |
|
|
|
ActiveViewInj, |
|
|
|
ActiveViewInj, |
|
|
@ -128,15 +128,6 @@ provide(CellUrlDisableOverlayInj, disableUrlOverlay) |
|
|
|
|
|
|
|
|
|
|
|
const showLoading = ref(true) |
|
|
|
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 skipRowRemovalOnCancel = ref(false) |
|
|
|
|
|
|
|
|
|
|
|
const expandForm = (row: Row, state?: Record<string, any>, fromToolbar = 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) => { |
|
|
|
const onresize = (colID: string, event: any) => { |
|
|
|
updateWidth(colID, event.detail) |
|
|
|
updateWidth(colID, event.detail) |
|
|
|
} |
|
|
|
} |
|
|
@ -272,30 +258,54 @@ const showContextMenu = (e: MouseEvent, target?: { row: number; col: number }) = |
|
|
|
|
|
|
|
|
|
|
|
const rowRefs = $ref<any[]>() |
|
|
|
const rowRefs = $ref<any[]>() |
|
|
|
|
|
|
|
|
|
|
|
/** save/update records before unmounting the component */ |
|
|
|
const saveOrUpdateRecords = async (args: { metaValue?: TableType; viewMetaValue?: ViewType; data?: any } = {}) => { |
|
|
|
onBeforeUnmount(async () => { |
|
|
|
|
|
|
|
let index = -1 |
|
|
|
let index = -1 |
|
|
|
for (const currentRow of data.value) { |
|
|
|
for (const currentRow of args.data || data.value) { |
|
|
|
index++ |
|
|
|
index++ |
|
|
|
/** if new record save row and save the LTAR cells */ |
|
|
|
/** if new record save row and save the LTAR cells */ |
|
|
|
if (currentRow.rowMeta.new) { |
|
|
|
if (currentRow.rowMeta.new) { |
|
|
|
const syncLTARRefs = rowRefs[index]!.syncLTARRefs |
|
|
|
const syncLTARRefs = rowRefs[index]!.syncLTARRefs |
|
|
|
const savedRow = await updateOrSaveRow(currentRow, '') |
|
|
|
const savedRow = await updateOrSaveRow(currentRow, '', {}, args) |
|
|
|
await syncLTARRefs(savedRow) |
|
|
|
await syncLTARRefs(savedRow, args) |
|
|
|
currentRow.rowMeta.changed = false |
|
|
|
currentRow.rowMeta.changed = false |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
/** if existing row check updated cell and invoke update method */ |
|
|
|
/** if existing row check updated cell and invoke update method */ |
|
|
|
if (currentRow.rowMeta.changed) { |
|
|
|
if (currentRow.rowMeta.changed) { |
|
|
|
currentRow.rowMeta.changed = false |
|
|
|
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 (isVirtualCol(field)) continue |
|
|
|
if (currentRow.row[field.title!] !== currentRow.oldRow[field.title!]) { |
|
|
|
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({ |
|
|
|
const expandedFormOnRowIdDlg = computed({ |
|
|
@ -320,9 +330,21 @@ provide(ReloadRowDataHookInj, reloadViewDataHook) |
|
|
|
// reloadViewDataHook.trigger() |
|
|
|
// reloadViewDataHook.trigger() |
|
|
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
watch( |
|
|
|
() => view.value?.id, |
|
|
|
view, |
|
|
|
async (next, old) => { |
|
|
|
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() |
|
|
|
await loadData() |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|