PersonnalizedList.vue 2.6 KB

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