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.

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