admin-storage.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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(
  15. v-for='tgt in targets'
  16. v-model='tgt.isEnabled'
  17. :key='tgt.key'
  18. :label='tgt.title'
  19. color='primary'
  20. :disabled='tgt.key === `local`'
  21. hide-details
  22. )
  23. v-tab-item(v-for='(tgt, n) in activeTargets', :key='tgt.key', :transition='false', :reverse-transition='false')
  24. v-card.pa-3(flat, tile)
  25. v-form
  26. v-subheader.pl-0 Target Configuration
  27. .body-1.ml-3(v-if='!tgt.config || tgt.config.length < 1') This storage target has no configuration options you can modify.
  28. v-text-field(
  29. v-else
  30. v-for='cfg in tgt.config'
  31. :key='cfg.key'
  32. :label='cfg.key'
  33. v-model='cfg.value'
  34. prepend-icon='settings_applications'
  35. )
  36. v-divider
  37. v-subheader.pl-0 Sync Direction
  38. .body-1.ml-3 Choose how content synchronization is handled for this storage target.
  39. .pr-3.pt-3
  40. v-radio-group.ml-3.py-0(v-model='tgt.mode')
  41. v-radio(
  42. label='Bi-directional'
  43. color='primary'
  44. value='sync'
  45. )
  46. v-radio(
  47. label='Push to target'
  48. color='primary'
  49. value='push'
  50. )
  51. v-radio(
  52. label='Pull from target'
  53. color='primary'
  54. value='pull'
  55. )
  56. .body-1.ml-3
  57. strong Bi-directional
  58. .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.
  59. strong Push to target
  60. .pb-3 Content is always pushed to the storage target, overwriting any existing content. This is the default and safest choice for backup scenarios.
  61. strong Pull from target
  62. .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!
  63. v-card-chin
  64. v-btn(color='primary', @click='save')
  65. v-icon(left) chevron_right
  66. span Apply Configuration
  67. v-spacer
  68. v-btn(icon, @click='refresh')
  69. v-icon.grey--text refresh
  70. </template>
  71. <script>
  72. import _ from 'lodash'
  73. import targetsQuery from 'gql/admin/storage/storage-query-targets.gql'
  74. import targetsSaveMutation from 'gql/admin/storage/storage-mutation-save-targets.gql'
  75. export default {
  76. data() {
  77. return {
  78. targets: []
  79. }
  80. },
  81. computed: {
  82. activeTargets() {
  83. return _.filter(this.targets, 'isEnabled')
  84. }
  85. },
  86. methods: {
  87. async refresh() {
  88. await this.$apollo.queries.targets.refetch()
  89. this.$store.commit('showNotification', {
  90. message: 'List of storage targets has been refreshed.',
  91. style: 'success',
  92. icon: 'cached'
  93. })
  94. },
  95. async save() {
  96. this.$store.commit(`loadingStart`, 'admin-storage-savetargets')
  97. await this.$apollo.mutate({
  98. mutation: targetsSaveMutation,
  99. variables: {
  100. targets: this.targets.map(tgt => _.pick(tgt, [
  101. 'isEnabled',
  102. 'key',
  103. 'config',
  104. 'mode'
  105. ]))
  106. }
  107. })
  108. this.$store.commit('showNotification', {
  109. message: 'Storage configuration saved successfully.',
  110. style: 'success',
  111. icon: 'check'
  112. })
  113. this.$store.commit(`loadingStop`, 'admin-storage-savetargets')
  114. }
  115. },
  116. apollo: {
  117. targets: {
  118. query: targetsQuery,
  119. fetchPolicy: 'network-only',
  120. update: (data) => _.cloneDeep(data.storage.targets),
  121. watchLoading (isLoading) {
  122. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-storage-refresh')
  123. }
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang='scss'>
  129. </style>