wikijs-fork/client/components/admin/admin-search.vue

216 lines
8.0 KiB
Vue
Raw Normal View History

<template lang='pug'>
v-container(fluid, grid-list-lg)
v-layout(row, wrap)
v-flex(xs12)
.admin-header
2019-03-17 17:39:58 +00:00
img.animated.fadeInUp(src='/svg/icon-search.svg', alt='Search Engine', style='width: 80px;')
.admin-header-title
2019-06-10 03:39:37 +00:00
.headline.primary--text.animated.fadeInLeft {{$t('admin:search.title')}}
.subheading.grey--text.animated.fadeInLeft.wait-p2s {{$t('admin:search.subtitle')}}
v-spacer
2019-03-17 17:39:58 +00:00
v-btn.animated.fadeInDown.wait-p2s(outline, color='grey', @click='refresh', large)
v-icon refresh
2019-03-17 17:39:58 +00:00
v-btn.animated.fadeInDown.wait-p1s(color='black', dark, large, depressed, @click='rebuild')
v-icon(left) cached
2019-06-10 03:39:37 +00:00
span {{$t('admin:search.rebuildIndex')}}
2019-03-17 17:39:58 +00:00
v-btn.animated.fadeInDown(color='success', @click='save', depressed, large)
v-icon(left) check
span {{$t('common:actions.apply')}}
2019-03-09 05:51:02 +00:00
v-flex(lg3, xs12)
2019-03-17 17:39:58 +00:00
v-card.animated.fadeInUp
2019-03-09 05:51:02 +00:00
v-toolbar(flat, color='primary', dark, dense)
2019-06-10 03:39:37 +00:00
.subheading {{$t('admin:search.searchEngine')}}
v-list.py-0(two-line, dense)
template(v-for='(eng, idx) in engines')
2019-07-29 04:50:03 +00:00
v-list-item(:key='eng.key', @click='selectedEngine = eng.key', :disabled='!eng.isAvailable')
v-list-item-avatar
v-icon(color='grey', v-if='!eng.isAvailable') cancel
v-icon(color='primary', v-else-if='eng.key === selectedEngine') radio_button_checked
v-icon(color='grey', v-else) radio_button_unchecked
2019-07-29 04:50:03 +00:00
v-list-item-content
v-list-item-title.body-2(:class='!eng.isAvailable ? `grey--text` : (selectedEngine === eng.key ? `primary--text` : ``)') {{ eng.title }}
v-list-item-sub-title.caption(:class='!eng.isAvailable ? `grey--text text--lighten-1` : (selectedEngine === eng.key ? `blue--text ` : ``)') {{ eng.description }}
v-list-item-avatar(v-if='selectedEngine === eng.key')
v-icon.animated.fadeInLeft(color='primary') arrow_forward_ios
v-divider(v-if='idx < engines.length - 1')
2018-09-02 02:37:20 +00:00
2019-03-09 05:51:02 +00:00
v-flex(lg9, xs12)
2019-03-17 17:39:58 +00:00
v-card.wiki-form.animated.fadeInUp.wait-p2s
2019-03-09 05:51:02 +00:00
v-toolbar(color='primary', dense, flat, dark)
.subheading {{engine.title}}
v-card-text
.enginelogo
img(:src='engine.logo', :alt='engine.title')
.caption.pt-3 {{engine.description}}
.caption.pb-3: a(:href='engine.website') {{engine.website}}
v-divider.mt-3
2019-06-10 03:39:37 +00:00
v-subheader.pl-0 {{$t('admin:search.engineConfig')}}
.body-1.ml-3(v-if='!engine.config || engine.config.length < 1') {{$t('admin:search.engineNoConfig')}}
2019-03-09 05:51:02 +00:00
template(v-else, v-for='cfg in engine.config')
v-select(
v-if='cfg.value.type === "string" && cfg.value.enum'
outline
background-color='grey lighten-2'
:items='cfg.value.enum'
:key='cfg.key'
:label='cfg.value.title'
v-model='cfg.value.value'
prepend-icon='settings_applications'
:hint='cfg.value.hint ? cfg.value.hint : ""'
persistent-hint
:class='cfg.value.hint ? "mb-2" : ""'
)
v-switch.mb-3(
v-else-if='cfg.value.type === "boolean"'
:key='cfg.key'
:label='cfg.value.title'
v-model='cfg.value.value'
color='primary'
prepend-icon='settings_applications'
:hint='cfg.value.hint ? cfg.value.hint : ""'
persistent-hint
)
2019-07-14 22:55:12 +00:00
v-textarea(
v-else-if='cfg.value.type === "string" && cfg.value.multiline'
outline
background-color='grey lighten-2'
:key='cfg.key'
:label='cfg.value.title'
v-model='cfg.value.value'
prepend-icon='settings_applications'
:hint='cfg.value.hint ? cfg.value.hint : ""'
persistent-hint
:class='cfg.value.hint ? "mb-2" : ""'
)
2019-03-09 05:51:02 +00:00
v-text-field(
v-else
outline
background-color='grey lighten-2'
:key='cfg.key'
:label='cfg.value.title'
v-model='cfg.value.value'
prepend-icon='settings_applications'
:hint='cfg.value.hint ? cfg.value.hint : ""'
persistent-hint
:class='cfg.value.hint ? "mb-2" : ""'
)
</template>
<script>
2018-09-02 02:37:20 +00:00
import _ from 'lodash'
import enginesQuery from 'gql/admin/search/search-query-engines.gql'
import enginesSaveMutation from 'gql/admin/search/search-mutation-save-engines.gql'
import enginesRebuildMutation from 'gql/admin/search/search-mutation-rebuild-index.gql'
2018-09-02 02:37:20 +00:00
export default {
data() {
return {
2018-09-02 02:37:20 +00:00
engines: [],
2019-03-09 05:51:02 +00:00
selectedEngine: '',
engine: {}
2018-09-02 02:37:20 +00:00
}
},
watch: {
selectedEngine(newValue, oldValue) {
2019-03-09 05:51:02 +00:00
this.engine = _.find(this.engines, ['key', newValue]) || {}
},
engines(newValue, oldValue) {
this.selectedEngine = _.get(_.find(this.engines, 'isEnabled'), 'key', 'db')
2018-09-02 02:37:20 +00:00
}
},
methods: {
async refresh() {
await this.$apollo.queries.engines.refetch()
this.$store.commit('showNotification', {
2019-06-10 03:39:37 +00:00
message: this.$t('admin:search.listRefreshSuccess'),
2018-09-02 02:37:20 +00:00
style: 'success',
icon: 'cached'
})
},
async save() {
this.$store.commit(`loadingStart`, 'admin-search-saveengines')
try {
const resp = await this.$apollo.mutate({
mutation: enginesSaveMutation,
variables: {
engines: this.engines.map(tgt => ({
isEnabled: tgt.key === this.selectedEngine,
key: tgt.key,
config: tgt.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))
}))
}
})
if (_.get(resp, 'data.search.updateSearchEngines.responseResult.succeeded', false)) {
this.$store.commit('showNotification', {
2019-06-10 03:39:37 +00:00
message: this.$t('admin:search.configSaveSuccess'),
style: 'success',
icon: 'check'
})
} else {
2019-06-10 03:39:37 +00:00
throw new Error(_.get(resp, 'data.search.updateSearchEngines.responseResult.message', this.$t('common:error.unexpected')))
2018-09-02 02:37:20 +00:00
}
} catch (err) {
this.$store.commit('pushGraphError', err)
}
2018-09-02 02:37:20 +00:00
this.$store.commit(`loadingStop`, 'admin-search-saveengines')
},
async rebuild () {
this.$store.commit(`loadingStart`, 'admin-search-rebuildindex')
try {
const resp = await this.$apollo.mutate({
mutation: enginesRebuildMutation
})
if (_.get(resp, 'data.search.rebuildIndex.responseResult.succeeded', false)) {
this.$store.commit('showNotification', {
2019-06-10 03:39:37 +00:00
message: this.$t('admin:search.indexRebuildSuccess'),
style: 'success',
icon: 'check'
})
} else {
2019-06-10 03:39:37 +00:00
throw new Error(_.get(resp, 'data.search.rebuildIndex.responseResult.message', this.$t('common:error.unexpected')))
}
} catch (err) {
this.$store.commit('pushGraphError', err)
}
this.$store.commit(`loadingStop`, 'admin-search-rebuildindex')
2018-09-02 02:37:20 +00:00
}
},
apollo: {
engines: {
query: enginesQuery,
fetchPolicy: 'network-only',
2019-03-09 05:51:02 +00:00
update: (data) => _.cloneDeep(data.search.searchEngines).map(str => ({
...str,
config: _.sortBy(str.config.map(cfg => ({
...cfg,
value: JSON.parse(cfg.value)
})), [t => t.value.order])
})),
2018-09-02 02:37:20 +00:00
watchLoading (isLoading) {
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-search-refresh')
}
}
}
}
</script>
2018-09-02 02:37:20 +00:00
<style lang='scss' scoped>
.enginelogo {
width: 250px;
height: 85px;
float:right;
display: flex;
justify-content: flex-end;
align-items: center;
img {
max-width: 100%;
max-height: 50px;
}
}
</style>