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.

215 lines
8.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. img.animated.fadeInUp(src='/_assets/svg/icon-search.svg', alt='Search Engine', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft {{$t('admin:search.title')}}
  9. .subtitle-1.grey--text.animated.fadeInLeft.wait-p2s {{$t('admin:search.subtitle')}}
  10. v-spacer
  11. v-btn.mr-3.animated.fadeInDown.wait-p3s(icon, outlined, color='grey', href='https://docs.requarks.io/search', target='_blank')
  12. v-icon mdi-help-circle
  13. v-btn.animated.fadeInDown.wait-p2s(icon, outlined, color='grey', @click='refresh')
  14. v-icon mdi-refresh
  15. v-btn.mx-3.animated.fadeInDown.wait-p1s(color='black', dark, depressed, @click='rebuild')
  16. v-icon(left) mdi-cached
  17. span {{$t('admin:search.rebuildIndex')}}
  18. v-btn.animated.fadeInDown(color='success', @click='save', depressed, large)
  19. v-icon(left) mdi-check
  20. span {{$t('common:actions.apply')}}
  21. v-flex(lg3, xs12)
  22. v-card.animated.fadeInUp
  23. v-toolbar(flat, color='primary', dark, dense)
  24. .subtitle-1 {{$t('admin:search.searchEngine')}}
  25. v-list.py-0(two-line, dense)
  26. template(v-for='(eng, idx) in engines')
  27. v-list-item(:key='eng.key', @click='selectedEngine = eng.key', :disabled='!eng.isAvailable')
  28. v-list-item-avatar(size='24')
  29. v-icon(color='grey', v-if='!eng.isAvailable') mdi-minus-box-outline
  30. v-icon(color='primary', v-else-if='eng.key === selectedEngine') mdi-checkbox-marked-circle-outline
  31. v-icon(color='grey', v-else) mdi-checkbox-blank-circle-outline
  32. v-list-item-content
  33. v-list-item-title.body-2(:class='!eng.isAvailable ? `grey--text` : (selectedEngine === eng.key ? `primary--text` : ``)') {{ eng.title }}
  34. v-list-item-subtitle: .caption(:class='!eng.isAvailable ? `grey--text text--lighten-1` : (selectedEngine === eng.key ? `blue--text ` : ``)') {{ eng.description }}
  35. v-list-item-avatar(v-if='selectedEngine === eng.key', size='24')
  36. v-icon.animated.fadeInLeft(color='primary', large) mdi-chevron-right
  37. v-divider(v-if='idx < engines.length - 1')
  38. v-flex(lg9, xs12)
  39. v-card.animated.fadeInUp.wait-p2s
  40. v-toolbar(color='primary', dense, flat, dark)
  41. .subtitle-1 {{engine.title}}
  42. v-card-text
  43. .enginelogo
  44. img(:src='engine.logo', :alt='engine.title')
  45. .caption.pt-3 {{engine.description}}
  46. .caption.pb-3: a(:href='engine.website') {{engine.website}}
  47. v-divider.mt-3
  48. .overline.my-5 {{$t('admin:search.engineConfig')}}
  49. .body-2.ml-3(v-if='!engine.config || engine.config.length < 1'): em {{$t('admin:search.engineNoConfig')}}
  50. template(v-else, v-for='cfg in engine.config')
  51. v-select(
  52. v-if='cfg.value.type === "string" && cfg.value.enum'
  53. outlined
  54. :items='cfg.value.enum'
  55. :key='cfg.key'
  56. :label='cfg.value.title'
  57. v-model='cfg.value.value'
  58. prepend-icon='mdi-cog-box'
  59. :hint='cfg.value.hint ? cfg.value.hint : ""'
  60. persistent-hint
  61. :class='cfg.value.hint ? "mb-2" : ""'
  62. )
  63. v-switch.mb-3(
  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='mdi-cog-box'
  70. :hint='cfg.value.hint ? cfg.value.hint : ""'
  71. persistent-hint
  72. inset
  73. )
  74. v-textarea(
  75. v-else-if='cfg.value.type === "string" && cfg.value.multiline'
  76. outlined
  77. :key='cfg.key'
  78. :label='cfg.value.title'
  79. v-model='cfg.value.value'
  80. prepend-icon='mdi-cog-box'
  81. :hint='cfg.value.hint ? cfg.value.hint : ""'
  82. persistent-hint
  83. :class='cfg.value.hint ? "mb-2" : ""'
  84. )
  85. v-text-field(
  86. v-else
  87. outlined
  88. :key='cfg.key'
  89. :label='cfg.value.title'
  90. v-model='cfg.value.value'
  91. prepend-icon='mdi-cog-box'
  92. :hint='cfg.value.hint ? cfg.value.hint : ""'
  93. persistent-hint
  94. :class='cfg.value.hint ? "mb-2" : ""'
  95. )
  96. </template>
  97. <script>
  98. import _ from 'lodash'
  99. import enginesQuery from 'gql/admin/search/search-query-engines.gql'
  100. import enginesSaveMutation from 'gql/admin/search/search-mutation-save-engines.gql'
  101. import enginesRebuildMutation from 'gql/admin/search/search-mutation-rebuild-index.gql'
  102. export default {
  103. data() {
  104. return {
  105. engines: [],
  106. selectedEngine: '',
  107. engine: {}
  108. }
  109. },
  110. watch: {
  111. selectedEngine(newValue, oldValue) {
  112. this.engine = _.find(this.engines, ['key', newValue]) || {}
  113. },
  114. engines(newValue, oldValue) {
  115. this.selectedEngine = _.get(_.find(this.engines, 'isEnabled'), 'key', 'db')
  116. }
  117. },
  118. methods: {
  119. async refresh() {
  120. await this.$apollo.queries.engines.refetch()
  121. this.$store.commit('showNotification', {
  122. message: this.$t('admin:search.listRefreshSuccess'),
  123. style: 'success',
  124. icon: 'cached'
  125. })
  126. },
  127. async save() {
  128. this.$store.commit(`loadingStart`, 'admin-search-saveengines')
  129. try {
  130. const resp = await this.$apollo.mutate({
  131. mutation: enginesSaveMutation,
  132. variables: {
  133. engines: this.engines.map(tgt => ({
  134. isEnabled: tgt.key === this.selectedEngine,
  135. key: tgt.key,
  136. config: tgt.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))
  137. }))
  138. }
  139. })
  140. if (_.get(resp, 'data.search.updateSearchEngines.responseResult.succeeded', false)) {
  141. this.$store.commit('showNotification', {
  142. message: this.$t('admin:search.configSaveSuccess'),
  143. style: 'success',
  144. icon: 'check'
  145. })
  146. } else {
  147. throw new Error(_.get(resp, 'data.search.updateSearchEngines.responseResult.message', this.$t('common:error.unexpected')))
  148. }
  149. } catch (err) {
  150. this.$store.commit('pushGraphError', err)
  151. }
  152. this.$store.commit(`loadingStop`, 'admin-search-saveengines')
  153. },
  154. async rebuild () {
  155. this.$store.commit(`loadingStart`, 'admin-search-rebuildindex')
  156. try {
  157. const resp = await this.$apollo.mutate({
  158. mutation: enginesRebuildMutation
  159. })
  160. if (_.get(resp, 'data.search.rebuildIndex.responseResult.succeeded', false)) {
  161. this.$store.commit('showNotification', {
  162. message: this.$t('admin:search.indexRebuildSuccess'),
  163. style: 'success',
  164. icon: 'check'
  165. })
  166. } else {
  167. throw new Error(_.get(resp, 'data.search.rebuildIndex.responseResult.message', this.$t('common:error.unexpected')))
  168. }
  169. } catch (err) {
  170. this.$store.commit('pushGraphError', err)
  171. }
  172. this.$store.commit(`loadingStop`, 'admin-search-rebuildindex')
  173. }
  174. },
  175. apollo: {
  176. engines: {
  177. query: enginesQuery,
  178. fetchPolicy: 'network-only',
  179. update: (data) => _.cloneDeep(data.search.searchEngines).map(str => ({
  180. ...str,
  181. config: _.sortBy(str.config.map(cfg => ({
  182. ...cfg,
  183. value: JSON.parse(cfg.value)
  184. })), [t => t.value.order])
  185. })),
  186. watchLoading (isLoading) {
  187. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-search-refresh')
  188. }
  189. }
  190. }
  191. }
  192. </script>
  193. <style lang='scss' scoped>
  194. .enginelogo {
  195. width: 250px;
  196. height: 85px;
  197. float:right;
  198. display: flex;
  199. justify-content: flex-end;
  200. align-items: center;
  201. img {
  202. max-width: 100%;
  203. max-height: 50px;
  204. }
  205. }
  206. </style>