admin-search.vue 8.0 KB

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