Search.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <div id="search" class="col-11">
  3. <form class="search-form row">
  4. <fieldset class="search">
  5. <div>
  6. <label for="keys">Search</label>
  7. <input
  8. id="keys"
  9. v-model="keys"
  10. type="text"
  11. placeholder="search"
  12. @keydown.enter.prevent="submit"
  13. >
  14. <v-select
  15. id="search-type"
  16. type="select"
  17. placeholder="dans ..."
  18. append-to-body
  19. :calculate-position="dropDownMenuPos"
  20. :options="searchTypeOptions"
  21. :clearable="false"
  22. :value="searchTypeValue"
  23. @input="onSearchTypeSelected"
  24. />
  25. </div>
  26. <span
  27. v-if="!isloading"
  28. class="mdi mdi-magnify"
  29. title="rechercher"
  30. @click.prevent="submit"
  31. @keydown.enter.prevent="submit"
  32. />
  33. <span
  34. v-else
  35. class="mdi mdi-loading"
  36. title="chargement"
  37. />
  38. </fieldset>
  39. <fieldset v-if="filters.persons.length" class="filters filters-nominum col-2">
  40. <v-select
  41. id="filters-nominum"
  42. type="select"
  43. placeholder="filtrer par personne"
  44. append-to-body
  45. :calculate-position="dropDownMenuPos"
  46. :options="personsOptions"
  47. :value="activeFilters.persons"
  48. multiple
  49. @input="onFiltersNominumSelected"
  50. />
  51. </fieldset>
  52. <fieldset v-if="filters.places.length" class="filters filters-locorum col-2">
  53. <v-select
  54. id="filters-locorum"
  55. type="select"
  56. placeholder="filtrer par lieux"
  57. append-to-body
  58. :calculate-position="dropDownMenuPos"
  59. :options="placesOptions"
  60. :value="activeFilters.places"
  61. multiple
  62. @input="onFiltersLocorumSelected"
  63. />
  64. </fieldset>
  65. <fieldset v-if="filters.objects.length" class="filters filters-operum col-2">
  66. <v-select
  67. id="filters-operum"
  68. type="select"
  69. placeholder="filtrer par objet"
  70. append-to-body
  71. :calculate-position="dropDownMenuPos"
  72. :options="objectsOptions"
  73. :value="activeFilters.objects"
  74. multiple
  75. @input="onFiltersOperumSelected"
  76. />
  77. </fieldset>
  78. </form>
  79. </div>
  80. </template>
  81. <script>
  82. import { createPopper } from '@popperjs/core'
  83. import { mapActions, mapState } from 'vuex'
  84. export default {
  85. name: 'Search',
  86. data: () => ({
  87. }),
  88. computed: {
  89. keys: {
  90. get () { return this.$store.state.Search.keys },
  91. set (value) { this.$store.commit('Search/setKeys', value) }
  92. },
  93. ...mapState({
  94. isloading: state => state.Search.isloading,
  95. searchTypeOptions: state => state.Search.searchTypeOptions,
  96. searchTypeValue: state => state.Search.searchTypeValue,
  97. filters: state => state.Search.filters,
  98. activeFilters: state => state.Search.activeFilters
  99. }),
  100. personsOptions () {
  101. return this.filters.persons.filter(option => !this.activeFilters.persons.includes(option))
  102. },
  103. placesOptions () {
  104. return this.filters.places.filter(option => !this.activeFilters.places.includes(option))
  105. },
  106. objectsOptions () {
  107. return this.filters.objects.filter(option => !this.activeFilters.objects.includes(option))
  108. }
  109. },
  110. methods: {
  111. ...mapActions({
  112. newSearch: 'Search/newSearch',
  113. setSearchTypeValue: 'Search/setSearchTypeValue',
  114. setSearchActiveFilters: 'Search/setSearchActiveFilters'
  115. }),
  116. submit () {
  117. console.log('submited', this.keys)
  118. this.newSearch()
  119. },
  120. dropDownMenuPos (dropdownList, component, { width }) {
  121. /**
  122. * We need to explicitly define the dropdown width since
  123. * it is usually inherited from the parent with CSS.
  124. */
  125. dropdownList.style.width = width
  126. /**
  127. * Here we position the dropdownList relative to the $refs.toggle Element.
  128. *
  129. * The 'offset' modifier aligns the dropdown so that the $refs.toggle and
  130. * the dropdownList overlap by 1 pixel.
  131. *
  132. * The 'toggleClass' modifier adds a 'drop-up' class to the Vue Select
  133. * wrapper so that we can set some styles for when the dropdown is placed
  134. * above.
  135. */
  136. const popper = createPopper(component.$refs.toggle, dropdownList, {
  137. placement: 'top',
  138. modifiers: [
  139. {
  140. name: 'offset',
  141. options: {
  142. offset: [0, -1]
  143. }
  144. },
  145. {
  146. name: 'toggleClass',
  147. enabled: true,
  148. phase: 'write',
  149. fn ({ state }) {
  150. component.$el.classList.toggle('drop-up', state.placement === 'top')
  151. }
  152. }]
  153. })
  154. /**
  155. * To prevent memory leaks Popper needs to be destroyed.
  156. * If you return function, it will be called just before dropdown is removed from DOM.
  157. */
  158. return () => popper.destroy()
  159. },
  160. onSearchTypeSelected (e) {
  161. console.log('onSearchTypeSelected', e)
  162. this.setSearchTypeValue(e)
  163. },
  164. onFiltersNominumSelected (e) {
  165. console.log('onFiltersNominumSelected', e)
  166. this.setSearchActiveFilters({ index: 'persons', value: e })
  167. },
  168. onFiltersLocorumSelected (e) {
  169. console.log('onFiltersLocorumSelected', e)
  170. this.setSearchActiveFilters({ index: 'places', value: e })
  171. },
  172. onFiltersOperumSelected (e) {
  173. console.log('onFiltersOperumSelected', e)
  174. this.setSearchActiveFilters({ index: 'objects', value: e })
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. </style>