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

179 lines
5.5 KiB
Vue
Raw Normal View History

<template lang='pug'>
v-container(fluid, grid-list-lg)
v-layout(row, wrap)
v-flex(xs12)
.admin-header
img(src='/svg/icon-search.svg', alt='Search Engine', style='width: 80px;')
.admin-header-title
.headline.primary--text Search Engine
2019-03-09 05:51:02 +00:00
.subheading.grey--text Configure the search capabilities of your wiki
v-spacer
v-btn(outline, color='grey', @click='refresh', large)
v-icon refresh
v-btn(color='black', dark, large, depressed, @click='rebuild')
v-icon(left) cached
span Rebuild Index
v-btn(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)
v-card
v-toolbar(flat, color='primary', dark, dense)
.subheading Search Engine
v-card-text
v-radio-group.my-0(v-model='selectedEngine')
v-radio.my-1(
v-for='(engine, n) in engines'
:key='engine.key'
:label='engine.title'
:value='engine.key'
color='primary'
hide-details
)
2018-09-02 02:37:20 +00:00
2019-03-09 05:51:02 +00:00
v-flex(lg9, xs12)
v-card.wiki-form
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
v-subheader.pl-0 Engine Configuration
.body-1.ml-3(v-if='!engine.config || engine.config.length < 1') This engine has no configuration options you can modify.
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
)
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'
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 = 'db'
2018-09-02 02:37:20 +00:00
}
},
methods: {
async refresh() {
await this.$apollo.queries.engines.refetch()
this.$store.commit('showNotification', {
message: 'List of search engines has been refreshed.',
style: 'success',
icon: 'cached'
})
},
async save() {
this.$store.commit(`loadingStart`, 'admin-search-saveengines')
await this.$apollo.mutate({
mutation: enginesSaveMutation,
variables: {
engines: this.engines.map(tgt => _.pick(tgt, [
'isEnabled',
'key',
'config'
])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
2018-09-02 02:37:20 +00:00
}
})
this.$store.commit('showNotification', {
message: 'Search engine configuration saved successfully.',
2018-09-02 02:37:20 +00:00
style: 'success',
icon: 'check'
})
this.$store.commit(`loadingStop`, 'admin-search-saveengines')
},
async rebuild () {
this.$store.commit('showNotification', {
style: 'indigo',
message: `Coming soon...`,
icon: 'directions_boat'
})
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>