CommonCalendarPreviewFlyout.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import { getAttachmentLinks } from '#shared/composables/getAttachmentLinks.ts'
  5. import { getIdFromGraphQLId } from '#shared/graphql/utils.ts'
  6. import QueryHandler from '#shared/server/apollo/handler/QueryHandler.ts'
  7. import { useApplicationStore } from '#shared/stores/application.ts'
  8. import getUuid from '#shared/utils/getUuid.ts'
  9. import openExternalLink from '#shared/utils/openExternalLink.ts'
  10. import CommonFlyout from '#desktop/components/CommonFlyout/CommonFlyout.vue'
  11. import CommonLoader from '#desktop/components/CommonLoader/CommonLoader.vue'
  12. import CommonSimpleTable from '#desktop/components/CommonSimpleTable/CommonSimpleTable.vue'
  13. import type { TableHeader } from '#desktop/components/CommonSimpleTable/types.ts'
  14. import { useCalendarIcsFileEventsQuery } from '#desktop/entities/calendar/ics-file/graphql/queries/events.api.ts'
  15. interface Props {
  16. fileId: string
  17. fileType: string
  18. fileName: string
  19. }
  20. const props = defineProps<Props>()
  21. const calendarEventsQuery = new QueryHandler(
  22. useCalendarIcsFileEventsQuery({
  23. fileId: props.fileId,
  24. }),
  25. )
  26. const calendarEventsQueryResult = calendarEventsQuery.result()
  27. const calendarEventsQueryLoading = calendarEventsQuery.loading()
  28. const tableHeaders: TableHeader[] = [
  29. {
  30. key: 'summary',
  31. label: __('Event Summary'),
  32. },
  33. {
  34. key: 'location',
  35. label: __('Event Location'),
  36. },
  37. {
  38. key: 'start',
  39. label: __('Event Starting'),
  40. type: 'timestamp_absolute',
  41. },
  42. {
  43. key: 'end',
  44. label: __('Event Ending'),
  45. type: 'timestamp_absolute',
  46. },
  47. ]
  48. const tableItems = computed(() => {
  49. if (!calendarEventsQueryResult.value?.calendarIcsFileEvents) return []
  50. return calendarEventsQueryResult.value?.calendarIcsFileEvents.map(
  51. (event) => ({
  52. id: getUuid(),
  53. summary: event.title,
  54. location: event.location,
  55. start: event.startDate,
  56. end: event.endDate,
  57. }),
  58. )
  59. })
  60. const downloadCalendar = () => {
  61. const application = useApplicationStore()
  62. const { downloadUrl } = getAttachmentLinks(
  63. {
  64. internalId: getIdFromGraphQLId(props.fileId),
  65. type: props.fileType,
  66. },
  67. application.config.api_path,
  68. )
  69. openExternalLink(downloadUrl, '_blank', props.fileName)
  70. }
  71. </script>
  72. <template>
  73. <CommonFlyout
  74. :header-title="__('Preview Calendar')"
  75. :footer-action-options="{
  76. actionLabel: __('Download'),
  77. actionButton: { variant: 'primary' },
  78. }"
  79. name="common-calendar-preview"
  80. no-close-on-action
  81. @action="downloadCalendar"
  82. >
  83. <CommonLoader :loading="calendarEventsQueryLoading">
  84. <CommonSimpleTable
  85. class="mb-4 w-full"
  86. :headers="tableHeaders"
  87. :items="tableItems"
  88. />
  89. </CommonLoader>
  90. </CommonFlyout>
  91. </template>