diff --git a/Services/client/src/components/FileForm.vue b/Services/client/src/components/FileForm.vue index c9f545c..9ac5b51 100644 --- a/Services/client/src/components/FileForm.vue +++ b/Services/client/src/components/FileForm.vue @@ -10,9 +10,18 @@ const props = withDefaults( defineProps<{ open: boolean error: { + externalFileExist?: boolean fileExist?: boolean fileName2Long?: boolean } + disableFields?: ( + | 'file' + | 'title' + | 'description' + | 'keyword' + | 'category' + | 'author' + )[] mode: 'create' | 'edit' fileNameLabel?: string title?: string @@ -63,6 +72,25 @@ function reset() { } function submit() { + if (props.mode === 'edit') { + return emit('submit', { + mode: props.mode, + file: props.disableFields?.includes('file') ? undefined : file.value, + title: props.disableFields?.includes('title') ? undefined : props.title, + description: props.disableFields?.includes('description') + ? undefined + : props.description ?? '', + keyword: props.disableFields?.includes('keyword') + ? undefined + : props.keyword, + category: props.disableFields?.includes('category') + ? undefined + : props.category, + author: props.disableFields?.includes('author') + ? undefined + : props.author, + }) + } emit('submit', { mode: props.mode, file: file.value, @@ -146,12 +174,13 @@ const file = ref() /> -
+
อัปโหลดไฟล์ +
ชื่อเรื่อง +
รายละเอียดของเอกสาร () class="q-mt-sm no-resize" type="textarea" placeholder="กรอกรายละเอียด" + :disable="disableFields?.includes('description')" :model-value="description" @update:model-value="(v) => $emit('update:description', v)" id="inputDescription" />
-
- กลุ่ม/หมวดหมู่ -
- - -
-
- -
- คำสำคัญ -
- - -
-
- -
+
เจ้าของผลงาน + กลุ่ม/หมวดหมู่ + + +
+ +
+ คำสำคัญ + + +
+
(false) const fileFormPath = ref('') @@ -18,10 +18,16 @@ const fileFormData = ref<{ keyword?: string[] category?: string[] author?: string + metadata?: Record }>({}) const fileFormType = ref<'edit' | 'create'>('create') -const fileFormError = ref<{ fileExist?: boolean; fileName2Long?: boolean }>({}) +const fileFormError = ref<{ + externalFileExist?: boolean + fileExist?: boolean + fileName2Long?: boolean +}>({}) const fileExistNotification = ref(false) +const errorState = ref<'fileExist' | 'externalFileExist'>('fileExist') const fileFormComponent = ref>() const fileNameLabel = ref() @@ -38,6 +44,7 @@ function triggerFileEdit( keyword: string[] category: string[] author: string + metadata?: Record }, pathname: string, file?: string, @@ -46,13 +53,18 @@ function triggerFileEdit( fileFormType.value = 'edit' fileFormPath.value = pathname fileFormData.value = { - title: value.title, + title: (value.metadata?.subject as string) ?? value.title, description: value.description, keyword: value.keyword, category: value.category, - author: value.author, + author: (value.metadata?.author as string) ?? value.author, + metadata: value.metadata, } fileNameLabel.value = file + + const arr = pathname.split('/') + arr[arr.length - 1] = '' + goto(arr.join('/')) } defineExpose({ @@ -62,6 +74,18 @@ defineExpose({ const currentParam = ref[0]>() +function checkFileExistMetadata(name: string) { + const fileInfo = file.value[currentInfo.value.path].find( + (v) => v.fileName === name, + ) + + if (fileInfo?.metadata && Object.keys(fileInfo?.metadata).length > 0) { + return Boolean(true) + } + + return Boolean(false) +} + function checkFileExist(name: string, except?: string) { return Boolean( file.value[currentInfo.value.path].find( @@ -88,6 +112,16 @@ async function submitFileForm( ) { currentParam.value = value + const fileInfo = file.value[currentInfo.value.path]?.find( + (v) => v.fileName === value.file?.name, + ) + + if (fileInfo?.metadata && Object.keys(fileInfo.metadata).length > 0) { + fileExistNotification.value = true + errorState.value = 'externalFileExist' + return + } + if ( value.file && file.value[currentInfo.value.path].find( @@ -96,6 +130,7 @@ async function submitFileForm( !force ) { fileExistNotification.value = true + errorState.value = 'fileExist' return } @@ -133,6 +168,11 @@ async function submitFileForm( :mode="fileFormType" :error="fileFormError" :fileNameLabel="fileNameLabel" + :disableFields=" + fileFormData.metadata && Object.keys(fileFormData.metadata).length > 0 + ? ['file', 'title', 'author'] + : [] + " v-model:open="fileFormState" v-model:title="fileFormData.title" v-model:description="fileFormData.description" @@ -142,6 +182,7 @@ async function submitFileForm( @reset="() => (fileFormError = {})" @filechange=" (name: string) => { + fileFormError.externalFileExist = checkFileExistMetadata(name) ;(fileFormError.fileExist = checkFileExist(name, fileNameLabel)), (fileFormError.fileName2Long = checkFileName2Long( name, @@ -153,6 +194,7 @@ async function submitFileForm( /> diff --git a/Services/client/src/components/FileItem.vue b/Services/client/src/components/FileItem.vue index aa7fef2..44f7360 100644 --- a/Services/client/src/components/FileItem.vue +++ b/Services/client/src/components/FileItem.vue @@ -117,6 +117,7 @@ function triggerFileDelete(pathname: string) { > +
diff --git a/Services/client/src/components/ListView.vue b/Services/client/src/components/ListView.vue index f76619c..9d54952 100644 --- a/Services/client/src/components/ListView.vue +++ b/Services/client/src/components/ListView.vue @@ -379,7 +379,7 @@ const onRowClick = ((_, row) => { fileFormComponent?.triggerFileEdit( data.row, data.row.pathname, - data.row.filename, + data.row.fileName, ) " id="listViewFileEdit" @@ -391,8 +391,20 @@ const onRowClick = ((_, row) => { color="negative" icon="mdi-trash-can-outline" @click.stop="() => triggerFileDelete(data.row.pathname)" + v-if=" + !( + data.row.metadata && + Object.keys(data.row.metadata).length > 0 + ) + " data-testid="listViewFileDelete" /> +
diff --git a/Services/client/src/components/UploadExistDialog.vue b/Services/client/src/components/UploadExistDialog.vue index 1d99ec1..873a0a4 100644 --- a/Services/client/src/components/UploadExistDialog.vue +++ b/Services/client/src/components/UploadExistDialog.vue @@ -1,6 +1,7 @@