You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
6.1 KiB

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