|
|
@ -2,7 +2,7 @@ import type { Ref } from 'vue' |
|
|
|
import { computed } from 'vue' |
|
|
|
import { computed } from 'vue' |
|
|
|
import dayjs from 'dayjs' |
|
|
|
import dayjs from 'dayjs' |
|
|
|
import type { MaybeRef } from '@vueuse/core' |
|
|
|
import type { MaybeRef } from '@vueuse/core' |
|
|
|
import type { ColumnType, LinkToAnotherRecordType, PaginatedType, TableType, UserFieldRecordType, ViewType } from 'nocodb-sdk' |
|
|
|
import type { AttachmentType, ColumnType, LinkToAnotherRecordType, PaginatedType, TableType, UserFieldRecordType, ViewType } from 'nocodb-sdk' |
|
|
|
import { UITypes, dateFormats, isDateMonthFormat, isSystemColumn, isVirtualCol, timeFormats } from 'nocodb-sdk' |
|
|
|
import { UITypes, dateFormats, isDateMonthFormat, isSystemColumn, isVirtualCol, timeFormats } from 'nocodb-sdk' |
|
|
|
import { parse } from 'papaparse' |
|
|
|
import { parse } from 'papaparse' |
|
|
|
import type { Cell } from './cellRange' |
|
|
|
import type { Cell } from './cellRange' |
|
|
@ -1115,12 +1115,9 @@ export function useMultiSelect( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if (columnObj.uidt === UITypes.Attachment && e.clipboardData?.files?.length && pasteValue?.length) { |
|
|
|
if (columnObj.uidt === UITypes.Attachment && e.clipboardData?.files?.length && pasteValue?.length) { |
|
|
|
const uploadedFiles = await handleFileUpload(pasteValue, columnObj.id!) |
|
|
|
const newAttachments = await handleFileUploadAndGetCellValue(pasteValue, columnObj.id!, rowObj.row[columnObj.title!]) |
|
|
|
|
|
|
|
|
|
|
|
rowObj.row[columnObj.title!] = |
|
|
|
rowObj.row[columnObj.title!] = newAttachments ? JSON.stringify(newAttachments) : null |
|
|
|
Array.isArray(uploadedFiles) && uploadedFiles.length |
|
|
|
|
|
|
|
? JSON.stringify([...handleParseAttachmentCellData(rowObj.row[columnObj.title!]), ...uploadedFiles]) |
|
|
|
|
|
|
|
: null |
|
|
|
|
|
|
|
} else if (pasteValue !== undefined) { |
|
|
|
} else if (pasteValue !== undefined) { |
|
|
|
rowObj.row[columnObj.title!] = pasteValue |
|
|
|
rowObj.row[columnObj.title!] = pasteValue |
|
|
|
} |
|
|
|
} |
|
|
@ -1177,12 +1174,9 @@ export function useMultiSelect( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if (fileUploadPayload?.length) { |
|
|
|
if (fileUploadPayload?.length) { |
|
|
|
const uploadedFiles = await handleFileUpload(fileUploadPayload, col.id!) |
|
|
|
const newAttachments = await handleFileUploadAndGetCellValue(fileUploadPayload, col.id!, row.row[col.title!]) |
|
|
|
|
|
|
|
|
|
|
|
pasteValue = |
|
|
|
pasteValue = newAttachments ? JSON.stringify(newAttachments) : null |
|
|
|
Array.isArray(uploadedFiles) && uploadedFiles.length |
|
|
|
|
|
|
|
? JSON.stringify([...handleParseAttachmentCellData(row.row[col.title]), ...uploadedFiles]) |
|
|
|
|
|
|
|
: null |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -1232,7 +1226,9 @@ export function useMultiSelect( |
|
|
|
event.preventDefault() |
|
|
|
event.preventDefault() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function handleFileUpload(files: File[], columnId: string) { |
|
|
|
async function handleFileUploadAndGetCellValue(files: File[], columnId: string, oldValue: AttachmentType[]) { |
|
|
|
|
|
|
|
const newAttachments: AttachmentType[] = [] |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const data = await api.storage.upload( |
|
|
|
const data = await api.storage.upload( |
|
|
|
{ |
|
|
|
{ |
|
|
@ -1242,19 +1238,27 @@ export function useMultiSelect( |
|
|
|
files, |
|
|
|
files, |
|
|
|
}, |
|
|
|
}, |
|
|
|
) |
|
|
|
) |
|
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
// add suffix in duplicate file title
|
|
|
|
|
|
|
|
for (const uploadedFile of data) { |
|
|
|
|
|
|
|
newAttachments.push({ |
|
|
|
|
|
|
|
...uploadedFile, |
|
|
|
|
|
|
|
title: populateUniqueFileName(uploadedFile?.title, [...handleParseAttachmentCellData(oldValue), ...newAttachments]), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return newAttachments |
|
|
|
} catch (e: any) { |
|
|
|
} catch (e: any) { |
|
|
|
message.error(e.message || t('msg.error.internalError')) |
|
|
|
message.error(e.message || t('msg.error.internalError')) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function handleParseAttachmentCellData(value: string | null) { |
|
|
|
function handleParseAttachmentCellData<T>(value: T): T { |
|
|
|
const parsedVal = parseProp(value) |
|
|
|
const parsedVal = parseProp(value) |
|
|
|
|
|
|
|
|
|
|
|
if (parsedVal && Array.isArray(parsedVal)) { |
|
|
|
if (parsedVal && Array.isArray(parsedVal)) { |
|
|
|
return parsedVal |
|
|
|
return parsedVal as T |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return [] |
|
|
|
return [] as T |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|