2020-04-07 02:21:42 +00:00
|
|
|
<template lang='pug'>
|
|
|
|
v-container(fluid, grid-list-lg)
|
|
|
|
v-layout(row, wrap)
|
|
|
|
v-flex(xs12)
|
|
|
|
.admin-header
|
2020-05-15 21:05:11 +00:00
|
|
|
img.animated.fadeInUp(src='/_assets/svg/icon-chat-bubble.svg', alt='Comments', style='width: 80px;')
|
2020-04-07 02:21:42 +00:00
|
|
|
.admin-header-title
|
|
|
|
.headline.primary--text.animated.fadeInLeft {{$t('admin:comments.title')}}
|
|
|
|
.subtitle-1.grey--text.animated.fadeInLeft.wait-p2s {{$t('admin:comments.subtitle')}}
|
|
|
|
v-spacer
|
|
|
|
v-btn.mx-1.animated.fadeInDown.wait-p2s(outlined, color='grey', @click='refresh', large)
|
|
|
|
v-icon mdi-refresh
|
|
|
|
v-btn.ml-1.animated.fadeInDown(color='success', @click='save', depressed, large)
|
|
|
|
v-icon(left) mdi-check
|
|
|
|
span {{$t('common:actions.apply')}}
|
|
|
|
|
|
|
|
v-flex(lg3, xs12)
|
|
|
|
v-card.animated.fadeInUp
|
|
|
|
v-toolbar(flat, color='primary', dark, dense)
|
2020-05-17 02:46:05 +00:00
|
|
|
.subtitle-1 {{$t('admin:comments.provider')}}
|
2020-04-07 02:21:42 +00:00
|
|
|
v-list.py-0(two-line, dense)
|
|
|
|
template(v-for='(provider, idx) in providers')
|
|
|
|
v-list-item(:key='provider.key', @click='selectedProvider = provider.key', :disabled='!provider.isAvailable')
|
|
|
|
v-list-item-avatar(size='24')
|
|
|
|
v-icon(color='grey', v-if='!provider.isAvailable') mdi-minus-box-outline
|
|
|
|
v-icon(color='primary', v-else-if='provider.key === selectedProvider') mdi-checkbox-marked-circle-outline
|
|
|
|
v-icon(color='grey', v-else) mdi-checkbox-blank-circle-outline
|
|
|
|
v-list-item-content
|
|
|
|
v-list-item-title.body-2(:class='!provider.isAvailable ? `grey--text` : (selectedProvider === provider.key ? `primary--text` : ``)') {{ provider.title }}
|
|
|
|
v-list-item-subtitle: .caption(:class='!provider.isAvailable ? `grey--text text--lighten-1` : (selectedProvider === provider.key ? `blue--text ` : ``)') {{ provider.description }}
|
|
|
|
v-list-item-avatar(v-if='selectedProvider === provider.key', size='24')
|
|
|
|
v-icon.animated.fadeInLeft(color='primary', large) mdi-chevron-right
|
|
|
|
v-divider(v-if='idx < providers.length - 1')
|
|
|
|
|
|
|
|
v-flex(lg9, xs12)
|
|
|
|
v-card.animated.fadeInUp.wait-p2s
|
|
|
|
v-toolbar(color='primary', dense, flat, dark)
|
|
|
|
.subtitle-1 {{provider.title}}
|
|
|
|
v-card-text
|
|
|
|
.providerlogo
|
|
|
|
img(:src='provider.logo', :alt='provider.title')
|
|
|
|
.caption.pt-3 {{provider.description}}
|
|
|
|
.caption.pb-3: a(:href='provider.website') {{provider.website}}
|
|
|
|
v-divider.mt-3
|
|
|
|
.overline.my-5 {{$t('admin:comments.providerConfig')}}
|
|
|
|
.body-2.ml-3(v-if='!provider.config || provider.config.length < 1'): em {{$t('admin:comments.providerNoConfig')}}
|
|
|
|
template(v-else, v-for='cfg in provider.config')
|
2020-05-15 21:05:11 +00:00
|
|
|
v-select.mb-3(
|
2020-04-07 02:21:42 +00:00
|
|
|
v-if='cfg.value.type === "string" && cfg.value.enum'
|
|
|
|
outlined
|
|
|
|
:items='cfg.value.enum'
|
|
|
|
:key='cfg.key'
|
|
|
|
:label='cfg.value.title'
|
|
|
|
v-model='cfg.value.value'
|
|
|
|
prepend-icon='mdi-cog-box'
|
|
|
|
:hint='cfg.value.hint ? cfg.value.hint : ""'
|
|
|
|
persistent-hint
|
|
|
|
:class='cfg.value.hint ? "mb-2" : ""'
|
2020-05-15 21:05:11 +00:00
|
|
|
:style='cfg.value.maxWidth > 0 ? `max-width:` + cfg.value.maxWidth + `px;` : ``'
|
2020-04-07 02:21:42 +00:00
|
|
|
)
|
2020-05-15 21:05:11 +00:00
|
|
|
v-switch.mb-6(
|
2020-04-07 02:21:42 +00:00
|
|
|
v-else-if='cfg.value.type === "boolean"'
|
|
|
|
:key='cfg.key'
|
|
|
|
:label='cfg.value.title'
|
|
|
|
v-model='cfg.value.value'
|
|
|
|
color='primary'
|
|
|
|
prepend-icon='mdi-cog-box'
|
|
|
|
:hint='cfg.value.hint ? cfg.value.hint : ""'
|
|
|
|
persistent-hint
|
|
|
|
inset
|
|
|
|
)
|
2020-05-15 21:05:11 +00:00
|
|
|
v-textarea.mb-3(
|
2020-04-07 02:21:42 +00:00
|
|
|
v-else-if='cfg.value.type === "string" && cfg.value.multiline'
|
|
|
|
outlined
|
|
|
|
:key='cfg.key'
|
|
|
|
:label='cfg.value.title'
|
|
|
|
v-model='cfg.value.value'
|
|
|
|
prepend-icon='mdi-cog-box'
|
|
|
|
:hint='cfg.value.hint ? cfg.value.hint : ""'
|
|
|
|
persistent-hint
|
|
|
|
:class='cfg.value.hint ? "mb-2" : ""'
|
|
|
|
)
|
2020-05-15 21:05:11 +00:00
|
|
|
v-text-field.mb-3(
|
2020-04-07 02:21:42 +00:00
|
|
|
v-else
|
|
|
|
outlined
|
|
|
|
:key='cfg.key'
|
|
|
|
:label='cfg.value.title'
|
|
|
|
v-model='cfg.value.value'
|
|
|
|
prepend-icon='mdi-cog-box'
|
|
|
|
:hint='cfg.value.hint ? cfg.value.hint : ""'
|
|
|
|
persistent-hint
|
|
|
|
:class='cfg.value.hint ? "mb-2" : ""'
|
2020-05-15 21:05:11 +00:00
|
|
|
:style='cfg.value.maxWidth > 0 ? `max-width:` + cfg.value.maxWidth + `px;` : ``'
|
2020-04-07 02:21:42 +00:00
|
|
|
)
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import _ from 'lodash'
|
|
|
|
import gql from 'graphql-tag'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
providers: [],
|
|
|
|
selectedProvider: '',
|
|
|
|
provider: {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
selectedProvider(newValue, oldValue) {
|
|
|
|
this.provider = _.find(this.providers, ['key', newValue]) || {}
|
|
|
|
},
|
|
|
|
providers(newValue, oldValue) {
|
|
|
|
this.selectedProvider = _.get(_.find(this.providers, 'isEnabled'), 'key', 'db')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async refresh() {
|
|
|
|
await this.$apollo.queries.providers.refetch()
|
|
|
|
this.$store.commit('showNotification', {
|
|
|
|
message: this.$t('admin:comments.listRefreshSuccess'),
|
|
|
|
style: 'success',
|
|
|
|
icon: 'cached'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
async save() {
|
|
|
|
this.$store.commit(`loadingStart`, 'admin-comments-saveproviders')
|
|
|
|
try {
|
|
|
|
const resp = await this.$apollo.mutate({
|
2020-05-17 02:46:05 +00:00
|
|
|
mutation: gql`
|
|
|
|
mutation($providers: [CommentProviderInput]!) {
|
|
|
|
comments {
|
|
|
|
updateProviders(providers: $providers) {
|
|
|
|
responseResult {
|
|
|
|
succeeded
|
|
|
|
errorCode
|
|
|
|
slug
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
2020-04-07 02:21:42 +00:00
|
|
|
variables: {
|
|
|
|
providers: this.providers.map(tgt => ({
|
|
|
|
isEnabled: tgt.key === this.selectedProvider,
|
|
|
|
key: tgt.key,
|
|
|
|
config: tgt.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
})
|
2020-05-17 02:46:05 +00:00
|
|
|
if (_.get(resp, 'data.comments.updateProviders.responseResult.succeeded', false)) {
|
2020-04-07 02:21:42 +00:00
|
|
|
this.$store.commit('showNotification', {
|
|
|
|
message: this.$t('admin:comments.configSaveSuccess'),
|
|
|
|
style: 'success',
|
|
|
|
icon: 'check'
|
|
|
|
})
|
|
|
|
} else {
|
2020-05-17 02:46:05 +00:00
|
|
|
throw new Error(_.get(resp, 'data.comments.updateProviders.responseResult.message', this.$t('common:error.unexpected')))
|
2020-04-07 02:21:42 +00:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
this.$store.commit('pushGraphError', err)
|
|
|
|
}
|
2020-05-17 02:46:05 +00:00
|
|
|
this.$store.commit(`loadingStop`, 'admin-comments-saveproviders')
|
2020-04-07 02:21:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
providers: {
|
|
|
|
query: gql`
|
|
|
|
query {
|
|
|
|
comments {
|
|
|
|
providers {
|
|
|
|
isEnabled
|
|
|
|
key
|
|
|
|
title
|
|
|
|
description
|
|
|
|
logo
|
|
|
|
website
|
|
|
|
isAvailable
|
|
|
|
config {
|
|
|
|
key
|
|
|
|
value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
fetchPolicy: 'network-only',
|
|
|
|
update: (data) => _.cloneDeep(data.comments.providers).map(str => ({
|
|
|
|
...str,
|
|
|
|
config: _.sortBy(str.config.map(cfg => ({
|
|
|
|
...cfg,
|
|
|
|
value: JSON.parse(cfg.value)
|
|
|
|
})), [t => t.value.order])
|
|
|
|
})),
|
|
|
|
watchLoading (isLoading) {
|
|
|
|
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-comments-refresh')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang='scss' scoped>
|
|
|
|
|
|
|
|
.providerlogo {
|
|
|
|
width: 250px;
|
|
|
|
height: 85px;
|
|
|
|
float:right;
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
img {
|
|
|
|
max-width: 100%;
|
|
|
|
max-height: 50px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|