Skip to content

Commit fd0cdf3

Browse files
PATCH: fix: make everything works without file in dms-tree (#652)
* PATCH: fix: make everything works without file in dms-tree * fix: use else if
1 parent 7fe30b3 commit fd0cdf3

7 files changed

Lines changed: 69 additions & 97 deletions

File tree

src/components/specific/files/document-viewer/DocumentViewer.vue

Lines changed: 32 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
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"
@@ -53,7 +53,7 @@
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

@@ -71,14 +71,14 @@
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" />
@@ -89,17 +89,17 @@
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";
9393
import { useRouter } from "vue-router";
9494
import { useAppModal } from "../../app/app-modal/app-modal.js";
9595
import { 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";
9799
import { useFiles } from "../../../../state/files.js";
98100
import { useModels } from "../../../../state/models.js";
99-
import { isFolder } from "../../../../utils/file-structure.js";
100101
import { fileExtension } from "../../../../utils/files.js";
101102
import { openInViewer } from "../../../../utils/models.js";
102-
import FileService from "../../../../services/FileService.js";
103103
104104
// Components
105105
import 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
132124
const router = useRouter();
133125
const { closeModal } = useAppModal();
134126
const { 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-
144128
const index = ref(0);
145129
146130
watch(
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
157141
const 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
165146
const fileType = computed(() => {
@@ -172,35 +153,23 @@ const file = ref(null);
172153
watchEffect(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
221190
onMounted(() => document.addEventListener("keyup", onKeyUp));
222-
onUnmounted(() => document.removeEventListener("keyup", onKeyUp));
191+
onBeforeUnmount(() => document.removeEventListener("keyup", onKeyUp));
223192
224193
const openViewer = () => {
225194
closeModal();

src/components/specific/files/files-manager/FilesManager.vue

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -291,34 +291,33 @@ export default {
291291
const sortByName = (a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase());
292292
293293
const filesTable = ref(null);
294-
const documentViewerFilesList = computed(() => {
295-
if (!filesTable.value) return [];
296-
297-
if (selectedFileTab.value.id === "folders") {
298-
// WARNING displayedRows is name from DS, may change
299-
return filesTable.value.filesTable.displayedRows.map((row) => row.data);
300-
}
301-
if (selectedFileTab.value.id === "files") {
302-
return filesTable.value.displayedListFiles;
303-
} else {
304-
return filesTable.value.enhancedVisas;
305-
}
306-
});
307294
308295
const onFileSelected = (file) => {
309296
if (isFolder(file)) {
310297
currentFolder.value = handler.deserialize(file);
311298
} else {
312-
openModal({
313-
component: DocumentViewer,
314-
props: {
315-
project: props.project,
316-
folder: currentFolder.value,
317-
document: file,
318-
currentView: documentViewerFilesList.value,
319-
selectedFileTab: selectedFileTab.value,
320-
},
321-
});
299+
if (filesTable.value) {
300+
let documentList = [];
301+
if (selectedFileTab.value.id === "folders") {
302+
// WARNING displayedRows is name from DS, may change
303+
const folderFiles = filesTable.value.filesTable.displayedRows.map((row) => row.data);
304+
documentList = folderFiles.filter(f => !isFolder(f));
305+
}
306+
if (selectedFileTab.value.id === "files") {
307+
documentList = filesTable.value.displayedListFiles;
308+
}
309+
if (selectedFileTab.value.id === "visas") {
310+
documentList = [file];
311+
}
312+
openModal({
313+
component: DocumentViewer,
314+
props: {
315+
project: props.project,
316+
documentList,
317+
document: file,
318+
},
319+
});
320+
}
322321
}
323322
};
324323

src/components/specific/models/models-manager/models-action-bar/ModelsActionBar.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="models-action-bar">
33
<BIMDataButton
4-
:disabled="!hasAdminPerm(project, modelDocument)"
4+
:disabled="!hasAdminPerm(project, modelDocuments)"
55
width="120px"
66
color="high"
77
ghost
@@ -13,7 +13,7 @@
1313
</BIMDataButton>
1414

1515
<BIMDataButton
16-
:disabled="!hasAdminPerm(project, modelDocument)"
16+
:disabled="!hasAdminPerm(project, modelDocuments)"
1717
width="120px"
1818
ghost
1919
squared
@@ -83,7 +83,9 @@ defineEmits([
8383
"unarchive",
8484
]);
8585
86-
const modelDocument = computed(() => handler.get({ nature: FILE_TYPE.DOCUMENT, id: props.model.document_id }));
86+
const modelDocuments = computed(() =>
87+
props.models.map(m => handler.get({ nature: FILE_TYPE.DOCUMENT, id: m.document_id }))
88+
);
8789
8890
const isArchived = computed(() => props.models.every(m => m.archived));
8991

src/config/files.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ const STANDARD_IGNORED_FILES = Object.freeze([".DS_Store"]);
1515

1616
const OFFICE_FILES = [".ppt", ".pptx", ".odp", ".xls", ".xlsx", ".ods", ".doc", ".docx", ".odt"];
1717

18-
const IMAGE_PREVIEW_FILES = [".apng", ".avif", ".gif", ".jpeg", ".jpg", ".png", ".svg", ".webp"];
18+
const IMAGE_FILES = [".apng", ".avif", ".gif", ".jpeg", ".jpg", ".png", ".svg", ".webp"];
1919

20-
export { FILE_PERMISSION, FILE_TYPE, STANDARD_IGNORED_FILES, OFFICE_FILES, IMAGE_PREVIEW_FILES };
20+
export { FILE_PERMISSION, FILE_TYPE, STANDARD_IGNORED_FILES, OFFICE_FILES, IMAGE_FILES };

src/services/FileService.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,12 @@ class FileService {
158158
return;
159159
}
160160
if (files.length === 1 && files[0].nature !== FILE_TYPE.FOLDER) {
161-
downloadName = files[0].file_name;
162-
downloadUrl = files[0].file;
161+
const document = files[0];
162+
if (!document.file) {
163+
document.file = (await this.getDocument(project, document)).file;
164+
}
165+
downloadName = document.file_name;
166+
downloadUrl = document.file;
163167
} else {
164168
downloadName = project.name;
165169
downloadUrl = this.getArchiveUrl(project, files, accessToken);

src/utils/visas.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const enhanceVisa = async (visa, user, project, t, handler) => {
4646
id: visa.document.id,
4747
nature: "Document",
4848
});
49-
if (!document) {
49+
if (!document?.file) {
5050
document = await FileService.getDocument(project, { id: visa.document_id });
5151
}
5252
} catch (error) {

src/views/project-board/project-bcf/ProjectBcf.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,10 +746,8 @@ export default {
746746
component: DocumentViewer,
747747
props: {
748748
project: currentProject.value,
749-
folder: {},
749+
documentList: files,
750750
document: file,
751-
currentView: files,
752-
selectedFileTab: {},
753751
},
754752
});
755753
};

0 commit comments

Comments
 (0)