Line data Source code
1 16 : <template>
2 0 : <div class="upload-model-dialog flex flex-col gap-6 border-t p-4 pt-6">
3 : <UploadModelFileUpload
4 : v-if="fileState.status !== 'idle'"
5 : v-model="fileModelType"
6 : :state="fileState"
7 : :folders="fileUpload.uploadFolders.value"
8 : @upload="handleUploadFile"
9 : @cancel="fileUpload.cancel"
10 : @back="fileUpload.reset"
11 : @close="handleClose"
12 : />
13 : <!-- Scrollable content area -->
14 : <div v-else class="min-h-0 flex-auto basis-0 overflow-y-auto">
15 : <!-- Step 1: Enter URL -->
16 : <UploadModelUrlInput
17 : v-if="currentStep === 1"
18 : v-model="wizardData.url"
19 : :error="uploadError"
20 : >
21 : <UploadModelFilePicker
22 : v-if="canUploadFile"
23 : :error="fileError"
24 : @choose="fileUpload.choose"
25 : />
26 : </UploadModelUrlInput>
27 :
28 : <!-- Step 2: Confirm Metadata -->
29 : <UploadModelConfirmation
30 : v-else-if="currentStep === 2"
31 : v-model="selectedModelType"
32 : :metadata="wizardData.metadata"
33 : :preview-image="wizardData.previewImage"
34 : :upload-context="uploadContext"
35 : />
36 :
37 : <!-- Step 3: Upload Progress -->
38 : <UploadModelProgress
39 : v-else-if="currentStep === 3 && uploadStatus != null"
40 : :result="uploadStatus"
41 : :error="uploadError"
42 : :type-mismatch="uploadTypeMismatch"
43 : :metadata="wizardData.metadata"
44 : :model-type="selectedModelType"
45 : :preview-image="wizardData.previewImage"
46 : />
47 : </div>
48 :
49 : <!-- Navigation Footer - always visible -->
50 : <UploadModelFooter
51 : v-if="fileState.status === 'idle'"
52 : class="shrink-0"
53 : :current-step="currentStep"
54 : :is-fetching-metadata="isFetchingMetadata"
55 : :is-uploading="isUploading"
56 : :can-fetch-metadata="canFetchMetadata"
57 : :can-upload-model="canUploadModel"
58 : :upload-status="uploadStatus"
59 : :can-import-another="!isMissingModelResolution"
60 : @back="goToPreviousStep"
61 : @fetch-metadata="handleFetchMetadata"
62 : @upload="handleUploadModel"
63 : @close="handleClose"
64 : @import-another="resetWizard"
65 : />
66 : </div>
67 : </template>
68 :
69 : <script setup lang="ts">
70 : import { computed, onMounted } from 'vue'
71 :
72 : import UploadModelConfirmation from '@/platform/assets/components/UploadModelConfirmation.vue'
73 : import UploadModelFilePicker from '@/platform/workspace/components/UploadModelFilePicker.vue'
74 : import UploadModelFileUpload from '@/platform/workspace/components/UploadModelFileUpload.vue'
75 : import UploadModelFooter from '@/platform/assets/components/UploadModelFooter.vue'
76 : import UploadModelProgress from '@/platform/assets/components/UploadModelProgress.vue'
77 : import UploadModelUrlInput from '@/platform/assets/components/UploadModelUrlInput.vue'
78 : import { useModelTypes } from '@/platform/assets/composables/useModelTypes'
79 : import { useUploadModelFile } from '@/platform/workspace/composables/useUploadModelFile'
80 : import type {
81 : UploadModelDialogContext,
82 : UploadModelSuccess
83 : } from '@/platform/assets/composables/useUploadModelWizard'
84 : import { useUploadModelWizard } from '@/platform/assets/composables/useUploadModelWizard'
85 : import { useDialogStore } from '@/stores/dialogStore'
86 :
87 0 : const dialogStore = useDialogStore()
88 0 : const fileUpload = useUploadModelFile()
89 0 : const { state: fileState, modelType: fileModelType } = fileUpload
90 0 : const { modelTypes, fetchModelTypes } = useModelTypes()
91 :
92 : const { uploadContext } = defineProps<{
93 : uploadContext?: UploadModelDialogContext
94 : }>()
95 :
96 0 : const emit = defineEmits<{
97 : 'upload-success': [result: UploadModelSuccess]
98 : }>()
99 :
100 0 : const isMissingModelResolution = computed(
101 : () => uploadContext?.kind === 'missing-model-resolution'
102 : )
103 : const requiredModelType = computed(() =>
104 : uploadContext?.kind === 'missing-model-resolution'
105 : ? uploadContext.requiredModelType
106 : : undefined
107 : )
108 :
109 0 : const {
110 : currentStep,
111 : isFetchingMetadata,
112 : isUploading,
113 : uploadStatus,
114 : uploadError,
115 : uploadTypeMismatch,
116 : wizardData,
117 : selectedModelType,
118 : canFetchMetadata,
119 : canUploadModel,
120 : fetchMetadata,
121 : uploadModel,
122 : goToPreviousStep,
123 : resetWizard
124 : } = useUploadModelWizard(modelTypes, {
125 : requiredModelType: requiredModelType.value
126 : })
127 :
128 0 : const fileError = computed(() =>
129 : fileState.value.status === 'idle' ? fileState.value.error : undefined
130 : )
131 0 : const canUploadFile = computed(
132 : () => fileUpload.isAvailable.value && !isMissingModelResolution.value
133 : )
134 :
135 0 : async function handleUploadFile() {
136 0 : const result = await fileUpload.upload()
137 0 : if (result) {
138 0 : emit('upload-success', result)
139 : }
140 : }
141 :
142 0 : async function handleFetchMetadata() {
143 0 : await fetchMetadata()
144 : }
145 :
146 0 : async function handleUploadModel() {
147 0 : const result = await uploadModel()
148 0 : if (result) {
149 0 : emit('upload-success', result)
150 : }
151 : }
152 :
153 0 : function handleClose() {
154 0 : dialogStore.closeDialog({ key: 'upload-model' })
155 : }
156 :
157 0 : onMounted(() => {
158 0 : fetchModelTypes()
159 : })
160 : </script>
161 :
162 : <style scoped>
163 : .upload-model-dialog {
164 : width: 90vw;
165 : max-width: 800px;
166 : height: min(400px, 80vh);
167 : max-height: 100%;
168 : }
169 :
170 : @media (min-width: 640px) {
171 : .upload-model-dialog {
172 : width: auto;
173 : min-width: 600px;
174 : }
175 : }
176 : </style>
|