Search.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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.texts.length" class="filters filters-texts small-col-4 med-col-2 large-col-2">
  40. <v-select
  41. id="filters-texts"
  42. type="select"
  43. placeholder="filtrer par texte"
  44. append-to-body
  45. :calculate-position="dropDownMenuPos"
  46. :options="textsOptions"
  47. :value="activeFilters.texts"
  48. @input="onFiltersTextSelected"
  49. />
  50. </fieldset>
  51. <fieldset v-if="filters.persons.length" class="filters filters-nominum small-col-4 med-col-2 large-col-2">
  52. <v-select
  53. id="filters-nominum"
  54. type="select"
  55. placeholder="filtrer par personne"
  56. append-to-body
  57. :calculate-position="dropDownMenuPos"
  58. :options="personsOptions"
  59. :value="activeFilters.persons"
  60. multiple
  61. @input="onFiltersNominumSelected"
  62. />
  63. </fieldset>
  64. <fieldset v-if="filters.places.length" class="filters filters-locorum small-col-4 med-col-2 large-col-2">
  65. <v-select
  66. id="filters-locorum"
  67. type="select"
  68. placeholder="filtrer par lieux"
  69. append-to-body
  70. :calculate-position="dropDownMenuPos"
  71. :options="placesOptions"
  72. :value="activeFilters.places"
  73. multiple
  74. @input="onFiltersLocorumSelected"
  75. />
  76. </fieldset>
  77. <fieldset v-if="filters.objects.length" class="filters filters-operum small-col-4 med-col-2 large-col-2">
  78. <v-select
  79. id="filters-operum"
  80. type="select"
  81. placeholder="filtrer par objet"
  82. append-to-body
  83. :calculate-position="dropDownMenuPos"
  84. :options="objectsOptions"
  85. :value="activeFilters.objects"
  86. multiple
  87. @input="onFiltersOperumSelected"
  88. />
  89. </fieldset>
  90. </form>
  91. </div>
  92. </template>
  93. <script>
  94. import { createPopper } from '@popperjs/core'
  95. import { mapActions, mapMutations, mapState } from 'vuex'
  96. export default {
  97. name: 'Search',
  98. data: () => ({
  99. }),
  100. computed: {
  101. // TODO: do not synch keys instantetly (infinite loading will drop)
  102. keys: {
  103. get () { return this.$store.state.Search.keys },
  104. set (value) { this.$store.commit('Search/setKeys', value) }
  105. },
  106. ...mapState({
  107. isloading: state => state.Search.isloading,
  108. searchTypeOptions: state => state.Search.searchTypeOptions,
  109. searchTypeValue: state => state.Search.searchTypeValue,
  110. filters: state => state.Search.filters,
  111. activeFilters: state => state.Search.activeFilters,
  112. corpusLoaded: state => state.Corpus.corpusLoaded
  113. }),
  114. personsOptions () {
  115. return this.filters.persons.filter(option => !this.activeFilters.persons.includes(option))
  116. },
  117. placesOptions () {
  118. return this.filters.places.filter(option => !this.activeFilters.places.includes(option))
  119. },
  120. objectsOptions () {
  121. return this.filters.objects.filter(option => !this.activeFilters.objects.includes(option))
  122. },
  123. textsOptions () {
  124. return this.filters.texts.filter(option => !this.activeFilters.texts.includes(option))
  125. }
  126. },
  127. methods: {
  128. ...mapMutations({
  129. setSearchTypeValue: 'Search/setSearchTypeValue',
  130. setActiveFilters: 'Search/setActiveFilters'
  131. }),
  132. ...mapActions({
  133. newSearch: 'Search/newSearch',
  134. updateSearch: 'Search/updateSearch'
  135. }),
  136. submit () {
  137. // console.log('submited', this.keys)
  138. this.newSearch()
  139. },
  140. dropDownMenuPos (dropdownList, component, { width }) {
  141. /**
  142. * We need to explicitly define the dropdown width since
  143. * it is usually inherited from the parent with CSS.
  144. */
  145. dropdownList.style.width = width
  146. /**
  147. * Here we position the dropdownList relative to the $refs.toggle Element.
  148. *
  149. * The 'offset' modifier aligns the dropdown so that the $refs.toggle and
  150. * the dropdownList overlap by 1 pixel.
  151. *
  152. * The 'toggleClass' modifier adds a 'drop-up' class to the Vue Select
  153. * wrapper so that we can set some styles for when the dropdown is placed
  154. * above.
  155. */
  156. const popper = createPopper(component.$refs.toggle, dropdownList, {
  157. placement: 'top',
  158. modifiers: [
  159. {
  160. name: 'offset',
  161. options: {
  162. offset: [0, -1]
  163. }
  164. },
  165. {
  166. name: 'toggleClass',
  167. enabled: true,
  168. phase: 'write',
  169. fn ({ state }) {
  170. component.$el.classList.toggle('drop-up', state.placement === 'top')
  171. }
  172. }]
  173. })
  174. /**
  175. * To prevent memory leaks Popper needs to be destroyed.
  176. * If you return function, it will be called just before dropdown is removed from DOM.
  177. */
  178. return () => popper.destroy()
  179. },
  180. onSearchTypeSelected (e) {
  181. console.log('onSearchTypeSelected', e)
  182. this.setSearchTypeValue(e)
  183. },
  184. onFiltersNominumSelected (e) {
  185. console.log('onFiltersNominumSelected', e)
  186. this.setActiveFilters({ filter: 'persons', value: e })
  187. this.updateSearch()
  188. },
  189. onFiltersLocorumSelected (e) {
  190. console.log('onFiltersLocorumSelected', e)
  191. this.setActiveFilters({ filter: 'places', value: e })
  192. this.updateSearch()
  193. },
  194. onFiltersOperumSelected (e) {
  195. console.log('onFiltersOperumSelected', e)
  196. this.setActiveFilters({ filter: 'objects', value: e })
  197. this.updateSearch()
  198. },
  199. onFiltersTextSelected (e) {
  200. console.log('onFiltersTextSelected', e)
  201. // as texts is not multiple, convert one object value to array [e]
  202. this.setActiveFilters({ filter: 'texts', value: e ? [e] : [] })
  203. this.updateSearch()
  204. }
  205. }
  206. }
  207. </script>
  208. <style lang="scss" scoped>
  209. </style>