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.

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