Line data Source code
1 : <template>
2 : <SidebarTabTemplate
3 : ref="panelRef"
4 : :title="isInFolderView ? '' : $t('sideToolbar.mediaAssets.title')"
5 : :closable
6 : v-bind="$attrs"
7 : >
8 : <template #alt-title>
9 : <div
10 : v-if="isInFolderView"
11 : class="flex w-full items-center justify-between gap-2"
12 : >
13 : <div class="flex min-w-0 flex-1 items-center gap-2">
14 : <Button
15 : :tooltip="$t('sideToolbar.backToAssets')"
16 : tooltip-side="bottom"
17 : variant="textonly"
18 : size="icon"
19 : type="button"
20 : class="shrink-0"
21 : :aria-label="$t('sideToolbar.backToAssets')"
22 : @click="exitFolderView"
23 : >
24 : <i class="icon-[lucide--arrow-left]" />
25 : </Button>
26 : <span class="shrink-0 font-bold">
27 : {{ $t('assetBrowser.jobId') }}:
28 : </span>
29 : <span class="min-w-0 truncate text-sm">{{ folderJobId }}</span>
30 : <Button
31 : :tooltip="$t('g.copyJobId')"
32 : tooltip-side="bottom"
33 : variant="textonly"
34 : size="icon"
35 : type="button"
36 : class="shrink-0"
37 : :aria-label="$t('g.copyJobId')"
38 : @click="copyFolderJobId"
39 : >
40 : <i class="icon-[lucide--copy]" />
41 : </Button>
42 : </div>
43 : <div class="shrink-0">
44 : <span>{{ formattedExecutionTime }}</span>
45 : </div>
46 : </div>
47 : </template>
48 : <template #header>
49 : <div v-if="!isInFolderView" class="overflow-x-auto px-4 pt-2 pb-px">
50 : <TabList v-model="activeTab">
51 : <Tab value="output">{{ $t('sideToolbar.labels.generated') }}</Tab>
52 : <Tab value="input">{{ $t('sideToolbar.labels.imported') }}</Tab>
53 : </TabList>
54 : </div>
55 : <MediaAssetFilterBar
56 : v-model:search-query="searchQuery"
57 : v-model:sort-by="sortBy"
58 : v-model:view-mode="viewMode"
59 : v-model:date-filter="dateFilter"
60 : v-model:media-type-filters="mediaTypeFilters"
61 : :show-generation-time-sort="activeTab === 'output'"
62 : />
63 : </template>
64 : <template #body>
65 : <div v-bind="tabPanelAttrs" class="size-full">
66 : <div
67 : v-if="showLoadingState"
68 : class="grid gap-2 p-2"
69 : :style="skeletonGridStyle"
70 : >
71 156 : <div
72 : v-for="n in skeletonCount"
73 : :key="`skeleton-${n}`"
74 : class="flex flex-col gap-2 p-2"
75 : >
76 : <Skeleton class="aspect-square w-full rounded-lg" />
77 : <div class="flex flex-col gap-1">
78 : <Skeleton class="h-4 w-3/4" />
79 : <Skeleton class="h-3 w-1/2" />
80 : </div>
81 : </div>
82 : </div>
83 : <div v-else-if="showEmptyState">
84 : <NoResultsPlaceholder
85 : icon="icon-[lucide--info]"
86 : :title="
87 : $t(
88 : activeTab === 'input'
89 : ? 'sideToolbar.noImportedFiles'
90 : : 'sideToolbar.noGeneratedFiles'
91 : )
92 : "
93 : :message="$t('sideToolbar.noFilesFoundMessage')"
94 : />
95 : </div>
96 : <div
97 : v-else
98 : class="relative size-full py-2"
99 : @click="handleEmptySpaceClick"
100 : >
101 : <AssetsSidebarListView
102 : v-if="isListView"
103 : :asset-items="
104 : isInFolderView ? listViewAssetItems : pagedListViewAssets
105 : "
106 : :is-selected
107 : :selectable-assets="listViewSelectableAssets"
108 : :is-stack-expanded="isListViewStackExpanded"
109 : :toggle-stack="toggleListViewStack"
110 : @select-asset="handleAssetSelect"
111 : @preview-asset="handleZoomClick"
112 : @context-menu="handleAssetContextMenu"
113 : />
114 : <div v-else class="size-full">
115 : <AssetsSidebarGridView
116 : :assets="isInFolderView ? filteredAssets : pagedFilteredAssets"
117 : :is-selected
118 : :show-output-count
119 : :get-output-count
120 : :grid-mode
121 : @select-asset="handleAssetSelect"
122 : @toggle-asset-selection="handleAssetSelectionToggle"
123 : @context-menu="handleAssetContextMenu"
124 : @zoom="handleZoomClick"
125 : @output-count-click="enterFolderView"
126 : />
127 : </div>
128 : </div>
129 : </div>
130 : </template>
131 : <template #footer>
132 : <MediaAssetSelectionBar
133 : v-if="hasSelection"
134 : :count="totalOutputCount"
135 : :show-delete="shouldShowDeleteButton"
136 : @deselect="handleDeselectAll"
137 : @download="handleBulkDownload(selectedAssets)"
138 : @delete="handleBulkDelete(selectedAssets)"
139 : />
140 : </template>
141 : </SidebarTabTemplate>
142 : <Teleport to="body">
143 : <div
144 : v-if="marqueeStyle"
145 : class="pointer-events-none fixed z-overlay border border-primary bg-primary/20"
146 : :style="marqueeStyle"
147 : />
148 : </Teleport>
149 : <MediaLightbox
150 : v-model:active-index="galleryActiveIndex"
151 : :all-gallery-items="galleryItems"
152 : />
153 : <Menu
154 : :id="contextMenuId"
155 : v-bind="contextMenuProps"
156 : :items="contextMenuItems"
157 : />
158 : </template>
159 :
160 : <script setup lang="ts">
161 : import { unrefElement, useAsyncState, useStorage } from '@vueuse/core'
162 : import { useToast } from '@/components/ui/toast/toastStore'
163 : import {
164 : computed,
165 : defineAsyncComponent,
166 : onMounted,
167 : onUnmounted,
168 : ref,
169 : toValue,
170 : useId,
171 : useTemplateRef,
172 : watch
173 : } from 'vue'
174 : import { useI18n } from 'vue-i18n'
175 :
176 : import NoResultsPlaceholder from '@comfyorg/design-system/common/NoResultsPlaceholder'
177 : import { LOAD3D_VIEWER_DIALOG_PROPS } from '@/extensions/core/load3d/components/load3dViewerDialog'
178 : import AssetsSidebarGridView from '@/components/sidebar/tabs/AssetsSidebarGridView.vue'
179 : import AssetsSidebarListView from '@/components/sidebar/tabs/AssetsSidebarListView.vue'
180 : import SidebarTabTemplate from '@/components/sidebar/tabs/SidebarTabTemplate.vue'
181 : import Skeleton from '@comfyorg/design-system/skeleton/Skeleton'
182 : import MediaLightbox from '@/components/sidebar/tabs/queue/MediaLightbox.vue'
183 : import Tab from '@comfyorg/design-system/tab/Tab'
184 : import TabList from '@comfyorg/design-system/tab/TabList'
185 : import Button from '@comfyorg/design-system/button/Button'
186 : import Menu from '@comfyorg/design-system/menu/Menu'
187 : import { usePointMenu } from '@comfyorg/design-system/lib/menu/usePointMenu'
188 : import type { MenuItem } from '@comfyorg/design-system/lib/menu/types'
189 : import { useDismissableOverlay } from '@/composables/useDismissableOverlay'
190 : import { useFeatureFlags } from '@/composables/useFeatureFlags'
191 : import MediaAssetFilterBar from '@/platform/assets/components/MediaAssetFilterBar.vue'
192 : import MediaAssetSelectionBar from '@/platform/assets/components/MediaAssetSelectionBar.vue'
193 : import {
194 : getMediaAssetGridColumns,
195 : MEDIA_ASSET_VIEW_MODE
196 : } from '@/platform/assets/components/mediaAssetViewOptions'
197 : import type {
198 : MediaAssetGridMode,
199 : MediaAssetViewMode
200 : } from '@/platform/assets/components/mediaAssetViewOptions'
201 : import { getAssetType } from '@/platform/assets/composables/media/assetMappers'
202 : import { useAssetGridSelection } from '@/platform/assets/composables/useAssetGridSelection'
203 : import { useAssetSelection } from '@/platform/assets/composables/useAssetSelection'
204 : import { useMediaAssetActions } from '@/platform/assets/composables/useMediaAssetActions'
205 : import { useMediaAssetFiltering } from '@/platform/assets/composables/useMediaAssetFiltering'
206 : import { useOutputStacks } from '@/platform/assets/composables/useOutputStacks'
207 : import type { OutputAssetMetadata } from '@/platform/assets/schemas/assetMetadataSchema'
208 : import { getOutputAssetMetadata } from '@/platform/assets/schemas/assetMetadataSchema'
209 : import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
210 : import { getAssetDisplayName } from '@/platform/assets/utils/assetMetadataUtils'
211 : import {
212 : getAssetFileUrl,
213 : getAssetInlineMediaUrl,
214 : getAssetSubfolder,
215 : getAssetViewUrl
216 : } from '@/platform/assets/utils/assetUrlUtil'
217 : import { resolveOutputAssetItems } from '@/platform/assets/utils/outputAssetUtil'
218 : import { isCloud } from '@/platform/distribution/types'
219 : import { supportsWorkflowMetadata } from '@/platform/workflow/utils/workflowExtractionUtil'
220 : import { openHdrViewer } from '@/services/hdrViewerService'
221 : import { useAssetsStore } from '@/stores/assetsStore'
222 : import { useDialogStore } from '@/stores/dialogStore'
223 : import {
224 : formatDuration,
225 : getMediaTypeFromFilename,
226 : isPreviewableMediaType
227 : } from '@/utils/formatUtil'
228 : import { isHdrImageFilename } from '@/utils/hdrFormatUtil'
229 : import { detectNodeTypeFromFilename } from '@/utils/loaderNodeUtil'
230 : import type { AugmentedResultItem } from '@/utils/resultItem'
231 : import { WrappedList } from '@/utils/pagedList'
232 :
233 84 : const Load3dViewerContent = defineAsyncComponent(
234 : () => import('@/extensions/core/load3d/components/Load3dViewerContent.vue')
235 : )
236 :
237 84 : const { t } = useI18n()
238 84 : const { flags } = useFeatureFlags()
239 :
240 : const { closable = true } = defineProps<{ closable?: boolean }>()
241 :
242 84 : const emit = defineEmits<{ assetSelected: [asset: AssetItem] }>()
243 :
244 84 : const activeTab = ref<'input' | 'output'>('output')
245 84 : const folderJobId = ref<string | null>(null)
246 84 : const folderExecutionTime = ref<number | undefined>(undefined)
247 84 : const expectedFolderCount = ref(0)
248 84 : const isInFolderView = computed(() => folderJobId.value !== null)
249 84 : const tabPanelAttrs = computed(() =>
250 : isInFolderView.value
251 : ? {}
252 : : {
253 : id: `tabpanel-${activeTab.value}`,
254 : role: 'tabpanel',
255 : tabindex: 0,
256 : 'aria-labelledby': `tab-${activeTab.value}`
257 : }
258 : )
259 84 : const viewMode = useStorage<MediaAssetViewMode>(
260 : 'Comfy.Assets.Sidebar.ViewMode',
261 : MEDIA_ASSET_VIEW_MODE.grid
262 : )
263 84 : const isListView = computed(() => viewMode.value === MEDIA_ASSET_VIEW_MODE.list)
264 84 : const gridMode = computed<MediaAssetGridMode>(() =>
265 : viewMode.value === MEDIA_ASSET_VIEW_MODE.gridSmall
266 : ? MEDIA_ASSET_VIEW_MODE.gridSmall
267 : : MEDIA_ASSET_VIEW_MODE.grid
268 : )
269 84 : const skeletonGridStyle = computed(() => ({
270 : gridTemplateColumns: getMediaAssetGridColumns(gridMode.value)
271 : }))
272 :
273 84 : const {
274 : open: contextMenuOpen,
275 : menuProps: contextMenuProps,
276 : show: showContextMenu,
277 : hide: hideContextMenu
278 : } = usePointMenu()
279 84 : const contextMenuId = useId()
280 84 : const contextMenuItems = ref<MenuItem[]>([])
281 :
282 84 : useDismissableOverlay({
283 : isOpen: () => contextMenuOpen.value,
284 : getOverlayEl: () => document.getElementById(contextMenuId),
285 : onDismiss: hideContextMenu,
286 : dismissOnScroll: true
287 : })
288 :
289 : // Determine if delete button should be shown
290 : // Hide delete button when in input tab and not in cloud (OSS mode - files are from local folders)
291 84 : const shouldShowDeleteButton = computed(
292 : () => activeTab.value !== 'input' || flags.assetDeletionEnabled
293 : )
294 :
295 84 : const showOutputCount = (item: AssetItem): boolean => {
296 776 : if (activeTab.value !== 'output' || isInFolderView.value) {
297 32 : return false
298 : }
299 744 : return getOutputCount(item) > 1
300 : }
301 :
302 84 : const formattedExecutionTime = computed(() => {
303 3 : if (!folderExecutionTime.value) return ''
304 3 : return formatDuration(folderExecutionTime.value * 1000)
305 : })
306 :
307 84 : const toast = useToast()
308 84 : const assetsStore = useAssetsStore()
309 :
310 : // Asset selection
311 84 : const {
312 : isSelected,
313 : selectedIds,
314 : handleAssetClick,
315 : toggleAssetSelection,
316 : selectAll,
317 : setSelectedIds,
318 : hasSelection,
319 : clearSelection,
320 : getSelectedAssets,
321 : reconcileSelection,
322 : getOutputCount,
323 : getTotalOutputCount,
324 : activate: activateSelection,
325 : deactivate: deactivateSelection
326 : } = useAssetSelection()
327 :
328 84 : const panelRef = useTemplateRef('panelRef')
329 84 : const marqueePanelRef = computed(() => {
330 168 : const el = unrefElement(panelRef)
331 168 : return el instanceof HTMLElement ? el : undefined
332 : })
333 :
334 84 : const {
335 : downloadAssets,
336 : deleteAssets,
337 : addWorkflow,
338 : openWorkflow,
339 : exportWorkflow,
340 : copyJobId,
341 : addMultipleToWorkflow,
342 : openMultipleWorkflows,
343 : exportMultipleWorkflows
344 : } = useMediaAssetActions()
345 :
346 84 : const currentAssets = computed(() =>
347 : activeTab.value === 'input'
348 : ? assetsStore.inputAssets
349 : : assetsStore.outputAssets
350 : )
351 84 : const loading = computed(() => toValue(currentAssets.value.isLoading))
352 84 : const mediaAssets = computed(() => toValue(currentAssets.value.items))
353 :
354 84 : const galleryActiveIndex = ref(-1)
355 84 : const currentGalleryAssetId = ref<string | null>(null)
356 :
357 2355 : const DEFAULT_SKELETON_COUNT = 6
358 84 : const skeletonCount = computed(() =>
359 : expectedFolderCount.value > 0
360 : ? expectedFolderCount.value
361 : : DEFAULT_SKELETON_COUNT
362 : )
363 :
364 84 : const {
365 : state: folderAssets,
366 : isLoading: folderLoading,
367 : error: folderError,
368 : execute: loadFolderAssets
369 : } = useAsyncState(
370 : (metadata: OutputAssetMetadata, options: { createdAt?: string } = {}) =>
371 : resolveOutputAssetItems(metadata, options),
372 : [] as AssetItem[],
373 : { immediate: false, resetOnExecute: true }
374 : )
375 :
376 : // Base assets before search filtering
377 : const baseAssets = computed(() => {
378 209 : if (isInFolderView.value) {
379 6 : return folderAssets.value
380 : }
381 203 : return mediaAssets.value
382 : })
383 :
384 : // Use media asset filtering composable
385 84 : const { searchQuery, sortBy, dateFilter, mediaTypeFilters, filteredAssets } =
386 : useMediaAssetFiltering(baseAssets)
387 :
388 84 : const {
389 : assetItems: listViewAssetItems,
390 : selectableAssets: listViewSelectableAssets,
391 : isStackExpanded: isListViewStackExpanded,
392 : toggleStack: toggleListViewStack
393 : } = useOutputStacks({
394 : assets: filteredAssets
395 : })
396 84 : const pagedListViewAssets = computed(
397 : () => new WrappedList(currentAssets.value, () => listViewAssetItems.value)
398 : )
399 84 : const pagedFilteredAssets = computed(
400 : () => new WrappedList(currentAssets.value, () => filteredAssets.value)
401 : )
402 :
403 84 : const visibleAssets = computed(() => {
404 218 : if (!isListView.value) return filteredAssets.value
405 2 : return listViewSelectableAssets.value
406 : })
407 :
408 84 : const { marqueeStyle } = useAssetGridSelection({
409 : marqueeContainerRef: marqueePanelRef,
410 : hoverTargetRef: marqueePanelRef,
411 : getAssets: () => visibleAssets.value,
412 : getSelectedIds: () => [...selectedIds.value],
413 : setSelectedIds,
414 : selectAll,
415 : isEnabled: () => !isListView.value
416 : })
417 :
418 84 : const previewableVisibleAssets = computed(() =>
419 : visibleAssets.value.filter((asset) =>
420 : isPreviewableMediaType(getMediaTypeFromFilename(asset.name))
421 : )
422 : )
423 :
424 84 : const selectedAssets = computed(() => getSelectedAssets(visibleAssets.value))
425 :
426 84 : const totalOutputCount = computed(() =>
427 : getTotalOutputCount(selectedAssets.value)
428 : )
429 :
430 84 : const isFolderLoading = computed(
431 : () => isInFolderView.value && folderLoading.value
432 : )
433 :
434 84 : const showLoadingState = computed(
435 : () =>
436 : (loading.value || isFolderLoading.value) &&
437 : filteredAssets.value.length === 0
438 : )
439 :
440 84 : const showEmptyState = computed(
441 : () =>
442 : !loading.value &&
443 : !isFolderLoading.value &&
444 : !canLoadMoreAssets.value &&
445 : filteredAssets.value.length === 0
446 : )
447 :
448 84 : watch(visibleAssets, (newAssets) => {
449 : // Alternative: keep hidden selections and surface them in UI; for now prune
450 : // so selection stays consistent with what this view can act on.
451 134 : reconcileSelection(newAssets)
452 134 : if (currentGalleryAssetId.value && galleryActiveIndex.value !== -1) {
453 0 : const newIndex = previewableVisibleAssets.value.findIndex(
454 : (asset) => asset.id === currentGalleryAssetId.value
455 : )
456 0 : galleryActiveIndex.value = newIndex
457 : }
458 : })
459 :
460 84 : watch(galleryActiveIndex, (index) => {
461 9 : if (index === -1) {
462 3 : currentGalleryAssetId.value = null
463 : }
464 : })
465 :
466 84 : const galleryItems = computed<AugmentedResultItem[]>(() => {
467 219 : return previewableVisibleAssets.value.map((asset) => {
468 804 : const mediaType = getMediaTypeFromFilename(asset.name)
469 804 : return {
470 : filename: asset.name,
471 : subfolder: getAssetSubfolder(asset),
472 : type: 'output',
473 : nodeId: '0',
474 : mediaType: mediaType === 'image' ? 'images' : mediaType,
475 : url: getAssetInlineMediaUrl(asset),
476 : filenameIsDisplayName: isCloud
477 : }
478 : })
479 : })
480 :
481 84 : const refreshAssets = async () => {
482 97 : await currentAssets.value.invalidate()
483 : }
484 :
485 84 : watch(
486 : activeTab,
487 : () => {
488 95 : clearSelection()
489 : // Clear search when switching tabs
490 95 : searchQuery.value = ''
491 : // Reset pagination state when tab changes
492 95 : void refreshAssets()
493 : },
494 : { immediate: true }
495 : )
496 :
497 25 : function handleAssetSelect(asset: AssetItem, assets?: AssetItem[]) {
498 25 : const assetList = assets ?? visibleAssets.value
499 25 : const index = assetList.findIndex((a) => a.id === asset.id)
500 25 : emit('assetSelected', asset)
501 25 : handleAssetClick(asset, index, assetList)
502 : }
503 :
504 0 : function handleAssetSelectionToggle(asset: AssetItem) {
505 0 : const index = visibleAssets.value.findIndex((item) => item.id === asset.id)
506 0 : emit('assetSelected', asset)
507 0 : toggleAssetSelection(asset, index, visibleAssets.value)
508 : }
509 :
510 25 : function handleAssetContextMenu(event: MouseEvent, asset: AssetItem) {
511 25 : const assetType = getAssetType(asset.tags)
512 25 : const canDelete =
513 : shouldShowDeleteButton.value &&
514 : (assetType === 'output' || (assetType === 'input' && isCloud))
515 25 : const selection = selectedAssets.value
516 : const isBulk = selection.length > 1 && isSelected(asset.id)
517 :
518 25 : if (isBulk) {
519 2 : contextMenuItems.value = [
520 : {
521 : label: t('mediaAsset.selection.multipleSelectedAssets'),
522 : disabled: true
523 : },
524 : {
525 : label: t('mediaAsset.selection.insertAllAssetsAsNodes'),
526 : icon: 'icon-[comfy--node]',
527 : command: () => handleBulkAddToWorkflow(selection)
528 : },
529 : {
530 : label: t('mediaAsset.selection.openWorkflowAll'),
531 : icon: 'icon-[comfy--workflow]',
532 : command: () => handleBulkOpenWorkflow(selection)
533 : },
534 : {
535 : label: t('mediaAsset.selection.exportWorkflowAll'),
536 : icon: 'icon-[lucide--file-output]',
537 : command: () => handleBulkExportWorkflow(selection)
538 : },
539 : {
540 : label: t('mediaAsset.selection.downloadSelectedAll'),
541 : icon: 'icon-[lucide--download]',
542 : command: () => handleBulkDownload(selection)
543 : },
544 : {
545 : label: t('mediaAsset.selection.deleteSelectedAll'),
546 : icon: 'icon-[lucide--trash-2]',
547 : visible: canDelete,
548 : command: () => handleBulkDelete(selection)
549 : }
550 : ]
551 : } else {
552 23 : const hasWorkflow =
553 : assetType === 'output' ||
554 : (assetType === 'input' && supportsWorkflowMetadata(asset.name))
555 23 : const hasJobId = assetType !== 'input'
556 23 : contextMenuItems.value = [
557 : {
558 : label: t('mediaAsset.actions.inspect'),
559 : icon: 'icon-[lucide--zoom-in]',
560 : visible:
561 : isPreviewableMediaType(getMediaTypeFromFilename(asset.name)) ||
562 : isHdrImageFilename(asset.name),
563 : command: () => handleZoomClick(asset)
564 : },
565 : {
566 : label: t('mediaAsset.actions.insertAsNodeInWorkflow'),
567 : icon: 'icon-[comfy--node]',
568 : visible: detectNodeTypeFromFilename(asset.name).nodeType !== null,
569 : command: () => addWorkflow(asset)
570 : },
571 : {
572 : label: t('mediaAsset.actions.download'),
573 : icon: 'icon-[lucide--download]',
574 : command: () => downloadAssets([asset])
575 : },
576 : { separator: true, visible: hasWorkflow },
577 : {
578 : label: t('mediaAsset.actions.openWorkflow'),
579 : icon: 'icon-[comfy--workflow]',
580 : visible: hasWorkflow,
581 : command: () => openWorkflow(asset)
582 : },
583 : {
584 : label: t('mediaAsset.actions.exportWorkflow'),
585 : icon: 'icon-[lucide--file-output]',
586 : visible: hasWorkflow,
587 : command: () => exportWorkflow(asset)
588 : },
589 : { separator: true, visible: hasJobId },
590 : {
591 : label: t('mediaAsset.actions.copyJobId'),
592 : icon: 'icon-[lucide--copy]',
593 : visible: hasJobId,
594 : command: () => copyJobId(asset)
595 : },
596 : { separator: true, visible: canDelete },
597 : {
598 : label: t('mediaAsset.actions.delete'),
599 : icon: 'icon-[lucide--trash-2]',
600 : visible: canDelete,
601 : command: async () => {
602 4 : if (await deleteAssets(asset)) await refreshAssets()
603 : }
604 : }
605 : ]
606 : }
607 25 : showContextMenu(event)
608 : }
609 :
610 84 : const handleBulkDownload = (assets: AssetItem[]) => {
611 0 : downloadAssets(assets)
612 0 : clearSelection()
613 : }
614 :
615 84 : const handleBulkDelete = async (assets: AssetItem[]) => {
616 0 : if (await deleteAssets(assets)) {
617 0 : clearSelection()
618 : }
619 : }
620 :
621 84 : const handleBulkAddToWorkflow = async (assets: AssetItem[]) => {
622 1 : await addMultipleToWorkflow(assets)
623 1 : clearSelection()
624 : }
625 :
626 84 : const handleBulkOpenWorkflow = async (assets: AssetItem[]) => {
627 0 : await openMultipleWorkflows(assets)
628 0 : clearSelection()
629 : }
630 :
631 84 : const handleBulkExportWorkflow = async (assets: AssetItem[]) => {
632 0 : await exportMultipleWorkflows(assets)
633 0 : clearSelection()
634 : }
635 :
636 84 : const handleZoomClick = (asset: AssetItem) => {
637 7 : if (isHdrImageFilename(asset.name)) {
638 1 : openHdrViewer(getAssetViewUrl(asset))
639 1 : return
640 : }
641 :
642 6 : const mediaType = getMediaTypeFromFilename(asset.name)
643 6 : if (!isPreviewableMediaType(mediaType)) {
644 0 : return
645 : }
646 :
647 6 : if (mediaType === '3D') {
648 : const dialogStore = useDialogStore()
649 0 : dialogStore.showDialog({
650 : key: 'asset-3d-viewer',
651 : title: getAssetDisplayName(asset),
652 : component: Load3dViewerContent,
653 : props: {
654 : modelUrl: getAssetFileUrl(asset)
655 : },
656 : dialogComponentProps: LOAD3D_VIEWER_DIALOG_PROPS
657 : })
658 0 : return
659 : }
660 :
661 6 : currentGalleryAssetId.value = asset.id
662 6 : const index = previewableVisibleAssets.value.findIndex(
663 : (a) => a.id === asset.id
664 : )
665 6 : if (index !== -1) {
666 6 : galleryActiveIndex.value = index
667 : }
668 : }
669 :
670 84 : const enterFolderView = async (asset: AssetItem) => {
671 3 : const metadata = getOutputAssetMetadata(asset.user_metadata)
672 3 : if (!metadata) {
673 0 : console.warn('Invalid output asset metadata')
674 0 : return
675 : }
676 :
677 3 : const { jobId, executionTimeInSeconds } = metadata
678 :
679 3 : if (!jobId) {
680 0 : console.warn('Missing required folder view data')
681 0 : return
682 : }
683 :
684 3 : folderJobId.value = jobId
685 3 : folderExecutionTime.value = executionTimeInSeconds
686 3 : expectedFolderCount.value = metadata.outputCount ?? 0
687 :
688 3 : await loadFolderAssets(0, metadata, { createdAt: asset.created_at })
689 :
690 3 : if (folderError.value) {
691 0 : toast.error(t('sideToolbar.folderView.errorSummary'), {
692 : description: t('sideToolbar.folderView.errorDetail')
693 : })
694 0 : exitFolderView()
695 : }
696 : }
697 :
698 84 : const exitFolderView = () => {
699 0 : folderJobId.value = null
700 0 : folderExecutionTime.value = undefined
701 0 : expectedFolderCount.value = 0
702 0 : folderAssets.value = []
703 0 : searchQuery.value = ''
704 : }
705 :
706 84 : onMounted(() => {
707 84 : activateSelection()
708 : })
709 :
710 84 : onUnmounted(() => {
711 4 : deactivateSelection()
712 : })
713 :
714 84 : const handleDeselectAll = () => {
715 1 : clearSelection()
716 : }
717 :
718 84 : const handleEmptySpaceClick = () => {
719 0 : if (hasSelection.value) {
720 0 : clearSelection()
721 : }
722 : }
723 :
724 84 : const copyFolderJobId = async () => {
725 0 : if (folderJobId.value) {
726 0 : try {
727 0 : await navigator.clipboard.writeText(folderJobId.value)
728 0 : toast.success(t('mediaAsset.jobIdToast.copied'), {
729 : description: t('mediaAsset.jobIdToast.jobIdCopied'),
730 : duration: 2000
731 : })
732 : } catch (error) {
733 0 : toast.error(t('mediaAsset.jobIdToast.error'), {
734 : description: t('mediaAsset.jobIdToast.jobIdCopyFailed')
735 : })
736 : }
737 : }
738 : }
739 :
740 84 : const canLoadMoreAssets = computed(
741 : () => !isInFolderView.value && toValue(currentAssets.value.hasMore)
742 : )
743 : </script>
|