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.

188 lines
6.7 KiB

  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. .targetlogo
  26. img(:src='tgt.logo', :alt='tgt.title')
  27. v-subheader.pl-0 {{tgt.title}}
  28. .caption {{tgt.description}}
  29. .caption: a(:href='tgt.website') {{tgt.website}}
  30. v-divider.mt-3
  31. v-subheader.pl-0 Target Configuration
  32. .body-1.ml-3(v-if='!tgt.config || tgt.config.length < 1') This storage target has no configuration options you can modify.
  33. template(v-else, v-for='cfg in tgt.config')
  34. v-select(
  35. v-if='cfg.value.type === "string" && cfg.value.enum'
  36. outline
  37. background-color='grey lighten-2'
  38. :items='cfg.value.enum'
  39. :key='cfg.key'
  40. :label='cfg.value.title'
  41. v-model='cfg.value.value'
  42. prepend-icon='settings_applications'
  43. :hint='cfg.value.hint ? cfg.value.hint : ""'
  44. persistent-hint
  45. :class='cfg.value.hint ? "mb-2" : ""'
  46. )
  47. v-switch(
  48. v-else-if='cfg.value.type === "boolean"'
  49. :key='cfg.key'
  50. :label='cfg.value.title'
  51. v-model='cfg.value.value'
  52. color='primary'
  53. prepend-icon='settings_applications'
  54. :hint='cfg.value.hint ? cfg.value.hint : ""'
  55. persistent-hint
  56. )
  57. v-text-field(
  58. v-else
  59. outline
  60. background-color='grey lighten-2'
  61. :key='cfg.key'
  62. :label='cfg.value.title'
  63. v-model='cfg.value.value'
  64. prepend-icon='settings_applications'
  65. :hint='cfg.value.hint ? cfg.value.hint : ""'
  66. persistent-hint
  67. :class='cfg.value.hint ? "mb-2" : ""'
  68. )
  69. v-divider.mt-3
  70. v-subheader.pl-0 Sync Direction
  71. .body-1.ml-3 Choose how content synchronization is handled for this storage target.
  72. .pr-3.pt-3
  73. v-radio-group.ml-3.py-0(v-model='tgt.mode')
  74. v-radio(
  75. label='Bi-directional'
  76. color='primary'
  77. value='sync'
  78. )
  79. v-radio(
  80. label='Push to target'
  81. color='primary'
  82. value='push'
  83. )
  84. v-radio(
  85. label='Pull from target'
  86. color='primary'
  87. value='pull'
  88. )
  89. .body-1.ml-3
  90. strong Bi-directional
  91. .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.
  92. strong Push to target
  93. .pb-3 Content is always pushed to the storage target, overwriting any existing content. This is the default and safest choice for backup scenarios.
  94. strong Pull from target
  95. .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!
  96. v-card-chin
  97. v-btn(color='primary', @click='save')
  98. v-icon(left) chevron_right
  99. span Apply Configuration
  100. v-spacer
  101. v-btn(icon, @click='refresh')
  102. v-icon.grey--text refresh
  103. </template>
  104. <script>
  105. import _ from 'lodash'
  106. import targetsQuery from 'gql/admin/storage/storage-query-targets.gql'
  107. import targetsSaveMutation from 'gql/admin/storage/storage-mutation-save-targets.gql'
  108. export default {
  109. filters: {
  110. startCase(val) { return _.startCase(val) }
  111. },
  112. data() {
  113. return {
  114. targets: []
  115. }
  116. },
  117. computed: {
  118. activeTargets() {
  119. return _.filter(this.targets, 'isEnabled')
  120. }
  121. },
  122. methods: {
  123. async refresh() {
  124. await this.$apollo.queries.targets.refetch()
  125. this.$store.commit('showNotification', {
  126. message: 'List of storage targets has been refreshed.',
  127. style: 'success',
  128. icon: 'cached'
  129. })
  130. },
  131. async save() {
  132. this.$store.commit(`loadingStart`, 'admin-storage-savetargets')
  133. await this.$apollo.mutate({
  134. mutation: targetsSaveMutation,
  135. variables: {
  136. targets: this.targets.map(tgt => _.pick(tgt, [
  137. 'isEnabled',
  138. 'key',
  139. 'config',
  140. 'mode'
  141. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: cfg.value.value}))}))
  142. }
  143. })
  144. this.$store.commit('showNotification', {
  145. message: 'Storage configuration saved successfully.',
  146. style: 'success',
  147. icon: 'check'
  148. })
  149. this.$store.commit(`loadingStop`, 'admin-storage-savetargets')
  150. }
  151. },
  152. apollo: {
  153. targets: {
  154. query: targetsQuery,
  155. fetchPolicy: 'network-only',
  156. update: (data) => _.cloneDeep(data.storage.targets).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.parse(cfg.value)}))})),
  157. watchLoading (isLoading) {
  158. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-storage-refresh')
  159. }
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang='scss' scoped>
  165. .targetlogo {
  166. width: 250px;
  167. height: 85px;
  168. float:right;
  169. display: flex;
  170. justify-content: flex-end;
  171. align-items: center;
  172. img {
  173. max-width: 100%;
  174. max-height: 50px;
  175. }
  176. }
  177. </style>