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

Issue with pdf-viewer-interface url generation #130

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
- timio23
- Dominic-Marcelino
- ukmadlz
- carlosgonzalezpdn
10 changes: 5 additions & 5 deletions packages/pdf-viewer-interface/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineInterface({
id: "directus-labs-pdf-viewer-interface",
name: "PDF Viewer",
icon: "picture_as_pdf",
description: "View PDF files from within the item editor",
description: "View PDF files from within the item editor modified by prodanet",
component: InterfaceComponent,
types: ["alias"],
localTypes: ["presentation"],
Expand All @@ -21,23 +21,23 @@ export default defineInterface({
type: "string",
name: "PDF Field",
meta: {
width: "half",
width: "full",
interface: "system-field",
options: {
collectionName: collection,
typeAllowList: ["uuid"],
},
}
},
},
{
field: "button_label",
name: "Button Label",
meta: {
width: "half",
width: "full",
interface: "system-input-translated-string",
options: { placeholder: defaultButtonLabel },
},
},
}
];
},
});
56 changes: 39 additions & 17 deletions packages/pdf-viewer-interface/src/interface.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<template>
<v-button @click="activeDialog = true" :disabled="!fileIsValid">{{ t(button_label) }}</v-button>

<v-dialog v-model="activeDialog" @esc="activeDialog = false">
<pdf-viewer :url="fileURL">
<template #nav>
<v-button v-tooltip.left="t('cancel')" icon rounded secondary @click="activeDialog = false">
<v-icon name="close" />
</v-button>
</template>
</pdf-viewer>
</v-dialog>
</template>

<div class="pdf-viewer-interface mb-4">
<v-button class="full-width" @click="activeDialog = true" :disabled="!fileIsValid">{{ t(button_label) }}</v-button>

<v-dialog v-model="activeDialog" @esc="activeDialog = false">
<pdf-viewer :url="fileURL">
<template #nav>
<v-button v-tooltip.left="t('cancel')" icon rounded secondary @click="activeDialog = false">
<v-icon name="close" />
</v-button>
</template>
</pdf-viewer>
</v-dialog>
</div>
</template>

<script setup lang="ts">
import { inject, ref, computed } from 'vue';
import { inject, ref, computed, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { defaultButtonLabel } from './default-button-label';
import PdfViewer from './pdf-viewer.vue'
Expand All @@ -24,6 +24,7 @@
file_field?: string;
button_label?: string;
}>(), {

button_label: defaultButtonLabel
});

Expand All @@ -40,11 +41,32 @@
return fieldValues.value[props.file_field] ?? null;
});
const fileURL = computed(() => {
if (!fileID.value) return null;
return `/assets/${fileID.value}`;
if (!fileID.value || !fileID.value.id) return null;
return `/assets/${fileID.value.id}`;
});
const fileIsValid = computed(() => !!fileID.value);

return { fileURL, fileIsValid };
}
</script>

onMounted(() => {
const pdfContent = document.querySelector('.pdf-viewer-interface');
const parent = pdfContent?.closest('.drawer-item-order');
const htmlContent = pdfContent?.closest('.interface')?.closest('.field');

if (!parent || !htmlContent || !pdfContent) { return; }

pdfContent.classList.add('pb-32');
pdfContent.querySelector('button')?.classList.add('full-width');
parent?.insertBefore(htmlContent, parent.firstChild);
});
</script>

<style scoped>
.full-width {
width: 100%;
}
.pb-32 {
padding-bottom: 32px;
}
</style>