PersonnalizedList.vue 2.8 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. 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 {ComputedRef, Ref, ref} from "@vue/reactivity";
  48. import {AnyJson} from "~/types/data";
  49. import ApiResource from "~/models/ApiResource";
  50. import UrlUtils from "~/services/utils/urlUtils";
  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 UrlUtils.join(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>