admin-search.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template lang='pug'>
  2. v-card(tile, :color='$vuetify.dark ? "grey darken-4" : "grey lighten-5"')
  3. .pa-3.pt-4
  4. .headline.primary--text Search Engine
  5. .subheading.grey--text Configure the search capabilities of your wiki
  6. v-tabs(:color='$vuetify.dark ? "primary" : "grey lighten-4"', fixed-tabs, :slider-color='$vuetify.dark ? "white" : "primary"', show-arrows)
  7. v-tab(key='settings'): v-icon settings
  8. v-tab(v-for='engine in activeEngines', :key='engine.key') {{ engine.title }}
  9. v-tab-item(key='settings', :transition='false', :reverse-transition='false')
  10. v-card.pa-3(flat, tile)
  11. .body-2.grey--text.text--darken-1 Select which search engine to enable:
  12. .caption.grey--text.pb-2 Some search engines require additional configuration in their dedicated tab (when selected).
  13. v-form
  14. v-radio-group(v-model='selectedEngine')
  15. v-radio.my-1(
  16. v-for='(engine, n) in engines'
  17. :key='engine.key'
  18. :label='engine.title'
  19. :value='engine.key'
  20. color='primary'
  21. hide-details
  22. )
  23. v-tab-item(v-for='(engine, n) in activeEngines', :key='engine.key', :transition='false', :reverse-transition='false')
  24. v-card.pa-3(flat, tile)
  25. v-form
  26. .enginelogo
  27. img(:src='engine.logo', :alt='engine.title')
  28. v-subheader.pl-0 {{engine.title}}
  29. .caption {{engine.description}}
  30. .caption: a(:href='engine.website') {{engine.website}}
  31. v-divider.mt-3
  32. v-subheader.pl-0 Engine Configuration
  33. .body-1.ml-3(v-if='!engine.config || engine.config.length < 1') This engine has no configuration options you can modify.
  34. template(v-else, v-for='cfg in logger.config')
  35. v-select(
  36. v-if='cfg.value.type === "string" && cfg.value.enum'
  37. outline
  38. background-color='grey lighten-2'
  39. :items='cfg.value.enum'
  40. :key='cfg.key'
  41. :label='cfg.value.title'
  42. v-model='cfg.value.value'
  43. prepend-icon='settings_applications'
  44. :hint='cfg.value.hint ? cfg.value.hint : ""'
  45. persistent-hint
  46. :class='cfg.value.hint ? "mb-2" : ""'
  47. )
  48. v-switch(
  49. v-else-if='cfg.value.type === "boolean"'
  50. :key='cfg.key'
  51. :label='cfg.value.title'
  52. v-model='cfg.value.value'
  53. color='primary'
  54. prepend-icon='settings_applications'
  55. :hint='cfg.value.hint ? cfg.value.hint : ""'
  56. persistent-hint
  57. )
  58. v-text-field(
  59. v-else
  60. outline
  61. background-color='grey lighten-2'
  62. :key='cfg.key'
  63. :label='cfg.value.title'
  64. v-model='cfg.value.value'
  65. prepend-icon='settings_applications'
  66. :hint='cfg.value.hint ? cfg.value.hint : ""'
  67. persistent-hint
  68. :class='cfg.value.hint ? "mb-2" : ""'
  69. )
  70. v-card-chin
  71. v-btn(color='primary', @click='save')
  72. v-icon(left) chevron_right
  73. span Apply Configuration
  74. v-btn(color='black', dark)
  75. v-icon(left) refresh
  76. | Rebuild Index
  77. v-spacer
  78. v-btn(icon, @click='refresh')
  79. v-icon.grey--text refresh
  80. </template>
  81. <script>
  82. import _ from 'lodash'
  83. import enginesQuery from 'gql/admin/search/search-query-engines.gql'
  84. import enginesSaveMutation from 'gql/admin/search/search-mutation-save-engines.gql'
  85. export default {
  86. data() {
  87. return {
  88. engines: [],
  89. selectedEngine: 'db'
  90. }
  91. },
  92. computed: {
  93. activeEngines() {
  94. return _.filter(this.engines, 'isEnabled')
  95. }
  96. },
  97. watch: {
  98. selectedEngine(newValue, oldValue) {
  99. this.engines.forEach(engine => {
  100. if (engine.key === newValue) {
  101. engine.isEnabled = true
  102. } else {
  103. engine.isEnabled = false
  104. }
  105. })
  106. }
  107. },
  108. methods: {
  109. async refresh() {
  110. await this.$apollo.queries.engines.refetch()
  111. this.$store.commit('showNotification', {
  112. message: 'List of search engines has been refreshed.',
  113. style: 'success',
  114. icon: 'cached'
  115. })
  116. },
  117. async save() {
  118. this.$store.commit(`loadingStart`, 'admin-search-saveengines')
  119. await this.$apollo.mutate({
  120. mutation: enginesSaveMutation,
  121. variables: {
  122. engines: this.engines.map(tgt => _.pick(tgt, [
  123. 'isEnabled',
  124. 'key',
  125. 'config'
  126. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: cfg.value.value}))}))
  127. }
  128. })
  129. this.$store.commit('showNotification', {
  130. message: 'Logging configuration saved successfully.',
  131. style: 'success',
  132. icon: 'check'
  133. })
  134. this.$store.commit(`loadingStop`, 'admin-search-saveengines')
  135. }
  136. },
  137. apollo: {
  138. engines: {
  139. query: enginesQuery,
  140. fetchPolicy: 'network-only',
  141. update: (data) => _.cloneDeep(data.search.searchEngines).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.parse(cfg.value)}))})),
  142. watchLoading (isLoading) {
  143. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-search-refresh')
  144. }
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang='scss' scoped>
  150. .enginelogo {
  151. width: 250px;
  152. height: 85px;
  153. float:right;
  154. display: flex;
  155. justify-content: flex-end;
  156. align-items: center;
  157. img {
  158. max-width: 100%;
  159. max-height: 50px;
  160. }
  161. }
  162. </style>