You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
7.8 KiB

  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-info(color='blue')
  40. div
  41. div {{provider.description}}
  42. span.caption: a(:href='provider.website') {{provider.website}}
  43. v-spacer
  44. .admin-providerlogo
  45. img(:src='provider.logo', :alt='provider.title')
  46. v-card-text
  47. .overline.my-5 {{$t('admin:comments.providerConfig')}}
  48. .body-2.ml-3(v-if='!provider.config || provider.config.length < 1'): em {{$t('admin:comments.providerNoConfig')}}
  49. template(v-else, v-for='cfg in provider.config')
  50. v-select.mb-3(
  51. v-if='cfg.value.type === "string" && cfg.value.enum'
  52. outlined
  53. :items='cfg.value.enum'
  54. :key='cfg.key'
  55. :label='cfg.value.title'
  56. v-model='cfg.value.value'
  57. prepend-icon='mdi-cog-box'
  58. :hint='cfg.value.hint ? cfg.value.hint : ""'
  59. persistent-hint
  60. :class='cfg.value.hint ? "mb-2" : ""'
  61. :style='cfg.value.maxWidth > 0 ? `max-width:` + cfg.value.maxWidth + `px;` : ``'
  62. )
  63. v-switch.mb-6(
  64. v-else-if='cfg.value.type === "boolean"'
  65. :key='cfg.key'
  66. :label='cfg.value.title'
  67. v-model='cfg.value.value'
  68. color='primary'
  69. prepend-icon='mdi-cog-box'
  70. :hint='cfg.value.hint ? cfg.value.hint : ""'
  71. persistent-hint
  72. inset
  73. )
  74. v-textarea.mb-3(
  75. v-else-if='cfg.value.type === "string" && cfg.value.multiline'
  76. outlined
  77. :key='cfg.key'
  78. :label='cfg.value.title'
  79. v-model='cfg.value.value'
  80. prepend-icon='mdi-cog-box'
  81. :hint='cfg.value.hint ? cfg.value.hint : ""'
  82. persistent-hint
  83. :class='cfg.value.hint ? "mb-2" : ""'
  84. )
  85. v-text-field.mb-3(
  86. v-else
  87. outlined
  88. :key='cfg.key'
  89. :label='cfg.value.title'
  90. v-model='cfg.value.value'
  91. prepend-icon='mdi-cog-box'
  92. :hint='cfg.value.hint ? cfg.value.hint : ""'
  93. persistent-hint
  94. :class='cfg.value.hint ? "mb-2" : ""'
  95. :style='cfg.value.maxWidth > 0 ? `max-width:` + cfg.value.maxWidth + `px;` : ``'
  96. )
  97. </template>
  98. <script>
  99. import _ from 'lodash'
  100. import gql from 'graphql-tag'
  101. export default {
  102. data() {
  103. return {
  104. providers: [],
  105. selectedProvider: '',
  106. provider: {}
  107. }
  108. },
  109. watch: {
  110. selectedProvider(newValue, oldValue) {
  111. this.provider = _.find(this.providers, ['key', newValue]) || {}
  112. },
  113. providers(newValue, oldValue) {
  114. this.selectedProvider = _.get(_.find(this.providers, 'isEnabled'), 'key', 'db')
  115. }
  116. },
  117. methods: {
  118. async refresh() {
  119. await this.$apollo.queries.providers.refetch()
  120. this.$store.commit('showNotification', {
  121. message: this.$t('admin:comments.listRefreshSuccess'),
  122. style: 'success',
  123. icon: 'cached'
  124. })
  125. },
  126. async save() {
  127. this.$store.commit(`loadingStart`, 'admin-comments-saveproviders')
  128. try {
  129. const resp = await this.$apollo.mutate({
  130. mutation: gql`
  131. mutation($providers: [CommentProviderInput]!) {
  132. comments {
  133. updateProviders(providers: $providers) {
  134. responseResult {
  135. succeeded
  136. errorCode
  137. slug
  138. message
  139. }
  140. }
  141. }
  142. }
  143. `,
  144. variables: {
  145. providers: this.providers.map(tgt => ({
  146. isEnabled: tgt.key === this.selectedProvider,
  147. key: tgt.key,
  148. config: tgt.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))
  149. }))
  150. }
  151. })
  152. if (_.get(resp, 'data.comments.updateProviders.responseResult.succeeded', false)) {
  153. this.$store.commit('showNotification', {
  154. message: this.$t('admin:comments.configSaveSuccess'),
  155. style: 'success',
  156. icon: 'check'
  157. })
  158. } else {
  159. throw new Error(_.get(resp, 'data.comments.updateProviders.responseResult.message', this.$t('common:error.unexpected')))
  160. }
  161. } catch (err) {
  162. this.$store.commit('pushGraphError', err)
  163. }
  164. this.$store.commit(`loadingStop`, 'admin-comments-saveproviders')
  165. }
  166. },
  167. apollo: {
  168. providers: {
  169. query: gql`
  170. query {
  171. comments {
  172. providers {
  173. isEnabled
  174. key
  175. title
  176. description
  177. logo
  178. website
  179. isAvailable
  180. config {
  181. key
  182. value
  183. }
  184. }
  185. }
  186. }
  187. `,
  188. fetchPolicy: 'network-only',
  189. update: (data) => _.cloneDeep(data.comments.providers).map(str => ({
  190. ...str,
  191. config: _.sortBy(str.config.map(cfg => ({
  192. ...cfg,
  193. value: JSON.parse(cfg.value)
  194. })), [t => t.value.order])
  195. })),
  196. watchLoading (isLoading) {
  197. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-comments-refresh')
  198. }
  199. }
  200. }
  201. }
  202. </script>