admin-comments.vue 7.2 KB

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