PersonnalizedList.vue 2.9 KB

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