Merge branch 'feat/overhaul-storage' into development
This commit is contained in:
commit
0d250f5d9c
19 changed files with 1027 additions and 1125 deletions
136
Services/client/src/components/FileFormWrapper.vue
Normal file
136
Services/client/src/components/FileFormWrapper.vue
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { storeToRefs } from 'pinia'
|
||||||
|
import useStorage from '@/stores/storage'
|
||||||
|
import FileForm from './FileForm.vue'
|
||||||
|
import UploadExistDialog from './UploadExistDialog.vue'
|
||||||
|
|
||||||
|
const storageStore = useStorage()
|
||||||
|
const { file, currentInfo } = storeToRefs(storageStore)
|
||||||
|
const { createFile, updateFile } = storageStore
|
||||||
|
|
||||||
|
const fileFormState = ref<boolean>(false)
|
||||||
|
const fileFormPath = ref<string>('')
|
||||||
|
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<boolean>(false)
|
||||||
|
const fileFormComponent = ref<InstanceType<typeof FileForm>>()
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
triggerFileCreate,
|
||||||
|
triggerFileEdit,
|
||||||
|
})
|
||||||
|
|
||||||
|
const currentParam = ref<Parameters<typeof submitFileForm>[0]>()
|
||||||
|
|
||||||
|
function checkFileExist(name: string) {
|
||||||
|
return Boolean(
|
||||||
|
file.value[currentInfo.value.path].find((v) => v.fileName === name),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 &&
|
||||||
|
file.value[currentInfo.value.path].find(
|
||||||
|
(v) => v.fileName === value.file?.name,
|
||||||
|
) &&
|
||||||
|
!force
|
||||||
|
) {
|
||||||
|
fileExistNotification.value = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.mode === 'create' && value.file) {
|
||||||
|
await createFile(value.file, {
|
||||||
|
title: value.title,
|
||||||
|
description: value.description,
|
||||||
|
keyword: value.keyword,
|
||||||
|
category: value.category,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await updateFile(
|
||||||
|
fileFormPath.value,
|
||||||
|
{
|
||||||
|
title: value.title,
|
||||||
|
description: value.description,
|
||||||
|
keyword: value.keyword,
|
||||||
|
category: value.category,
|
||||||
|
},
|
||||||
|
value.file,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
fileFormData.value = {}
|
||||||
|
fileFormState.value = false
|
||||||
|
currentParam.value = undefined
|
||||||
|
fileFormComponent.value?.reset()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<file-form
|
||||||
|
ref="fileFormComponent"
|
||||||
|
:mode="fileFormType"
|
||||||
|
:error="fileFormError"
|
||||||
|
v-model:open="fileFormState"
|
||||||
|
v-model:title="fileFormData.title"
|
||||||
|
v-model:description="fileFormData.description"
|
||||||
|
v-model:keyword="fileFormData.keyword"
|
||||||
|
v-model:category="fileFormData.category"
|
||||||
|
@reset="() => (fileFormError = {})"
|
||||||
|
@filechange="
|
||||||
|
(name: string) => (fileFormError.fileExist = checkFileExist(name))
|
||||||
|
"
|
||||||
|
@submit="submitFileForm"
|
||||||
|
/>
|
||||||
|
<upload-exist-dialog
|
||||||
|
v-model:notification="fileExistNotification"
|
||||||
|
@confirm="() => currentParam && submitFileForm(currentParam, true)"
|
||||||
|
@cancel="() => (currentParam = undefined)"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useFileInfoStore } from '@/stores/file-info-data'
|
|
||||||
import mime from 'mime'
|
import mime from 'mime'
|
||||||
|
import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
|
|
||||||
const { mimeFileMapping } = useFileInfoStore()
|
const { mimeFileMapping } = useFileInfoStore()
|
||||||
|
|
||||||
|
|
@ -11,44 +11,33 @@ defineProps<{
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
function getIcon(mimeType: string | undefined, fileName: string | undefined) {
|
function getIcon(mimeType: string | undefined, fileName: string | undefined) {
|
||||||
if (mimeType === undefined) {
|
if (!mimeType) return 'mdi-file-question-outline'
|
||||||
return 'mdi-file-question-outline'
|
|
||||||
}
|
const extension = mime.getExtension(mimeType)
|
||||||
|
|
||||||
|
if (extension) return mimeFileMapping[mimeType].icon
|
||||||
|
if (fileName && fileName.includes('.')) return 'mdi-file-outline'
|
||||||
|
|
||||||
const extFomMime = mime.getExtension(mimeType)
|
|
||||||
if (extFomMime) {
|
|
||||||
return mimeFileMapping[mimeType].icon
|
|
||||||
}
|
|
||||||
if (fileName && fileName.includes('.')) {
|
|
||||||
return 'mdi-file-outline'
|
|
||||||
}
|
|
||||||
return 'mdi-file-question-outline'
|
return 'mdi-file-question-outline'
|
||||||
}
|
}
|
||||||
|
|
||||||
function getColor(mimeType: string | undefined, fileName: string | undefined) {
|
function getColor(mimeType: string | undefined, fileName: string | undefined) {
|
||||||
if (mimeType === undefined) {
|
if (mimeType === undefined) return 'grey-5'
|
||||||
return 'grey-5'
|
|
||||||
}
|
const extension = mime.getExtension(mimeType)
|
||||||
|
|
||||||
|
if (extension) return mimeFileMapping[mimeType].color
|
||||||
|
if (fileName && fileName.includes('.')) return 'blue-11'
|
||||||
|
|
||||||
const extFomMime = mime.getExtension(mimeType)
|
|
||||||
if (extFomMime) {
|
|
||||||
return mimeFileMapping[mimeType].color
|
|
||||||
}
|
|
||||||
if (fileName && fileName.includes('.')) {
|
|
||||||
return 'blue-11'
|
|
||||||
}
|
|
||||||
return 'grey-5'
|
return 'grey-5'
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIconSize(s: string) {
|
function getIconSize(size: string) {
|
||||||
type SizeMapping = {
|
const sizeMapping = {
|
||||||
[key: string]: string
|
|
||||||
}
|
|
||||||
const sizeMapping: SizeMapping = {
|
|
||||||
preview: '6em',
|
preview: '6em',
|
||||||
list: '2em',
|
list: '2em',
|
||||||
}
|
}
|
||||||
return sizeMapping[s]
|
return sizeMapping[size as keyof typeof sizeMapping]
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,233 +2,109 @@
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
|
|
||||||
import FileIcon from '@/components/FileIcon.vue'
|
import FileIcon from './FileIcon.vue'
|
||||||
import FileItemAction from '@/components/FileItemAction.vue'
|
import FileItemAction from './FileItemAction.vue'
|
||||||
import DialogDelete from '@/components/DialogDelete.vue'
|
import DialogDelete from './DialogDelete.vue'
|
||||||
import FileForm from './FileForm.vue'
|
import FileFormWrapper from './FileFormWrapper.vue'
|
||||||
import FolderForm from './FolderForm.vue'
|
import FolderFormWrapper from './FolderFormWrapper.vue'
|
||||||
import UploadExistDialog from './UploadExistDialog.vue'
|
|
||||||
import { useTreeDataStore } from '@/stores/tree-data'
|
|
||||||
import { useFileInfoStore } from '@/stores/file-info-data'
|
import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
|
import useStorage from '@/stores/storage'
|
||||||
|
|
||||||
|
const TREE_LEVEL_NAME = ['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย'] as const
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{ action: boolean; viewMode: 'view_list' | 'view_module' }>(),
|
defineProps<{ action: boolean; viewMode: 'view_list' | 'view_module' }>(),
|
||||||
{
|
{ action: false },
|
||||||
action: false,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
const DEPT_NAME = ['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย'] as const
|
|
||||||
const { getFileInfo } = useFileInfoStore()
|
const { getFileInfo } = useFileInfoStore()
|
||||||
const { currentFolder, currentFile, currentDept, currentPath } =
|
|
||||||
storeToRefs(useTreeDataStore())
|
const storageStore = useStorage()
|
||||||
const {
|
const { folder, file, currentInfo } = storeToRefs(storageStore)
|
||||||
createFolder,
|
const { goto, deleteFolder, deleteFile } = storageStore
|
||||||
editFolder,
|
|
||||||
getFolder,
|
const fileFormComponent = ref<InstanceType<typeof FileFormWrapper>>()
|
||||||
deleteFolder,
|
const folderFormComponent = ref<InstanceType<typeof FolderFormWrapper>>()
|
||||||
uploadFile,
|
|
||||||
updateFile,
|
const deleteState = ref<boolean>(false)
|
||||||
deleteFile,
|
const deletePath = ref<string>('')
|
||||||
checkFile,
|
const deleteTarget = ref<'deleteFolder' | 'deleteFile'>()
|
||||||
checkFileName,
|
const deleteMap = { deleteFolder, deleteFile }
|
||||||
refaceFile,
|
|
||||||
} = useTreeDataStore()
|
|
||||||
|
|
||||||
const currentIcon = computed(() =>
|
const currentIcon = computed(() =>
|
||||||
currentDept.value === 0
|
currentInfo.value.dept === 0
|
||||||
? 'mdi-file-cabinet'
|
? 'mdi-file-cabinet'
|
||||||
: currentDept.value === 1
|
: currentInfo.value.dept === 1
|
||||||
? 'o_inbox'
|
? 'o_inbox'
|
||||||
: 'o_folder_open',
|
: 'o_folder_open',
|
||||||
)
|
)
|
||||||
|
|
||||||
const dialogDeleteState = ref<boolean>(false)
|
|
||||||
const deleteFormPath = ref<string>('')
|
|
||||||
const deleteFormType = ref<'deleteFolder' | 'deleteFile'>()
|
|
||||||
|
|
||||||
const folderFormState = ref<boolean>(false)
|
|
||||||
const folderFormPath = ref<string>('')
|
|
||||||
const folderFormData = ref<{
|
|
||||||
name?: string
|
|
||||||
}>({})
|
|
||||||
const folderFormType = ref<'edit' | 'create'>('create')
|
|
||||||
const fileFormState = ref<boolean>(false)
|
|
||||||
const fileFormPath = ref<string>('')
|
|
||||||
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<boolean>(false)
|
|
||||||
const fileFormComponent = ref<InstanceType<typeof FileForm>>()
|
|
||||||
|
|
||||||
function triggerFolderDelete(pathname: string) {
|
function triggerFolderDelete(pathname: string) {
|
||||||
deleteFormType.value = 'deleteFolder'
|
deleteTarget.value = 'deleteFolder'
|
||||||
deleteFormPath.value = pathname
|
deletePath.value = pathname
|
||||||
dialogDeleteState.value = !dialogDeleteState.value
|
deleteState.value = !deleteState.value
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerFileDelete(pathname: string) {
|
function triggerFileDelete(pathname: string) {
|
||||||
deleteFormType.value = 'deleteFile'
|
deleteTarget.value = 'deleteFile'
|
||||||
deleteFormPath.value = pathname
|
deletePath.value = pathname
|
||||||
dialogDeleteState.value = !dialogDeleteState.value
|
deleteState.value = !deleteState.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<Parameters<typeof submitFileForm>[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()
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="text-h6 q-mt-md" v-if="currentDept > 2 && currentDept < 4">
|
<file-form-wrapper ref="fileFormComponent" />
|
||||||
|
<folder-form-wrapper ref="folderFormComponent" />
|
||||||
|
<dialog-delete
|
||||||
|
v-model:open="deleteState"
|
||||||
|
@confirm="() => deleteTarget && deleteMap[deleteTarget](deletePath)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="text-h6 q-mt-md"
|
||||||
|
v-if="currentInfo.dept > 2 && currentInfo.dept < 4"
|
||||||
|
>
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<div>{{ DEPT_NAME[currentDept] }}</div>
|
<div>{{ TREE_LEVEL_NAME[currentInfo.dept] }}</div>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="action"
|
|
||||||
outline
|
outline
|
||||||
push
|
push
|
||||||
|
dense
|
||||||
|
id="listViewFolderCreate"
|
||||||
class="q-px-md q-ml-md"
|
class="q-px-md q-ml-md"
|
||||||
:label="'สร้าง' + DEPT_NAME[currentDept]"
|
|
||||||
type="submit"
|
type="submit"
|
||||||
color="primary"
|
color="primary"
|
||||||
dense
|
|
||||||
icon="add"
|
icon="add"
|
||||||
@click.stop="() => triggerFolderCreate()"
|
v-if="action"
|
||||||
id="listViewFolderCreate"
|
:label="'สร้าง' + TREE_LEVEL_NAME[currentInfo.dept]"
|
||||||
|
@click.stop="() => folderFormComponent?.triggerFolderCreate()"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid q-mt-md" v-if="currentDept < 4">
|
<div
|
||||||
<div v-for="value in currentFolder" :data-pathname="value.pathname">
|
class="grid q-mt-md"
|
||||||
|
v-if="currentInfo.dept < 4 && folder[currentInfo.path]"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="value in folder[currentInfo.path]"
|
||||||
|
:data-pathname="value.pathname"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
|
class="box"
|
||||||
:style="{
|
:style="{
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
gap: '0.5rem',
|
gap: '0.5rem',
|
||||||
flexDirection: currentDept > 2 ? 'row' : 'column',
|
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
padding: currentDept > 2 ? '.5rem 0' : '.5rem',
|
flexDirection: currentInfo.dept > 2 ? 'row' : 'column',
|
||||||
|
padding: currentInfo.dept > 2 ? '.5rem 0' : '.5rem',
|
||||||
}"
|
}"
|
||||||
class="box"
|
@click="() => goto(value.pathname)"
|
||||||
@click="
|
|
||||||
() => {
|
|
||||||
;(folderFormState = false), getFolder(value.pathname)
|
|
||||||
}
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
<div class="q-px-md flex items-center justify-center">
|
<div class="q-px-md flex items-center justify-center">
|
||||||
<q-icon
|
<q-icon
|
||||||
:name="currentIcon"
|
:name="currentIcon"
|
||||||
:size="currentDept > 2 ? '3em' : '6em'"
|
:size="currentInfo.dept > 2 ? '3em' : '6em'"
|
||||||
color="primary"
|
color="primary"
|
||||||
class="col"
|
class="col"
|
||||||
/>
|
/>
|
||||||
|
|
@ -236,40 +112,46 @@ async function submitFileForm(
|
||||||
<div
|
<div
|
||||||
class="absolute flex items-center justify-center"
|
class="absolute flex items-center justify-center"
|
||||||
style="top: 0.5rem; right: 0.5rem"
|
style="top: 0.5rem; right: 0.5rem"
|
||||||
:style="{ bottom: currentDept > 2 ? '0.5rem' : 'unset' }"
|
|
||||||
v-if="props.action"
|
v-if="props.action"
|
||||||
|
:style="{ bottom: currentInfo.dept > 2 ? '0.5rem' : 'unset' }"
|
||||||
>
|
>
|
||||||
<file-item-action
|
<file-item-action
|
||||||
:nameId="value.pathname"
|
:nameId="value.pathname"
|
||||||
@delete="() => triggerFolderDelete(value.pathname)"
|
@delete="() => triggerFolderDelete(value.pathname)"
|
||||||
@edit="() => triggerFolderEdit(value.name, value.pathname)"
|
@edit="
|
||||||
|
() =>
|
||||||
|
folderFormComponent?.triggerFolderEdit(
|
||||||
|
value.name,
|
||||||
|
value.pathname,
|
||||||
|
)
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="text-overflow-handle block text-center"
|
class="text-overflow-handle block text-center"
|
||||||
:class="{
|
|
||||||
'q-px-md': currentDept < 3,
|
|
||||||
'q-pr-xl': currentDept > 2,
|
|
||||||
}"
|
|
||||||
style="max-width: 100%"
|
style="max-width: 100%"
|
||||||
|
:class="{
|
||||||
|
'q-px-md': currentInfo.dept < 3,
|
||||||
|
'q-pr-xl': currentInfo.dept > 2,
|
||||||
|
}"
|
||||||
>
|
>
|
||||||
{{ value.name }}
|
{{ value.name }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="props.action && currentDept < 4">
|
<div v-if="props.action && currentInfo.dept < 4">
|
||||||
<div
|
<div
|
||||||
|
id="triggerFolderCreateFileItem"
|
||||||
class="dashed"
|
class="dashed"
|
||||||
:style="{
|
:style="{
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
gap: '0.5rem',
|
gap: '0.5rem',
|
||||||
flexDirection: currentDept > 2 ? 'row' : 'column',
|
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
padding: currentDept > 2 ? '.5rem 0' : '.5rem',
|
flexDirection: currentInfo.dept > 2 ? 'row' : 'column',
|
||||||
|
padding: currentInfo.dept > 2 ? '.5rem 0' : '.5rem',
|
||||||
}"
|
}"
|
||||||
@click.stop="() => triggerFolderCreate()"
|
@click.stop="() => folderFormComponent?.triggerFolderCreate()"
|
||||||
id="triggerFolderCreateFileItem"
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="q-px-md flex items-center justify-center"
|
class="q-px-md flex items-center justify-center"
|
||||||
|
|
@ -277,17 +159,17 @@ async function submitFileForm(
|
||||||
>
|
>
|
||||||
<q-icon
|
<q-icon
|
||||||
:name="currentIcon"
|
:name="currentIcon"
|
||||||
:size="currentDept > 2 ? '3em' : '6em'"
|
:size="currentInfo.dept > 2 ? '3em' : '6em'"
|
||||||
color="primary"
|
color="primary"
|
||||||
class="col"
|
class="col"
|
||||||
/>
|
/>
|
||||||
<q-btn
|
<q-btn
|
||||||
round
|
round
|
||||||
:dense="currentDept > 2"
|
|
||||||
color="white"
|
color="white"
|
||||||
size="10px"
|
size="10px"
|
||||||
style="position: absolute; bottom: 0"
|
style="position: absolute; bottom: 0"
|
||||||
:style="{ right: currentDept > 2 ? '.5rem' : '1rem' }"
|
:dense="currentInfo.dept > 2"
|
||||||
|
:style="{ right: currentInfo.dept > 2 ? '.5rem' : '1rem' }"
|
||||||
>
|
>
|
||||||
<q-icon name="add" color="primary" size="1.5rem" />
|
<q-icon name="add" color="primary" size="1.5rem" />
|
||||||
</q-btn>
|
</q-btn>
|
||||||
|
|
@ -295,60 +177,58 @@ async function submitFileForm(
|
||||||
<div
|
<div
|
||||||
class="text-overflow-handle block text-center"
|
class="text-overflow-handle block text-center"
|
||||||
:class="{
|
:class="{
|
||||||
'q-px-md': currentDept < 3,
|
'q-px-md': currentInfo.dept < 3,
|
||||||
'q-pr-xl': currentDept > 2,
|
'q-pr-xl': currentInfo.dept > 2,
|
||||||
}"
|
}"
|
||||||
style="max-width: 100%"
|
style="max-width: 100%"
|
||||||
>
|
>
|
||||||
สร้าง{{ DEPT_NAME[currentDept] }}
|
สร้าง{{ TREE_LEVEL_NAME[currentInfo.dept] }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="grid-column: 1 / span 5" class="q-mt-md" v-if="currentDept > 2">
|
<div
|
||||||
|
style="grid-column: 1 / span 5"
|
||||||
|
class="q-mt-md"
|
||||||
|
v-if="currentInfo.dept > 2 && file[currentInfo.path]"
|
||||||
|
>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<div>
|
<div>
|
||||||
<span class="text-h6 q-mr-md">เอกสาร</span>
|
<span class="text-h6 q-mr-md">เอกสาร</span>
|
||||||
<span class="text-body text-grey"
|
<span class="text-body text-grey"
|
||||||
>จำนวน {{ currentFile.length }} รายการ</span
|
>จำนวน {{ file[currentInfo.path].length }} รายการ</span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<q-btn
|
<q-btn
|
||||||
outline
|
outline
|
||||||
push
|
push
|
||||||
v-if="action"
|
dense
|
||||||
|
id="listViewFileCreate"
|
||||||
class="q-px-md q-ml-md"
|
class="q-px-md q-ml-md"
|
||||||
label="สร้างเอกสาร"
|
label="สร้างเอกสาร"
|
||||||
type="submit"
|
type="submit"
|
||||||
color="primary"
|
color="primary"
|
||||||
dense
|
|
||||||
icon="add"
|
icon="add"
|
||||||
@click.stop="() => triggerFileCreate()"
|
v-if="action"
|
||||||
id="listViewFileCreate"
|
@click.stop="() => fileFormComponent?.triggerFileCreate()"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid q-mt-md">
|
<div class="grid q-mt-md">
|
||||||
<div v-for="(value, index) in currentFile" :data-pathname="value.pathname">
|
<div
|
||||||
|
v-for="(value, index) in file[currentInfo.path]"
|
||||||
|
:data-pathname="value.pathname"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
:style="{
|
|
||||||
position: 'relative',
|
|
||||||
display: 'flex',
|
|
||||||
gap: '0.5rem',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
padding: '1rem',
|
|
||||||
maxWidth: '100%',
|
|
||||||
}"
|
|
||||||
class="box"
|
class="box"
|
||||||
@click="() => getFileInfo(value)"
|
|
||||||
:id="`getFileInfoFileItem${index}`"
|
:id="`getFileInfoFileItem${index}`"
|
||||||
|
@click="() => getFileInfo(value)"
|
||||||
>
|
>
|
||||||
<div class="q-px-md flex items-center justify-center">
|
<div class="q-px-md flex items-center justify-center">
|
||||||
<file-icon
|
<file-icon
|
||||||
size="preview"
|
size="preview"
|
||||||
:fileMimeType="value.fileType ? value.fileType : 'unknow'"
|
:fileMimeType="value.fileType ? value.fileType : '-'"
|
||||||
:fileName="value.fileName ? value.fileName : 'unknow'"
|
:fileName="value.fileName ? value.fileName : '-'"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
|
@ -360,7 +240,7 @@ async function submitFileForm(
|
||||||
:nameId="value.pathname"
|
:nameId="value.pathname"
|
||||||
@edit="
|
@edit="
|
||||||
() =>
|
() =>
|
||||||
triggerFileEdit(
|
fileFormComponent?.triggerFileEdit(
|
||||||
{
|
{
|
||||||
title: value.title,
|
title: value.title,
|
||||||
description: value.description,
|
description: value.description,
|
||||||
|
|
@ -381,8 +261,10 @@ async function submitFileForm(
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="props.action && currentDept > 2">
|
<div v-if="props.action && currentInfo.dept > 2">
|
||||||
<div
|
<div
|
||||||
|
id="triggerFileCreateFileItem"
|
||||||
|
class="dashed"
|
||||||
:style="{
|
:style="{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
gap: '0.5rem',
|
gap: '0.5rem',
|
||||||
|
|
@ -391,9 +273,7 @@ async function submitFileForm(
|
||||||
padding: '1rem',
|
padding: '1rem',
|
||||||
maxWidth: '100%',
|
maxWidth: '100%',
|
||||||
}"
|
}"
|
||||||
class="dashed"
|
@click.stop="() => fileFormComponent?.triggerFileCreate()"
|
||||||
@click.stop="() => triggerFileCreate()"
|
|
||||||
id="triggerFileCreateFileItem"
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="q-px-md flex items-center justify-center"
|
class="q-px-md flex items-center justify-center"
|
||||||
|
|
@ -418,55 +298,19 @@ async function submitFileForm(
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<file-form
|
|
||||||
ref="fileFormComponent"
|
|
||||||
:mode="fileFormType"
|
|
||||||
:error="fileFormError"
|
|
||||||
v-model:open="fileFormState"
|
|
||||||
v-model:title="fileFormData.title"
|
|
||||||
v-model:description="fileFormData.description"
|
|
||||||
v-model:keyword="fileFormData.keyword"
|
|
||||||
v-model:category="fileFormData.category"
|
|
||||||
@reset="() => (fileFormError = {})"
|
|
||||||
@filechange="
|
|
||||||
(name: string) => (
|
|
||||||
(fileFormError.fileExist = checkFile(name)),
|
|
||||||
(fileFormError.fileName2Long = checkFileName(name))
|
|
||||||
)
|
|
||||||
"
|
|
||||||
@submit="submitFileForm"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<folder-form
|
|
||||||
:mode="folderFormType"
|
|
||||||
:tree="DEPT_NAME[currentDept]"
|
|
||||||
v-if="currentDept < 4"
|
|
||||||
v-model:open="folderFormState"
|
|
||||||
v-model:name="folderFormData.name"
|
|
||||||
@submit="submitFolderForm"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<upload-exist-dialog
|
|
||||||
v-model:notification="fileExistNotification"
|
|
||||||
@confirm="() => currentParam && submitFileForm(currentParam, true)"
|
|
||||||
@cancel="() => (currentParam = undefined)"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<dialog-delete
|
|
||||||
v-model:open="dialogDeleteState"
|
|
||||||
@confirm="
|
|
||||||
() =>
|
|
||||||
deleteFormType &&
|
|
||||||
{ deleteFolder, deleteFile }[deleteFormType](deleteFormPath)
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.box {
|
.box {
|
||||||
border: 2px solid $separator-color;
|
border: 2px solid $separator-color;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding: 1rem;
|
||||||
|
max-width: 100%;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -483,20 +327,6 @@ async function submitFileForm(
|
||||||
margin: auto auto;
|
margin: auto auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.add-button {
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
right: 30%;
|
|
||||||
background-color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.add-button-folder-level {
|
|
||||||
position: absolute;
|
|
||||||
left: 30px;
|
|
||||||
top: 22px;
|
|
||||||
background-color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.text-overflow-handle {
|
.text-overflow-handle {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { storeToRefs } from 'pinia'
|
|
||||||
import { useSearchDataStore } from '@/stores/searched-data'
|
|
||||||
import { useFileInfoStore } from '@/stores/file-info-data'
|
|
||||||
import { useTreeDataStore } from '@/stores/tree-data'
|
|
||||||
|
|
||||||
import DialogDelete from './DialogDelete.vue'
|
|
||||||
import UploadExistDialog from './UploadExistDialog.vue'
|
|
||||||
import FileForm from './FileForm.vue'
|
|
||||||
import FileItemAction from '@/components/FileItemAction.vue'
|
|
||||||
import FileIcon from '@/components/FileIcon.vue'
|
|
||||||
|
|
||||||
import type { QTableProps } from 'quasar'
|
import type { QTableProps } from 'quasar'
|
||||||
import { onMounted, ref, watch } from 'vue'
|
import { onMounted, ref, watch } from 'vue'
|
||||||
|
import { storeToRefs } from 'pinia'
|
||||||
|
|
||||||
|
import { useSearchDataStore } from '@/stores/searched-data'
|
||||||
|
import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
|
import useStorage from '@/stores/storage'
|
||||||
|
|
||||||
|
import DialogDelete from './DialogDelete.vue'
|
||||||
|
import FileFormWrapper from './FileFormWrapper.vue'
|
||||||
|
import FileItemAction from '@/components/FileItemAction.vue'
|
||||||
|
import FileIcon from '@/components/FileIcon.vue'
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
|
|
@ -24,30 +23,22 @@ const props = withDefaults(
|
||||||
)
|
)
|
||||||
const { foundFile, isActFoundFile } = storeToRefs(useSearchDataStore())
|
const { foundFile, isActFoundFile } = storeToRefs(useSearchDataStore())
|
||||||
const { getFileInfo, getSize, getType } = useFileInfoStore()
|
const { getFileInfo, getSize, getType } = useFileInfoStore()
|
||||||
const { updateFile, deleteFile, checkFile } = useTreeDataStore()
|
|
||||||
|
const storageStore = useStorage()
|
||||||
|
const { deleteFile } = storageStore
|
||||||
|
|
||||||
|
const fileFormComponent = ref<InstanceType<typeof FileFormWrapper>>()
|
||||||
|
|
||||||
const keywordList = ref<string[]>([])
|
const keywordList = ref<string[]>([])
|
||||||
const categoryList = ref<string[]>([])
|
const categoryList = ref<string[]>([])
|
||||||
const selectKeyword = ref<string[]>([])
|
const selectKeyword = ref<string[]>([])
|
||||||
const selectCategory = ref<string[]>([])
|
const selectCategory = ref<string[]>([])
|
||||||
const filterFoundFile = ref<any>()
|
const filterFoundFile = ref<any>()
|
||||||
|
|
||||||
const fileExistNotification = ref<boolean>(false)
|
|
||||||
const fileFormError = ref<{ fileExist?: boolean }>({})
|
|
||||||
const deleteFormType = ref<'deleteFile'>('deleteFile')
|
const deleteFormType = ref<'deleteFile'>('deleteFile')
|
||||||
const dialogDeleteState = ref<boolean>(false)
|
const dialogDeleteState = ref<boolean>(false)
|
||||||
const deleteFormPath = ref<string>('')
|
const deleteFormPath = ref<string>('')
|
||||||
|
|
||||||
const fileFormType = ref<'edit'>('edit')
|
|
||||||
const fileFormState = ref<boolean>(false)
|
|
||||||
const fileFormPath = ref<string>('')
|
|
||||||
const fileFormData = ref<{
|
|
||||||
file?: File
|
|
||||||
title?: string
|
|
||||||
description?: string
|
|
||||||
keyword?: string[]
|
|
||||||
category?: string[]
|
|
||||||
}>({})
|
|
||||||
|
|
||||||
const columns: QTableProps['columns'] = [
|
const columns: QTableProps['columns'] = [
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
|
|
@ -84,66 +75,6 @@ const columns: QTableProps['columns'] = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const currentParam = ref<Parameters<typeof submitFileForm>[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 === 'edit') {
|
|
||||||
await updateFile(
|
|
||||||
fileFormPath.value,
|
|
||||||
{
|
|
||||||
title: value.title,
|
|
||||||
description: value.description,
|
|
||||||
keyword: value.keyword,
|
|
||||||
category: value.category,
|
|
||||||
},
|
|
||||||
value.file,
|
|
||||||
)
|
|
||||||
setTimeout(() => {
|
|
||||||
isActFoundFile.value = true
|
|
||||||
}, 400)
|
|
||||||
}
|
|
||||||
|
|
||||||
fileFormData.value = {}
|
|
||||||
fileFormState.value = false
|
|
||||||
currentParam.value = undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function triggerFileDelete(pathname: string) {
|
function triggerFileDelete(pathname: string) {
|
||||||
deleteFormType.value = 'deleteFile'
|
deleteFormType.value = 'deleteFile'
|
||||||
deleteFormPath.value = pathname
|
deleteFormPath.value = pathname
|
||||||
|
|
@ -161,36 +92,30 @@ function confirmDelete() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterSearch() {
|
function filterSearch() {
|
||||||
function updateList() {
|
keywordList.value = []
|
||||||
keywordList.value = []
|
categoryList.value = []
|
||||||
categoryList.value = []
|
foundFile.value.forEach((obj) => {
|
||||||
foundFile.value.forEach((obj) => {
|
obj.keyword.forEach((keyword) => {
|
||||||
obj.keyword.forEach((keyword) => {
|
if (!keywordList.value.includes(keyword)) {
|
||||||
if (!keywordList.value.includes(keyword)) {
|
keywordList.value.push(keyword)
|
||||||
keywordList.value.push(keyword)
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
obj.category.forEach((category) => {
|
|
||||||
if (!categoryList.value.includes(category)) {
|
|
||||||
categoryList.value.push(category)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
obj.category.forEach((category) => {
|
||||||
|
if (!categoryList.value.includes(category)) {
|
||||||
|
categoryList.value.push(category)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
function filterArray() {
|
if (!(selectKeyword.value.length || selectCategory.value.length)) {
|
||||||
if (!(selectKeyword.value.length || selectCategory.value.length)) {
|
filterFoundFile.value = foundFile.value
|
||||||
filterFoundFile.value = foundFile.value
|
} else {
|
||||||
} else {
|
filterFoundFile.value = foundFile.value.filter(
|
||||||
filterFoundFile.value = foundFile.value.filter(
|
(entry) =>
|
||||||
(entry) =>
|
entry.keyword.some((kw) => selectKeyword.value.includes(kw)) ||
|
||||||
entry.keyword.some((kw) => selectKeyword.value.includes(kw)) ||
|
entry.category.some((kw) => selectCategory.value.includes(kw)),
|
||||||
entry.category.some((kw) => selectCategory.value.includes(kw)),
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
updateList()
|
|
||||||
filterArray()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -208,6 +133,9 @@ onMounted(() => {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<file-form-wrapper ref="fileFormComponent" />
|
||||||
|
<dialog-delete v-model:open="dialogDeleteState" @confirm="confirmDelete" />
|
||||||
|
|
||||||
<div class="row grid q-py-md q-gutter-sm">
|
<div class="row grid q-py-md q-gutter-sm">
|
||||||
<q-select
|
<q-select
|
||||||
outlined
|
outlined
|
||||||
|
|
@ -265,7 +193,7 @@ onMounted(() => {
|
||||||
:nameId="value.pathname"
|
:nameId="value.pathname"
|
||||||
@edit="
|
@edit="
|
||||||
() =>
|
() =>
|
||||||
triggerFileEdit(
|
fileFormComponent?.triggerFileEdit(
|
||||||
{
|
{
|
||||||
title: value.title,
|
title: value.title,
|
||||||
description: value.description,
|
description: value.description,
|
||||||
|
|
@ -344,7 +272,11 @@ onMounted(() => {
|
||||||
dense
|
dense
|
||||||
icon="o_edit"
|
icon="o_edit"
|
||||||
@click="
|
@click="
|
||||||
() => triggerFileEdit(actionData.row, actionData.row.pathname)
|
() =>
|
||||||
|
fileFormComponent?.triggerFileEdit(
|
||||||
|
actionData.row,
|
||||||
|
actionData.row.pathname,
|
||||||
|
)
|
||||||
"
|
"
|
||||||
id="listViewFileEdit"
|
id="listViewFileEdit"
|
||||||
/>
|
/>
|
||||||
|
|
@ -365,26 +297,6 @@ onMounted(() => {
|
||||||
<div class="q-mt-md" v-if="foundFile.length == 0">
|
<div class="q-mt-md" v-if="foundFile.length == 0">
|
||||||
<span>ไม่พบรายการที่ค้นหา</span>
|
<span>ไม่พบรายการที่ค้นหา</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<file-form
|
|
||||||
:mode="fileFormType"
|
|
||||||
:error="fileFormError"
|
|
||||||
v-model:open="fileFormState"
|
|
||||||
v-model:title="fileFormData.title"
|
|
||||||
v-model:description="fileFormData.description"
|
|
||||||
v-model:keyword="fileFormData.keyword"
|
|
||||||
v-model:category="fileFormData.category"
|
|
||||||
@filechange="(name: string) => (fileFormError.fileExist = checkFile(name))"
|
|
||||||
@submit="submitFileForm"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<upload-exist-dialog
|
|
||||||
v-model:notification="fileExistNotification"
|
|
||||||
@confirm="() => currentParam && submitFileForm(currentParam, true)"
|
|
||||||
@cancel="() => (currentParam = undefined)"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<dialog-delete v-model:open="dialogDeleteState" @confirm="confirmDelete" />
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|
|
||||||
59
Services/client/src/components/FolderFormWrapper.vue
Normal file
59
Services/client/src/components/FolderFormWrapper.vue
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { storeToRefs } from 'pinia'
|
||||||
|
import useStorage from '@/stores/storage'
|
||||||
|
import FolderForm from './FolderForm.vue'
|
||||||
|
|
||||||
|
const storageStore = useStorage()
|
||||||
|
const { file, currentInfo } = storeToRefs(storageStore)
|
||||||
|
const { createFolder, editFolder } = storageStore
|
||||||
|
|
||||||
|
const folderFormState = ref<boolean>(false)
|
||||||
|
const folderFormPath = ref<string>('')
|
||||||
|
const folderFormData = ref<{
|
||||||
|
name?: string
|
||||||
|
}>({})
|
||||||
|
const folderFormType = ref<'edit' | 'create'>('create')
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
triggerFolderCreate,
|
||||||
|
triggerFolderEdit,
|
||||||
|
})
|
||||||
|
|
||||||
|
async function submitFolderForm(value: {
|
||||||
|
mode: 'create' | 'edit'
|
||||||
|
name: string
|
||||||
|
}) {
|
||||||
|
if (value.mode === 'create') {
|
||||||
|
await createFolder(value.name)
|
||||||
|
} else {
|
||||||
|
await editFolder(value.name, folderFormPath.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<folder-form
|
||||||
|
:mode="folderFormType"
|
||||||
|
:tree="
|
||||||
|
(['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย'] as const)[currentInfo.dept]
|
||||||
|
"
|
||||||
|
v-if="currentInfo.dept < 4"
|
||||||
|
v-model:open="folderFormState"
|
||||||
|
v-model:name="folderFormData.name"
|
||||||
|
@submit="submitFolderForm"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
@ -1,22 +1,20 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { watch, ref } from 'vue'
|
import { watch, ref } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({ visibility: Boolean })
|
||||||
visibility: Boolean,
|
const visible = ref<boolean>(props.visibility)
|
||||||
})
|
|
||||||
|
|
||||||
const loaderVisibility = ref<boolean>(props.visibility)
|
watch(props, () => (visible.value = props.visibility))
|
||||||
|
|
||||||
watch(props, () => (loaderVisibility.value = props.visibility))
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<q-inner-loading :showing="loaderVisibility" class="loader">
|
<q-inner-loading :showing="visible" class="loader">
|
||||||
<q-spinner-cube size="80px" color="primary" />
|
<q-spinner-cube size="80px" color="primary" />
|
||||||
</q-inner-loading>
|
</q-inner-loading>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="sass">
|
<style lang="scss">
|
||||||
.loader
|
.loader {
|
||||||
z-index: 1000
|
z-index: 1000;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,340 +1,188 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { QTableProps } from 'quasar'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import type { QTableProps } from 'quasar'
|
|
||||||
import { useTreeDataStore, type TreeDataFolder } from '@/stores/tree-data'
|
|
||||||
import { useFileInfoStore } from '@/stores/file-info-data'
|
|
||||||
import FileIcon from '@/components/FileIcon.vue'
|
import FileIcon from '@/components/FileIcon.vue'
|
||||||
import DialogDelete from '@/components/DialogDelete.vue'
|
import DialogDelete from '@/components/DialogDelete.vue'
|
||||||
import UploadExistDialog from './UploadExistDialog.vue'
|
import FileFormWrapper from './FileFormWrapper.vue'
|
||||||
import FileForm from './FileForm.vue'
|
import FolderFormWrapper from './FolderFormWrapper.vue'
|
||||||
import FolderForm from './FolderForm.vue'
|
|
||||||
|
import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
|
import useStorage from '@/stores/storage'
|
||||||
|
|
||||||
|
const storageStore = useStorage()
|
||||||
|
const { folder, file, currentInfo } = storeToRefs(storageStore)
|
||||||
|
const { goto, deleteFolder, deleteFile } = storageStore
|
||||||
|
|
||||||
const { getFormatDate, getSize, getType, getFileInfo } = useFileInfoStore()
|
const { getFormatDate, getSize, getType, getFileInfo } = useFileInfoStore()
|
||||||
const { listDataFile, listDataFolder, currentDept, currentPath } =
|
|
||||||
storeToRefs(useTreeDataStore())
|
|
||||||
const {
|
|
||||||
createFolder,
|
|
||||||
editFolder,
|
|
||||||
getFolder,
|
|
||||||
deleteFolder,
|
|
||||||
uploadFile,
|
|
||||||
updateFile,
|
|
||||||
deleteFile,
|
|
||||||
checkFile,
|
|
||||||
refaceFile,
|
|
||||||
} = useTreeDataStore()
|
|
||||||
|
|
||||||
const DEPT_NAME = ['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย'] as const
|
const fileFormComponent = ref<InstanceType<typeof FileFormWrapper>>()
|
||||||
|
const folderFormComponent = ref<InstanceType<typeof FolderFormWrapper>>()
|
||||||
|
|
||||||
|
const currentIcon = computed(() =>
|
||||||
|
currentInfo.value.dept === 0
|
||||||
|
? 'mdi-file-cabinet'
|
||||||
|
: currentInfo.value.dept === 1
|
||||||
|
? 'inbox'
|
||||||
|
: 'o_folder_open',
|
||||||
|
)
|
||||||
|
const TREE_LEVEL_NAME = ['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย'] as const
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
mode: 'admin' | 'user'
|
mode: 'admin' | 'user'
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const currentLevel = computed(() =>
|
const deleteState = ref<boolean>(false)
|
||||||
currentDept.value === 0
|
const deletePath = ref<string>('')
|
||||||
? 'ตู้จัดเก็บเอกสาร'
|
const deleteTarget = ref<'deleteFolder' | 'deleteFile'>()
|
||||||
: currentDept.value === 1
|
const deleteMap = { deleteFolder, deleteFile }
|
||||||
? 'ลิ้นชัก'
|
|
||||||
: currentDept.value === 2
|
|
||||||
? 'แฟ้ม'
|
|
||||||
: 'แฟ้มย่อย',
|
|
||||||
)
|
|
||||||
|
|
||||||
const currentIcon = computed(() =>
|
|
||||||
currentDept.value === 0
|
|
||||||
? 'mdi-file-cabinet'
|
|
||||||
: currentDept.value === 1
|
|
||||||
? 'inbox'
|
|
||||||
: 'o_folder_open',
|
|
||||||
)
|
|
||||||
|
|
||||||
const folderFormState = ref<boolean>(false)
|
|
||||||
const folderFormPath = ref<string>('')
|
|
||||||
const folderFormData = ref<{
|
|
||||||
name?: string
|
|
||||||
}>({})
|
|
||||||
const folderFormType = ref<'edit' | 'create'>('create')
|
|
||||||
const fileFormError = ref<{ fileExist?: boolean }>({})
|
|
||||||
const fileExistNotification = ref<boolean>(false)
|
|
||||||
|
|
||||||
const fileFormState = ref<boolean>(false)
|
|
||||||
const fileFormPath = ref<string>('')
|
|
||||||
const fileFormData = ref<{
|
|
||||||
file?: File
|
|
||||||
title?: string
|
|
||||||
description?: string
|
|
||||||
keyword?: string[]
|
|
||||||
category?: string[]
|
|
||||||
}>({})
|
|
||||||
const fileFormType = ref<'edit' | 'create'>('create')
|
|
||||||
const fileFormComponent = ref<InstanceType<typeof FileForm>>()
|
|
||||||
|
|
||||||
const dialogDeleteState = ref<boolean>(false)
|
|
||||||
const deleteFormPath = ref<string>('')
|
|
||||||
const deleteFormType = ref<'deleteFolder' | 'deleteFile'>()
|
|
||||||
|
|
||||||
function triggerFolderDelete(pathname: string) {
|
function triggerFolderDelete(pathname: string) {
|
||||||
deleteFormType.value = 'deleteFolder'
|
deleteTarget.value = 'deleteFolder'
|
||||||
deleteFormPath.value = pathname
|
deletePath.value = pathname
|
||||||
dialogDeleteState.value = !dialogDeleteState.value
|
deleteState.value = !deleteState.value
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerFileDelete(pathname: string) {
|
function triggerFileDelete(pathname: string) {
|
||||||
deleteFormType.value = 'deleteFile'
|
deleteTarget.value = 'deleteFile'
|
||||||
deleteFormPath.value = pathname
|
deletePath.value = pathname
|
||||||
dialogDeleteState.value = !dialogDeleteState.value
|
deleteState.value = !deleteState.value
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerFolderCreate() {
|
const colFolder = [
|
||||||
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<Parameters<typeof submitFileForm>[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()
|
|
||||||
}
|
|
||||||
|
|
||||||
const columnsFolder: QTableProps['columns'] = [
|
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
required: true,
|
required: true,
|
||||||
label: 'ชื่อ',
|
label: 'ชื่อ',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
field: (row) => row.name,
|
field: 'name',
|
||||||
format: (val) => `${val}`,
|
|
||||||
sortable: true,
|
sortable: true,
|
||||||
style: 'width: 1000px',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'createdBy',
|
name: 'createdBy',
|
||||||
align: 'center',
|
|
||||||
label: 'สร้างโดย',
|
label: 'สร้างโดย',
|
||||||
|
align: 'center',
|
||||||
field: 'createdBy',
|
field: 'createdBy',
|
||||||
style: 'width: 20px',
|
|
||||||
sortable: true,
|
sortable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'createdAt',
|
name: 'createdAt',
|
||||||
align: 'center',
|
|
||||||
label: 'วันที่สร้าง',
|
label: 'วันที่สร้าง',
|
||||||
|
align: 'center',
|
||||||
field: 'createdAt',
|
field: 'createdAt',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
style: 'width: 20px',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'actions',
|
name: 'actions',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
label: '',
|
label: '',
|
||||||
field: '',
|
field: '',
|
||||||
style: 'width: 5px',
|
|
||||||
},
|
},
|
||||||
]
|
] satisfies QTableProps['columns']
|
||||||
|
|
||||||
const columnsFile: QTableProps['columns'] = [
|
const colFile = [
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
required: true,
|
|
||||||
label: 'ชื่อไฟล์',
|
label: 'ชื่อไฟล์',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
field: (row) => row.fileName,
|
field: 'fileName',
|
||||||
format: (val) => `${val}`,
|
|
||||||
sortable: true,
|
sortable: true,
|
||||||
style: 'width: 200px',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'title',
|
name: 'title',
|
||||||
align: 'center',
|
|
||||||
label: 'ชื่อเรื่อง',
|
label: 'ชื่อเรื่อง',
|
||||||
|
align: 'center',
|
||||||
field: 'title',
|
field: 'title',
|
||||||
style: 'width: 200px',
|
|
||||||
|
|
||||||
sortable: true,
|
sortable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'fileType',
|
name: 'fileType',
|
||||||
align: 'center',
|
|
||||||
label: 'ประเภทของไฟล์',
|
label: 'ประเภทของไฟล์',
|
||||||
|
align: 'center',
|
||||||
field: 'fileType',
|
field: 'fileType',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
style: 'width: 200px',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'actions',
|
name: 'actions',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
label: '',
|
label: '',
|
||||||
field: '',
|
field: '',
|
||||||
style: 'width: 20px',
|
|
||||||
},
|
},
|
||||||
]
|
] satisfies QTableProps['columns']
|
||||||
|
|
||||||
const onRowClick = ((_evt, row) => {
|
const onRowClick = ((_, row) => {
|
||||||
getFolder(row.pathname)
|
goto(row.pathname)
|
||||||
}) satisfies QTableProps['onRowClick']
|
}) satisfies QTableProps['onRowClick']
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<file-form-wrapper ref="fileFormComponent" />
|
||||||
|
<folder-form-wrapper ref="folderFormComponent" />
|
||||||
|
<dialog-delete
|
||||||
|
v-model:open="deleteState"
|
||||||
|
@confirm="() => deleteTarget && deleteMap[deleteTarget](deletePath)"
|
||||||
|
/>
|
||||||
<div class="q-mt-md">
|
<div class="q-mt-md">
|
||||||
<div class="q-gutter-sm">
|
<div class="q-gutter-sm">
|
||||||
<div
|
<div
|
||||||
class="flex flex-break d justify-between space-between"
|
class="flex flex-break d justify-between space-between"
|
||||||
v-if="currentDept >= 1 && props.mode == 'admin' && currentDept != 4"
|
v-if="
|
||||||
|
currentInfo.dept >= 1 &&
|
||||||
|
currentInfo.dept < 4 &&
|
||||||
|
props.mode === 'admin'
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<span class="text-h6">{{ currentLevel }}</span>
|
<span class="text-h6">{{ TREE_LEVEL_NAME[currentInfo.dept] }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<q-btn
|
<q-btn
|
||||||
outline
|
outline
|
||||||
push
|
push
|
||||||
|
dense
|
||||||
class="q-px-md q-ml-md"
|
class="q-px-md q-ml-md"
|
||||||
:label="'สร้าง' + currentLevel"
|
|
||||||
type="submit"
|
type="submit"
|
||||||
color="primary"
|
color="primary"
|
||||||
dense
|
|
||||||
icon="add"
|
icon="add"
|
||||||
@click.stop="() => triggerFolderCreate()"
|
|
||||||
id="listViewFolderCreate"
|
id="listViewFolderCreate"
|
||||||
|
:label="'สร้าง' + TREE_LEVEL_NAME[currentInfo.dept]"
|
||||||
|
@click.stop="() => folderFormComponent?.triggerFolderCreate()"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<q-table
|
<q-table
|
||||||
flat
|
flat
|
||||||
bordered
|
bordered
|
||||||
:rows="listDataFolder"
|
|
||||||
:columns="columnsFolder"
|
|
||||||
:pagination="{
|
|
||||||
rowsPerPage: 20,
|
|
||||||
}"
|
|
||||||
@row-click="onRowClick"
|
|
||||||
row-key="name"
|
row-key="name"
|
||||||
class="cursor"
|
class="cursor"
|
||||||
v-if="currentDept != 4"
|
v-if="currentInfo.dept !== 4"
|
||||||
|
:pagination="{ rowsPerPage: 20 }"
|
||||||
|
:rows="folder[currentInfo.path]"
|
||||||
|
:columns="colFolder"
|
||||||
|
@row-click="onRowClick"
|
||||||
>
|
>
|
||||||
<template v-slot:body-cell-name="nameRow">
|
<template v-slot:body-cell-name="data">
|
||||||
<q-td style="width: 50%">
|
<q-td>
|
||||||
<q-icon :name="currentIcon" size="2em" color="primary" />
|
<q-icon :name="currentIcon" size="2em" color="primary" />
|
||||||
{{ nameRow.row.name }}
|
{{ data.row.name }}
|
||||||
</q-td>
|
</q-td>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:body-cell-createdBy="createdByRow">
|
<template v-slot:body-cell-createdBy="data">
|
||||||
<q-td>
|
<q-td class="text-center">
|
||||||
<div class="justify-center center-content">
|
<span class="sort-icon-offset-margin">
|
||||||
{{ createdByRow.row.createdBy }}
|
{{ data.row.createdBy }}
|
||||||
</div>
|
</span>
|
||||||
</q-td>
|
</q-td>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:body-cell-createdAt="createdAtRow">
|
<template v-slot:body-cell-createdAt="data">
|
||||||
<q-td>
|
<q-td class="text-center">
|
||||||
<div class="justify-center">
|
<span class="sort-icon-offset-margin">
|
||||||
{{ getFormatDate(createdAtRow.row.createdAt) }}
|
{{ getFormatDate(data.row.createdAt) }}
|
||||||
</div>
|
</span>
|
||||||
</q-td>
|
</q-td>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:body-cell-actions="actionsRow">
|
<template v-slot:body-cell-actions="data">
|
||||||
<q-td class="justify-center">
|
<q-td class="justify-center">
|
||||||
<div>
|
<div>
|
||||||
<q-icon
|
<q-icon
|
||||||
|
|
@ -349,32 +197,31 @@ const onRowClick = ((_evt, row) => {
|
||||||
self="center right"
|
self="center right"
|
||||||
:offset="[5, 1]"
|
:offset="[5, 1]"
|
||||||
>
|
>
|
||||||
{{ actionsRow.row.name }}
|
{{ data.row.name }}
|
||||||
</q-tooltip>
|
</q-tooltip>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="props.mode === 'admin'">
|
<div v-if="props.mode === 'admin'">
|
||||||
<q-btn
|
<q-btn
|
||||||
flat
|
flat
|
||||||
color="positive"
|
|
||||||
dense
|
dense
|
||||||
|
id="listViewFolderEdit"
|
||||||
icon="o_edit"
|
icon="o_edit"
|
||||||
|
color="positive"
|
||||||
@click.stop="
|
@click.stop="
|
||||||
triggerFolderEdit(
|
folderFormComponent?.triggerFolderEdit(
|
||||||
actionsRow.row.name,
|
data.row.name,
|
||||||
actionsRow.row.pathname,
|
data.row.pathname,
|
||||||
)
|
)
|
||||||
"
|
"
|
||||||
id="listViewFolderEdit"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<q-btn
|
<q-btn
|
||||||
flat
|
flat
|
||||||
color="negative"
|
|
||||||
dense
|
dense
|
||||||
:data-testid="actionsRow.row.name"
|
|
||||||
icon="mdi-trash-can-outline"
|
|
||||||
@click.stop="triggerFolderDelete(actionsRow.row.pathname)"
|
|
||||||
id="listViewFolderDelete"
|
id="listViewFolderDelete"
|
||||||
|
color="negative"
|
||||||
|
icon="mdi-trash-can-outline"
|
||||||
|
:data-testid="data.row.name"
|
||||||
|
@click.stop="triggerFolderDelete(data.row.pathname)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
@ -382,74 +229,62 @@ const onRowClick = ((_evt, row) => {
|
||||||
</q-table>
|
</q-table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="q-mt-md" v-if="currentInfo.dept >= 3">
|
||||||
<div class="q-mt-md" v-if="currentDept >= 3">
|
|
||||||
<div class="q-gutter-sm">
|
<div class="q-gutter-sm">
|
||||||
<div class="flex flex-break d justify-between space-between">
|
<div class="flex flex-break justify-between space-between">
|
||||||
<div>
|
<div><span class="text-h6">เอกสาร</span></div>
|
||||||
<span class="text-h6">เอกสาร</span>
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="props.mode == 'admin'"
|
|
||||||
outline
|
outline
|
||||||
push
|
push
|
||||||
|
dense
|
||||||
|
id="listViewFileCreate"
|
||||||
class="q-px-md q-ml-md"
|
class="q-px-md q-ml-md"
|
||||||
label="สร้างเอกสาร"
|
label="สร้างเอกสาร"
|
||||||
type="submit"
|
type="submit"
|
||||||
color="primary"
|
color="primary"
|
||||||
dense
|
|
||||||
icon="add"
|
icon="add"
|
||||||
@click.stop="() => triggerFileCreate()"
|
v-if="props.mode == 'admin'"
|
||||||
id="listViewFileCreate"
|
@click.stop="() => fileFormComponent?.triggerFileCreate()"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<q-table
|
<q-table
|
||||||
flat
|
flat
|
||||||
bordered
|
bordered
|
||||||
:rows="listDataFile"
|
|
||||||
:columns="columnsFile"
|
|
||||||
row-key="name"
|
|
||||||
:pagination="{
|
|
||||||
rowsPerPage: 20,
|
|
||||||
}"
|
|
||||||
class="cursor"
|
class="cursor"
|
||||||
|
row-key="name"
|
||||||
|
:rows="file[currentInfo.path]"
|
||||||
|
:columns="colFile"
|
||||||
|
:pagination="{ rowsPerPage: 20 }"
|
||||||
>
|
>
|
||||||
<template v-slot:body-cell-name="nameRow">
|
<template v-slot:body-cell-name="data">
|
||||||
<q-td
|
<q-td
|
||||||
style="width: 50%"
|
|
||||||
@click="
|
|
||||||
() => {
|
|
||||||
currentDept >= 3
|
|
||||||
? getFileInfo(nameRow.row)
|
|
||||||
: getFolder(nameRow.row.pathname)
|
|
||||||
}
|
|
||||||
"
|
|
||||||
id="listViewGetFileInfo"
|
id="listViewGetFileInfo"
|
||||||
|
style="width: 50%"
|
||||||
|
@click="() => getFileInfo(data.row)"
|
||||||
>
|
>
|
||||||
<file-icon
|
<file-icon
|
||||||
size="list"
|
size="list"
|
||||||
:fileMimeType="
|
:fileMimeType="data.row.fileType || '-'"
|
||||||
nameRow.row.fileType ? nameRow.row.fileType : 'unknown'
|
:fileName="data.row.fileName || '-'"
|
||||||
"
|
|
||||||
:fileName="
|
|
||||||
nameRow.row.fileName ? nameRow.row.fileName : 'unknown'
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
{{ nameRow.row.fileName }}
|
{{ data.row.fileName }}
|
||||||
</q-td>
|
</q-td>
|
||||||
</template>
|
</template>
|
||||||
|
<template v-slot:body-cell-title="data">
|
||||||
<template v-slot:body-cell-fileType="fileTypeRow">
|
<q-td class="text-center">
|
||||||
<q-td>
|
<span class="sort-icon-offset-margin">{{ data.row.title }}</span>
|
||||||
<div class="justify-center">
|
|
||||||
{{ getType(fileTypeRow.row.fileType, fileTypeRow.row.fileName) }}
|
|
||||||
</div>
|
|
||||||
</q-td>
|
</q-td>
|
||||||
</template>
|
</template>
|
||||||
|
<template v-slot:body-cell-fileType="data">
|
||||||
<template v-slot:body-cell-actions="actionsRow">
|
<q-td class="text-center">
|
||||||
|
<span class="sort-icon-offset-margin">
|
||||||
|
{{ getType(data.row.fileType, data.row.fileName) }}
|
||||||
|
</span>
|
||||||
|
</q-td>
|
||||||
|
</template>
|
||||||
|
<template v-slot:body-cell-actions="data">
|
||||||
<q-td class="justify-center">
|
<q-td class="justify-center">
|
||||||
<div>
|
<div>
|
||||||
<q-icon
|
<q-icon
|
||||||
|
|
@ -463,7 +298,7 @@ const onRowClick = ((_evt, row) => {
|
||||||
self="center right"
|
self="center right"
|
||||||
:offset="[5, 1]"
|
:offset="[5, 1]"
|
||||||
>
|
>
|
||||||
{{ getSize(actionsRow.row.fileSize) }}
|
{{ getSize(data.row.fileSize) }}
|
||||||
</q-tooltip>
|
</q-tooltip>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="props.mode === 'admin'">
|
<div v-if="props.mode === 'admin'">
|
||||||
|
|
@ -473,17 +308,21 @@ const onRowClick = ((_evt, row) => {
|
||||||
dense
|
dense
|
||||||
icon="o_edit"
|
icon="o_edit"
|
||||||
@click.stop="
|
@click.stop="
|
||||||
() => triggerFileEdit(actionsRow.row, actionsRow.row.pathname)
|
() =>
|
||||||
|
fileFormComponent?.triggerFileEdit(
|
||||||
|
data.row,
|
||||||
|
data.row.pathname,
|
||||||
|
)
|
||||||
"
|
"
|
||||||
id="listViewFileEdit"
|
id="listViewFileEdit"
|
||||||
/>
|
/>
|
||||||
<q-btn
|
<q-btn
|
||||||
flat
|
flat
|
||||||
color="negative"
|
|
||||||
dense
|
dense
|
||||||
icon="mdi-trash-can-outline"
|
|
||||||
@click.stop="() => triggerFileDelete(actionsRow.row.pathname)"
|
|
||||||
id="listViewFileDelete"
|
id="listViewFileDelete"
|
||||||
|
color="negative"
|
||||||
|
icon="mdi-trash-can-outline"
|
||||||
|
@click.stop="() => triggerFileDelete(data.row.pathname)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
@ -491,44 +330,6 @@ const onRowClick = ((_evt, row) => {
|
||||||
</q-table>
|
</q-table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<file-form
|
|
||||||
ref="fileFormComponent"
|
|
||||||
:mode="fileFormType"
|
|
||||||
:error="fileFormError"
|
|
||||||
v-model:open="fileFormState"
|
|
||||||
v-model:title="fileFormData.title"
|
|
||||||
v-model:description="fileFormData.description"
|
|
||||||
v-model:keyword="fileFormData.keyword"
|
|
||||||
v-model:category="fileFormData.category"
|
|
||||||
@reset="() => (fileFormError = {})"
|
|
||||||
@filechange="(name: string) => (fileFormError.fileExist = checkFile(name))"
|
|
||||||
@submit="submitFileForm"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<folder-form
|
|
||||||
:mode="folderFormType"
|
|
||||||
:tree="DEPT_NAME[currentDept]"
|
|
||||||
v-if="currentDept < 4"
|
|
||||||
v-model:open="folderFormState"
|
|
||||||
v-model:name="folderFormData.name"
|
|
||||||
@submit="submitFolderForm"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<upload-exist-dialog
|
|
||||||
v-model:notification="fileExistNotification"
|
|
||||||
@confirm="() => currentParam && submitFileForm(currentParam, true)"
|
|
||||||
@cancel="() => (currentParam = undefined)"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<dialog-delete
|
|
||||||
v-model:open="dialogDeleteState"
|
|
||||||
@confirm="
|
|
||||||
() =>
|
|
||||||
deleteFormType &&
|
|
||||||
(deleteFolder(deleteFormPath), deleteFile(deleteFormPath))
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
@ -538,7 +339,7 @@ const onRowClick = ((_evt, row) => {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.center-content {
|
.sort-icon-offset-margin {
|
||||||
margin-right: 18px;
|
margin-right: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,65 +1,39 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onMounted, ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { useTreeDataStore } from '@/stores/tree-data'
|
|
||||||
import { useSearchDataStore } from '@/stores/searched-data'
|
import { useSearchDataStore } from '@/stores/searched-data'
|
||||||
import { useFileInfoStore } from '@/stores/file-info-data'
|
import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
import { useSocketStore } from '@/stores/socket'
|
|
||||||
|
|
||||||
import FileItem from './FileItem.vue'
|
import FileItem from './FileItem.vue'
|
||||||
import TreeExplorer from './TreeExplorer.vue'
|
import TreeExplorer from './TreeExplorer.vue'
|
||||||
import FileSearched from './FileSearched.vue'
|
import FileSearched from './FileSearched.vue'
|
||||||
import ListView from './ListView.vue'
|
import ListView from './ListView.vue'
|
||||||
import FolderForm from './FolderForm.vue'
|
import FolderFormWrapper from './FolderFormWrapper.vue'
|
||||||
import GlobalErrorDialog from './GlobalErrorDialog.vue'
|
import GlobalErrorDialog from './GlobalErrorDialog.vue'
|
||||||
|
|
||||||
import SearchBar from '@/modules/01_user/components/SearchBar.vue'
|
import SearchBar from '@/modules/01_user/components/SearchBar.vue'
|
||||||
import FileDownload from '@/modules/01_user/components/FileDownload.vue'
|
import FileDownload from '@/modules/01_user/components/FileDownload.vue'
|
||||||
|
import useStorage from '@/stores/storage'
|
||||||
|
|
||||||
const DEPT_NAME = ['ตู้เอกสาร', 'ลิ้นชัก', 'แฟ้ม', 'แฟ้มย่อย'] as const
|
|
||||||
|
|
||||||
const { isFilePreview } = storeToRefs(useFileInfoStore())
|
|
||||||
const { isSearch } = storeToRefs(useSearchDataStore())
|
|
||||||
const { data, currentDept, currentPath } = storeToRefs(useTreeDataStore())
|
|
||||||
const { createFolder, getCabinet, gotoParent, getFolder } = useTreeDataStore()
|
|
||||||
|
|
||||||
useSocketStore()
|
|
||||||
|
|
||||||
const viewMode = ref<'view_list' | 'view_module'>('view_list')
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
mode: 'admin' | 'user'
|
mode: 'admin' | 'user'
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const folderFormState = ref<boolean>(false)
|
const { isFilePreview } = storeToRefs(useFileInfoStore())
|
||||||
const folderFormType = ref<'edit' | 'create'>('create')
|
const { isSearch } = storeToRefs(useSearchDataStore())
|
||||||
const folderFormData = ref<{
|
|
||||||
name?: string
|
|
||||||
}>({})
|
|
||||||
|
|
||||||
function triggerFolderCreate() {
|
const storageStore = useStorage()
|
||||||
folderFormType.value = 'create'
|
const { tree, currentInfo } = storeToRefs(storageStore)
|
||||||
folderFormData.value = {}
|
const { goto, gotoParent } = storageStore
|
||||||
folderFormState.value = !folderFormState.value
|
|
||||||
}
|
|
||||||
|
|
||||||
async function submitFolderForm(value: {
|
const viewMode = ref<'view_list' | 'view_module'>('view_list')
|
||||||
mode: 'create' | 'edit'
|
|
||||||
name: string
|
|
||||||
}) {
|
|
||||||
if (value.mode === 'create') {
|
|
||||||
await createFolder(value.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
const folderFormComponent = ref<InstanceType<typeof FolderFormWrapper>>()
|
||||||
await getCabinet()
|
|
||||||
|
|
||||||
const sessionCurrentPath = sessionStorage.getItem('currentPath')
|
|
||||||
|
|
||||||
if (sessionCurrentPath) await getFolder(sessionCurrentPath)
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
<folder-form-wrapper ref="folderFormComponent" />
|
||||||
|
<global-error-dialog />
|
||||||
|
|
||||||
<section id="header" class="q-px-md q-pt-md q-pb-none">
|
<section id="header" class="q-px-md q-pt-md q-pb-none">
|
||||||
<div class="q-my-md row items-center">
|
<div class="q-my-md row items-center">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
|
@ -84,8 +58,7 @@ onMounted(async () => {
|
||||||
class="block q-my-sm text-weight-bold pointer"
|
class="block q-my-sm text-weight-bold pointer"
|
||||||
@click="
|
@click="
|
||||||
() => {
|
() => {
|
||||||
currentPath = ''
|
goto()
|
||||||
getFolder(currentPath)
|
|
||||||
isSearch = false
|
isSearch = false
|
||||||
isFilePreview = false
|
isFilePreview = false
|
||||||
}
|
}
|
||||||
|
|
@ -98,13 +71,13 @@ onMounted(async () => {
|
||||||
flat
|
flat
|
||||||
color="primary"
|
color="primary"
|
||||||
icon="add"
|
icon="add"
|
||||||
@click.stop="() => triggerFolderCreate()"
|
|
||||||
data-testid="createFolder"
|
data-testid="createFolder"
|
||||||
|
@click.stop="() => folderFormComponent?.triggerFolderCreate()"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<q-separator />
|
<q-separator />
|
||||||
<div class="q-pa-md">
|
<div class="q-pa-md">
|
||||||
<tree-explorer :data="data" :level="1" />
|
<tree-explorer :data="tree" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -123,54 +96,57 @@ onMounted(async () => {
|
||||||
flat
|
flat
|
||||||
dense
|
dense
|
||||||
class="q-mr-sm q-px-sm"
|
class="q-mr-sm q-px-sm"
|
||||||
v-if="isSearch == true || currentDept > 0"
|
v-if="isSearch || currentInfo.dept > 0"
|
||||||
@click="
|
@click="
|
||||||
() => {
|
() => {
|
||||||
isSearch
|
isSearch ? (isSearch = false) : gotoParent()
|
||||||
? (isSearch = false)
|
|
||||||
: ((folderFormState = false), gotoParent())
|
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
<q-icon name="arrow_back" size="1rem" color="primary" />
|
<q-icon name="arrow_back" size="1rem" color="primary" />
|
||||||
</q-btn>
|
</q-btn>
|
||||||
<span v-if="isSearch === true">ผลการค้นหา</span>
|
<span v-if="isSearch">ผลการค้นหา</span>
|
||||||
<q-breadcrumbs v-if="isSearch === false" active-color="primary">
|
<q-breadcrumbs
|
||||||
|
v-if="!isSearch"
|
||||||
|
active-color="grey"
|
||||||
|
separator-color="grey"
|
||||||
|
>
|
||||||
<q-breadcrumbs-el
|
<q-breadcrumbs-el
|
||||||
v-if="currentPath === '/' || !currentPath"
|
v-if="currentInfo.path === '/' || !currentInfo.path"
|
||||||
label="ตู้เอกสารทั้งหมด"
|
label="ตู้เอกสารทั้งหมด"
|
||||||
/>
|
/>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="
|
dense
|
||||||
mode === 'admin' &&
|
id="createFolder"
|
||||||
viewMode === 'view_module' &&
|
|
||||||
currentDept === 0
|
|
||||||
"
|
|
||||||
class="q-px-md q-ml-md al"
|
class="q-px-md q-ml-md al"
|
||||||
label="สร้างตู้เก็บเอกสาร"
|
label="สร้างตู้เก็บเอกสาร"
|
||||||
type="submit"
|
type="submit"
|
||||||
color="primary"
|
color="primary"
|
||||||
dense
|
|
||||||
icon="add"
|
icon="add"
|
||||||
@click.stop="() => triggerFolderCreate()"
|
v-if="
|
||||||
id="createFolder"
|
mode === 'admin' &&
|
||||||
|
viewMode === 'view_module' &&
|
||||||
|
currentInfo.dept === 0
|
||||||
|
"
|
||||||
|
@click.stop="
|
||||||
|
() => folderFormComponent?.triggerFolderCreate()
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
<q-breadcrumbs-el
|
<q-breadcrumbs-el
|
||||||
class="text-primary pointer"
|
class="pointer"
|
||||||
v-for="(fragments, index) in currentPath
|
v-for="(fragments, index) in currentInfo.path
|
||||||
.split('/')
|
.split('/')
|
||||||
.filter(Boolean)"
|
.filter(Boolean)"
|
||||||
:label="fragments"
|
:label="fragments"
|
||||||
@click="
|
@click="
|
||||||
() => {
|
() => {
|
||||||
currentPath =
|
goto(
|
||||||
currentPath
|
currentInfo.path
|
||||||
.split('/')
|
.split('/')
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.slice(0, index + 1)
|
.slice(0, index + 1)
|
||||||
.join('/') + '/'
|
.join('/') + '/',
|
||||||
|
)
|
||||||
getFolder(currentPath)
|
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
|
|
@ -181,15 +157,16 @@ onMounted(async () => {
|
||||||
<q-btn
|
<q-btn
|
||||||
flat
|
flat
|
||||||
dense
|
dense
|
||||||
|
id="getFolder"
|
||||||
color="blue-grey-2"
|
color="blue-grey-2"
|
||||||
icon="refresh"
|
icon="refresh"
|
||||||
class="q-mr-sm"
|
class="q-mr-sm"
|
||||||
@click="() => getFolder(currentPath)"
|
@click="() => goto(currentInfo.path, true)"
|
||||||
id="getFolder"
|
|
||||||
/>
|
/>
|
||||||
<q-btn
|
<q-btn
|
||||||
flat
|
flat
|
||||||
dense
|
dense
|
||||||
|
id="viewMode"
|
||||||
color="blue-grey-2"
|
color="blue-grey-2"
|
||||||
:icon="viewMode"
|
:icon="viewMode"
|
||||||
@click="
|
@click="
|
||||||
|
|
@ -198,7 +175,6 @@ onMounted(async () => {
|
||||||
viewMode === 'view_list' ? 'view_module' : 'view_list'
|
viewMode === 'view_list' ? 'view_module' : 'view_list'
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
id="viewMode"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -206,15 +182,15 @@ onMounted(async () => {
|
||||||
<file-searched
|
<file-searched
|
||||||
:viewMode="viewMode"
|
:viewMode="viewMode"
|
||||||
:action="props.mode === 'admin'"
|
:action="props.mode === 'admin'"
|
||||||
v-if="isSearch === true"
|
v-if="isSearch"
|
||||||
/>
|
/>
|
||||||
<file-item
|
<file-item
|
||||||
:viewMode="viewMode"
|
:viewMode="viewMode"
|
||||||
:action="props.mode === 'admin'"
|
:action="props.mode === 'admin'"
|
||||||
v-if="isSearch === false && viewMode === 'view_list'"
|
v-if="!isSearch && viewMode === 'view_list'"
|
||||||
/>
|
/>
|
||||||
<list-view
|
<list-view
|
||||||
v-if="isSearch === false && viewMode === 'view_module'"
|
v-if="!isSearch && viewMode === 'view_module'"
|
||||||
:mode="mode"
|
:mode="mode"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -222,17 +198,6 @@ onMounted(async () => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<folder-form
|
|
||||||
:mode="folderFormType"
|
|
||||||
:tree="DEPT_NAME[currentDept]"
|
|
||||||
v-if="currentDept < 4"
|
|
||||||
v-model:open="folderFormState"
|
|
||||||
v-model:name="folderFormData.name"
|
|
||||||
@submit="submitFolderForm"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<global-error-dialog />
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getUsername, logout } from '@/services/KeyCloakService'
|
import { getUsername, logout } from '@/services/KeyCloakService'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
const dropdownOpen = ref<boolean>(false)
|
const dropdown = ref<boolean>(false)
|
||||||
const accountName = ref<string>(getUsername())
|
const name = ref<string>(getUsername())
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
@click="() => (dropdownOpen = !dropdownOpen)"
|
@click="() => (dropdown = !dropdown)"
|
||||||
class="row q-px-xs cursor"
|
class="row q-px-xs cursor"
|
||||||
id="app-toolbar-title"
|
id="app-toolbar-title"
|
||||||
>
|
>
|
||||||
|
|
@ -19,20 +19,28 @@ const accountName = ref<string>(getUsername())
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class="row q-pl-sm">
|
<div class="row q-pl-sm">
|
||||||
<span class="text-body1" style="font-size:13px">
|
<span class="text-body1" style="font-size: 13px">
|
||||||
{{ accountName }}
|
{{ name }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="row q-pl-sm">
|
<div class="row q-pl-sm">
|
||||||
<span class="text-caption text-grey" style="font-size:10px"> เจ้าหน้าที่ </span>
|
<span class="text-caption text-grey" style="font-size: 10px">
|
||||||
|
เจ้าหน้าที่
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<q-btn-dropdown stretch flat v-model="dropdownOpen">
|
<q-btn-dropdown stretch flat v-model="dropdown">
|
||||||
<q-list>
|
<q-list>
|
||||||
<q-item clickable v-close-popup tabindex="0" @click="() => logout()">
|
<q-item clickable v-close-popup tabindex="0" @click="() => logout()">
|
||||||
<q-item-section avatar>
|
<q-item-section avatar>
|
||||||
<q-avatar icon="logout" color="primary" text-color="white" caption>
|
<q-avatar
|
||||||
|
caption
|
||||||
|
icon="logout"
|
||||||
|
color="primary"
|
||||||
|
text-color="white"
|
||||||
|
size="1.5rem"
|
||||||
|
>
|
||||||
</q-avatar>
|
</q-avatar>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
<q-item-section>
|
<q-item-section>
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,31 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { useTreeDataStore, type TreeDataFolder } from '@/stores/tree-data'
|
|
||||||
import { useSearchDataStore } from '@/stores/searched-data'
|
import { useSearchDataStore } from '@/stores/searched-data'
|
||||||
import { useFileInfoStore } from '@/stores/file-info-data'
|
import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
|
import useStorage from '@/stores/storage'
|
||||||
|
|
||||||
const { isSearch } = storeToRefs(useSearchDataStore())
|
const { isSearch } = storeToRefs(useSearchDataStore())
|
||||||
const { isFilePreview } = storeToRefs(useFileInfoStore())
|
const { isFilePreview } = storeToRefs(useFileInfoStore())
|
||||||
const { getFolder } = useTreeDataStore()
|
const store = useStorage()
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
data: TreeDataFolder[]
|
data: typeof store.tree
|
||||||
level: number
|
level?: number
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
level: 0,
|
level: 1,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<q-list v-for="folder in data" class="rounded-borders">
|
<q-list v-for="v in data" class="rounded-borders">
|
||||||
<q-expansion-item
|
<q-expansion-item
|
||||||
@click="
|
@click="
|
||||||
() => {
|
() => {
|
||||||
getFolder(folder.pathname, false)
|
store.goto(v.pathname)
|
||||||
isSearch = false
|
isSearch = false
|
||||||
isFilePreview = false
|
isFilePreview = false
|
||||||
}
|
}
|
||||||
|
|
@ -40,13 +40,12 @@ const props = withDefaults(
|
||||||
? 'inbox'
|
? 'inbox'
|
||||||
: 'o_folder_open'
|
: 'o_folder_open'
|
||||||
"
|
"
|
||||||
:label="folder.name"
|
:label="v.name"
|
||||||
class="text-overflow-handle"
|
class="text-overflow-handle active"
|
||||||
v-model="folder.status"
|
|
||||||
>
|
>
|
||||||
<tree-explorer
|
<tree-explorer
|
||||||
v-if="folder.folder"
|
v-if="v.folder"
|
||||||
:data="folder.folder"
|
:data="v.folder"
|
||||||
:level="props.level + 1"
|
:level="props.level + 1"
|
||||||
/>
|
/>
|
||||||
</q-expansion-item>
|
</q-expansion-item>
|
||||||
|
|
@ -55,7 +54,7 @@ const props = withDefaults(
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
:deep(.q-item[aria-expanded='true']) {
|
.active :deep(.q-item[aria-expanded='true']) {
|
||||||
color: $primary;
|
color: $primary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import axios from 'axios'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import axiosClient from '@/services/HttpService'
|
import axiosClient from '@/services/HttpService'
|
||||||
|
|
||||||
import type { EhrFile } from '@/stores/tree-data'
|
import type { StorageFile } from '@/stores/storage'
|
||||||
import { useFileInfoStore } from '@/stores/file-info-data'
|
import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
|
|
||||||
import FileIcon from '@/components/FileIcon.vue'
|
import FileIcon from '@/components/FileIcon.vue'
|
||||||
|
|
@ -25,7 +25,7 @@ async function downloadSubmit(path: string | undefined) {
|
||||||
formatPath = `cabinet/${cabinet}/drawer/${drawer}/folder/${folder}/subfolder/${subfolder}/file/${file}`
|
formatPath = `cabinet/${cabinet}/drawer/${drawer}/folder/${folder}/subfolder/${subfolder}/file/${file}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await axiosClient.get<EhrFile & { download: string }>(
|
const res = await axiosClient.get<StorageFile & { download: string }>(
|
||||||
`${import.meta.env.VITE_API_ENDPOINT}${formatPath}`,
|
`${import.meta.env.VITE_API_ENDPOINT}${formatPath}`,
|
||||||
)
|
)
|
||||||
await axios
|
await axios
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { storeToRefs } from 'pinia'
|
||||||
import axiosClient from '@/services/HttpService'
|
import axiosClient from '@/services/HttpService'
|
||||||
import mime from 'mime'
|
import mime from 'mime'
|
||||||
|
|
||||||
import type { EhrFile } from '@/stores/tree-data'
|
import type { StorageFile } from '@/stores/storage'
|
||||||
import { useSearchDataStore } from '@/stores/searched-data'
|
import { useSearchDataStore } from '@/stores/searched-data'
|
||||||
import { useLoader } from '@/stores/loader'
|
import { useLoader } from '@/stores/loader'
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ async function searchSubmit() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loaderStore.show()
|
loaderStore.show()
|
||||||
const res = await axiosClient.post<EhrFile[]>(
|
const res = await axiosClient.post<StorageFile[]>(
|
||||||
`${import.meta.env.VITE_API_ENDPOINT}/search`,
|
`${import.meta.env.VITE_API_ENDPOINT}/search`,
|
||||||
submitSearchData.value,
|
submitSearchData.value,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@ import axios from 'axios'
|
||||||
import { getToken } from './KeyCloakService'
|
import { getToken } from './KeyCloakService'
|
||||||
import { useErrorStore } from '@/stores/error'
|
import { useErrorStore } from '@/stores/error'
|
||||||
|
|
||||||
const error = useErrorStore()
|
|
||||||
|
|
||||||
const instance = axios.create()
|
const instance = axios.create()
|
||||||
|
|
||||||
instance.interceptors.request.use(async (config) => {
|
instance.interceptors.request.use(async (config) => {
|
||||||
|
|
@ -14,6 +12,7 @@ instance.interceptors.request.use(async (config) => {
|
||||||
instance.interceptors.response.use(
|
instance.interceptors.response.use(
|
||||||
(res) => res,
|
(res) => res,
|
||||||
(err) => {
|
(err) => {
|
||||||
|
const error = useErrorStore()
|
||||||
const status = err.response.status
|
const status = err.response.status
|
||||||
const data = err.response.data
|
const data = err.response.data
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,20 @@ import Keycloak from 'keycloak-js'
|
||||||
|
|
||||||
const keycloak = new Keycloak('/keycloak.json')
|
const keycloak = new Keycloak('/keycloak.json')
|
||||||
|
|
||||||
export async function login(cb?: (...args: any[]) => void) {
|
let init = false
|
||||||
const auth = await keycloak
|
|
||||||
.init({
|
|
||||||
onLoad: 'login-required',
|
|
||||||
responseMode: 'query',
|
|
||||||
checkLoginIframe: false,
|
|
||||||
})
|
|
||||||
.catch((e) => console.dir(e))
|
|
||||||
|
|
||||||
|
export async function login(cb?: (...args: any[]) => void) {
|
||||||
|
const auth = !init
|
||||||
|
? await keycloak
|
||||||
|
.init({
|
||||||
|
onLoad: 'login-required',
|
||||||
|
responseMode: 'query',
|
||||||
|
checkLoginIframe: false,
|
||||||
|
})
|
||||||
|
.catch((e) => console.dir(e))
|
||||||
|
: await keycloak.login().catch((e) => console.dir(e))
|
||||||
|
|
||||||
|
if (auth) init = true
|
||||||
if (auth && cb) cb()
|
if (auth && cb) cb()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,19 @@ import { ref } from 'vue'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import mime from 'mime'
|
import mime from 'mime'
|
||||||
|
|
||||||
import type { EhrFile } from '@/stores/tree-data'
|
import type { StorageFile } from '@/stores/storage'
|
||||||
|
|
||||||
export interface MimeMap {
|
export interface MimeMap {
|
||||||
[key: string]: { icon: string; color: string }
|
[key: string]: { icon: string; color: string }
|
||||||
}
|
}
|
||||||
export interface TypeSetting {
|
export interface IconMap {
|
||||||
[key: string]: { icon: string; color: string }
|
[key: string]: { icon: string; color: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useFileInfoStore = defineStore('info', () => {
|
export const useFileInfoStore = defineStore('info', () => {
|
||||||
const fileInfo = ref<EhrFile>()
|
|
||||||
const isFilePreview = ref<Boolean>(false)
|
const isFilePreview = ref<Boolean>(false)
|
||||||
const fileIcon: TypeSetting = {
|
const fileInfo = ref<StorageFile>()
|
||||||
|
const fileIcon: IconMap = {
|
||||||
word: { icon: 'mdi-file-word-outline', color: 'blue-11' },
|
word: { icon: 'mdi-file-word-outline', color: 'blue-11' },
|
||||||
excel: { icon: 'mdi-file-excel-outline', color: 'green-4' },
|
excel: { icon: 'mdi-file-excel-outline', color: 'green-4' },
|
||||||
powerpoint: { icon: 'mdi-file-powerpoint-outline', color: 'orange-4' },
|
powerpoint: { icon: 'mdi-file-powerpoint-outline', color: 'orange-4' },
|
||||||
|
|
@ -23,103 +23,55 @@ export const useFileInfoStore = defineStore('info', () => {
|
||||||
image: { icon: 'mdi-file-image-outline', color: 'blue-11' },
|
image: { icon: 'mdi-file-image-outline', color: 'blue-11' },
|
||||||
}
|
}
|
||||||
const mimeFileMapping: MimeMap = {
|
const mimeFileMapping: MimeMap = {
|
||||||
'application/msword': {
|
'application/msword': fileIcon.word,
|
||||||
...fileIcon.word,
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
|
||||||
},
|
fileIcon.word,
|
||||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': {
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.template':
|
||||||
...fileIcon.word,
|
fileIcon.word,
|
||||||
},
|
'application/vnd.ms-word.document.macroEnabled.12': fileIcon.word,
|
||||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.template': {
|
'application/vnd.ms-word.template.macroEnabled.12': fileIcon.word,
|
||||||
...fileIcon.word,
|
'application/vnd.ms-excel': fileIcon.excel,
|
||||||
},
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
||||||
'application/vnd.ms-word.document.macroEnabled.12': {
|
fileIcon.excel,
|
||||||
...fileIcon.word,
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.template':
|
||||||
},
|
fileIcon.excel,
|
||||||
'application/vnd.ms-word.template.macroEnabled.12': {
|
'application/vnd.ms-excel.sheet.macroEnabled.12': fileIcon.excel,
|
||||||
...fileIcon.word,
|
'application/vnd.ms-excel.template.macroEnabled.12': fileIcon.excel,
|
||||||
},
|
'application/vnd.ms-excel.addin.macroEnabled.12': fileIcon.excel,
|
||||||
|
'application/vnd.ms-excel.sheet.binary.macroEnabled.12': fileIcon.excel,
|
||||||
'application/vnd.ms-excel': {
|
'application/vnd.ms-powerpoint': fileIcon.powerpoint,
|
||||||
...fileIcon.excel,
|
|
||||||
},
|
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': {
|
|
||||||
...fileIcon.excel,
|
|
||||||
},
|
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.template': {
|
|
||||||
...fileIcon.excel,
|
|
||||||
},
|
|
||||||
'application/vnd.ms-excel.sheet.macroEnabled.12': {
|
|
||||||
...fileIcon.excel,
|
|
||||||
},
|
|
||||||
'application/vnd.ms-excel.template.macroEnabled.12': {
|
|
||||||
...fileIcon.excel,
|
|
||||||
},
|
|
||||||
'application/vnd.ms-excel.addin.macroEnabled.12': {
|
|
||||||
...fileIcon.excel,
|
|
||||||
},
|
|
||||||
'application/vnd.ms-excel.sheet.binary.macroEnabled.12': {
|
|
||||||
...fileIcon.excel,
|
|
||||||
},
|
|
||||||
|
|
||||||
'application/vnd.ms-powerpoint': {
|
|
||||||
...fileIcon.powerpoint,
|
|
||||||
},
|
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation':
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation':
|
||||||
{
|
fileIcon.powerpoint,
|
||||||
...fileIcon.powerpoint,
|
'application/vnd.openxmlformats-officedocument.presentationml.template':
|
||||||
},
|
fileIcon.powerpoint,
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.template': {
|
'application/vnd.openxmlformats-officedocument.presentationml.slideshow':
|
||||||
...fileIcon.powerpoint,
|
fileIcon.powerpoint,
|
||||||
},
|
'application/vnd.ms-powerpoint.addin.macroEnabled.12': fileIcon.powerpoint,
|
||||||
'application/vnd.openxmlformats-officedocument.presentationml.slideshow': {
|
'application/vnd.ms-powerpoint.presentation.macroEnabled.12':
|
||||||
...fileIcon.powerpoint,
|
fileIcon.powerpoint,
|
||||||
},
|
'application/vnd.ms-powerpoint.template.macroEnabled.12':
|
||||||
'application/vnd.ms-powerpoint.addin.macroEnabled.12': {
|
fileIcon.powerpoint,
|
||||||
...fileIcon.powerpoint,
|
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12':
|
||||||
},
|
fileIcon.powerpoint,
|
||||||
'application/vnd.ms-powerpoint.presentation.macroEnabled.12': {
|
'application/pdf': fileIcon.pdf,
|
||||||
...fileIcon.powerpoint,
|
'text/plain': fileIcon.txt,
|
||||||
},
|
'image/png': fileIcon.image,
|
||||||
'application/vnd.ms-powerpoint.template.macroEnabled.12': {
|
'image/jpeg': fileIcon.image,
|
||||||
...fileIcon.powerpoint,
|
|
||||||
},
|
|
||||||
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12': {
|
|
||||||
...fileIcon.powerpoint,
|
|
||||||
},
|
|
||||||
|
|
||||||
'application/pdf': {
|
|
||||||
...fileIcon.pdf,
|
|
||||||
},
|
|
||||||
|
|
||||||
'text/plain': {
|
|
||||||
...fileIcon.txt,
|
|
||||||
},
|
|
||||||
|
|
||||||
'image/png': {
|
|
||||||
...fileIcon.image,
|
|
||||||
},
|
|
||||||
'image/jpeg': {
|
|
||||||
...fileIcon.image,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getType(
|
function getType(
|
||||||
mimeType: string | undefined,
|
mimeType: string | undefined,
|
||||||
fileName: string | undefined,
|
fileName: string | undefined,
|
||||||
): string {
|
): string {
|
||||||
if (mimeType === undefined) {
|
if (mimeType === undefined) return 'ไม่ทราบประเภท'
|
||||||
return 'ไม่ทราบประเภท'
|
|
||||||
|
const extension = mime.getExtension(mimeType)
|
||||||
|
|
||||||
|
if (extension) return '.' + extension
|
||||||
|
if (fileName && fileName.includes('.')) {
|
||||||
|
return fileName.substring(fileName.lastIndexOf('.'))
|
||||||
}
|
}
|
||||||
|
|
||||||
const extFomMime = mime.getExtension(mimeType)
|
|
||||||
if (extFomMime) {
|
|
||||||
return '.' + extFomMime
|
|
||||||
}
|
|
||||||
if (fileName && fileName.includes('.')) {
|
|
||||||
const dotIndex = fileName.lastIndexOf('.')
|
|
||||||
const extension = fileName.substring(dotIndex)
|
|
||||||
return extension
|
|
||||||
}
|
|
||||||
return 'ไม่ทราบประเภท'
|
return 'ไม่ทราบประเภท'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,20 +88,19 @@ export const useFileInfoStore = defineStore('info', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSize(size: string | undefined): string {
|
function getSize(size: string | undefined): string {
|
||||||
if (size === undefined) {
|
if (size === undefined) return 'ไม่ทราบขนาด'
|
||||||
return 'ไม่ทราบขนาด'
|
|
||||||
}
|
|
||||||
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||||
|
|
||||||
let i = 0
|
let i = 0
|
||||||
let sizeNumber = parseFloat(size)
|
let sizeNumber = parseFloat(size)
|
||||||
while (sizeNumber >= 1024 && i < units.length - 1) {
|
while (sizeNumber >= 1024 && i++ < units.length - 1) {
|
||||||
sizeNumber /= 1024
|
sizeNumber /= 1024
|
||||||
i++
|
|
||||||
}
|
}
|
||||||
return sizeNumber.toFixed(2) + ' ' + units[i]
|
return sizeNumber.toFixed(2) + ' ' + units[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFileInfo(data: EhrFile) {
|
function getFileInfo(data: StorageFile) {
|
||||||
isFilePreview.value = true
|
isFilePreview.value = true
|
||||||
fileInfo.value = data
|
fileInfo.value = data
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,45 @@
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import type { EhrFile } from '@/stores/tree-data'
|
import type { StorageFile } from '@/stores/storage'
|
||||||
|
|
||||||
export interface searchData {
|
export interface Search {
|
||||||
field: string
|
field: string
|
||||||
value: string
|
value: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface advSearchDataRow {
|
export interface AdvancedSearch {
|
||||||
op: 'AND' | 'OR'
|
op: 'AND' | 'OR'
|
||||||
field: 'title' | 'keyword'
|
field: 'title' | 'keyword'
|
||||||
value: string
|
value: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface advSearchDataField {
|
export interface AdvancedSearchFields {
|
||||||
keyword: string[]
|
keyword: string[]
|
||||||
description: string
|
description: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useSearchDataStore = defineStore('searched', () => {
|
export const useSearchDataStore = defineStore('searched', () => {
|
||||||
const foundFile = ref<EhrFile[]>([])
|
const foundFile = ref<StorageFile[]>([])
|
||||||
const isAdvSearchCall = ref<boolean>(false)
|
const isAdvSearchCall = ref<boolean>(false)
|
||||||
const isSearch = ref<Boolean>(false)
|
const isSearch = ref<Boolean>(false)
|
||||||
const isActFoundFile = ref<Boolean>(false)
|
const isActFoundFile = ref<Boolean>(false)
|
||||||
const searchData = ref<searchData>({
|
const searchData = ref<Search>({
|
||||||
field: 'title',
|
field: 'title',
|
||||||
value: '',
|
value: '',
|
||||||
})
|
})
|
||||||
const advSearchDataRow = ref<advSearchDataRow[]>([
|
const advSearchDataRow = ref<AdvancedSearch[]>([
|
||||||
{
|
{
|
||||||
op: 'AND',
|
op: 'AND',
|
||||||
field: 'title',
|
field: 'title',
|
||||||
value: '',
|
value: '',
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
const advSearchDataField = ref<advSearchDataField>({
|
const advSearchDataField = ref<AdvancedSearchFields>({
|
||||||
keyword: [],
|
keyword: [],
|
||||||
description: '',
|
description: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
async function getFoundFile(data: EhrFile[]) {
|
async function getFoundFile(data: StorageFile[]) {
|
||||||
foundFile.value = data
|
foundFile.value = data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
import { defineStore } from 'pinia'
|
|
||||||
import { reactive } from 'vue'
|
|
||||||
import { useFileInfoStore } from '@/stores/file-info-data'
|
|
||||||
import { io } from 'socket.io-client'
|
|
||||||
import { useTreeDataStore } from '@/stores/tree-data'
|
|
||||||
import { storeToRefs } from 'pinia'
|
|
||||||
|
|
||||||
const {
|
|
||||||
data,
|
|
||||||
listDataFolder,
|
|
||||||
currentFolder,
|
|
||||||
currentPath,
|
|
||||||
currentFile,
|
|
||||||
listDataFile,
|
|
||||||
} = storeToRefs(useTreeDataStore())
|
|
||||||
const {
|
|
||||||
updateEditFolder,
|
|
||||||
updateDeleteFolder,
|
|
||||||
updateCreateFolder,
|
|
||||||
updateDeleteFile,
|
|
||||||
updateNewFile,
|
|
||||||
} = useTreeDataStore()
|
|
||||||
|
|
||||||
export const state = reactive({
|
|
||||||
connected: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
export const useSocketStore = defineStore('socket', () => {
|
|
||||||
const socket = io('http://localhost:25570')
|
|
||||||
|
|
||||||
socket.on('connect', () => {
|
|
||||||
state.connected = true
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.on('CreateFolder', (dataSocket) => {
|
|
||||||
const { pathname } = dataSocket
|
|
||||||
|
|
||||||
const pathArray: string[] = pathname.split('/').filter(Boolean)
|
|
||||||
const currentPathResult = pathArray.slice(0, -1).join('/') + '/'
|
|
||||||
|
|
||||||
if (currentPath.value == currentPathResult) {
|
|
||||||
data.value = updateCreateFolder(
|
|
||||||
data.value,
|
|
||||||
pathArray.length,
|
|
||||||
currentPathResult,
|
|
||||||
pathname,
|
|
||||||
{
|
|
||||||
pathname: pathname,
|
|
||||||
name: pathArray[pathArray.length - 1],
|
|
||||||
status: true,
|
|
||||||
folder: [],
|
|
||||||
file: [],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
currentFolder.value.push({
|
|
||||||
pathname: pathname,
|
|
||||||
name: pathArray[pathArray.length - 1],
|
|
||||||
status: true,
|
|
||||||
folder: [],
|
|
||||||
file: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
listDataFolder.value = currentFolder.value
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.on('EditFolder', (dataSocket) => {
|
|
||||||
const { from, to } = dataSocket
|
|
||||||
data.value = updateEditFolder(data.value, from, to)
|
|
||||||
currentFolder.value = updateEditFolder(currentFolder.value, from, to)
|
|
||||||
listDataFolder.value = updateEditFolder(listDataFolder.value, from, to)
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.on('DeleteFolder', (dataSocket) => {
|
|
||||||
const { pathname } = dataSocket
|
|
||||||
data.value = updateDeleteFolder(data.value, pathname)
|
|
||||||
currentFolder.value = updateDeleteFolder(currentFolder.value, pathname)
|
|
||||||
listDataFolder.value = updateDeleteFolder(listDataFolder.value, pathname)
|
|
||||||
})
|
|
||||||
|
|
||||||
socket?.on('FileDelete', (dataSocket) => {
|
|
||||||
const { pathname } = dataSocket
|
|
||||||
|
|
||||||
currentFile.value = updateDeleteFile(currentFile.value, pathname)
|
|
||||||
listDataFile.value = updateDeleteFile(listDataFile.value, pathname)
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.on('FileUpdate', (dataSocket) => {
|
|
||||||
const metadata = dataSocket
|
|
||||||
|
|
||||||
const pathArray: string[] = metadata.pathname.split('/').filter(Boolean)
|
|
||||||
const currentPathResult = pathArray.slice(0, -1).join('/') + '/'
|
|
||||||
|
|
||||||
if (currentPath.value == currentPathResult) {
|
|
||||||
listDataFile.value = currentFile.value = updateNewFile(
|
|
||||||
currentFile.value,
|
|
||||||
metadata.pathname,
|
|
||||||
metadata,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.on('disconnect', () => {
|
|
||||||
state.connected = false
|
|
||||||
})
|
|
||||||
})
|
|
||||||
362
Services/client/src/stores/storage.ts
Normal file
362
Services/client/src/stores/storage.ts
Normal file
|
|
@ -0,0 +1,362 @@
|
||||||
|
import { computed, reactive, ref } from 'vue'
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { io } from 'socket.io-client'
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
import api from '@/services/HttpService'
|
||||||
|
|
||||||
|
import { useLoader } from './loader'
|
||||||
|
|
||||||
|
type Path = string
|
||||||
|
|
||||||
|
export interface StorageFolder {
|
||||||
|
pathname: string
|
||||||
|
name: string
|
||||||
|
createdAt: string
|
||||||
|
createdBy: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StorageFile {
|
||||||
|
pathname: string
|
||||||
|
path: string
|
||||||
|
fileName: string
|
||||||
|
fileSize: string
|
||||||
|
fileType: string
|
||||||
|
title: string
|
||||||
|
description: string
|
||||||
|
category: string[]
|
||||||
|
keyword: string[]
|
||||||
|
updatedAt: string
|
||||||
|
updatedBy: string
|
||||||
|
createdAt: string
|
||||||
|
createdBy: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Structure extends StorageFolder {
|
||||||
|
folder: Structure[]
|
||||||
|
file: StorageFile[]
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tree = Structure[]
|
||||||
|
|
||||||
|
function constructUrl(path: string | string[], append = true) {
|
||||||
|
const arr = Array.isArray(path) ? path : path.split('/').filter(Boolean)
|
||||||
|
const url =
|
||||||
|
import.meta.env.VITE_API_ENDPOINT +
|
||||||
|
arr.reduce<string>((a, v, i) => {
|
||||||
|
switch (String(i)) {
|
||||||
|
case '0':
|
||||||
|
return `cabinet/${v}`
|
||||||
|
case '1':
|
||||||
|
return `${a}/drawer/${v}`
|
||||||
|
case '2':
|
||||||
|
return `${a}/folder/${v}`
|
||||||
|
case '3':
|
||||||
|
return `${a}/subfolder/${v}`
|
||||||
|
default:
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
}, '')
|
||||||
|
return append
|
||||||
|
? url + ['cabinet', '/drawer', '/folder', '/subfolder'][arr.length]
|
||||||
|
: url
|
||||||
|
}
|
||||||
|
|
||||||
|
function consistantPath(path: string | string[]) {
|
||||||
|
return Array.isArray(path)
|
||||||
|
? path.join('/') + '/'
|
||||||
|
: path.split('/').filter(Boolean).join('/') + '/'
|
||||||
|
}
|
||||||
|
|
||||||
|
const useStorage = defineStore('storageStore', () => {
|
||||||
|
const loader = useLoader()
|
||||||
|
const init = ref<boolean>(false)
|
||||||
|
const folder = ref<Record<Path, StorageFolder[]>>({})
|
||||||
|
const file = ref<Record<Path, StorageFile[]>>({})
|
||||||
|
const tree = computed(() => {
|
||||||
|
let structure: Tree = []
|
||||||
|
|
||||||
|
// parse list of folder and list of file into tree
|
||||||
|
Object.entries(folder.value).forEach(([key, value]) => {
|
||||||
|
const arr = key.split('/').filter(Boolean)
|
||||||
|
|
||||||
|
// Once run then it is init
|
||||||
|
if (!init.value) init.value = true
|
||||||
|
|
||||||
|
if (arr.length === 0) {
|
||||||
|
structure = value.map((v) => ({
|
||||||
|
pathname: v.pathname,
|
||||||
|
name: v.name,
|
||||||
|
createdAt: v.createdAt,
|
||||||
|
createdBy: v.createdBy,
|
||||||
|
folder: [],
|
||||||
|
file: [],
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
let current: Structure | undefined
|
||||||
|
|
||||||
|
// traverse into tree
|
||||||
|
arr.forEach((v, i) => {
|
||||||
|
current =
|
||||||
|
i === 0
|
||||||
|
? structure.find((x) => x.name === v)
|
||||||
|
: current?.folder.find((x) => x.name === v)
|
||||||
|
})
|
||||||
|
|
||||||
|
// set data in tree (object is references to the same object)
|
||||||
|
if (current) {
|
||||||
|
current.folder = value.map((v) => ({
|
||||||
|
pathname: v.pathname,
|
||||||
|
name: v.name,
|
||||||
|
createdAt: v.createdAt,
|
||||||
|
createdBy: v.createdBy,
|
||||||
|
folder: [],
|
||||||
|
file: [],
|
||||||
|
}))
|
||||||
|
current.file = file.value[key] ?? []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(structure, folder.value, file.value)
|
||||||
|
return structure
|
||||||
|
})
|
||||||
|
const currentInfo = reactive<{
|
||||||
|
path: string
|
||||||
|
dept: number
|
||||||
|
}>({
|
||||||
|
path: '',
|
||||||
|
dept: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!init.value) goto(sessionStorage.getItem('path') || '')
|
||||||
|
|
||||||
|
async function getStorage(path: string = '') {
|
||||||
|
const arr = path.split('/').filter(Boolean)
|
||||||
|
|
||||||
|
if (arr.length >= 4) return // this system does not have more than 4 level
|
||||||
|
|
||||||
|
const res = await api.get<(typeof folder.value)[string]>(constructUrl(arr))
|
||||||
|
if (res.status === 200 && res.data && Array.isArray(res.data))
|
||||||
|
folder.value[consistantPath(path)] = res.data.sort((a, b) =>
|
||||||
|
a.pathname.localeCompare(b.pathname),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getStorageFile(path: string = '') {
|
||||||
|
const arr = path.split('/').filter(Boolean)
|
||||||
|
|
||||||
|
if (arr.length < 3) return // file in this system only lives in level 3 and 4
|
||||||
|
|
||||||
|
const res = await api.get<(typeof file.value)[string]>(
|
||||||
|
constructUrl(arr, false) + '/file',
|
||||||
|
)
|
||||||
|
if (res.status === 200 && res.data && Array.isArray(res.data))
|
||||||
|
file.value[consistantPath(path)] = res.data.sort((a, b) =>
|
||||||
|
a.pathname.localeCompare(b.pathname),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function goto(path: string = '', force = false) {
|
||||||
|
loader.show()
|
||||||
|
const arr = path.split('/').filter(Boolean)
|
||||||
|
|
||||||
|
// get all parent to the root structure
|
||||||
|
// this will also triggher init structure as it get root structure
|
||||||
|
for (let i = 0; i < arr.length; i++) {
|
||||||
|
const current = consistantPath(arr.slice(0, i - arr.length))
|
||||||
|
if (!folder.value[current] || force) await getStorage(current)
|
||||||
|
}
|
||||||
|
|
||||||
|
path = consistantPath(path)
|
||||||
|
|
||||||
|
// only get this path once, after that will get from socket.io-client instead
|
||||||
|
if (!folder.value[path] || force) await getStorage(path)
|
||||||
|
if (!file.value[path] || force) await getStorageFile(path)
|
||||||
|
|
||||||
|
currentInfo.path = path
|
||||||
|
currentInfo.dept = path.split('/').filter(Boolean).length
|
||||||
|
sessionStorage.setItem('path', path)
|
||||||
|
loader.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function gotoParent() {
|
||||||
|
const arr = currentInfo.path.split('/').filter(Boolean)
|
||||||
|
await goto(consistantPath(arr.slice(0, -1)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// socket.io zone
|
||||||
|
const socket = io('http://localhost:25565')
|
||||||
|
|
||||||
|
socket.on('connect', () => console.info('Socket.io connected.'))
|
||||||
|
socket.on('disconnect', () => console.info('Socket.io disconnected.'))
|
||||||
|
socket.on('CreateFolder', (data: { pathname: string }) => {
|
||||||
|
const arr = data.pathname.split('/').filter(Boolean)
|
||||||
|
const path = consistantPath(arr.slice(0, -1))
|
||||||
|
|
||||||
|
if (folder.value[path]) {
|
||||||
|
folder.value[path].push({
|
||||||
|
pathname: data.pathname,
|
||||||
|
name: arr[arr.length - 1],
|
||||||
|
createdAt: 'n/a',
|
||||||
|
createdBy: 'n/a',
|
||||||
|
})
|
||||||
|
folder.value[path].sort((a, b) => a.pathname.localeCompare(b.pathname))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// NOTE:
|
||||||
|
// API planned to make new endpoint that can move and rename in one go.
|
||||||
|
// Need to change if api handle move and rename file instead of just edit.
|
||||||
|
socket.on('EditFolder', (data: { from: string; to: string }) => {
|
||||||
|
const src = data.from.split('/').filter(Boolean)
|
||||||
|
const dst = data.to.split('/').filter(Boolean)
|
||||||
|
const path = consistantPath(src.slice(0, -1))
|
||||||
|
|
||||||
|
if (folder.value[path]) {
|
||||||
|
const val = folder.value[path].find((v) => v.pathname === data.from)
|
||||||
|
|
||||||
|
if (val) {
|
||||||
|
val.pathname = data.to
|
||||||
|
val.name = dst[dst.length - 1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const regex = new RegExp(`^${data.from}`)
|
||||||
|
|
||||||
|
for (let key in folder.value) {
|
||||||
|
if (key.startsWith(data.from)) {
|
||||||
|
folder.value[key.replace(regex, data.to)] = folder.value[key].map(
|
||||||
|
(v) => {
|
||||||
|
v.pathname = v.pathname.replace(regex, data.to)
|
||||||
|
return v
|
||||||
|
},
|
||||||
|
)
|
||||||
|
delete folder.value[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let key in file.value) {
|
||||||
|
if (key.startsWith(data.from)) {
|
||||||
|
file.value[key.replace(regex, data.to)] = file.value[key].map((v) => {
|
||||||
|
v.pathname = v.pathname.replace(regex, data.to)
|
||||||
|
return v
|
||||||
|
})
|
||||||
|
delete file.value[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
socket.on('DeleteFolder', (data: { pathname: string }) => {
|
||||||
|
for (let key in folder.value) {
|
||||||
|
if (key.startsWith(data.pathname)) {
|
||||||
|
delete folder.value[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const arr = data.pathname.split('/').filter(Boolean)
|
||||||
|
const path = consistantPath(arr.slice(0, -1))
|
||||||
|
|
||||||
|
if (folder.value[path]) {
|
||||||
|
folder.value[path] = folder.value[path].filter(
|
||||||
|
(v) => v.pathname !== data.pathname,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
async function createFolder(name: string, path: string = currentInfo.path) {
|
||||||
|
loader.show()
|
||||||
|
await api.post(constructUrl(path, true), { name })
|
||||||
|
loader.hide()
|
||||||
|
}
|
||||||
|
async function editFolder(name: string, path: string) {
|
||||||
|
loader.show()
|
||||||
|
await api.put(constructUrl(path, false), { name })
|
||||||
|
loader.hide()
|
||||||
|
}
|
||||||
|
async function deleteFolder(path: string) {
|
||||||
|
loader.show()
|
||||||
|
await api.delete(constructUrl(path, false))
|
||||||
|
loader.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileMetadata = {
|
||||||
|
title?: string
|
||||||
|
description?: string
|
||||||
|
keyword?: string[]
|
||||||
|
category?: string[]
|
||||||
|
}
|
||||||
|
async function createFile(
|
||||||
|
file: File,
|
||||||
|
data: FileMetadata,
|
||||||
|
path: string = currentInfo.path,
|
||||||
|
) {
|
||||||
|
if (path.split('/').filter(Boolean).length < 3) return // the system only allow file to live in level 3 and 4
|
||||||
|
|
||||||
|
loader.show()
|
||||||
|
const res = await api.post(constructUrl(path, false) + '/file', {
|
||||||
|
file: file.name,
|
||||||
|
...data,
|
||||||
|
})
|
||||||
|
if (res && res.status === 201 && res.data && res.data.upload) {
|
||||||
|
await axios
|
||||||
|
.put(res.data.upload, file, {
|
||||||
|
headers: { 'Content-Type': file.type },
|
||||||
|
onUploadProgress: (e) => console.log(e),
|
||||||
|
})
|
||||||
|
.catch((e) => console.error(e))
|
||||||
|
}
|
||||||
|
loader.hide()
|
||||||
|
}
|
||||||
|
async function updateFile(pathname: string, data: FileMetadata, file?: File) {
|
||||||
|
const arr = pathname.split('/')
|
||||||
|
|
||||||
|
if (arr.length < 4) return // the system only allow file to live in level 3 and 4
|
||||||
|
|
||||||
|
loader.show()
|
||||||
|
const res = await api.patch(
|
||||||
|
constructUrl(arr.slice(0, -1), false) + `/file/${arr[arr.length - 1]}`,
|
||||||
|
{ file: file?.name, ...data },
|
||||||
|
)
|
||||||
|
if (res && res.status === 201 && res.data && res.data.upload) {
|
||||||
|
await axios
|
||||||
|
.put(res.data.upload, file, {
|
||||||
|
headers: { 'Content-Type': file?.type },
|
||||||
|
onUploadProgress: (e) => console.log(e),
|
||||||
|
})
|
||||||
|
.catch((e) => console.error(e))
|
||||||
|
}
|
||||||
|
loader.hide()
|
||||||
|
}
|
||||||
|
async function deleteFile(pathname: string) {
|
||||||
|
const arr = pathname.split('/')
|
||||||
|
|
||||||
|
if (arr.length < 4) return // the system only allow file to live in level 3 and 4
|
||||||
|
|
||||||
|
loader.show()
|
||||||
|
await api.delete(
|
||||||
|
constructUrl(arr.slice(0, -1), false) + `/file/${arr[arr.length - 1]}`,
|
||||||
|
)
|
||||||
|
loader.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
// information
|
||||||
|
currentInfo,
|
||||||
|
folder,
|
||||||
|
file,
|
||||||
|
tree,
|
||||||
|
// fetch
|
||||||
|
getStorage,
|
||||||
|
getStorageFile,
|
||||||
|
// traverse
|
||||||
|
goto,
|
||||||
|
gotoParent,
|
||||||
|
// operation
|
||||||
|
createFolder,
|
||||||
|
editFolder,
|
||||||
|
deleteFolder,
|
||||||
|
createFile,
|
||||||
|
updateFile,
|
||||||
|
deleteFile,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default useStorage
|
||||||
|
|
@ -1,16 +1,17 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useLoader } from '@/stores/loader'
|
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
|
|
||||||
|
import { useLoader } from '@/stores/loader'
|
||||||
|
import { useSearchDataStore } from '@/stores/searched-data'
|
||||||
|
import { useFileInfoStore } from '@/stores/file-info-data'
|
||||||
|
import useStorage from '@/stores/storage'
|
||||||
|
|
||||||
import profile from '@/components/Profile.vue'
|
import profile from '@/components/Profile.vue'
|
||||||
import { useTreeDataStore } from '@/stores/tree-data'
|
|
||||||
import { useSearchDataStore } from '@/stores/searched-data';
|
|
||||||
import { useFileInfoStore } from '@/stores/file-info-data';
|
|
||||||
const { currentPath } = storeToRefs(useTreeDataStore())
|
|
||||||
const { isFilePreview } = storeToRefs(useFileInfoStore())
|
const { isFilePreview } = storeToRefs(useFileInfoStore())
|
||||||
const { isSearch } = storeToRefs(useSearchDataStore())
|
const { isSearch } = storeToRefs(useSearchDataStore())
|
||||||
const { getFolder } = useTreeDataStore()
|
const { loader } = storeToRefs(useLoader())
|
||||||
const loaderStore = useLoader()
|
const { goto } = useStorage()
|
||||||
const { loader } = storeToRefs(loaderStore)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -22,20 +23,14 @@ const { loader } = storeToRefs(loaderStore)
|
||||||
src="@/assets/logo-edm.png"
|
src="@/assets/logo-edm.png"
|
||||||
spinner-color="white"
|
spinner-color="white"
|
||||||
style="height: 45px; max-width: 45px"
|
style="height: 45px; max-width: 45px"
|
||||||
@click="
|
@click="() => goto()"
|
||||||
() => {
|
|
||||||
currentPath = ''
|
|
||||||
getFolder(currentPath)
|
|
||||||
}
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="column q-px-md pointer"
|
class="column q-px-md pointer"
|
||||||
id="app-toolbar-title"
|
id="app-toolbar-title"
|
||||||
@click="
|
@click="
|
||||||
() => {
|
() => {
|
||||||
currentPath = ''
|
goto()
|
||||||
getFolder(currentPath)
|
|
||||||
isSearch = false
|
isSearch = false
|
||||||
isFilePreview = false
|
isFilePreview = false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue