admin-analytics.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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(outline, color='grey', @click='refresh', large)
  12. v-icon refresh
  13. v-btn.animated.fadeInDown(color='success', @click='save', depressed, large)
  14. v-icon(left) 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-tile(:key='str.key', @click='selectedProvider = str.key', :disabled='!str.isAvailable')
  23. v-list-tile-avatar
  24. v-icon(color='grey', v-if='!str.isAvailable') indeterminate_check_box
  25. v-icon(color='primary', v-else-if='str.isEnabled', v-ripple, @click='str.isEnabled = false') check_box
  26. v-icon(color='grey', v-else, v-ripple, @click='str.isEnabled = true') check_box_outline_blank
  27. v-list-tile-content
  28. v-list-tile-title.body-2(:class='!str.isAvailable ? `grey--text` : (selectedProvider === str.key ? `primary--text` : ``)') {{ str.title }}
  29. v-list-tile-sub-title.caption(:class='!str.isAvailable ? `grey--text text--lighten-1` : (selectedProvider === str.key ? `blue--text ` : ``)') {{ str.description }}
  30. v-list-tile-avatar(v-if='selectedProvider === str.key')
  31. v-icon.animated.fadeInLeft(color='primary') arrow_forward_ios
  32. v-divider(v-if='idx < providers.length - 1')
  33. v-flex(xs12, lg9)
  34. v-card.wiki-form.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. v-subheader.pl-0 {{$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. outline
  50. background-color='grey lighten-2'
  51. :items='cfg.value.enum'
  52. :key='cfg.key'
  53. :label='cfg.value.title'
  54. v-model='cfg.value.value'
  55. prepend-icon='settings_applications'
  56. :hint='cfg.value.hint ? cfg.value.hint : ""'
  57. persistent-hint
  58. :class='cfg.value.hint ? "mb-2" : ""'
  59. )
  60. v-switch.mb-3(
  61. v-else-if='cfg.value.type === "boolean"'
  62. :key='cfg.key'
  63. :label='cfg.value.title'
  64. v-model='cfg.value.value'
  65. color='primary'
  66. prepend-icon='settings_applications'
  67. :hint='cfg.value.hint ? cfg.value.hint : ""'
  68. persistent-hint
  69. )
  70. v-text-field(
  71. v-else
  72. outline
  73. background-color='grey lighten-2'
  74. :key='cfg.key'
  75. :label='cfg.value.title'
  76. v-model='cfg.value.value'
  77. prepend-icon='settings_applications'
  78. :hint='cfg.value.hint ? cfg.value.hint : ""'
  79. persistent-hint
  80. :class='cfg.value.hint ? "mb-2" : ""'
  81. )
  82. </template>
  83. <script>
  84. import _ from 'lodash'
  85. import providersQuery from 'gql/admin/analytics/analytics-query-providers.gql'
  86. import providersSaveMutation from 'gql/admin/analytics/analytics-mutation-save-providers.gql'
  87. export default {
  88. data() {
  89. return {
  90. providers: [],
  91. selectedProvider: '',
  92. provider: {}
  93. }
  94. },
  95. watch: {
  96. selectedProvider(newValue, oldValue) {
  97. this.provider = _.find(this.providers, ['key', newValue]) || {}
  98. },
  99. providers(newValue, oldValue) {
  100. this.selectedProvider = 'google'
  101. }
  102. },
  103. methods: {
  104. async refresh() {
  105. await this.$apollo.queries.providers.refetch()
  106. this.$store.commit('showNotification', {
  107. message: this.$t('admin:analytics.refreshSuccess'),
  108. style: 'success',
  109. icon: 'cached'
  110. })
  111. },
  112. async save() {
  113. this.$store.commit(`loadingStart`, 'admin-analytics-saveproviders')
  114. try {
  115. await this.$apollo.mutate({
  116. mutation: providersSaveMutation,
  117. variables: {
  118. providers: this.providers.map(str => _.pick(str, [
  119. 'isEnabled',
  120. 'key',
  121. 'config'
  122. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
  123. }
  124. })
  125. this.$store.commit('showNotification', {
  126. message: this.$t('admin:analytics.saveSuccess'),
  127. style: 'success',
  128. icon: 'check'
  129. })
  130. } catch (err) {
  131. this.$store.commit('pushGraphError', err)
  132. }
  133. this.$store.commit(`loadingStop`, 'admin-analytics-saveproviders')
  134. }
  135. },
  136. apollo: {
  137. providers: {
  138. query: providersQuery,
  139. fetchPolicy: 'network-only',
  140. update: (data) => _.cloneDeep(data.analytics.providers).map(str => ({
  141. ...str,
  142. config: _.sortBy(str.config.map(cfg => ({
  143. ...cfg,
  144. value: JSON.parse(cfg.value)
  145. })), [t => t.value.order])
  146. })),
  147. watchLoading (isLoading) {
  148. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-analytics-refresh')
  149. }
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang='scss' scoped>
  155. .analytic-provider-logo {
  156. width: 250px;
  157. height: 85px;
  158. float:right;
  159. display: flex;
  160. justify-content: flex-end;
  161. align-items: center;
  162. img {
  163. max-width: 100%;
  164. max-height: 50px;
  165. }
  166. }
  167. </style>