You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
7.2 KiB

  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-text
  47. v-form
  48. .analytic-provider-logo
  49. img(:src='provider.logo', :alt='provider.title')
  50. .body-2.pt-3 {{provider.description}}
  51. .body-2.pt-3: a(:href='provider.website') {{provider.website}}
  52. v-divider.mt-5
  53. .overline.py-5 {{$t('admin:analytics.providerConfiguration')}}
  54. .body-1.ml-3(v-if='!provider.config || provider.config.length < 1'): em {{$t('admin:analytics.providerNoConfiguration')}}
  55. template(v-else, v-for='cfg in provider.config')
  56. v-select(
  57. v-if='cfg.value.type === "string" && cfg.value.enum'
  58. outlined
  59. :items='cfg.value.enum'
  60. :key='cfg.key'
  61. :label='cfg.value.title'
  62. v-model='cfg.value.value'
  63. prepend-icon='mdi-cog-box'
  64. :hint='cfg.value.hint ? cfg.value.hint : ""'
  65. persistent-hint
  66. :class='cfg.value.hint ? "mb-2" : ""'
  67. )
  68. v-switch.mb-3(
  69. v-else-if='cfg.value.type === "boolean"'
  70. :key='cfg.key'
  71. :label='cfg.value.title'
  72. v-model='cfg.value.value'
  73. color='primary'
  74. prepend-icon='mdi-cog-box'
  75. :hint='cfg.value.hint ? cfg.value.hint : ""'
  76. persistent-hint
  77. inset
  78. )
  79. v-textarea(
  80. v-else-if='cfg.value.type === "string" && cfg.value.multiline'
  81. outlined
  82. :key='cfg.key'
  83. :label='cfg.value.title'
  84. v-model='cfg.value.value'
  85. prepend-icon='mdi-cog-box'
  86. :hint='cfg.value.hint ? cfg.value.hint : ""'
  87. persistent-hint
  88. :class='cfg.value.hint ? "mb-2" : ""'
  89. )
  90. v-text-field(
  91. v-else
  92. outlined
  93. :key='cfg.key'
  94. :label='cfg.value.title'
  95. v-model='cfg.value.value'
  96. prepend-icon='mdi-cog-box'
  97. :hint='cfg.value.hint ? cfg.value.hint : ""'
  98. persistent-hint
  99. :class='cfg.value.hint ? "mb-2" : ""'
  100. )
  101. </template>
  102. <script>
  103. import _ from 'lodash'
  104. import providersQuery from 'gql/admin/analytics/analytics-query-providers.gql'
  105. import providersSaveMutation from 'gql/admin/analytics/analytics-mutation-save-providers.gql'
  106. export default {
  107. data() {
  108. return {
  109. providers: [],
  110. selectedProvider: '',
  111. provider: {}
  112. }
  113. },
  114. watch: {
  115. selectedProvider(newValue, oldValue) {
  116. this.provider = _.find(this.providers, ['key', newValue]) || {}
  117. },
  118. providers(newValue, oldValue) {
  119. this.selectedProvider = 'google'
  120. }
  121. },
  122. methods: {
  123. async refresh() {
  124. await this.$apollo.queries.providers.refetch()
  125. this.$store.commit('showNotification', {
  126. message: this.$t('admin:analytics.refreshSuccess'),
  127. style: 'success',
  128. icon: 'cached'
  129. })
  130. },
  131. async save() {
  132. this.$store.commit(`loadingStart`, 'admin-analytics-saveproviders')
  133. try {
  134. await this.$apollo.mutate({
  135. mutation: providersSaveMutation,
  136. variables: {
  137. providers: this.providers.map(str => _.pick(str, [
  138. 'isEnabled',
  139. 'key',
  140. 'config'
  141. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
  142. }
  143. })
  144. this.$store.commit('showNotification', {
  145. message: this.$t('admin:analytics.saveSuccess'),
  146. style: 'success',
  147. icon: 'check'
  148. })
  149. } catch (err) {
  150. this.$store.commit('pushGraphError', err)
  151. }
  152. this.$store.commit(`loadingStop`, 'admin-analytics-saveproviders')
  153. }
  154. },
  155. apollo: {
  156. providers: {
  157. query: providersQuery,
  158. fetchPolicy: 'network-only',
  159. update: (data) => _.cloneDeep(data.analytics.providers).map(str => ({
  160. ...str,
  161. config: _.sortBy(str.config.map(cfg => ({
  162. ...cfg,
  163. value: JSON.parse(cfg.value)
  164. })), [t => t.value.order])
  165. })),
  166. watchLoading (isLoading) {
  167. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-analytics-refresh')
  168. }
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang='scss' scoped>
  174. .analytic-provider-logo {
  175. width: 250px;
  176. height: 85px;
  177. float:right;
  178. display: flex;
  179. justify-content: flex-end;
  180. align-items: center;
  181. img {
  182. max-width: 100%;
  183. max-height: 50px;
  184. }
  185. }
  186. </style>