|
| 1 | +<template> |
| 2 | + <div class="flex"> |
| 3 | + <div class="flex-grow"> |
| 4 | + <h2>{{ title }}</h2> |
| 5 | + </div> |
| 6 | + <div class="flex-shrink-0"> |
| 7 | + <DropdownActions |
| 8 | + :actions="exportOptions" |
| 9 | + :label="t('editor.review.download')" |
| 10 | + @action="handleExport" |
| 11 | + /> |
| 12 | + </div> |
| 13 | + </div> |
| 14 | +</template> |
| 15 | +<script setup> |
| 16 | +import DropdownActions from '@/components/DropdownActions/DropdownActions.vue'; |
| 17 | +import {useLocalize} from '@/composables/useLocalize'; |
| 18 | +import {useApiUrl} from '@/composables/useApiUrl'; |
| 19 | +import {useFetch} from '@/composables/useFetch'; |
| 20 | +const props = defineProps({ |
| 21 | + title: {type: String, required: true}, |
| 22 | + submissionId: {type: String, required: true}, |
| 23 | + reviewRoundId: {type: String, required: true}, |
| 24 | + reviewAssignmentId: {type: String, required: true}, |
| 25 | + submissionStageId: {type: String, required: true}, |
| 26 | +}); |
| 27 | +
|
| 28 | +const {t} = useLocalize(); |
| 29 | +const exportOptions = [ |
| 30 | + { |
| 31 | + label: `${t('editor.review.authorOnly')} (PDF)`, |
| 32 | + name: 'authorPdf', |
| 33 | + }, |
| 34 | + { |
| 35 | + label: `${t('editor.review.authorOnly')} (XML)`, |
| 36 | + name: 'authorXml', |
| 37 | + }, |
| 38 | + { |
| 39 | + label: `${t('editor.review.allSections')} (PDF)`, |
| 40 | + name: 'editorPdf', |
| 41 | + }, |
| 42 | + { |
| 43 | + label: `${t('editor.review.allSections')} (XML)`, |
| 44 | + name: 'editorXml', |
| 45 | + }, |
| 46 | +]; |
| 47 | +
|
| 48 | +async function handleExport(name) { |
| 49 | + let op; |
| 50 | + let authorFriendly; |
| 51 | + switch (name) { |
| 52 | + case 'authorPdf': |
| 53 | + op = 'export-pdf'; |
| 54 | + authorFriendly = 1; |
| 55 | + break; |
| 56 | + case 'authorXml': |
| 57 | + op = 'export-xml'; |
| 58 | + authorFriendly = 1; |
| 59 | + break; |
| 60 | + case 'editorPdf': |
| 61 | + op = 'export-pdf'; |
| 62 | + authorFriendly = 0; |
| 63 | + break; |
| 64 | + case 'editorXml': |
| 65 | + op = 'export-xml'; |
| 66 | + authorFriendly = 0; |
| 67 | + break; |
| 68 | + } |
| 69 | +
|
| 70 | + const {apiUrl} = useApiUrl( |
| 71 | + `reviews/${props.submissionId}/${props.reviewAssignmentId}/${op}?authorFriendly=${authorFriendly}`, |
| 72 | + ); |
| 73 | +
|
| 74 | + const {data, fetch, isSuccess, validationError} = useFetch(apiUrl, { |
| 75 | + method: 'GET', |
| 76 | + expectValidationError: true, |
| 77 | + }); |
| 78 | + await fetch(); |
| 79 | + if (validationError.value) { |
| 80 | + pkp.eventBus.$emit('notify', validationError.value.error, 'warning'); |
| 81 | + } else if (isSuccess.value) { |
| 82 | + const anchor = document.createElement('a'); |
| 83 | + anchor.href = useApiUrl( |
| 84 | + `reviews/${props.submissionId}/exports/${data.value.temporaryFileId}`, |
| 85 | + ).apiUrl.value; |
| 86 | + document.body.appendChild(anchor); |
| 87 | + anchor.click(); |
| 88 | + document.body.removeChild(anchor); |
| 89 | + } |
| 90 | +} |
| 91 | +</script> |
0 commit comments