PersonnalizedList.vue 2.7 KB

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