admin-storage.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template lang='pug'>
  2. v-card(tile, :color='$vuetify.dark ? "grey darken-4" : "grey lighten-5"')
  3. .pa-3.pt-4
  4. .headline.primary--text Storage
  5. .subheading.grey--text Set backup and sync targets for your content
  6. v-tabs(:color='$vuetify.dark ? "primary" : "grey lighten-4"', fixed-tabs, :slider-color='$vuetify.dark ? "white" : "primary"', show-arrows)
  7. v-tab(key='settings'): v-icon settings
  8. v-tab(v-for='tgt in activeTargets', :key='tgt.key') {{ tgt.title }}
  9. v-tab-item(key='settings', :transition='false', :reverse-transition='false')
  10. v-card.pa-3(flat, tile)
  11. .body-2.grey--text.text--darken-1 Select which storage targets to enable:
  12. .caption.grey--text.pb-2 Some storage targets require additional configuration in their dedicated tab (when selected).
  13. v-form
  14. v-checkbox.my-1(
  15. v-for='tgt in targets'
  16. v-model='tgt.isEnabled'
  17. :key='tgt.key'
  18. :label='tgt.title'
  19. color='primary'
  20. hide-details
  21. )
  22. v-tab-item(v-for='(tgt, n) in activeTargets', :key='tgt.key', :transition='false', :reverse-transition='false')
  23. v-card.pa-3(flat, tile)
  24. v-form
  25. v-subheader.pl-0 Target Configuration
  26. .body-1.ml-3(v-if='!tgt.config || tgt.config.length < 1') This storage target has no configuration options you can modify.
  27. template(v-else, v-for='cfg in tgt.config')
  28. v-select(
  29. v-if='cfg.value.type === "string" && cfg.value.enum'
  30. outline
  31. background-color='grey lighten-2'
  32. :items='cfg.value.enum'
  33. :key='cfg.key'
  34. :label='cfg.value.title'
  35. v-model='cfg.value.value'
  36. prepend-icon='settings_applications'
  37. :hint='cfg.value.hint ? cfg.value.hint : ""'
  38. persistent-hint
  39. :class='cfg.value.hint ? "mb-2" : ""'
  40. )
  41. v-switch(
  42. v-else-if='cfg.value.type === "boolean"'
  43. :key='cfg.key'
  44. :label='cfg.value.title'
  45. v-model='cfg.value.value'
  46. color='primary'
  47. prepend-icon='settings_applications'
  48. :hint='cfg.value.hint ? cfg.value.hint : ""'
  49. persistent-hint
  50. )
  51. v-text-field(
  52. v-else
  53. outline
  54. background-color='grey lighten-2'
  55. :key='cfg.key'
  56. :label='cfg.value.title'
  57. v-model='cfg.value.value'
  58. prepend-icon='settings_applications'
  59. :hint='cfg.value.hint ? cfg.value.hint : ""'
  60. persistent-hint
  61. :class='cfg.value.hint ? "mb-2" : ""'
  62. )
  63. v-divider.mt-3
  64. v-subheader.pl-0 Sync Direction
  65. .body-1.ml-3 Choose how content synchronization is handled for this storage target.
  66. .pr-3.pt-3
  67. v-radio-group.ml-3.py-0(v-model='tgt.mode')
  68. v-radio(
  69. label='Bi-directional'
  70. color='primary'
  71. value='sync'
  72. )
  73. v-radio(
  74. label='Push to target'
  75. color='primary'
  76. value='push'
  77. )
  78. v-radio(
  79. label='Pull from target'
  80. color='primary'
  81. value='pull'
  82. )
  83. .body-1.ml-3
  84. strong Bi-directional
  85. .pb-3 In bi-directional mode, content is first pulled from the storage target. Any newer content overwrites local content. New content since last sync is then pushed to the storage target, overwriting any content on target if present.
  86. strong Push to target
  87. .pb-3 Content is always pushed to the storage target, overwriting any existing content. This is the default and safest choice for backup scenarios.
  88. strong Pull from target
  89. .pb-3 Content is always pulled from the storage target, overwriting any local content which already exists. This choice is usually reserved for single-use content import. Caution with this option as any local content will always be overwritten!
  90. v-card-chin
  91. v-btn(color='primary', @click='save')
  92. v-icon(left) chevron_right
  93. span Apply Configuration
  94. v-spacer
  95. v-btn(icon, @click='refresh')
  96. v-icon.grey--text refresh
  97. </template>
  98. <script>
  99. import _ from 'lodash'
  100. import targetsQuery from 'gql/admin/storage/storage-query-targets.gql'
  101. import targetsSaveMutation from 'gql/admin/storage/storage-mutation-save-targets.gql'
  102. export default {
  103. filters: {
  104. startCase(val) { return _.startCase(val) }
  105. },
  106. data() {
  107. return {
  108. targets: []
  109. }
  110. },
  111. computed: {
  112. activeTargets() {
  113. return _.filter(this.targets, 'isEnabled')
  114. }
  115. },
  116. methods: {
  117. async refresh() {
  118. await this.$apollo.queries.targets.refetch()
  119. this.$store.commit('showNotification', {
  120. message: 'List of storage targets has been refreshed.',
  121. style: 'success',
  122. icon: 'cached'
  123. })
  124. },
  125. async save() {
  126. this.$store.commit(`loadingStart`, 'admin-storage-savetargets')
  127. await this.$apollo.mutate({
  128. mutation: targetsSaveMutation,
  129. variables: {
  130. targets: this.targets.map(tgt => _.pick(tgt, [
  131. 'isEnabled',
  132. 'key',
  133. 'config',
  134. 'mode'
  135. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: cfg.value.value}))}))
  136. }
  137. })
  138. this.$store.commit('showNotification', {
  139. message: 'Storage configuration saved successfully.',
  140. style: 'success',
  141. icon: 'check'
  142. })
  143. this.$store.commit(`loadingStop`, 'admin-storage-savetargets')
  144. }
  145. },
  146. apollo: {
  147. targets: {
  148. query: targetsQuery,
  149. fetchPolicy: 'network-only',
  150. update: (data) => _.cloneDeep(data.storage.targets).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.parse(cfg.value)}))})),
  151. watchLoading (isLoading) {
  152. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-storage-refresh')
  153. }
  154. }
  155. }
  156. }
  157. </script>
  158. <style lang='scss'>
  159. </style>