TicketObjectAttributes.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, toRef, ref } from 'vue'
  4. import type { TicketById } from '#shared/entities/ticket/types.ts'
  5. import { useApplicationStore } from '#shared/stores/application.ts'
  6. import { capitalize } from '#shared/utils/formatter.ts'
  7. import CommonSectionMenu from '#mobile/components/CommonSectionMenu/CommonSectionMenu.vue'
  8. import CommonSectionMenuItem from '#mobile/components/CommonSectionMenu/CommonSectionMenuItem.vue'
  9. import CommonShowMoreButton from '#mobile/components/CommonShowMoreButton/CommonShowMoreButton.vue'
  10. interface Props {
  11. ticket: TicketById
  12. }
  13. const props = defineProps<Props>()
  14. const ticketData = toRef(props, 'ticket')
  15. const application = useApplicationStore()
  16. const timeAccountingDisplayUnit = computed(() => {
  17. switch (application.config.time_accounting_unit) {
  18. case 'hour':
  19. return __('hour(s)')
  20. case 'quarter':
  21. return __('quarter-hour(s)')
  22. case 'minute':
  23. return __('minute(s)')
  24. case 'custom':
  25. return application.config.time_accounting_unit_custom
  26. default:
  27. return ''
  28. }
  29. })
  30. const isShown = toRef(() => Boolean(ticketData.value.timeUnit))
  31. const showAll = ref(false)
  32. const MIN_SHOWN = 3
  33. const allUnits = computed(() => {
  34. if (!application.config.time_accounting_types) return []
  35. if (
  36. props.ticket.timeUnitsPerType &&
  37. props.ticket.timeUnitsPerType.length === 1 &&
  38. props.ticket.timeUnitsPerType[0].name === 'None'
  39. ) {
  40. return []
  41. }
  42. return props.ticket.timeUnitsPerType || []
  43. })
  44. const shownUnits = computed(() => {
  45. if (showAll.value) return allUnits.value
  46. return allUnits.value.slice(0, MIN_SHOWN)
  47. })
  48. </script>
  49. <template>
  50. <CommonSectionMenu v-if="isShown">
  51. <CommonSectionMenuItem
  52. v-if="ticketData.timeUnit"
  53. :label="__('Total Accounted Time')"
  54. >
  55. {{ ticketData.timeUnit }}
  56. {{ $t(timeAccountingDisplayUnit) }}
  57. </CommonSectionMenuItem>
  58. <CommonSectionMenuItem
  59. v-if="allUnits.length"
  60. data-test-id="timeUnitsEntries"
  61. >
  62. <div class="grid grid-cols-[1fr_auto_auto] py-2" role="list">
  63. <template
  64. v-for="({ name, timeUnit }, index) of shownUnits"
  65. :key="index"
  66. >
  67. <div class="col-[1] truncate text-white/80 ltr:mr-2 rtl:ml-2">
  68. {{ capitalize($t(name)) }}
  69. </div>
  70. <div>{{ timeUnit }} {{ $t(timeAccountingDisplayUnit) }}</div>
  71. </template>
  72. </div>
  73. </CommonSectionMenuItem>
  74. <CommonShowMoreButton
  75. :entities="shownUnits"
  76. :total-count="allUnits.length"
  77. @click="showAll = true"
  78. />
  79. </CommonSectionMenu>
  80. </template>