PersonnalizedList.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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="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. const btn: Ref = ref(null)
  58. const { fetchCollection } = useEntityFetch()
  59. const { data: collection, pending } = fetchCollection(PersonalizedList)
  60. const i18n = useI18n()
  61. const items: ComputedRef<Array<AnyJson>> = computed(() => {
  62. const lists: Array<ApiResource> =
  63. collection.value !== null ? collection.value.items : []
  64. lists.map((item) => {
  65. item.menuKey = i18n.t(item.menuKey) as string
  66. })
  67. return lists
  68. })
  69. const search = ref('')
  70. const filteredItems = computed(() => {
  71. return items.value.filter((item) => {
  72. return (
  73. !search.value ||
  74. item.label.toLowerCase().includes(search.value.toLowerCase()) ||
  75. item.menuKey.toLowerCase().includes(search.value.toLowerCase())
  76. )
  77. })
  78. })
  79. const runtimeConfig = useRuntimeConfig()
  80. const homeUrl: string = runtimeConfig.baseUrlAdminLegacy
  81. const getListURL = (list: PersonalizedList) => {
  82. return UrlUtils.join(homeUrl, '#', list.entity ?? '', 'list', list.id ?? '')
  83. }
  84. </script>
  85. <style scoped lang="scss">
  86. #activator {
  87. cursor: pointer;
  88. }
  89. #activator:hover {
  90. color: rgb(var(--var-theme-on-neutral)) !important;
  91. }
  92. .header-personalized {
  93. margin-bottom: 0;
  94. padding-bottom: 0;
  95. }
  96. </style>