PersonnalizedList.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <main>
  3. <a ref="btn">
  4. {{ $t('my_list') }}
  5. </a>
  6. <v-menu
  7. :activator="btn"
  8. :model-value="showMenu"
  9. location="start"
  10. :close-on-content-click="false"
  11. min-width="500"
  12. @update:modelValue="onMenuToggled($event)"
  13. >
  14. <v-card v-if="collection.totalItems === 0" height="80" class="pa-4">
  15. <v-card-text class="ma-0 pa-0 header_menu">
  16. {{ $t('nothing_to_show') }}
  17. </v-card-text>
  18. </v-card>
  19. <v-card v-else>
  20. <v-card-title class="text-body-2 header-personalized">
  21. <v-text-field
  22. v-model="search"
  23. :label="$t('searchList')"
  24. :loading="pending"
  25. density="compact"
  26. clear-icon="header-personalized"
  27. />
  28. </v-card-title>
  29. <v-card-text class="ma-0 pa-0 mt-n3 header_menu">
  30. <v-list density="compact" :subheader="true">
  31. <v-list-item
  32. v-for="(item, index) in filteredItems"
  33. :key="index"
  34. :value="item"
  35. :href="getListURL(item)"
  36. exact
  37. >
  38. <v-list-item-title>
  39. {{item.label}} - <strong>{{item.menuKey}}</strong>
  40. </v-list-item-title>
  41. </v-list-item>
  42. </v-list>
  43. </v-card-text>
  44. </v-card>
  45. </v-menu>
  46. </main>
  47. </template>
  48. <script setup lang="ts">
  49. import PersonalizedList from '~/models/Access/PersonalizedList'
  50. import {useEntityFetch} from "~/composables/data/useEntityFetch";
  51. import {ComputedRef, Ref, ref} from "@vue/reactivity";
  52. import {AnyJson} from "~/types/data";
  53. import ApiResource from "~/models/ApiResource";
  54. const btn: Ref = ref(null)
  55. const showMenu: Ref<boolean> = ref(false)
  56. const onMenuToggled = (event: any) => {
  57. showMenu.value = event
  58. }
  59. const { fetch, fetchCollection } = useEntityFetch()
  60. const { data: collection, pending } = await fetchCollection(PersonalizedList)
  61. const i18n = useI18n()
  62. const items: ComputedRef<Array<AnyJson>> = computed(() => {
  63. const lists: Array<ApiResource> = 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 !search.value ||
  73. item.label.toLowerCase().indexOf(search.value.toLowerCase()) >= 0 ||
  74. item.menuKey.toLowerCase().indexOf(search.value.toLowerCase()) >= 0
  75. }
  76. )
  77. })
  78. const runtimeConfig = useRuntimeConfig()
  79. const homeUrl: string = runtimeConfig.baseUrlAdminLegacy
  80. const getListURL = (list: PersonalizedList) => {
  81. return `${homeUrl}/${list.entity}/list/${list.id}`
  82. }
  83. </script>
  84. <style lang="scss">
  85. .header-personalized {
  86. margin-bottom: 0;
  87. padding-bottom: 0;
  88. }
  89. </style>