admin-storage.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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
  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-container.pa-3(fluid, grid-list-md)
  22. v-layout(row, wrap)
  23. v-flex(xs12, md6)
  24. .body-2.grey--text.text--darken-1 Select which storage targets to enable:
  25. .caption.grey--text.pb-2 Some storage targets require additional configuration in their dedicated tab (when selected).
  26. v-form
  27. v-checkbox.my-0(
  28. :disabled='!tgt.isAvailable'
  29. v-for='tgt in targets'
  30. v-model='tgt.isEnabled'
  31. :key='tgt.key'
  32. :label='tgt.title'
  33. color='primary'
  34. hide-details
  35. )
  36. v-flex(xs12, md6)
  37. .pa-3.grey.radius-7(:class='$vuetify.dark ? "darken-4" : "lighten-5"')
  38. .body-2.grey--text.text--darken-1 Advanced Settings
  39. v-text-field.mt-3.md2(
  40. v-model='syncInterval'
  41. outline
  42. background-color='grey lighten-2'
  43. prepend-icon='schedule'
  44. label='Synchronization Interval'
  45. hint='For performance reasons, some storage targets synchronize changes on an interval-based schedule, instead of on every change. Define at which interval should the synchronization occur for all storage targets.'
  46. persistent-hint
  47. )
  48. v-tab-item(v-for='(tgt, n) in activeTargets', :key='tgt.key', :transition='false', :reverse-transition='false')
  49. v-card.pa-3(flat, tile)
  50. v-form
  51. .targetlogo
  52. img(:src='tgt.logo', :alt='tgt.title')
  53. v-subheader.pl-0 {{tgt.title}}
  54. .caption {{tgt.description}}
  55. .caption: a(:href='tgt.website') {{tgt.website}}
  56. v-divider.mt-3
  57. v-subheader.pl-0 Target Configuration
  58. .body-1.ml-3(v-if='!tgt.config || tgt.config.length < 1') This storage target has no configuration options you can modify.
  59. template(v-else, v-for='cfg in tgt.config')
  60. v-select(
  61. v-if='cfg.value.type === "string" && cfg.value.enum'
  62. outline
  63. background-color='grey lighten-2'
  64. :items='cfg.value.enum'
  65. :key='cfg.key'
  66. :label='cfg.value.title'
  67. v-model='cfg.value.value'
  68. prepend-icon='settings_applications'
  69. :hint='cfg.value.hint ? cfg.value.hint : ""'
  70. persistent-hint
  71. :class='cfg.value.hint ? "mb-2" : ""'
  72. )
  73. v-switch.mb-3(
  74. v-else-if='cfg.value.type === "boolean"'
  75. :key='cfg.key'
  76. :label='cfg.value.title'
  77. v-model='cfg.value.value'
  78. color='primary'
  79. prepend-icon='settings_applications'
  80. :hint='cfg.value.hint ? cfg.value.hint : ""'
  81. persistent-hint
  82. )
  83. v-text-field(
  84. v-else
  85. outline
  86. background-color='grey lighten-2'
  87. :key='cfg.key'
  88. :label='cfg.value.title'
  89. v-model='cfg.value.value'
  90. prepend-icon='settings_applications'
  91. :hint='cfg.value.hint ? cfg.value.hint : ""'
  92. persistent-hint
  93. :class='cfg.value.hint ? "mb-2" : ""'
  94. )
  95. v-divider.mt-3
  96. v-subheader.pl-0 Sync Direction
  97. .body-1.ml-3 Choose how content synchronization is handled for this storage target.
  98. .pr-3.pt-3
  99. v-radio-group.ml-3.py-0(v-model='tgt.mode')
  100. v-radio(
  101. label='Bi-directional'
  102. color='primary'
  103. value='sync'
  104. :disabled='tgt.supportedModes.indexOf(`sync`) < 0'
  105. )
  106. v-radio(
  107. label='Push to target'
  108. color='primary'
  109. value='push'
  110. :disabled='tgt.supportedModes.indexOf(`push`) < 0'
  111. )
  112. v-radio(
  113. label='Pull from target'
  114. color='primary'
  115. value='pull'
  116. :disabled='tgt.supportedModes.indexOf(`pull`) < 0'
  117. )
  118. .body-1.ml-3
  119. strong Bi-directional #[em.red--text.text--lighten-2(v-if='tgt.supportedModes.indexOf(`sync`) < 0') Unsupported]
  120. .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.
  121. strong Push to target #[em.red--text.text--lighten-2(v-if='tgt.supportedModes.indexOf(`push`) < 0') Unsupported]
  122. .pb-3 Content is always pushed to the storage target, overwriting any existing content. This is safest choice for backup scenarios.
  123. strong Pull from target #[em.red--text.text--lighten-2(v-if='tgt.supportedModes.indexOf(`pull`) < 0') Unsupported]
  124. .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!
  125. </template>
  126. <script>
  127. import _ from 'lodash'
  128. import targetsQuery from 'gql/admin/storage/storage-query-targets.gql'
  129. import targetsSaveMutation from 'gql/admin/storage/storage-mutation-save-targets.gql'
  130. export default {
  131. filters: {
  132. startCase(val) { return _.startCase(val) }
  133. },
  134. data() {
  135. return {
  136. syncInterval: '5m',
  137. targets: []
  138. }
  139. },
  140. computed: {
  141. activeTargets() {
  142. return _.filter(this.targets, 'isEnabled')
  143. }
  144. },
  145. methods: {
  146. async refresh() {
  147. await this.$apollo.queries.targets.refetch()
  148. this.$store.commit('showNotification', {
  149. message: 'List of storage targets has been refreshed.',
  150. style: 'success',
  151. icon: 'cached'
  152. })
  153. },
  154. async save() {
  155. this.$store.commit(`loadingStart`, 'admin-storage-savetargets')
  156. await this.$apollo.mutate({
  157. mutation: targetsSaveMutation,
  158. variables: {
  159. targets: this.targets.map(tgt => _.pick(tgt, [
  160. 'isEnabled',
  161. 'key',
  162. 'config',
  163. 'mode'
  164. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
  165. }
  166. })
  167. this.$store.commit('showNotification', {
  168. message: 'Storage configuration saved successfully.',
  169. style: 'success',
  170. icon: 'check'
  171. })
  172. this.$store.commit(`loadingStop`, 'admin-storage-savetargets')
  173. }
  174. },
  175. apollo: {
  176. targets: {
  177. query: targetsQuery,
  178. fetchPolicy: 'network-only',
  179. update: (data) => _.cloneDeep(data.storage.targets).map(str => ({
  180. ...str,
  181. config: _.sortBy(str.config.map(cfg => ({
  182. ...cfg,
  183. value: JSON.parse(cfg.value)
  184. })), [t => t.value.order])
  185. })),
  186. watchLoading (isLoading) {
  187. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-storage-refresh')
  188. }
  189. }
  190. }
  191. }
  192. </script>
  193. <style lang='scss' scoped>
  194. .targetlogo {
  195. width: 250px;
  196. height: 85px;
  197. float:right;
  198. display: flex;
  199. justify-content: flex-end;
  200. align-items: center;
  201. img {
  202. max-width: 100%;
  203. max-height: 50px;
  204. }
  205. }
  206. </style>