2525 <BIMDataTextbox :text =" currentDocument?.name" />
2626 </div >
2727
28- <div class =" btn-box" v-if =" selectedFileTab.id !== 'visas' " >
28+ <div class =" btn-box" v-if =" documentList.length > 1 " >
2929 <BIMDataButton
3030 width =" 40px"
3131 height =" 40px"
5353
5454 <template v-else-if =" [... OFFICE_FILES , PDF , ' .pdf' ].includes (fileType ) " >
5555 <div class =" pdf-container" >
56- <BIMDataPDFViewer :pdf =" file" />
56+ <BIMDataPDFViewer :pdf =" { file } " />
5757 </div >
5858 </template >
5959
7171 </div >
7272 </template >
7373
74- <div class =" btn-box" v-if =" selectedFileTab.id !== 'visas' " >
74+ <div class =" btn-box" v-if =" documentList.length > 1 " >
7575 <BIMDataButton
7676 width =" 40px"
7777 height =" 40px"
7878 fill
7979 rounded
8080 icon
81- :disabled =" index === documents .length - 1"
81+ :disabled =" index === documentList .length - 1"
8282 @click =" index++"
8383 >
8484 <BIMDataIconChevron size =" xs" />
8989</template >
9090
9191<script setup>
92- import { computed , ref , watch , onMounted , onUnmounted , watchEffect } from " vue" ;
92+ import { computed , onBeforeUnmount , onMounted , ref , watch , watchEffect } from " vue" ;
9393import { useRouter } from " vue-router" ;
9494import { useAppModal } from " ../../app/app-modal/app-modal.js" ;
9595import { MODEL_CONFIG , MODEL_TYPE } from " ../../../../config/models.js" ;
96- import { OFFICE_FILES , IMAGE_PREVIEW_FILES } from " ../../../../config/files.js" ;
96+ import { OFFICE_FILES , IMAGE_FILES } from " ../../../../config/files.js" ;
97+ import FileService from " ../../../../services/FileService.js" ;
98+ import ModelService from " ../../../../services/ModelService.js" ;
9799import { useFiles } from " ../../../../state/files.js" ;
98100import { useModels } from " ../../../../state/models.js" ;
99- import { isFolder } from " ../../../../utils/file-structure.js" ;
100101import { fileExtension } from " ../../../../utils/files.js" ;
101102import { openInViewer } from " ../../../../utils/models.js" ;
102- import FileService from " ../../../../services/FileService.js" ;
103103
104104// Components
105105import NoDocPreviewImage from " ../../../images/NoDocPreviewImage.vue" ;
@@ -111,42 +111,26 @@ const props = defineProps({
111111 type: Object ,
112112 required: true ,
113113 },
114- folder : {
115- type: Object ,
114+ documentList : {
115+ type: Array ,
116116 required: true ,
117117 },
118118 document : {
119119 type: Object ,
120120 default: null ,
121121 },
122- currentView: {
123- type: Array ,
124- required: true ,
125- },
126- selectedFileTab: {
127- type: Object ,
128- required: true ,
129- },
130122});
131123
132124const router = useRouter ();
133125const { closeModal } = useAppModal ();
134126const { projectModels } = useModels ();
135127
136- const isVisas = computed (() => {
137- return props .selectedFileTab .id === " visas" ;
138- });
139-
140- const documents = computed (() => {
141- return isVisas .value ? props .currentView : props .currentView .filter ((f ) => ! isFolder (f));
142- });
143-
144128const index = ref (0 );
145129
146130watch (
147131 () => props .document ,
148132 (newDocument ) => {
149- const docIndex = documents . value .findIndex ((d ) => d .id === newDocument .id );
133+ const docIndex = props . documentList .findIndex ((d ) => d .id === newDocument .id );
150134 index .value = docIndex !== - 1 ? docIndex : 0 ;
151135 },
152136 {
@@ -155,11 +139,8 @@ watch(
155139);
156140
157141const currentDocument = computed (() => {
158- if (! documents .value || documents .value .length === 0 ) return null ;
159- if (props .selectedFileTab .id === " visas" ) {
160- return props .document ;
161- }
162- return isVisas .value ? documents .value [index .value ].document : documents .value [index .value ];
142+ if (! props .documentList || props .documentList .length === 0 ) return null ;
143+ return props .documentList [index .value ];
163144});
164145
165146const fileType = computed (() => {
@@ -172,35 +153,23 @@ const file = ref(null);
172153watchEffect (async () => {
173154 const doc = currentDocument .value ;
174155 if (! doc) return ;
175- const models = projectModels .value ;
176- switch (fileType .value ) {
177- case IFC :
178- case DWG :
179- case DXF :
180- file .value = models .find ((m ) => m .id === doc .model_id )? .preview_file ;
181- break ;
182- case PDF :
183- case " .pdf" :
184- file .value = { file: doc .file };
185- break ;
186- case JPEG :
187- case PNG :
188- file .value = doc .file ;
189- break ;
190- default :
191- if (OFFICE_FILES .includes (fileType .value )) {
192- if (doc .office_preview ) {
193- file .value = { file: doc .office_preview };
194- } else {
195- const newDoc = await FileService .getDocument (props .project , { id: doc .id });
196- if (newDoc .office_preview ) {
197- currentDocument .value .office_preview = newDoc .office_preview ;
198- file .value = { file: newDoc .office_preview };
199- }
200- }
201- } else if (IMAGE_PREVIEW_FILES .includes (fileType .value )) {
202- file .value = doc .file ;
203- }
156+
157+ if ([DWG , DXF , IFC ].includes (fileType .value )) {
158+ const model = projectModels .value .find (m => m .id === doc .model_id );
159+ if (! model .preview_file ) {
160+ model .preview_file = (await ModelService .fetchModelByID (props .project , model .id )).preview_file ;
161+ }
162+ file .value = model .preview_file ;
163+ } else if ([PDF , " .pdf" , JPEG , PNG , ... IMAGE_FILES].includes (fileType .value )) {
164+ if (! doc .file ) {
165+ doc .file = (await FileService .getDocument (props .project , { id: doc .id })).file ;
166+ }
167+ file .value = doc .file ;
168+ } else if (OFFICE_FILES .includes (fileType .value )) {
169+ if (! doc .office_preview ) {
170+ doc .office_preview = (await FileService .getDocument (props .project , { id: doc .id })).office_preview ;
171+ }
172+ file .value = doc .office_preview ;
204173 }
205174});
206175
@@ -210,7 +179,7 @@ const onKeyUp = ({ key }) => {
210179 if (index .value > 0 ) index .value -- ;
211180 break ;
212181 case " ArrowRight" :
213- if (index .value < documents . value .length - 1 ) index .value ++ ;
182+ if (index .value < props . documentList .length - 1 ) index .value ++ ;
214183 break ;
215184 case " Escape" :
216185 closeModal ();
@@ -219,7 +188,7 @@ const onKeyUp = ({ key }) => {
219188};
220189
221190onMounted (() => document .addEventListener (" keyup" , onKeyUp));
222- onUnmounted (() => document .removeEventListener (" keyup" , onKeyUp));
191+ onBeforeUnmount (() => document .removeEventListener (" keyup" , onKeyUp));
223192
224193const openViewer = () => {
225194 closeModal ();
0 commit comments