PersonnalizedList.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. <v-list-item-title>
  37. {{item.label}} - <strong>{{item.menuKey}}</strong>
  38. </v-list-item-title>
  39. </v-list-item>
  40. </v-list>
  41. </v-card-text>
  42. </v-card>
  43. </v-menu>
  44. </main>
  45. </template>
  46. <script setup lang="ts">
  47. import PersonalizedList from '~/models/Access/PersonalizedList'
  48. import {useEntityFetch} from "~/composables/data/useEntityFetch";
  49. import {ComputedRef, Ref, ref} from "@vue/reactivity";
  50. import {AnyJson} from "~/types/data";
  51. import ApiResource from "~/models/ApiResource";
  52. import UrlUtils from "~/services/utils/urlUtils";
  53. const btn: Ref = ref(null)
  54. const { fetch, fetchCollection } = useEntityFetch()
  55. const { data: collection, pending } = await fetchCollection(PersonalizedList)
  56. const i18n = useI18n()
  57. const items: ComputedRef<Array<AnyJson>> = computed(() => {
  58. const lists: Array<ApiResource> = collection.value !== null ? collection.value.items : []
  59. lists.map(item => {
  60. item.menuKey = i18n.t(item.menuKey) as string
  61. })
  62. return lists
  63. })
  64. const search = ref('');
  65. const filteredItems = computed(() => {
  66. return items.value.filter( item => {
  67. return !search.value ||
  68. item.label.toLowerCase().indexOf(search.value.toLowerCase()) >= 0 ||
  69. item.menuKey.toLowerCase().indexOf(search.value.toLowerCase()) >= 0
  70. }
  71. )
  72. })
  73. const runtimeConfig = useRuntimeConfig()
  74. const homeUrl: string = runtimeConfig.baseUrlAdminLegacy
  75. const getListURL = (list: PersonalizedList) => {
  76. return UrlUtils.join(homeUrl, '#', list.entity ?? '', 'list', list.id ?? '')
  77. }
  78. </script>
  79. <style scoped lang="scss">
  80. #activator {
  81. cursor: pointer;
  82. }
  83. #activator:hover {
  84. color: rgb(var(--var-theme-on-neutral)) !important;
  85. }
  86. .header-personalized {
  87. margin-bottom: 0;
  88. padding-bottom: 0;
  89. }
  90. </style>