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.

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