Skip to content

Commit

Permalink
PATCH: fix: pdf page selection modification
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Aug 16, 2023
1 parent 8651811 commit ac2c7be
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 18 deletions.
46 changes: 37 additions & 9 deletions src/BIMDataFileManager/BIMDataFileManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
>
<PdfPageSelector
:model="pdfModel"
:modelSelectedPage="pdfModelSelectedPage"
@select="selectPdfPage"
@close="selectPdfPage"
/>
Expand Down Expand Up @@ -268,6 +269,7 @@ export default {
successFileIds: [],
pdfToView: null,
pdfModel: null,
pdfModelSelectedPage: null,
pdfModelLoading: null,
pdfPageSelectorDisplayed: false,
};
Expand Down Expand Up @@ -525,16 +527,36 @@ export default {
});
},
async onToggleFileSelect(file) {
let pdfPage = null;
if (this.isFileSelected(file)) {
this.selectedFiles = this.selectedFiles.filter(
({ document }) => document !== file
);
const selectedPdfPage = this.selectedPdfPage(file);
if (this.pdfPageSelect && file.model_type === "PDF" && selectedPdfPage) {
this.selectedFiles = this.selectedFiles.filter(
({ document }) => document !== file
);
this.pdfModelLoading = file.id;
const model = await this.apiClient.modelApi.getModel(
this.spaceId,
file.model_id,
this.projectId
);
this.pdfModelLoading = null;
if (model.children?.length > 0) {
pdfPage = await this.openPdfPageSelector(model, selectedPdfPage);
if (!pdfPage) return;
}
this.selectedFiles.push({ document: file, pdfPage });
} else {
this.selectedFiles = this.selectedFiles.filter(
({ document }) => document !== file
);
}
} else {
if (!this.multi) {
this.selectedFiles = [];
}
let pdfPage = null;
if (this.pdfPageSelect && file.model_type === "PDF") {
// If 'pdfPageSelect' mode is on and the selected file is a PDF model
// fetch the corresponding model to check its children (pages)
Expand All @@ -547,11 +569,7 @@ export default {
this.pdfModelLoading = null;
if (model.children?.length > 0) {
// If this is a multipage PDF open the page selector
this.pdfModel = model;
this.pdfPageSelectorDisplayed = true;
pdfPage = await new Promise(res => (this.selectPdfPage = res));
this.pdfPageSelectorDisplayed = false;
this.pdfModel = null;
pdfPage = await this.openPdfPageSelector(model);
if (!pdfPage) return; // If no page has been selected then the file is not selected
}
}
Expand All @@ -563,6 +581,16 @@ export default {
isFileSelected(file) {
return this.selectedFiles.some(({ document }) => file === document);
},
async openPdfPageSelector(model, page) {
this.pdfModel = model;
this.pdfModelSelectedPage = page;
this.pdfPageSelectorDisplayed = true;
const pdfPage = await new Promise(res => (this.selectPdfPage = res));
this.pdfPageSelectorDisplayed = false;
this.pdfModelSelectedPage = null;
this.pdfModel = null;
return pdfPage;
},
selectedPdfPage(file) {
return this.selectedFiles.find(({ document }) => file === document)?.pdfPage;
},
Expand Down
28 changes: 19 additions & 9 deletions src/BIMDataFileManager/components/PdfPageSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,34 @@
</template>

<script>
import { computed, ref, watch } from 'vue';
export default {
inject: ["$translate"],
props: {
model: {
type: Object,
required: true,
},
modelSelectedPage: {
type: Object,
default: null,
},
},
emits: ["select", "close"],
data() {
return {
selectedPage: null,
};
},
computed: {
pages() {
return [this.model].concat(this.model.children ?? []);
},
setup(props, emit) {
const pages = computed(() => [props.model].concat(props.model.children ?? []))
const selectedPage = ref(null);
watch(
() => props.modelSelectedPage,
page => {
if (page) selectedPage.value = page;
},
{ immediate: true }
);
return { pages, selectedPage };
},
};
</script>
Expand Down

0 comments on commit ac2c7be

Please sign in to comment.