From 54b47788e81d866a11e0c0de530ab74810d76005 Mon Sep 17 00:00:00 2001 From: Adrian <95376249+asylves1@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:16:55 -0400 Subject: [PATCH] Link equations to page (#5018) --- .../src/components/widgets/tera-pdf-embed.vue | 82 ++++++++++++------- .../model-from-equations-operation.ts | 3 +- .../tera-model-from-equations-drilldown.vue | 43 +++++----- 3 files changed, 77 insertions(+), 51 deletions(-) diff --git a/packages/client/hmi-client/src/components/widgets/tera-pdf-embed.vue b/packages/client/hmi-client/src/components/widgets/tera-pdf-embed.vue index 726f6d5ccf..f5edd046bc 100644 --- a/packages/client/hmi-client/src/components/widgets/tera-pdf-embed.vue +++ b/packages/client/hmi-client/src/components/widgets/tera-pdf-embed.vue @@ -13,9 +13,19 @@ const props = defineProps<{ }>(); const adobeDCView = ref(); +const adobeApis = ref(); const isAdobePdfApiReady = ref(false); let apiKey = null; +function goToPage(pageNumber) { + if (!adobeApis.value) return; + adobeApis.value.gotoLocation(pageNumber, 0, 0); +} + +defineExpose({ + goToPage +}); + onMounted(async () => { const apiKeyResponse = await API.get('/adobe'); apiKey = apiKeyResponse.data; @@ -44,39 +54,51 @@ watch(isAdobePdfApiReady, () => { ); if (props.pdfLink) { - adobeDCView.value.previewFile( - { - content: { - location: { - url: props.pdfLink - } + adobeDCView.value + .previewFile( + { + content: { + location: { + url: props.pdfLink + } + }, + metaData: { fileName: props.title } }, - metaData: { fileName: props.title } - }, - { - embedMode: 'FULL_WINDOW', - showPrintPDF: true, - showDownloadPDF: true, - showAnnotationTools: false, - viewMode: 'FIT_WIDTH' - } - ); + { + embedMode: 'FULL_WINDOW', + showPrintPDF: true, + showDownloadPDF: true, + showAnnotationTools: false, + viewMode: 'FIT_WIDTH' + } + ) + .then((viewer) => + viewer.getAPIs().then((apis) => { + adobeApis.value = apis; + }) + ); } else if (props.filePromise) { - adobeDCView.value.previewFile( - { - content: { - promise: props.filePromise + adobeDCView.value + .previewFile( + { + content: { + promise: props.filePromise + }, + metaData: { fileName: props.title } }, - metaData: { fileName: props.title } - }, - { - embedMode: 'FULL_WINDOW', - showPrintPDF: true, - showDownloadPDF: true, - showAnnotationTools: false, - viewMode: 'FIT_WIDTH' - } - ); + { + embedMode: 'FULL_WINDOW', + showPrintPDF: true, + showDownloadPDF: true, + showAnnotationTools: false, + viewMode: 'FIT_WIDTH' + } + ) + .then((viewer) => + viewer.getAPIs().then((apis) => { + adobeApis.value = apis; + }) + ); } } }); diff --git a/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/model-from-equations-operation.ts b/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/model-from-equations-operation.ts index 011dcaea88..14db8e882a 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/model-from-equations-operation.ts +++ b/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/model-from-equations-operation.ts @@ -7,6 +7,7 @@ const DOCUMENTATION_URL = export interface EquationBlock { text: string; + pageNumber?: number; extractionError?: boolean; } export interface EquationFromImageBlock extends DocumentExtraction { @@ -21,7 +22,7 @@ export function instanceOfEquationFromImageBlock( } export interface ModelFromEquationsState { - equations: AssetBlock[]; + equations: AssetBlock[]; text: string; modelFramework: string; modelId: string | null; diff --git a/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue b/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue index 2524d25bec..21ccf83664 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue +++ b/packages/client/hmi-client/src/components/workflow/ops/model-from-equations/tera-model-from-equations-drilldown.vue @@ -10,7 +10,7 @@ @@ -39,17 +39,16 @@
Use {{ includedEquations.length > 1 ? 'these equations' : 'this equation' }}
    -
  • +
  • +
    Other equations extracted from document
      -
    • +
    • +
      const notIncludedEquations = computed(() => clonedState.value.equations.filter((equation) => equation.includeInProcess === false) ); + +const pdfViewer = ref(); + const selectedItem = ref(''); -const selectItem = (item, event) => { - selectedItem.value = item; +const selectItem = (equation, event) => { + selectedItem.value = equation.name; + if (pdfViewer.value) { + pdfViewer.value.goToPage(equation.asset.pageNumber); + } // Prevent the child’s click handler from firing event.stopImmediatePropagation(); @@ -257,17 +261,17 @@ onMounted(async () => { } } isFetchingPDF.value = false; - const state = cloneDeep(props.node.state); if (state.equations.length) return; if (document.value?.metadata?.equations) { - documentEquations.value = document.value.metadata.equations.flatMap((page) => + documentEquations.value = document.value.metadata.equations.flatMap((page, index) => page.map((equation) => { const asset: AssetBlock = { name: 'Equation', includeInProcess: false, asset: { + pageNumber: index + 1, text: equation } }; @@ -279,7 +283,7 @@ onMounted(async () => { clonedState.value.equations = documentEquations.value.map((e, index) => ({ name: `${e.name} ${index}`, includeInProcess: e.includeInProcess, - asset: { text: e.asset.text } + asset: { text: e.asset.text, pageNumber: e.asset.pageNumber } })); state.equations = clonedState.value.equations; @@ -417,10 +421,6 @@ watch(