Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: open pdf button uses generated link as fallback #950

Merged
merged 2 commits into from
Apr 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 36 additions & 25 deletions packages/client/hmi-client/src/components/documents/Document.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,22 @@
/>
</div>
<div v-html="highlightSearchTerms(doc.publisher)" />
<Button
v-if="linkIsPDF()"
class="p-button-sm p-button-outlined"
label="Open PDF"
@click="openPDF"
/>
<Button
v-if="doi"
class="p-button-sm p-button-outlined"
@click="downloadPDF"
:icon="'pi pi-cloud-download'"
:loading="!pdfLink"
label="Download PDF"
/>
<section class="pdf-buttons" v-if="doi">
<Button
class="p-button-sm p-button-outlined"
icon="pi pi-external-link"
label="Open PDF"
@click="openPDF"
:loading="!pdfLink && !linkIsPDF()"
/>
<Button
class="p-button-sm p-button-outlined"
@click="downloadPDF"
:icon="'pi pi-cloud-download'"
:loading="!pdfLink"
label="Download PDF"
/>
</section>
</header>
<Accordion :multiple="true" :active-index="[0, 1, 2, 3, 4, 5, 6, 7]">
<AccordionTab v-if="!isEmpty(formattedAbstract)" header="Abstract" id="Abstract">
Expand Down Expand Up @@ -392,11 +394,25 @@ function downloadPDF() {
}
}

function linkIsPDF() {
const link = docLink.value ?? doi.value;
return link.match(/^.*\.(pdf|PDF)$/);
}

const openPDF = () => {
if (linkIsPDF()) {
if (docLink.value) window.open(docLink.value as string);
else if (doi.value) window.open(`https://doi.org/${doi.value}`);
return;
}
if (pdfLink.value) window.open(pdfLink.value);
};

watch(doi, async (currentValue, oldValue) => {
if (currentValue !== oldValue) {
fetchDocumentArtifacts();
fetchRelatedTerariumArtifacts();
pdfLink.value = '';
pdfLink.value = null;
pdfLink.value = await generatePdfDownloadLink(doi.value); // Generate PDF download link on (doi change)
}
});
Expand All @@ -412,16 +428,6 @@ const relatedTerariumDocuments = computed(
() => relatedTerariumArtifacts.value.filter((d) => isDocument(d)) as DocumentType[]
);

function linkIsPDF() {
const link = docLink.value ?? doi.value;
return link.match(/^.*\.(pdf|PDF)$/);
}

const openPDF = () => {
if (docLink.value) window.open(docLink.value as string);
else if (doi.value) window.open(`https://doi.org/${doi.value}`);
};

/**
* Format from xDD citation_list object.
* - author (year), title, journal, doi
Expand Down Expand Up @@ -451,6 +457,11 @@ onMounted(async () => {
display: inline;
}

.pdf-buttons {
display: flex;
gap: 0.5rem;
}

.content-navigator {
padding: 1rem;
margin-top: 8.5rem;
Expand Down