Line data Source code
1 : <template>
2 9 : <SidebarTabTemplate
3 : data-testid="job-history-sidebar"
4 : :title="$t('queue.jobHistory')"
5 : >
6 : <template #tool-buttons>
7 : <JobHistoryActionsMenu @clear-history="onClearHistory" />
8 : </template>
9 : <template #header>
10 : <div class="overflow-x-auto px-4 pt-2 pb-px">
11 : <TabList
12 : :aria-label="$t('queue.jobHistory')"
13 : :model-value="selectedJobTab"
14 : @update:model-value="onUpdateSelectedJobTab"
15 : >
16 33 : <Tab v-for="tab in visibleJobTabs" :key="tab" :value="tab">
17 : {{ t(jobTabLabelKeys[tab]) }}
18 : </Tab>
19 : </TabList>
20 : </div>
21 : <JobFilterActions
22 : v-model:selected-workflow-filter="selectedWorkflowFilter"
23 : v-model:selected-sort-mode="selectedSortMode"
24 : v-model:search-query="searchQuery"
25 : class="px-4 py-2"
26 : :hide-show-assets-action="true"
27 : :show-search="true"
28 : :search-placeholder="t('g.searchPlaceholder', { subject: t('g.jobs') })"
29 : />
30 : <div
31 : class="flex items-center justify-between px-4 pb-2 text-xs leading-none"
32 : >
33 : <span class="text-muted-foreground">{{ activeQueueSummary }}</span>
34 : <div class="flex items-center gap-2">
35 : <span>
36 : {{ t('sideToolbar.queueProgressOverlay.clearQueueTooltip') }}
37 : </span>
38 : <Button
39 : variant="destructive"
40 : size="icon"
41 : :aria-label="
42 : t('sideToolbar.queueProgressOverlay.clearQueueTooltip')
43 : "
44 : :disabled="queuedCount === 0"
45 : @click="clearQueuedWorkflows"
46 : >
47 : <i class="icon-[lucide--list-x]" />
48 : </Button>
49 : </div>
50 : </div>
51 : </template>
52 : <template #body>
53 : <div class="flex h-full min-h-0 flex-col">
54 : <div
55 : :id="`tabpanel-${selectedJobTab}`"
56 : role="tabpanel"
57 : :aria-labelledby="`tab-${selectedJobTab}`"
58 : class="flex min-h-0 flex-1 flex-col"
59 : >
60 : <JobAssetsList
61 : class="scrollbar-custom min-h-0 flex-1"
62 : :displayed-job-groups="displayedJobGroups"
63 : @cancel-item="onCancelItem"
64 : @delete-item="onDeleteItem"
65 : @view-item="onViewItem"
66 : @menu="onMenuItem"
67 : />
68 : </div>
69 : <Menu v-bind="jobMenuProps" :items="jobMenuEntries" />
70 : <MediaLightbox
71 : v-model:active-index="galleryActiveIndex"
72 : :all-gallery-items="galleryItems"
73 : />
74 : </div>
75 : </template>
76 : </SidebarTabTemplate>
77 : </template>
78 :
79 : <script setup lang="ts">
80 : import { computed, defineAsyncComponent, ref } from 'vue'
81 : import { useI18n } from 'vue-i18n'
82 :
83 : import { LOAD3D_VIEWER_DIALOG_PROPS } from '@/extensions/core/load3d/components/load3dViewerDialog'
84 : import JobFilterActions from '@/components/queue/job/JobFilterActions.vue'
85 : import JobAssetsList from '@/components/queue/job/JobAssetsList.vue'
86 : import JobHistoryActionsMenu from '@/components/queue/JobHistoryActionsMenu.vue'
87 : import Menu from '@comfyorg/design-system/menu/Menu'
88 : import { usePointMenu } from '@comfyorg/design-system/lib/menu/usePointMenu'
89 : import { useJobMenu } from '@/composables/queue/useJobMenu'
90 : import { getVisibleJobTabs, jobTabLabelKeys } from '@/composables/queue/jobTabs'
91 : import type { JobTab } from '@/composables/queue/jobTabs'
92 : import { useJobList } from '@/composables/queue/useJobList'
93 : import type { JobListItem } from '@/composables/queue/useJobList'
94 : import { useQueueClearHistoryDialog } from '@/composables/queue/useQueueClearHistoryDialog'
95 : import { useResultGallery } from '@/composables/queue/useResultGallery'
96 : import { useErrorHandling } from '@/composables/useErrorHandling'
97 : import SidebarTabTemplate from '@/components/sidebar/tabs/SidebarTabTemplate.vue'
98 : import MediaLightbox from '@/components/sidebar/tabs/queue/MediaLightbox.vue'
99 : import Tab from '@comfyorg/design-system/tab/Tab'
100 : import TabList from '@comfyorg/design-system/tab/TabList'
101 : import Button from '@comfyorg/design-system/button/Button'
102 : import { useSurveyFeatureTracking } from '@/platform/surveys/useSurveyFeatureTracking'
103 : import { useCommandStore } from '@/platform/keybindings/commandStore'
104 : import { useDialogStore } from '@/stores/dialogStore'
105 : import { useExecutionStore } from '@/stores/executionStore'
106 : import { useQueueStore } from '@/stores/queueStore'
107 : import { is3DResult } from '@/utils/resultItem'
108 :
109 9 : const Load3dViewerContent = defineAsyncComponent(
110 : () => import('@/extensions/core/load3d/components/Load3dViewerContent.vue')
111 : )
112 :
113 9 : const { t, n } = useI18n()
114 9 : const commandStore = useCommandStore()
115 9 : const dialogStore = useDialogStore()
116 9 : const executionStore = useExecutionStore()
117 9 : const queueStore = useQueueStore()
118 9 : const { showQueueClearHistoryDialog } = useQueueClearHistoryDialog()
119 9 : const { wrapWithErrorHandlingAsync } = useErrorHandling()
120 9 : const { trackFeatureUsed } = useSurveyFeatureTracking('queue-progress-overlay')
121 :
122 9 : const onClearHistory = () => {
123 1 : trackFeatureUsed()
124 1 : showQueueClearHistoryDialog()
125 : }
126 :
127 9 : const onUpdateSelectedJobTab = (value: JobTab) => {
128 2 : trackFeatureUsed()
129 2 : selectedJobTab.value = value
130 : }
131 9 : const {
132 : selectedJobTab,
133 : selectedWorkflowFilter,
134 : selectedSortMode,
135 : searchQuery,
136 : hasFailedJobs,
137 : filteredTasks,
138 : groupedJobItems
139 : } = useJobList()
140 :
141 9 : const visibleJobTabs = computed(() => getVisibleJobTabs(hasFailedJobs.value))
142 :
143 9 : const displayedJobGroups = computed(() => groupedJobItems.value)
144 9 : const runningCount = computed(() => queueStore.runningTasks.length)
145 9 : const queuedCount = computed(() => queueStore.pendingTasks.length)
146 :
147 9 : const runningJobsLabel = computed(() =>
148 : t('sideToolbar.queueProgressOverlay.runningJobsLabel', {
149 : count: n(runningCount.value)
150 : })
151 : )
152 9 : const queuedJobsLabel = computed(() =>
153 : t('sideToolbar.queueProgressOverlay.queuedJobsLabel', {
154 : count: n(queuedCount.value)
155 : })
156 : )
157 9 : const activeQueueSummary = computed(() => {
158 10 : if (runningCount.value === 0 && queuedCount.value === 0) {
159 2 : return t('sideToolbar.queueProgressOverlay.noActiveJobs')
160 : }
161 8 : if (queuedCount.value === 0) {
162 2 : return runningJobsLabel.value
163 : }
164 7 : if (runningCount.value === 0) {
165 0 : return queuedJobsLabel.value
166 : }
167 6 : return t('sideToolbar.queueProgressOverlay.runningQueuedSummary', {
168 : running: runningJobsLabel.value,
169 : queued: queuedJobsLabel.value
170 : })
171 : })
172 :
173 9 : const clearQueuedWorkflows = wrapWithErrorHandlingAsync(async () => {
174 1 : trackFeatureUsed()
175 1 : const pendingJobIds = queueStore.pendingTasks
176 : .map((task) => task.jobId)
177 : .filter((id): id is string => typeof id === 'string' && id.length > 0)
178 :
179 1 : await commandStore.execute('Comfy.ClearPendingTasks')
180 1 : executionStore.clearInitializationByJobIds(pendingJobIds)
181 : })
182 :
183 9 : const {
184 : galleryActiveIndex,
185 : galleryItems,
186 : onViewItem: openResultGallery
187 : } = useResultGallery(() => filteredTasks.value)
188 :
189 9 : const onViewItem = wrapWithErrorHandlingAsync(async (item: JobListItem) => {
190 1 : trackFeatureUsed()
191 1 : const previewOutput = item.taskRef?.previewOutput
192 :
193 1 : if (previewOutput && is3DResult(previewOutput)) {
194 0 : dialogStore.showDialog({
195 : key: 'asset-3d-viewer',
196 : title: item.title,
197 : component: Load3dViewerContent,
198 : props: {
199 : modelUrl: previewOutput.url || ''
200 : },
201 : dialogComponentProps: LOAD3D_VIEWER_DIALOG_PROPS
202 : })
203 0 : return
204 : }
205 :
206 1 : await openResultGallery(item)
207 : })
208 :
209 9 : const onInspectAsset = (item: JobListItem) => {
210 0 : void onViewItem(item)
211 : }
212 :
213 9 : const currentMenuItem = ref<JobListItem | null>(null)
214 9 : const {
215 : menuProps: jobMenuProps,
216 : show: showJobMenu,
217 : toggle: toggleJobMenu
218 : } = usePointMenu()
219 :
220 9 : const { jobMenuEntries, cancelJob } = useJobMenu(
221 : () => currentMenuItem.value,
222 : onInspectAsset
223 : )
224 9 : const onCancelItem = wrapWithErrorHandlingAsync(async (item: JobListItem) => {
225 0 : trackFeatureUsed()
226 0 : await cancelJob(item)
227 : })
228 :
229 9 : const onDeleteItem = wrapWithErrorHandlingAsync(async (item: JobListItem) => {
230 0 : trackFeatureUsed()
231 0 : if (!item.taskRef) return
232 0 : await queueStore.delete(item.taskRef)
233 : })
234 :
235 9 : const onMenuItem = (item: JobListItem, event: Event) => {
236 0 : const isSameJob = currentMenuItem.value?.id === item.id
237 0 : currentMenuItem.value = item
238 0 : if (event.type === 'click' && isSameJob) toggleJobMenu(event)
239 0 : else showJobMenu(event)
240 : }
241 : </script>
|