admin-search.vue 5.7 KB

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