diff --git a/Services/client/src/components/FileFormWrapper.vue b/Services/client/src/components/FileFormWrapper.vue new file mode 100644 index 0000000..7b3dc92 --- /dev/null +++ b/Services/client/src/components/FileFormWrapper.vue @@ -0,0 +1,136 @@ + + + diff --git a/Services/client/src/components/FileIcon.vue b/Services/client/src/components/FileIcon.vue index c8c6957..7c524a5 100644 --- a/Services/client/src/components/FileIcon.vue +++ b/Services/client/src/components/FileIcon.vue @@ -1,6 +1,6 @@ diff --git a/Services/client/src/components/FileItem.vue b/Services/client/src/components/FileItem.vue index 23d8e19..0a14030 100644 --- a/Services/client/src/components/FileItem.vue +++ b/Services/client/src/components/FileItem.vue @@ -2,233 +2,109 @@ import { computed, ref } from 'vue' import { storeToRefs } from 'pinia' -import FileIcon from '@/components/FileIcon.vue' -import FileItemAction from '@/components/FileItemAction.vue' -import DialogDelete from '@/components/DialogDelete.vue' -import FileForm from './FileForm.vue' -import FolderForm from './FolderForm.vue' -import UploadExistDialog from './UploadExistDialog.vue' -import { useTreeDataStore } from '@/stores/tree-data' +import FileIcon from './FileIcon.vue' +import FileItemAction from './FileItemAction.vue' +import DialogDelete from './DialogDelete.vue' +import FileFormWrapper from './FileFormWrapper.vue' +import FolderFormWrapper from './FolderFormWrapper.vue' + import { useFileInfoStore } from '@/stores/file-info-data' +import useStorage from '@/stores/storage' + +const TREE_LEVEL_NAME = ['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย'] as const const props = withDefaults( defineProps<{ action: boolean; viewMode: 'view_list' | 'view_module' }>(), - { - action: false, - }, + { action: false }, ) -const DEPT_NAME = ['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย'] as const const { getFileInfo } = useFileInfoStore() -const { currentFolder, currentFile, currentDept, currentPath } = - storeToRefs(useTreeDataStore()) -const { - createFolder, - editFolder, - getFolder, - deleteFolder, - uploadFile, - updateFile, - deleteFile, - checkFile, - checkFileName, - refaceFile, -} = useTreeDataStore() + +const storageStore = useStorage() +const { folder, file, currentInfo } = storeToRefs(storageStore) +const { goto, deleteFolder, deleteFile } = storageStore + +const fileFormComponent = ref>() +const folderFormComponent = ref>() + +const deleteState = ref(false) +const deletePath = ref('') +const deleteTarget = ref<'deleteFolder' | 'deleteFile'>() +const deleteMap = { deleteFolder, deleteFile } const currentIcon = computed(() => - currentDept.value === 0 + currentInfo.value.dept === 0 ? 'mdi-file-cabinet' - : currentDept.value === 1 + : currentInfo.value.dept === 1 ? 'o_inbox' : 'o_folder_open', ) -const dialogDeleteState = ref(false) -const deleteFormPath = ref('') -const deleteFormType = ref<'deleteFolder' | 'deleteFile'>() - -const folderFormState = ref(false) -const folderFormPath = ref('') -const folderFormData = ref<{ - name?: string -}>({}) -const folderFormType = ref<'edit' | 'create'>('create') -const fileFormState = ref(false) -const fileFormPath = ref('') -const fileFormData = ref<{ - file?: File - title?: string - description?: string - keyword?: string[] - category?: string[] -}>({}) -const fileFormType = ref<'edit' | 'create'>('create') -const fileFormError = ref<{ fileExist?: boolean; fileName2Long?: boolean }>({}) -const fileExistNotification = ref(false) -const fileFormComponent = ref>() - function triggerFolderDelete(pathname: string) { - deleteFormType.value = 'deleteFolder' - deleteFormPath.value = pathname - dialogDeleteState.value = !dialogDeleteState.value + deleteTarget.value = 'deleteFolder' + deletePath.value = pathname + deleteState.value = !deleteState.value } function triggerFileDelete(pathname: string) { - deleteFormType.value = 'deleteFile' - deleteFormPath.value = pathname - dialogDeleteState.value = !dialogDeleteState.value -} - -function triggerFolderCreate() { - folderFormType.value = 'create' - folderFormData.value = {} - folderFormState.value = !folderFormState.value -} - -function triggerFolderEdit(name: string, pathname: string) { - folderFormType.value = 'edit' - folderFormPath.value = pathname - folderFormData.value.name = name - folderFormState.value = true -} - -async function submitFolderForm(value: { - mode: 'create' | 'edit' - name: string -}) { - if (value.mode === 'create') { - await createFolder(value.name) - } else { - await editFolder(value.name, folderFormPath.value) - } -} - -function triggerFileCreate() { - fileFormType.value = 'create' - fileFormData.value = {} - fileFormState.value = !fileFormState.value -} - -function triggerFileEdit( - value: { - title: string - description: string - keyword: string[] - category: string[] - }, - pathname: string, -) { - fileFormState.value = true - fileFormType.value = 'edit' - fileFormPath.value = pathname - fileFormData.value = { - title: value.title, - description: value.description, - keyword: value.keyword, - category: value.category, - } -} - -const currentParam = ref[0]>() - -async function submitFileForm( - value: { - mode: 'create' | 'edit' - file?: File - title: string - description: string - keyword: string[] - category: string[] - }, - force = false, -) { - currentParam.value = value - - if (value.file && checkFile(value.file.name) && !force) { - fileExistNotification.value = true - return - } - - if (value.mode === 'create' && value.file) { - await uploadFile(currentPath.value, value.file, { - title: value.title, - description: value.description, - keyword: value.keyword, - category: value.category, - }) - setTimeout(() => { - refaceFile(currentPath.value) - }, 3000) - - setTimeout(() => { - refaceFile(currentPath.value) - }, 10000) - } else { - await updateFile( - fileFormPath.value, - { - title: value.title, - description: value.description, - keyword: value.keyword, - category: value.category, - }, - value.file, - ) - setTimeout(() => { - refaceFile(currentPath.value) - }, 3000) - - setTimeout(() => { - refaceFile(currentPath.value) - }, 10000) - } - fileFormData.value = {} - fileFormState.value = false - currentParam.value = undefined - fileFormComponent.value?.reset() + deleteTarget.value = 'deleteFile' + deletePath.value = pathname + deleteState.value = !deleteState.value } diff --git a/Services/client/src/components/ListView.vue b/Services/client/src/components/ListView.vue index e9d558e..73080a7 100644 --- a/Services/client/src/components/ListView.vue +++ b/Services/client/src/components/ListView.vue @@ -1,340 +1,188 @@