TicketSidebarAttachmentContent.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, toRef } from 'vue'
  4. import CommonFilePreview from '#shared/components/CommonFilePreview/CommonFilePreview.vue'
  5. import { useAttachments } from '#shared/composables/useAttachments.ts'
  6. import type { Attachment } from '#shared/entities/attachment/types.ts'
  7. import type { ObjectLike } from '#shared/types/utils.ts'
  8. import CommonLoader from '#desktop/components/CommonLoader/CommonLoader.vue'
  9. import { useFilePreviewViewer } from '#desktop/composables/useFilePreviewViewer.ts'
  10. import type { TicketSidebarContentProps } from '#desktop/pages/ticket/types/sidebar.ts'
  11. import TicketSidebarContent from '../TicketSidebarContent.vue'
  12. interface Props extends TicketSidebarContentProps {
  13. ticketAttachments: Attachment[]
  14. loading: boolean
  15. }
  16. const props = defineProps<Props>()
  17. const persistentStates = defineModel<ObjectLike>({ required: true })
  18. const { attachments: attachmentsWithUrls } = useAttachments({
  19. attachments: toRef(props, 'ticketAttachments'),
  20. })
  21. const { showPreview } = useFilePreviewViewer(
  22. computed(() => attachmentsWithUrls.value),
  23. )
  24. </script>
  25. <template>
  26. <TicketSidebarContent
  27. v-model="persistentStates.scrollPosition"
  28. :title="sidebarPlugin.title"
  29. :icon="sidebarPlugin.icon"
  30. >
  31. <CommonLoader :loading="loading">
  32. <div
  33. v-if="ticketAttachments && ticketAttachments.length > 0"
  34. class="flex flex-col rounded-lg bg-blue-200 p-1 text-gray-100 dark:bg-gray-700 dark:text-neutral-400"
  35. >
  36. <CommonFilePreview
  37. v-for="attachment of attachmentsWithUrls"
  38. :key="attachment.internalId"
  39. :download-url="attachment.downloadUrl"
  40. :preview-url="attachment.preview"
  41. :file="attachment"
  42. :no-preview="!$c.ui_ticket_zoom_attachments_preview"
  43. no-remove
  44. @preview="($event, type) => showPreview(type, attachment)"
  45. />
  46. </div>
  47. <CommonLabel v-else>
  48. {{ $t('No attached files') }}
  49. </CommonLabel>
  50. </CommonLoader>
  51. </TicketSidebarContent>
  52. </template>