admin-analytics.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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-line-chart.svg', alt='Analytics', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft {{ $t('admin:analytics.title') }}
  9. .subheading.grey--text.animated.fadeInLeft.wait-p4s {{ $t('admin:analytics.subtitle') }}
  10. v-spacer
  11. v-btn.animated.fadeInDown.wait-p2s.mr-3(outlined, color='grey', @click='refresh', large)
  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. .subheading {{$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. .subheading {{provider.title}}
  37. v-card-text
  38. v-form
  39. .analytic-provider-logo
  40. img(:src='provider.logo', :alt='provider.title')
  41. .caption.pt-3 {{provider.description}}
  42. .caption.pb-3: a(:href='provider.website') {{provider.website}}
  43. v-divider.mt-3
  44. .overline.py-4 {{$t('admin:analytics.providerConfiguration')}}
  45. .body-1.ml-3(v-if='!provider.config || provider.config.length < 1'): em {{$t('admin:analytics.providerNoConfiguration')}}
  46. template(v-else, v-for='cfg in provider.config')
  47. v-select(
  48. v-if='cfg.value.type === "string" && cfg.value.enum'
  49. outlined
  50. :items='cfg.value.enum'
  51. :key='cfg.key'
  52. :label='cfg.value.title'
  53. v-model='cfg.value.value'
  54. prepend-icon='mdi-settings-box'
  55. :hint='cfg.value.hint ? cfg.value.hint : ""'
  56. persistent-hint
  57. :class='cfg.value.hint ? "mb-2" : ""'
  58. )
  59. v-switch.mb-3(
  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-settings-box'
  66. :hint='cfg.value.hint ? cfg.value.hint : ""'
  67. persistent-hint
  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-settings-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-settings-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 providersQuery from 'gql/admin/analytics/analytics-query-providers.gql'
  95. import providersSaveMutation from 'gql/admin/analytics/analytics-mutation-save-providers.gql'
  96. export default {
  97. data() {
  98. return {
  99. providers: [],
  100. selectedProvider: '',
  101. provider: {}
  102. }
  103. },
  104. watch: {
  105. selectedProvider(newValue, oldValue) {
  106. this.provider = _.find(this.providers, ['key', newValue]) || {}
  107. },
  108. providers(newValue, oldValue) {
  109. this.selectedProvider = 'google'
  110. }
  111. },
  112. methods: {
  113. async refresh() {
  114. await this.$apollo.queries.providers.refetch()
  115. this.$store.commit('showNotification', {
  116. message: this.$t('admin:analytics.refreshSuccess'),
  117. style: 'success',
  118. icon: 'cached'
  119. })
  120. },
  121. async save() {
  122. this.$store.commit(`loadingStart`, 'admin-analytics-saveproviders')
  123. try {
  124. await this.$apollo.mutate({
  125. mutation: providersSaveMutation,
  126. variables: {
  127. providers: this.providers.map(str => _.pick(str, [
  128. 'isEnabled',
  129. 'key',
  130. 'config'
  131. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
  132. }
  133. })
  134. this.$store.commit('showNotification', {
  135. message: this.$t('admin:analytics.saveSuccess'),
  136. style: 'success',
  137. icon: 'check'
  138. })
  139. } catch (err) {
  140. this.$store.commit('pushGraphError', err)
  141. }
  142. this.$store.commit(`loadingStop`, 'admin-analytics-saveproviders')
  143. }
  144. },
  145. apollo: {
  146. providers: {
  147. query: providersQuery,
  148. fetchPolicy: 'network-only',
  149. update: (data) => _.cloneDeep(data.analytics.providers).map(str => ({
  150. ...str,
  151. config: _.sortBy(str.config.map(cfg => ({
  152. ...cfg,
  153. value: JSON.parse(cfg.value)
  154. })), [t => t.value.order])
  155. })),
  156. watchLoading (isLoading) {
  157. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-analytics-refresh')
  158. }
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang='scss' scoped>
  164. .analytic-provider-logo {
  165. width: 250px;
  166. height: 85px;
  167. float:right;
  168. display: flex;
  169. justify-content: flex-end;
  170. align-items: center;
  171. img {
  172. max-width: 100%;
  173. max-height: 50px;
  174. }
  175. }
  176. </style>