admin-search.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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.animated.fadeInUp(src='/svg/icon-search.svg', alt='Search Engine', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft Search Engine
  9. .subheading.grey--text.animated.fadeInLeft.wait-p2s Configure the search capabilities of your wiki
  10. v-spacer
  11. v-btn.animated.fadeInDown.wait-p2s(outline, color='grey', @click='refresh', large)
  12. v-icon refresh
  13. v-btn.animated.fadeInDown.wait-p1s(color='black', dark, large, depressed, @click='rebuild')
  14. v-icon(left) cached
  15. span Rebuild Index
  16. v-btn.animated.fadeInDown(color='success', @click='save', depressed, large)
  17. v-icon(left) check
  18. span {{$t('common:actions.apply')}}
  19. v-flex(lg3, xs12)
  20. v-card.animated.fadeInUp
  21. v-toolbar(flat, color='primary', dark, dense)
  22. .subheading Search Engine
  23. v-card-text
  24. v-radio-group.my-0(v-model='selectedEngine')
  25. v-radio.my-1(
  26. v-for='(engine, n) in engines'
  27. :key='engine.key'
  28. :label='engine.title'
  29. :value='engine.key'
  30. :disabled='!engine.isAvailable'
  31. color='primary'
  32. hide-details
  33. )
  34. v-flex(lg9, xs12)
  35. v-card.wiki-form.animated.fadeInUp.wait-p2s
  36. v-toolbar(color='primary', dense, flat, dark)
  37. .subheading {{engine.title}}
  38. v-card-text
  39. .enginelogo
  40. img(:src='engine.logo', :alt='engine.title')
  41. .caption.pt-3 {{engine.description}}
  42. .caption.pb-3: a(:href='engine.website') {{engine.website}}
  43. v-divider.mt-3
  44. v-subheader.pl-0 Engine Configuration
  45. .body-1.ml-3(v-if='!engine.config || engine.config.length < 1') This engine has no configuration options you can modify.
  46. template(v-else, v-for='cfg in engine.config')
  47. v-select(
  48. v-if='cfg.value.type === "string" && cfg.value.enum'
  49. outline
  50. background-color='grey lighten-2'
  51. :items='cfg.value.enum'
  52. :key='cfg.key'
  53. :label='cfg.value.title'
  54. v-model='cfg.value.value'
  55. prepend-icon='settings_applications'
  56. :hint='cfg.value.hint ? cfg.value.hint : ""'
  57. persistent-hint
  58. :class='cfg.value.hint ? "mb-2" : ""'
  59. )
  60. v-switch.mb-3(
  61. v-else-if='cfg.value.type === "boolean"'
  62. :key='cfg.key'
  63. :label='cfg.value.title'
  64. v-model='cfg.value.value'
  65. color='primary'
  66. prepend-icon='settings_applications'
  67. :hint='cfg.value.hint ? cfg.value.hint : ""'
  68. persistent-hint
  69. )
  70. v-text-field(
  71. v-else
  72. outline
  73. background-color='grey lighten-2'
  74. :key='cfg.key'
  75. :label='cfg.value.title'
  76. v-model='cfg.value.value'
  77. prepend-icon='settings_applications'
  78. :hint='cfg.value.hint ? cfg.value.hint : ""'
  79. persistent-hint
  80. :class='cfg.value.hint ? "mb-2" : ""'
  81. )
  82. </template>
  83. <script>
  84. import _ from 'lodash'
  85. import enginesQuery from 'gql/admin/search/search-query-engines.gql'
  86. import enginesSaveMutation from 'gql/admin/search/search-mutation-save-engines.gql'
  87. import enginesRebuildMutation from 'gql/admin/search/search-mutation-rebuild-index.gql'
  88. export default {
  89. data() {
  90. return {
  91. engines: [],
  92. selectedEngine: '',
  93. engine: {}
  94. }
  95. },
  96. watch: {
  97. selectedEngine(newValue, oldValue) {
  98. this.engine = _.find(this.engines, ['key', newValue]) || {}
  99. },
  100. engines(newValue, oldValue) {
  101. this.selectedEngine = _.get(_.find(this.engines, 'isEnabled'), 'key', 'db')
  102. }
  103. },
  104. methods: {
  105. async refresh() {
  106. await this.$apollo.queries.engines.refetch()
  107. this.$store.commit('showNotification', {
  108. message: 'List of search engines has been refreshed.',
  109. style: 'success',
  110. icon: 'cached'
  111. })
  112. },
  113. async save() {
  114. this.$store.commit(`loadingStart`, 'admin-search-saveengines')
  115. try {
  116. const resp = await this.$apollo.mutate({
  117. mutation: enginesSaveMutation,
  118. variables: {
  119. engines: this.engines.map(tgt => ({
  120. isEnabled: tgt.key === this.selectedEngine,
  121. key: tgt.key,
  122. config: tgt.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))
  123. }))
  124. }
  125. })
  126. if (_.get(resp, 'data.search.updateSearchEngines.responseResult.succeeded', false)) {
  127. this.$store.commit('showNotification', {
  128. message: 'Search engine configuration saved successfully.',
  129. style: 'success',
  130. icon: 'check'
  131. })
  132. } else {
  133. throw new Error(_.get(resp, 'data.search.updateSearchEngines.responseResult.message', 'An unexpected error occured'))
  134. }
  135. } catch (err) {
  136. this.$store.commit('pushGraphError', err)
  137. }
  138. this.$store.commit(`loadingStop`, 'admin-search-saveengines')
  139. },
  140. async rebuild () {
  141. this.$store.commit(`loadingStart`, 'admin-search-rebuildindex')
  142. try {
  143. const resp = await this.$apollo.mutate({
  144. mutation: enginesRebuildMutation
  145. })
  146. if (_.get(resp, 'data.search.rebuildIndex.responseResult.succeeded', false)) {
  147. this.$store.commit('showNotification', {
  148. message: 'Index rebuilt successfully.',
  149. style: 'success',
  150. icon: 'check'
  151. })
  152. } else {
  153. throw new Error(_.get(resp, 'data.search.rebuildIndex.responseResult.message', 'An unexpected error occured'))
  154. }
  155. } catch (err) {
  156. this.$store.commit('pushGraphError', err)
  157. }
  158. this.$store.commit(`loadingStop`, 'admin-search-rebuildindex')
  159. }
  160. },
  161. apollo: {
  162. engines: {
  163. query: enginesQuery,
  164. fetchPolicy: 'network-only',
  165. update: (data) => _.cloneDeep(data.search.searchEngines).map(str => ({
  166. ...str,
  167. config: _.sortBy(str.config.map(cfg => ({
  168. ...cfg,
  169. value: JSON.parse(cfg.value)
  170. })), [t => t.value.order])
  171. })),
  172. watchLoading (isLoading) {
  173. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-search-refresh')
  174. }
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang='scss' scoped>
  180. .enginelogo {
  181. width: 250px;
  182. height: 85px;
  183. float:right;
  184. display: flex;
  185. justify-content: flex-end;
  186. align-items: center;
  187. img {
  188. max-width: 100%;
  189. max-height: 50px;
  190. }
  191. }
  192. </style>