diff --git a/bo/components.d.ts b/bo/components.d.ts index 5fb392d..45e6d33 100644 --- a/bo/components.d.ts +++ b/bo/components.d.ts @@ -13,7 +13,9 @@ declare module 'vue' { export interface GlobalComponents { ButtonGoToProfile: typeof import('./src/components/customer-management/ButtonGoToProfile.vue')['default'] CartDetails: typeof import('./src/components/customer/CartDetails.vue')['default'] - CategoryMenu: typeof import('./src/components/inner/categoryMenu.vue')['default'] + CategoryMenu: typeof import('./src/components/inner/CategoryMenu.vue')['default'] + copy: typeof import('./src/components/admin/ProductDetailView copy.vue')['default'] + CountryCurrencySwitch: typeof import('./src/components/inner/CountryCurrencySwitch.vue')['default'] Cs_PrivacyPolicyView: typeof import('./src/components/terms/cs_PrivacyPolicyView.vue')['default'] Cs_TermsAndConditionsView: typeof import('./src/components/terms/cs_TermsAndConditionsView.vue')['default'] En_PrivacyPolicyView: typeof import('./src/components/terms/en_PrivacyPolicyView.vue')['default'] diff --git a/bo/src/components/customer/StorageFileBrowser.vue b/bo/src/components/customer/StorageFileBrowser.vue index 30f0a5b..bec8461 100644 --- a/bo/src/components/customer/StorageFileBrowser.vue +++ b/bo/src/components/customer/StorageFileBrowser.vue @@ -1,27 +1,37 @@ @@ -54,106 +64,106 @@ interface TreeItem { const props = defineProps<{ initialPath?: string }>() const currentPath = ref(props.initialPath || '') -const allData = ref>(new Map()) + +const allData = ref>({}) const expandedFolders = ref([]) +const treeKey = ref(0) + const loading = ref(false) const error = ref(null) +const showTree = computed(() => !error.value) async function fetchFolderContents(path: string): Promise { const url = `/api/v1/restricted/storage/list-content/${path}` const data = await useFetchJson(url) + return (data.items || []).map(i => ({ name: i.Name, type: i.IsFolder ? 'folder' : 'file' })) } - async function loadFolder(path: string) { - if (allData.value.has(path)) return - loading.value = true - error.value = null + if (allData.value[path]) return + try { const items = await fetchFolderContents(path) - allData.value.set(path, items) + allData.value[path] = items } catch (e) { error.value = e instanceof Error ? e.message : 'Failed to load folder contents' - } finally { - loading.value = false } } +function buildTree(path: string): TreeItem[] { + const items = allData.value[path] || [] -async function toggleFolder(item: TreeItem) { - if (!item.isFolder) return - - if (!expandedFolders.value.includes(item.value)) { - expandedFolders.value.push(item.value) - await loadFolder(item.value) - } else { - expandedFolders.value = expandedFolders.value.filter(v => v !== item.value) - } -} - -function onItemClick(item: TreeItem) { - if (item.isFolder) { - toggleFolder(item) - } -} - - -function buildTreeItems(items: FileItem[], path: string): TreeItem[] { return items.map(item => { const itemPath = path ? `${path}/${item.name}` : item.name const isFolder = item.type === 'folder' - const children = isFolder - ? buildTreeItems(allData.value.get(itemPath) || [], itemPath) - : undefined + const isExpanded = expandedFolders.value.includes(itemPath) + const isLoaded = !!allData.value[itemPath] return { label: item.name, - icon: isFolder ? 'fxemoji:folder' : 'flat-color-icons:file', isFolder, path: isFolder ? itemPath : path, value: itemPath, fileName: isFolder ? undefined : item.name, - children + + children: isFolder && isExpanded && isLoaded + ? buildTree(itemPath) + : [] } }) } +const treeItems = computed(() => buildTree(currentPath.value)) + +async function toggleFolder(item: TreeItem) { + if (!item.isFolder) return + + const isOpen = expandedFolders.value.includes(item.value) + + if (!isOpen) { + await loadFolder(item.value) + treeKey.value++ + } else { + treeKey.value++ + } +} + +function onToggle(_event: unknown, item: TreeItem) { + console.log('Toggle:', item) + if (item.isFolder) { + toggleFolder(item) + } +} + async function downloadFile(path: string, fileName: string) { try { const response = await fetch(`/api/v1/restricted/storage/download-file/${path}/${fileName}`) - if (!response.ok) throw new Error('Failed to download file') + if (!response.ok) throw new Error('Download failed') const blob = await response.blob() const url = window.URL.createObjectURL(blob) + const a = document.createElement('a') a.href = url a.download = fileName + document.body.appendChild(a) a.click() a.remove() + window.URL.revokeObjectURL(url) } catch (e) { - console.error('Download error:', e) - alert('Failed to download file') + console.error(e) + alert('Download failed') } } -const treeItems = computed(() => { - const items = allData.value.get(currentPath.value) || [] - return buildTreeItems(items, currentPath.value) -}) - -loadFolder(currentPath.value).then(() => { - const rootItems = treeItems.value - if (rootItems.length > 0 && rootItems[0].isFolder) { - toggleFolder(rootItems[0]) - } -}) +loadFolder(currentPath.value) \ No newline at end of file