TicketObjectAttributes.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 { useTicketAccountedTime } from '#shared/entities/ticket/composables/useTicketAccountedTime.ts'
  5. import type { TicketById } from '#shared/entities/ticket/types.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 { timeAccountingDisplayUnit, timeAccountingConfig } =
  16. useTicketAccountedTime()
  17. const isShown = toRef(() => Boolean(ticketData.value.timeUnit))
  18. const showAll = ref(false)
  19. const MIN_SHOWN = 3
  20. const allUnits = computed(() => {
  21. if (!timeAccountingConfig.value.time_accounting_types) return []
  22. if (
  23. props.ticket.timeUnitsPerType &&
  24. props.ticket.timeUnitsPerType.length === 1 &&
  25. props.ticket.timeUnitsPerType[0].name === 'None'
  26. ) {
  27. return []
  28. }
  29. return props.ticket.timeUnitsPerType || []
  30. })
  31. const shownUnits = computed(() => {
  32. if (showAll.value) return allUnits.value
  33. return allUnits.value.slice(0, MIN_SHOWN)
  34. })
  35. </script>
  36. <template>
  37. <CommonSectionMenu v-if="isShown">
  38. <CommonSectionMenuItem
  39. v-if="ticketData.timeUnit"
  40. :label="__('Total Accounted Time')"
  41. >
  42. {{ ticketData.timeUnit }}
  43. {{ $t(timeAccountingDisplayUnit) }}
  44. </CommonSectionMenuItem>
  45. <CommonSectionMenuItem
  46. v-if="allUnits.length"
  47. data-test-id="timeUnitsEntries"
  48. >
  49. <div class="grid grid-cols-[1fr_auto_auto] py-2" role="list">
  50. <template
  51. v-for="({ name, timeUnit }, index) of shownUnits"
  52. :key="index"
  53. >
  54. <div class="col-[1] truncate text-white/80 ltr:mr-2 rtl:ml-2">
  55. {{ capitalize($t(name)) }}
  56. </div>
  57. <div>{{ timeUnit }} {{ $t(timeAccountingDisplayUnit) }}</div>
  58. </template>
  59. </div>
  60. </CommonSectionMenuItem>
  61. <CommonShowMoreButton
  62. :entities="shownUnits"
  63. :total-count="allUnits.length"
  64. @click="showAll = true"
  65. />
  66. </CommonSectionMenu>
  67. </template>