Search.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <div id="search" class="col-11" :class="{ loading: isloading }">
  3. <form class="search-form row">
  4. <fieldset class="search small-col-10 med-col-2 large-col-2">
  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 small-col-4 med-col-2 large-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 small-col-4 med-col-2 large-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 small-col-4 med-col-2 large-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, mapMutations, mapState } from 'vuex'
  84. export default {
  85. name: 'Search',
  86. data: () => ({
  87. }),
  88. computed: {
  89. // TODO: do not synch keys instantetly (infinite loading will drop)
  90. keys: {
  91. get () { return this.$store.state.Search.keys },
  92. set (value) { this.$store.commit('Search/setKeys', value) }
  93. },
  94. ...mapState({
  95. isloading: state => state.Search.isloading,
  96. searchTypeOptions: state => state.Search.searchTypeOptions,
  97. searchTypeValue: state => state.Search.searchTypeValue,
  98. filters: state => state.Search.filters,
  99. activeFilters: state => state.Search.activeFilters,
  100. corpusLoaded: state => state.Corpus.corpusLoaded
  101. }),
  102. personsOptions () {
  103. return this.filters.persons.filter(option => !this.activeFilters.persons.includes(option))
  104. },
  105. placesOptions () {
  106. return this.filters.places.filter(option => !this.activeFilters.places.includes(option))
  107. },
  108. objectsOptions () {
  109. return this.filters.objects.filter(option => !this.activeFilters.objects.includes(option))
  110. }
  111. },
  112. methods: {
  113. ...mapMutations({
  114. setSearchTypeValue: 'Search/setSearchTypeValue',
  115. setActiveFilters: 'Search/setActiveFilters'
  116. }),
  117. ...mapActions({
  118. newSearch: 'Search/newSearch',
  119. updateSearch: 'Search/updateSearch'
  120. }),
  121. submit () {
  122. // console.log('submited', this.keys)
  123. this.newSearch()
  124. },
  125. dropDownMenuPos (dropdownList, component, { width }) {
  126. /**
  127. * We need to explicitly define the dropdown width since
  128. * it is usually inherited from the parent with CSS.
  129. */
  130. dropdownList.style.width = width
  131. /**
  132. * Here we position the dropdownList relative to the $refs.toggle Element.
  133. *
  134. * The 'offset' modifier aligns the dropdown so that the $refs.toggle and
  135. * the dropdownList overlap by 1 pixel.
  136. *
  137. * The 'toggleClass' modifier adds a 'drop-up' class to the Vue Select
  138. * wrapper so that we can set some styles for when the dropdown is placed
  139. * above.
  140. */
  141. const popper = createPopper(component.$refs.toggle, dropdownList, {
  142. placement: 'top',
  143. modifiers: [
  144. {
  145. name: 'offset',
  146. options: {
  147. offset: [0, -1]
  148. }
  149. },
  150. {
  151. name: 'toggleClass',
  152. enabled: true,
  153. phase: 'write',
  154. fn ({ state }) {
  155. component.$el.classList.toggle('drop-up', state.placement === 'top')
  156. }
  157. }]
  158. })
  159. /**
  160. * To prevent memory leaks Popper needs to be destroyed.
  161. * If you return function, it will be called just before dropdown is removed from DOM.
  162. */
  163. return () => popper.destroy()
  164. },
  165. onSearchTypeSelected (e) {
  166. console.log('onSearchTypeSelected', e)
  167. this.setSearchTypeValue(e)
  168. },
  169. onFiltersNominumSelected (e) {
  170. console.log('onFiltersNominumSelected', e)
  171. this.setActiveFilters({ index: 'persons', value: e })
  172. this.updateSearch()
  173. },
  174. onFiltersLocorumSelected (e) {
  175. console.log('onFiltersLocorumSelected', e)
  176. this.setActiveFilters({ index: 'places', value: e })
  177. this.updateSearch()
  178. },
  179. onFiltersOperumSelected (e) {
  180. console.log('onFiltersOperumSelected', e)
  181. this.setActiveFilters({ index: 'objects', value: e })
  182. this.updateSearch()
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. </style>