PersonnalizedList.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <main>
  3. <a id="activator" ref="btn">
  4. {{ $t('my_list') }}
  5. </a>
  6. <v-menu
  7. :activator="btn"
  8. offset="10"
  9. min-width="440"
  10. :close-on-content-click="false"
  11. >
  12. <v-card
  13. v-if="collection.totalItems === 0"
  14. height="80"
  15. width="440"
  16. class="pa-4"
  17. >
  18. <v-card-text class="ma-0 pa-0 header_menu">
  19. {{ $t('nothing_to_show') }}
  20. </v-card-text>
  21. </v-card>
  22. <v-card v-else width="440">
  23. <v-card-title class="text-body-2 header-personalized">
  24. <v-text-field
  25. v-model="search"
  26. :label="$t('searchList')"
  27. :loading="status == FETCHING_STATUS.PENDING"
  28. density="compact"
  29. clear-icon="header-personalized"
  30. />
  31. </v-card-title>
  32. <v-card-text class="ma-0 pa-0 mt-n3 header_menu">
  33. <v-list density="compact" :subheader="true">
  34. <v-list-item
  35. v-for="(item, index) in filteredItems"
  36. :key="index"
  37. :value="item"
  38. :href="getListURL(item)"
  39. exact
  40. >
  41. <strong>{{ item.menuKey }}</strong> - {{ item.label }}
  42. </v-list-item>
  43. </v-list>
  44. </v-card-text>
  45. </v-card>
  46. </v-menu>
  47. </main>
  48. </template>
  49. <script setup lang="ts">
  50. import { ref } from 'vue'
  51. import type { ComputedRef, Ref } from 'vue'
  52. import PersonalizedList from '~/models/Access/PersonalizedList'
  53. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  54. import type { AnyJson } from '~/types/data'
  55. import type ApiResource from '~/models/ApiResource'
  56. import UrlUtils from '~/services/utils/urlUtils'
  57. import { FETCHING_STATUS } from '~/types/enum/data'
  58. const btn: Ref = ref(null)
  59. const { fetchCollection } = useEntityFetch()
  60. const { data: collection, status } = fetchCollection(PersonalizedList)
  61. const i18n = useI18n()
  62. const items: ComputedRef<Array<AnyJson>> = computed(() => {
  63. const lists: Array<ApiResource> =
  64. collection.value !== null ? collection.value.items : []
  65. lists.map((item) => {
  66. item.menuKey = i18n.t(item.menuKey) as string
  67. })
  68. return lists
  69. })
  70. const search = ref('')
  71. const filteredItems = computed(() => {
  72. return items.value.filter((item) => {
  73. return (
  74. !search.value ||
  75. item.label.toLowerCase().includes(search.value.toLowerCase()) ||
  76. item.menuKey.toLowerCase().includes(search.value.toLowerCase())
  77. )
  78. })
  79. })
  80. const runtimeConfig = useRuntimeConfig()
  81. const homeUrl: string = runtimeConfig.baseUrlAdminLegacy
  82. const getListURL = (list: PersonalizedList) => {
  83. return UrlUtils.join(homeUrl, '#', list.entity ?? '', 'list', list.id ?? '')
  84. }
  85. </script>
  86. <style scoped lang="scss">
  87. #activator {
  88. cursor: pointer;
  89. }
  90. #activator:hover {
  91. color: rgb(var(--var-theme-on-neutral)) !important;
  92. }
  93. .header-personalized {
  94. margin-bottom: 0;
  95. padding-bottom: 0;
  96. }
  97. </style>