admin-analytics.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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-line-chart.svg', alt='Analytics', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft {{ $t('admin:analytics.title') }}
  9. .subtitle-1.grey--text.animated.fadeInLeft.wait-p4s {{ $t('admin:analytics.subtitle') }}
  10. v-spacer
  11. v-btn.animated.fadeInDown.wait-p2s.mr-3(icon, outlined, color='grey', @click='refresh')
  12. v-icon mdi-refresh
  13. v-btn.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:analytics.providers')}}
  20. v-list(two-line, dense).py-0
  21. template(v-for='(str, idx) in providers')
  22. v-list-item(:key='str.key', @click='selectedProvider = str.key', :disabled='!str.isAvailable')
  23. v-list-item-avatar(size='24')
  24. v-icon(color='grey', v-if='!str.isAvailable') mdi-minus-box-outline
  25. v-icon(color='primary', v-else-if='str.isEnabled', v-ripple, @click='str.isEnabled = false') mdi-checkbox-marked-outline
  26. v-icon(color='grey', v-else, v-ripple, @click='str.isEnabled = true') mdi-checkbox-blank-outline
  27. v-list-item-content
  28. v-list-item-title.body-2(:class='!str.isAvailable ? `grey--text` : (selectedProvider === str.key ? `primary--text` : ``)') {{ str.title }}
  29. v-list-item-subtitle: .caption(:class='!str.isAvailable ? `grey--text text--lighten-1` : (selectedProvider === str.key ? `blue--text ` : ``)') {{ str.description }}
  30. v-list-item-avatar(v-if='selectedProvider === str.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(xs12, lg9)
  34. v-card.animated.fadeInUp.wait-p2s
  35. v-toolbar(color='primary', dense, flat, dark)
  36. .subtitle-1 {{provider.title}}
  37. v-spacer
  38. v-switch(
  39. dark
  40. color='blue lighten-5'
  41. label='Active'
  42. v-model='provider.isEnabled'
  43. hide-details
  44. inset
  45. )
  46. v-card-info(color='blue')
  47. div
  48. div {{provider.description}}
  49. span.caption: a(:href='provider.website') {{provider.website}}
  50. v-spacer
  51. .admin-providerlogo
  52. img(:src='provider.logo', :alt='provider.title')
  53. v-card-text
  54. v-form
  55. .overline.pb-5 {{$t('admin:analytics.providerConfiguration')}}
  56. .body-1.ml-3(v-if='!provider.config || provider.config.length < 1'): em {{$t('admin:analytics.providerNoConfiguration')}}
  57. template(v-else, v-for='cfg in provider.config')
  58. v-select(
  59. v-if='cfg.value.type === "string" && cfg.value.enum'
  60. outlined
  61. :items='cfg.value.enum'
  62. :key='cfg.key'
  63. :label='cfg.value.title'
  64. v-model='cfg.value.value'
  65. prepend-icon='mdi-cog-box'
  66. :hint='cfg.value.hint ? cfg.value.hint : ""'
  67. persistent-hint
  68. :class='cfg.value.hint ? "mb-2" : ""'
  69. )
  70. v-switch.mb-3(
  71. v-else-if='cfg.value.type === "boolean"'
  72. :key='cfg.key'
  73. :label='cfg.value.title'
  74. v-model='cfg.value.value'
  75. color='primary'
  76. prepend-icon='mdi-cog-box'
  77. :hint='cfg.value.hint ? cfg.value.hint : ""'
  78. persistent-hint
  79. inset
  80. )
  81. v-textarea(
  82. v-else-if='cfg.value.type === "string" && cfg.value.multiline'
  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. )
  92. v-text-field(
  93. v-else
  94. outlined
  95. :key='cfg.key'
  96. :label='cfg.value.title'
  97. v-model='cfg.value.value'
  98. prepend-icon='mdi-cog-box'
  99. :hint='cfg.value.hint ? cfg.value.hint : ""'
  100. persistent-hint
  101. :class='cfg.value.hint ? "mb-2" : ""'
  102. )
  103. </template>
  104. <script>
  105. import _ from 'lodash'
  106. import providersQuery from 'gql/admin/analytics/analytics-query-providers.gql'
  107. import providersSaveMutation from 'gql/admin/analytics/analytics-mutation-save-providers.gql'
  108. export default {
  109. data() {
  110. return {
  111. providers: [],
  112. selectedProvider: '',
  113. provider: {}
  114. }
  115. },
  116. watch: {
  117. selectedProvider(newValue, oldValue) {
  118. this.provider = _.find(this.providers, ['key', newValue]) || {}
  119. },
  120. providers(newValue, oldValue) {
  121. this.selectedProvider = 'google'
  122. }
  123. },
  124. methods: {
  125. async refresh() {
  126. await this.$apollo.queries.providers.refetch()
  127. this.$store.commit('showNotification', {
  128. message: this.$t('admin:analytics.refreshSuccess'),
  129. style: 'success',
  130. icon: 'cached'
  131. })
  132. },
  133. async save() {
  134. this.$store.commit(`loadingStart`, 'admin-analytics-saveproviders')
  135. try {
  136. await this.$apollo.mutate({
  137. mutation: providersSaveMutation,
  138. variables: {
  139. providers: this.providers.map(str => _.pick(str, [
  140. 'isEnabled',
  141. 'key',
  142. 'config'
  143. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
  144. }
  145. })
  146. this.$store.commit('showNotification', {
  147. message: this.$t('admin:analytics.saveSuccess'),
  148. style: 'success',
  149. icon: 'check'
  150. })
  151. } catch (err) {
  152. this.$store.commit('pushGraphError', err)
  153. }
  154. this.$store.commit(`loadingStop`, 'admin-analytics-saveproviders')
  155. }
  156. },
  157. apollo: {
  158. providers: {
  159. query: providersQuery,
  160. fetchPolicy: 'network-only',
  161. update: (data) => _.cloneDeep(data.analytics.providers).map(str => ({
  162. ...str,
  163. config: _.sortBy(str.config.map(cfg => ({
  164. ...cfg,
  165. value: JSON.parse(cfg.value)
  166. })), [t => t.value.order])
  167. })),
  168. watchLoading (isLoading) {
  169. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-analytics-refresh')
  170. }
  171. }
  172. }
  173. }
  174. </script>