|
|
@ -1,50 +1,61 @@ |
|
|
|
import { UITypes } from 'nocodb-sdk' |
|
|
|
import { UITypes } from 'nocodb-sdk' |
|
|
|
import type { ColumnType, TableType } from 'nocodb-sdk' |
|
|
|
import type { ColumnType, TableType } from 'nocodb-sdk' |
|
|
|
import type { Ref } from 'vue' |
|
|
|
import type { Ref } from 'vue' |
|
|
|
import { message } from 'ant-design-vue' |
|
|
|
|
|
|
|
import dayjs from 'dayjs' |
|
|
|
import dayjs from 'dayjs' |
|
|
|
import { useI18n } from 'vue-i18n' |
|
|
|
|
|
|
|
import { |
|
|
|
import { |
|
|
|
NOCO, |
|
|
|
NOCO, |
|
|
|
|
|
|
|
computed, |
|
|
|
extractPkFromRow, |
|
|
|
extractPkFromRow, |
|
|
|
extractSdkResponseErrorMsg, |
|
|
|
extractSdkResponseErrorMsg, |
|
|
|
getHTMLEncodedText, |
|
|
|
getHTMLEncodedText, |
|
|
|
|
|
|
|
message, |
|
|
|
|
|
|
|
ref, |
|
|
|
useApi, |
|
|
|
useApi, |
|
|
|
|
|
|
|
useI18n, |
|
|
|
useInjectionState, |
|
|
|
useInjectionState, |
|
|
|
useNuxtApp, |
|
|
|
useNuxtApp, |
|
|
|
useProject, |
|
|
|
useProject, |
|
|
|
useProvideSmartsheetRowStore, |
|
|
|
useProvideSmartsheetRowStore, |
|
|
|
|
|
|
|
useSharedView, |
|
|
|
} from '#imports' |
|
|
|
} from '#imports' |
|
|
|
import type { Row } from '~/composables' |
|
|
|
import type { Row } from '~/lib' |
|
|
|
|
|
|
|
|
|
|
|
const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((meta: Ref<TableType>, row: Ref<Row>) => { |
|
|
|
const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((meta: Ref<TableType>, row: Ref<Row>) => { |
|
|
|
const { $e, $state, $api } = useNuxtApp() |
|
|
|
const { $e, $state, $api } = useNuxtApp() |
|
|
|
|
|
|
|
|
|
|
|
const { api, isLoading: isCommentsLoading, error: commentsError } = useApi() |
|
|
|
const { api, isLoading: isCommentsLoading, error: commentsError } = useApi() |
|
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n() |
|
|
|
const { t } = useI18n() |
|
|
|
|
|
|
|
|
|
|
|
const commentsOnly = ref(false) |
|
|
|
const commentsOnly = ref(false) |
|
|
|
|
|
|
|
|
|
|
|
const commentsAndLogs = ref<any[]>([]) |
|
|
|
const commentsAndLogs = ref<any[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
const comment = ref('') |
|
|
|
const comment = ref('') |
|
|
|
|
|
|
|
|
|
|
|
const commentsDrawer = ref(false) |
|
|
|
const commentsDrawer = ref(false) |
|
|
|
|
|
|
|
|
|
|
|
const changedColumns = ref(new Set<string>()) |
|
|
|
const changedColumns = ref(new Set<string>()) |
|
|
|
|
|
|
|
|
|
|
|
const { project } = useProject() |
|
|
|
const { project } = useProject() |
|
|
|
const rowStore = useProvideSmartsheetRowStore(meta, row) |
|
|
|
|
|
|
|
const { sharedView } = useSharedView() as Record<string, any> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// todo
|
|
|
|
const rowStore = useProvideSmartsheetRowStore(meta, row) |
|
|
|
// const activeView = inject(ActiveViewInj)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const { updateOrSaveRow, insertRow } = useViewData(meta, activeView as any)
|
|
|
|
const { sharedView } = useSharedView() |
|
|
|
|
|
|
|
|
|
|
|
// getters
|
|
|
|
// getters
|
|
|
|
const primaryValue = computed(() => { |
|
|
|
const primaryValue = computed(() => { |
|
|
|
if (row?.value?.row) { |
|
|
|
if (row?.value?.row) { |
|
|
|
const col = meta?.value?.columns?.find((c) => c.pv) |
|
|
|
const col = meta?.value?.columns?.find((c) => c.pv) |
|
|
|
|
|
|
|
|
|
|
|
if (!col) { |
|
|
|
if (!col) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const value = row.value.row?.[col.title as string] |
|
|
|
const value = row.value.row?.[col.title as string] |
|
|
|
|
|
|
|
|
|
|
|
const uidt = col.uidt |
|
|
|
const uidt = col.uidt |
|
|
|
|
|
|
|
|
|
|
|
if (uidt === UITypes.Date) { |
|
|
|
if (uidt === UITypes.Date) { |
|
|
|
return (/^\d+$/.test(value) ? dayjs(+value) : dayjs(value)).format('YYYY-MM-DD') |
|
|
|
return (/^\d+$/.test(value) ? dayjs(+value) : dayjs(value)).format('YYYY-MM-DD') |
|
|
|
} else if (uidt === UITypes.DateTime) { |
|
|
|
} else if (uidt === UITypes.DateTime) { |
|
|
@ -73,8 +84,11 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m |
|
|
|
// actions
|
|
|
|
// actions
|
|
|
|
const loadCommentsAndLogs = async () => { |
|
|
|
const loadCommentsAndLogs = async () => { |
|
|
|
if (!row.value) return |
|
|
|
if (!row.value) return |
|
|
|
|
|
|
|
|
|
|
|
const rowId = extractPkFromRow(row.value.row, meta.value.columns as ColumnType[]) |
|
|
|
const rowId = extractPkFromRow(row.value.row, meta.value.columns as ColumnType[]) |
|
|
|
|
|
|
|
|
|
|
|
if (!rowId) return |
|
|
|
if (!rowId) return |
|
|
|
|
|
|
|
|
|
|
|
commentsAndLogs.value = |
|
|
|
commentsAndLogs.value = |
|
|
|
( |
|
|
|
( |
|
|
|
await api.utils.commentList({ |
|
|
|
await api.utils.commentList({ |
|
|
@ -92,7 +106,9 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m |
|
|
|
const saveComment = async () => { |
|
|
|
const saveComment = async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (!row.value || !comment.value) return |
|
|
|
if (!row.value || !comment.value) return |
|
|
|
|
|
|
|
|
|
|
|
const rowId = extractPkFromRow(row.value.row, meta.value.columns as ColumnType[]) |
|
|
|
const rowId = extractPkFromRow(row.value.row, meta.value.columns as ColumnType[]) |
|
|
|
|
|
|
|
|
|
|
|
if (!rowId) return |
|
|
|
if (!rowId) return |
|
|
|
|
|
|
|
|
|
|
|
await api.utils.commentRow({ |
|
|
|
await api.utils.commentRow({ |
|
|
@ -114,14 +130,6 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m |
|
|
|
const save = async () => { |
|
|
|
const save = async () => { |
|
|
|
let data |
|
|
|
let data |
|
|
|
try { |
|
|
|
try { |
|
|
|
// todo:
|
|
|
|
|
|
|
|
// if (this.presetValues) {
|
|
|
|
|
|
|
|
// // cater presetValues
|
|
|
|
|
|
|
|
// for (const k in this.presetValues) {
|
|
|
|
|
|
|
|
// this.$set(this.changedColumns, k, true);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updateOrInsertObj = [...changedColumns.value].reduce((obj, col) => { |
|
|
|
const updateOrInsertObj = [...changedColumns.value].reduce((obj, col) => { |
|
|
|
obj[col] = row.value.row[col] |
|
|
|
obj[col] = row.value.row[col] |
|
|
|
return obj |
|
|
|
return obj |
|
|
@ -141,7 +149,9 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m |
|
|
|
if (!id) { |
|
|
|
if (!id) { |
|
|
|
return message.info("Update not allowed for table which doesn't have primary Key") |
|
|
|
return message.info("Update not allowed for table which doesn't have primary Key") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await $api.dbTableRow.update(NOCO, project.value.title as string, meta.value.title, id, updateOrInsertObj) |
|
|
|
await $api.dbTableRow.update(NOCO, project.value.title as string, meta.value.title, id, updateOrInsertObj) |
|
|
|
|
|
|
|
|
|
|
|
for (const key of Object.keys(updateOrInsertObj)) { |
|
|
|
for (const key of Object.keys(updateOrInsertObj)) { |
|
|
|
// audit
|
|
|
|
// audit
|
|
|
|
$api.utils |
|
|
|
$api.utils |
|
|
@ -164,11 +174,6 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m |
|
|
|
return message.info(t('msg.info.noColumnsToUpdate')) |
|
|
|
return message.info(t('msg.info.noColumnsToUpdate')) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// this.$emit('update:oldRow', { ...this.localState });
|
|
|
|
|
|
|
|
// this.changedColumns = {};
|
|
|
|
|
|
|
|
// this.$emit('input', this.localState);
|
|
|
|
|
|
|
|
// this.$emit('update:isNew', false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
message.success(`${primaryValue.value || 'Row'} updated successfully.`) |
|
|
|
message.success(`${primaryValue.value || 'Row'} updated successfully.`) |
|
|
|
|
|
|
|
|
|
|
|
changedColumns.value = new Set() |
|
|
|
changedColumns.value = new Set() |
|
|
@ -182,7 +187,8 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m |
|
|
|
const loadRow = async (rowId?: string) => { |
|
|
|
const loadRow = async (rowId?: string) => { |
|
|
|
const record = await $api.dbTableRow.read( |
|
|
|
const record = await $api.dbTableRow.read( |
|
|
|
NOCO, |
|
|
|
NOCO, |
|
|
|
(project?.value?.id || sharedView.value.view.project_id) as string, |
|
|
|
// todo: project_id missing on view type
|
|
|
|
|
|
|
|
(project?.value?.id || (sharedView.value?.view as any)?.project_id) as string, |
|
|
|
meta.value.title, |
|
|
|
meta.value.title, |
|
|
|
rowId ?? extractPkFromRow(row.value.row, meta.value.columns as ColumnType[]), |
|
|
|
rowId ?? extractPkFromRow(row.value.row, meta.value.columns as ColumnType[]), |
|
|
|
) |
|
|
|
) |
|
|
@ -218,6 +224,8 @@ export { useProvideExpandedFormStore } |
|
|
|
|
|
|
|
|
|
|
|
export function useExpandedFormStoreOrThrow() { |
|
|
|
export function useExpandedFormStoreOrThrow() { |
|
|
|
const expandedFormStore = useExpandedFormStore() |
|
|
|
const expandedFormStore = useExpandedFormStore() |
|
|
|
|
|
|
|
|
|
|
|
if (expandedFormStore == null) throw new Error('Please call `useExpandedFormStore` on the appropriate parent component') |
|
|
|
if (expandedFormStore == null) throw new Error('Please call `useExpandedFormStore` on the appropriate parent component') |
|
|
|
|
|
|
|
|
|
|
|
return expandedFormStore |
|
|
|
return expandedFormStore |
|
|
|
} |
|
|
|
} |
|
|
|