admin-comments.vue 7.5 KB

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