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.

217 lines
8.2 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-info(color='blue')
  43. div
  44. div {{engine.description}}
  45. span.caption: a(:href='engine.website') {{engine.website}}
  46. v-spacer
  47. .admin-providerlogo
  48. img(:src='engine.logo', :alt='engine.title')
  49. v-card-text
  50. .overline.mb-5 {{$t('admin:search.engineConfig')}}
  51. .body-2.ml-3(v-if='!engine.config || engine.config.length < 1'): em {{$t('admin:search.engineNoConfig')}}
  52. template(v-else, v-for='cfg in engine.config')
  53. v-select(
  54. v-if='cfg.value.type === "string" && cfg.value.enum'
  55. outlined
  56. :items='cfg.value.enum'
  57. :key='cfg.key'
  58. :label='cfg.value.title'
  59. v-model='cfg.value.value'
  60. prepend-icon='mdi-cog-box'
  61. :hint='cfg.value.hint ? cfg.value.hint : ""'
  62. persistent-hint
  63. :class='cfg.value.hint ? "mb-2" : ""'
  64. )
  65. v-switch.mb-3(
  66. v-else-if='cfg.value.type === "boolean"'
  67. :key='cfg.key'
  68. :label='cfg.value.title'
  69. v-model='cfg.value.value'
  70. color='primary'
  71. prepend-icon='mdi-cog-box'
  72. :hint='cfg.value.hint ? cfg.value.hint : ""'
  73. persistent-hint
  74. inset
  75. )
  76. v-textarea(
  77. v-else-if='cfg.value.type === "string" && cfg.value.multiline'
  78. outlined
  79. :key='cfg.key'
  80. :label='cfg.value.title'
  81. v-model='cfg.value.value'
  82. prepend-icon='mdi-cog-box'
  83. :hint='cfg.value.hint ? cfg.value.hint : ""'
  84. persistent-hint
  85. :class='cfg.value.hint ? "mb-2" : ""'
  86. )
  87. v-text-field(
  88. v-else
  89. outlined
  90. :key='cfg.key'
  91. :label='cfg.value.title'
  92. v-model='cfg.value.value'
  93. prepend-icon='mdi-cog-box'
  94. :hint='cfg.value.hint ? cfg.value.hint : ""'
  95. persistent-hint
  96. :class='cfg.value.hint ? "mb-2" : ""'
  97. )
  98. </template>
  99. <script>
  100. import _ from 'lodash'
  101. import enginesQuery from 'gql/admin/search/search-query-engines.gql'
  102. import enginesSaveMutation from 'gql/admin/search/search-mutation-save-engines.gql'
  103. import enginesRebuildMutation from 'gql/admin/search/search-mutation-rebuild-index.gql'
  104. export default {
  105. data() {
  106. return {
  107. engines: [],
  108. selectedEngine: '',
  109. engine: {}
  110. }
  111. },
  112. watch: {
  113. selectedEngine(newValue, oldValue) {
  114. this.engine = _.find(this.engines, ['key', newValue]) || {}
  115. },
  116. engines(newValue, oldValue) {
  117. this.selectedEngine = _.get(_.find(this.engines, 'isEnabled'), 'key', 'db')
  118. }
  119. },
  120. methods: {
  121. async refresh() {
  122. await this.$apollo.queries.engines.refetch()
  123. this.$store.commit('showNotification', {
  124. message: this.$t('admin:search.listRefreshSuccess'),
  125. style: 'success',
  126. icon: 'cached'
  127. })
  128. },
  129. async save() {
  130. this.$store.commit(`loadingStart`, 'admin-search-saveengines')
  131. try {
  132. const resp = await this.$apollo.mutate({
  133. mutation: enginesSaveMutation,
  134. variables: {
  135. engines: this.engines.map(tgt => ({
  136. isEnabled: tgt.key === this.selectedEngine,
  137. key: tgt.key,
  138. config: tgt.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))
  139. }))
  140. }
  141. })
  142. if (_.get(resp, 'data.search.updateSearchEngines.responseResult.succeeded', false)) {
  143. this.$store.commit('showNotification', {
  144. message: this.$t('admin:search.configSaveSuccess'),
  145. style: 'success',
  146. icon: 'check'
  147. })
  148. } else {
  149. throw new Error(_.get(resp, 'data.search.updateSearchEngines.responseResult.message', this.$t('common:error.unexpected')))
  150. }
  151. } catch (err) {
  152. this.$store.commit('pushGraphError', err)
  153. }
  154. this.$store.commit(`loadingStop`, 'admin-search-saveengines')
  155. },
  156. async rebuild () {
  157. this.$store.commit(`loadingStart`, 'admin-search-rebuildindex')
  158. try {
  159. const resp = await this.$apollo.mutate({
  160. mutation: enginesRebuildMutation
  161. })
  162. if (_.get(resp, 'data.search.rebuildIndex.responseResult.succeeded', false)) {
  163. this.$store.commit('showNotification', {
  164. message: this.$t('admin:search.indexRebuildSuccess'),
  165. style: 'success',
  166. icon: 'check'
  167. })
  168. } else {
  169. throw new Error(_.get(resp, 'data.search.rebuildIndex.responseResult.message', this.$t('common:error.unexpected')))
  170. }
  171. } catch (err) {
  172. this.$store.commit('pushGraphError', err)
  173. }
  174. this.$store.commit(`loadingStop`, 'admin-search-rebuildindex')
  175. }
  176. },
  177. apollo: {
  178. engines: {
  179. query: enginesQuery,
  180. fetchPolicy: 'network-only',
  181. update: (data) => _.cloneDeep(data.search.searchEngines).map(str => ({
  182. ...str,
  183. config: _.sortBy(str.config.map(cfg => ({
  184. ...cfg,
  185. value: JSON.parse(cfg.value)
  186. })), [t => t.value.order])
  187. })),
  188. watchLoading (isLoading) {
  189. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-search-refresh')
  190. }
  191. }
  192. }
  193. }
  194. </script>
  195. <style lang='scss' scoped>
  196. .enginelogo {
  197. width: 250px;
  198. height: 85px;
  199. float:right;
  200. display: flex;
  201. justify-content: flex-end;
  202. align-items: center;
  203. img {
  204. max-width: 100%;
  205. max-height: 50px;
  206. }
  207. }
  208. </style>