PersonnalizedList.vue 2.8 KB

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