2
0

admin-search.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. .subheading.grey--text.animated.fadeInLeft.wait-p2s {{$t('admin:search.subtitle')}}
  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 {{$t('admin:search.rebuildIndex')}}
  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 {{$t('admin:search.searchEngine')}}
  23. v-list.py-0(two-line, dense)
  24. template(v-for='(eng, idx) in engines')
  25. v-list-tile(:key='eng.key', @click='selectedEngine = eng.key', :disabled='!eng.isAvailable')
  26. v-list-tile-avatar
  27. v-icon(color='grey', v-if='!eng.isAvailable') cancel
  28. v-icon(color='primary', v-else-if='eng.key === selectedEngine') radio_button_checked
  29. v-icon(color='grey', v-else) radio_button_unchecked
  30. v-list-tile-content
  31. v-list-tile-title.body-2(:class='!eng.isAvailable ? `grey--text` : (selectedEngine === eng.key ? `primary--text` : ``)') {{ eng.title }}
  32. v-list-tile-sub-title.caption(:class='!eng.isAvailable ? `grey--text text--lighten-1` : (selectedEngine === eng.key ? `blue--text ` : ``)') {{ eng.description }}
  33. v-list-tile-avatar(v-if='selectedEngine === eng.key')
  34. v-icon.animated.fadeInLeft(color='primary') arrow_forward_ios
  35. v-divider(v-if='idx < engines.length - 1')
  36. v-flex(lg9, xs12)
  37. v-card.wiki-form.animated.fadeInUp.wait-p2s
  38. v-toolbar(color='primary', dense, flat, dark)
  39. .subheading {{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. v-subheader.pl-0 {{$t('admin:search.engineConfig')}}
  47. .body-1.ml-3(v-if='!engine.config || engine.config.length < 1') {{$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. outline
  52. background-color='grey lighten-2'
  53. :items='cfg.value.enum'
  54. :key='cfg.key'
  55. :label='cfg.value.title'
  56. v-model='cfg.value.value'
  57. prepend-icon='settings_applications'
  58. :hint='cfg.value.hint ? cfg.value.hint : ""'
  59. persistent-hint
  60. :class='cfg.value.hint ? "mb-2" : ""'
  61. )
  62. v-switch.mb-3(
  63. v-else-if='cfg.value.type === "boolean"'
  64. :key='cfg.key'
  65. :label='cfg.value.title'
  66. v-model='cfg.value.value'
  67. color='primary'
  68. prepend-icon='settings_applications'
  69. :hint='cfg.value.hint ? cfg.value.hint : ""'
  70. persistent-hint
  71. )
  72. v-textarea(
  73. v-else-if='cfg.value.type === "string" && cfg.value.multiline'
  74. outline
  75. background-color='grey lighten-2'
  76. :key='cfg.key'
  77. :label='cfg.value.title'
  78. v-model='cfg.value.value'
  79. prepend-icon='settings_applications'
  80. :hint='cfg.value.hint ? cfg.value.hint : ""'
  81. persistent-hint
  82. :class='cfg.value.hint ? "mb-2" : ""'
  83. )
  84. v-text-field(
  85. v-else
  86. outline
  87. background-color='grey lighten-2'
  88. :key='cfg.key'
  89. :label='cfg.value.title'
  90. v-model='cfg.value.value'
  91. prepend-icon='settings_applications'
  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>