admin-comments.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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='/_assets/svg/icon-chat-bubble.svg', alt='Comments', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft {{$t('admin:comments.title')}}
  9. .subtitle-1.grey--text.animated.fadeInLeft.wait-p2s {{$t('admin:comments.subtitle')}}
  10. v-spacer
  11. v-btn.animated.fadeInDown.wait-p3s(icon, outlined, color='grey', href='https://docs.requarks.io/comments', target='_blank')
  12. v-icon mdi-help-circle
  13. v-btn.mx-3.animated.fadeInDown.wait-p2s(icon, outlined, color='grey', @click='refresh')
  14. v-icon mdi-refresh
  15. v-btn.animated.fadeInDown(color='success', @click='save', depressed, large)
  16. v-icon(left) mdi-check
  17. span {{$t('common:actions.apply')}}
  18. v-flex(lg3, xs12)
  19. v-card.animated.fadeInUp
  20. v-toolbar(flat, color='primary', dark, dense)
  21. .subtitle-1 {{$t('admin:comments.provider')}}
  22. v-list.py-0(two-line, dense)
  23. template(v-for='(provider, idx) in providers')
  24. v-list-item(:key='provider.key', @click='selectedProvider = provider.key', :disabled='!provider.isAvailable')
  25. v-list-item-avatar(size='24')
  26. v-icon(color='grey', v-if='!provider.isAvailable') mdi-minus-box-outline
  27. v-icon(color='primary', v-else-if='provider.key === selectedProvider') mdi-checkbox-marked-circle-outline
  28. v-icon(color='grey', v-else) mdi-checkbox-blank-circle-outline
  29. v-list-item-content
  30. v-list-item-title.body-2(:class='!provider.isAvailable ? `grey--text` : (selectedProvider === provider.key ? `primary--text` : ``)') {{ provider.title }}
  31. v-list-item-subtitle: .caption(:class='!provider.isAvailable ? `grey--text text--lighten-1` : (selectedProvider === provider.key ? `blue--text ` : ``)') {{ provider.description }}
  32. v-list-item-avatar(v-if='selectedProvider === provider.key', size='24')
  33. v-icon.animated.fadeInLeft(color='primary', large) mdi-chevron-right
  34. v-divider(v-if='idx < providers.length - 1')
  35. v-flex(lg9, xs12)
  36. v-card.animated.fadeInUp.wait-p2s
  37. v-toolbar(color='primary', dense, flat, dark)
  38. .subtitle-1 {{provider.title}}
  39. v-card-text
  40. .providerlogo
  41. img(:src='provider.logo', :alt='provider.title')
  42. .caption.pt-3 {{provider.description}}
  43. .caption.pb-3: a(:href='provider.website') {{provider.website}}
  44. v-divider.mt-3
  45. .overline.my-5 {{$t('admin:comments.providerConfig')}}
  46. .body-2.ml-3(v-if='!provider.config || provider.config.length < 1'): em {{$t('admin:comments.providerNoConfig')}}
  47. template(v-else, v-for='cfg in provider.config')
  48. v-select.mb-3(
  49. v-if='cfg.value.type === "string" && cfg.value.enum'
  50. outlined
  51. :items='cfg.value.enum'
  52. :key='cfg.key'
  53. :label='cfg.value.title'
  54. v-model='cfg.value.value'
  55. prepend-icon='mdi-cog-box'
  56. :hint='cfg.value.hint ? cfg.value.hint : ""'
  57. persistent-hint
  58. :class='cfg.value.hint ? "mb-2" : ""'
  59. :style='cfg.value.maxWidth > 0 ? `max-width:` + cfg.value.maxWidth + `px;` : ``'
  60. )
  61. v-switch.mb-6(
  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-cog-box'
  68. :hint='cfg.value.hint ? cfg.value.hint : ""'
  69. persistent-hint
  70. inset
  71. )
  72. v-textarea.mb-3(
  73. v-else-if='cfg.value.type === "string" && cfg.value.multiline'
  74. outlined
  75. :key='cfg.key'
  76. :label='cfg.value.title'
  77. v-model='cfg.value.value'
  78. prepend-icon='mdi-cog-box'
  79. :hint='cfg.value.hint ? cfg.value.hint : ""'
  80. persistent-hint
  81. :class='cfg.value.hint ? "mb-2" : ""'
  82. )
  83. v-text-field.mb-3(
  84. v-else
  85. outlined
  86. :key='cfg.key'
  87. :label='cfg.value.title'
  88. v-model='cfg.value.value'
  89. prepend-icon='mdi-cog-box'
  90. :hint='cfg.value.hint ? cfg.value.hint : ""'
  91. persistent-hint
  92. :class='cfg.value.hint ? "mb-2" : ""'
  93. :style='cfg.value.maxWidth > 0 ? `max-width:` + cfg.value.maxWidth + `px;` : ``'
  94. )
  95. </template>
  96. <script>
  97. import _ from 'lodash'
  98. import gql from 'graphql-tag'
  99. export default {
  100. data() {
  101. return {
  102. providers: [],
  103. selectedProvider: '',
  104. provider: {}
  105. }
  106. },
  107. watch: {
  108. selectedProvider(newValue, oldValue) {
  109. this.provider = _.find(this.providers, ['key', newValue]) || {}
  110. },
  111. providers(newValue, oldValue) {
  112. this.selectedProvider = _.get(_.find(this.providers, 'isEnabled'), 'key', 'db')
  113. }
  114. },
  115. methods: {
  116. async refresh() {
  117. await this.$apollo.queries.providers.refetch()
  118. this.$store.commit('showNotification', {
  119. message: this.$t('admin:comments.listRefreshSuccess'),
  120. style: 'success',
  121. icon: 'cached'
  122. })
  123. },
  124. async save() {
  125. this.$store.commit(`loadingStart`, 'admin-comments-saveproviders')
  126. try {
  127. const resp = await this.$apollo.mutate({
  128. mutation: gql`
  129. mutation($providers: [CommentProviderInput]!) {
  130. comments {
  131. updateProviders(providers: $providers) {
  132. responseResult {
  133. succeeded
  134. errorCode
  135. slug
  136. message
  137. }
  138. }
  139. }
  140. }
  141. `,
  142. variables: {
  143. providers: this.providers.map(tgt => ({
  144. isEnabled: tgt.key === this.selectedProvider,
  145. key: tgt.key,
  146. config: tgt.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))
  147. }))
  148. }
  149. })
  150. if (_.get(resp, 'data.comments.updateProviders.responseResult.succeeded', false)) {
  151. this.$store.commit('showNotification', {
  152. message: this.$t('admin:comments.configSaveSuccess'),
  153. style: 'success',
  154. icon: 'check'
  155. })
  156. } else {
  157. throw new Error(_.get(resp, 'data.comments.updateProviders.responseResult.message', this.$t('common:error.unexpected')))
  158. }
  159. } catch (err) {
  160. this.$store.commit('pushGraphError', err)
  161. }
  162. this.$store.commit(`loadingStop`, 'admin-comments-saveproviders')
  163. }
  164. },
  165. apollo: {
  166. providers: {
  167. query: gql`
  168. query {
  169. comments {
  170. providers {
  171. isEnabled
  172. key
  173. title
  174. description
  175. logo
  176. website
  177. isAvailable
  178. config {
  179. key
  180. value
  181. }
  182. }
  183. }
  184. }
  185. `,
  186. fetchPolicy: 'network-only',
  187. update: (data) => _.cloneDeep(data.comments.providers).map(str => ({
  188. ...str,
  189. config: _.sortBy(str.config.map(cfg => ({
  190. ...cfg,
  191. value: JSON.parse(cfg.value)
  192. })), [t => t.value.order])
  193. })),
  194. watchLoading (isLoading) {
  195. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-comments-refresh')
  196. }
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang='scss' scoped>
  202. .providerlogo {
  203. width: 250px;
  204. height: 85px;
  205. float:right;
  206. display: flex;
  207. justify-content: flex-end;
  208. align-items: center;
  209. img {
  210. max-width: 100%;
  211. max-height: 50px;
  212. }
  213. }
  214. </style>