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.

366 lines
15 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.animated.fadeInUp(src='/svg/icon-cloud-storage.svg', alt='Storage', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft {{$t('admin:storage.title')}}
  9. .subtitle-1.grey--text.animated.fadeInLeft.wait-p4s {{$t('admin:storage.subtitle')}}
  10. v-spacer
  11. v-btn.mx-3.animated.fadeInDown.wait-p2s(outlined, color='grey', @click='refresh', large)
  12. v-icon mdi-refresh
  13. v-btn.animated.fadeInDown(color='success', @click='save', depressed, large)
  14. v-icon(left) mdi-check
  15. span {{$t('common:actions.apply')}}
  16. v-flex(lg3, xs12)
  17. v-card.animated.fadeInUp
  18. v-toolbar(flat, color='primary', dark, dense)
  19. .subtitle-1 {{$t('admin:storage.targets')}}
  20. v-list(two-line, dense).py-0
  21. template(v-for='(tgt, idx) in targets')
  22. v-list-item(:key='tgt.key', @click='selectedTarget = tgt.key', :disabled='!tgt.isAvailable')
  23. v-list-item-avatar(size='24')
  24. v-icon(color='grey', v-if='!tgt.isAvailable') mdi-minus-box-outline
  25. v-icon(color='primary', v-else-if='tgt.isEnabled', v-ripple, @click='tgt.key !== `local` && (tgt.isEnabled = false)') mdi-checkbox-marked-outline
  26. v-icon(color='grey', v-else, v-ripple, @click='tgt.isEnabled = true') mdi-checkbox-blank-outline
  27. v-list-item-content
  28. v-list-item-title.body-2(:class='!tgt.isAvailable ? `grey--text` : (selectedTarget === tgt.key ? `primary--text` : ``)') {{ tgt.title }}
  29. v-list-item-subtitle: .caption(:class='!tgt.isAvailable ? `grey--text text--lighten-1` : (selectedTarget === tgt.key ? `blue--text ` : ``)') {{ tgt.description }}
  30. v-list-item-avatar(v-if='selectedTarget === tgt.key', size='24')
  31. v-icon.animated.fadeInLeft(color='primary', large) mdi-chevron-right
  32. v-divider(v-if='idx < targets.length - 1')
  33. v-card.mt-3.animated.fadeInUp.wait-p2s
  34. v-toolbar(flat, :color='$vuetify.theme.dark ? `grey darken-3-l5` : `grey darken-3`', dark, dense)
  35. .subtitle-1 {{$t('admin:storage.status')}}
  36. v-spacer
  37. looping-rhombuses-spinner(
  38. :animation-duration='5000'
  39. :rhombus-size='10'
  40. color='#FFF'
  41. )
  42. v-list.py-0(two-line, dense)
  43. template(v-for='(tgt, n) in status')
  44. v-list-item(:key='tgt.key')
  45. template(v-if='tgt.status === `pending`')
  46. v-list-item-avatar(color='purple')
  47. v-icon(color='white') mdi-clock-outline
  48. v-list-item-content
  49. v-list-item-title.body-2 {{tgt.title}}
  50. v-list-item-subtitle.purple--text.caption {{tgt.status}}
  51. v-list-item-action
  52. v-progress-circular(indeterminate, :size='20', :width='2', color='purple')
  53. template(v-else-if='tgt.status === `operational`')
  54. v-list-item-avatar(color='green')
  55. v-icon(color='white') mdi-check-circle
  56. v-list-item-content
  57. v-list-item-title.body-2 {{tgt.title}}
  58. v-list-item-subtitle.green--text.caption {{$t('admin:storage.lastSync', { time: $options.filters.moment(tgt.lastAttempt, 'from') })}}
  59. template(v-else)
  60. v-list-item-avatar(color='red')
  61. v-icon(color='white') mdi-close-circle-outline
  62. v-list-item-content
  63. v-list-item-title.body-2 {{tgt.title}}
  64. v-list-item-subtitle.red--text.caption {{$t('admin:storage.lastSyncAttempt', { time: $options.filters.moment(tgt.lastAttempt, 'from') })}}
  65. v-list-item-action
  66. v-menu
  67. v-btn(slot='activator', icon)
  68. v-icon(color='red') mdi-information
  69. v-card(width='450')
  70. v-toolbar(flat, color='red', dark, dense) {{$t('admin:storage.errorMsg')}}
  71. v-card-text {{tgt.message}}
  72. v-divider(v-if='n < status.length - 1')
  73. v-list-item(v-if='status.length < 1')
  74. em {{$t('admin:storage.noTarget')}}
  75. v-flex(xs12, lg9)
  76. v-card.wiki-form.animated.fadeInUp.wait-p2s
  77. v-toolbar(color='primary', dense, flat, dark)
  78. .subtitle-1 {{target.title}}
  79. v-spacer
  80. v-switch(
  81. dark
  82. color='blue lighten-5'
  83. label='Active'
  84. v-model='target.isEnabled'
  85. hide-details
  86. inset
  87. )
  88. v-card-text
  89. v-form
  90. .targetlogo
  91. img(:src='target.logo', :alt='target.title')
  92. .body-2.pt-3 {{target.description}}
  93. .body-2.pt-3.pb-5: a(:href='target.website') {{target.website}}
  94. i18next.body-2(path='admin:storage.targetState', tag='div', v-if='target.isEnabled')
  95. v-chip(color='green', small, dark, label, place='state') {{$t('admin:storage.targetStateActive')}}
  96. i18next.body-2(path='admin:storage.targetState', tag='div', v-else)
  97. v-chip(color='red', small, dark, label, place='state') {{$t('admin:storage.targetStateInactive')}}
  98. v-divider.mt-3
  99. .overline.my-5 {{$t('admin:storage.targetConfig')}}
  100. .body-2.ml-3(v-if='!target.config || target.config.length < 1'): em {{$t('admin:storage.noConfigOption')}}
  101. template(v-else, v-for='cfg in target.config')
  102. v-select(
  103. v-if='cfg.value.type === "string" && cfg.value.enum'
  104. outlined
  105. :items='cfg.value.enum'
  106. :key='cfg.key'
  107. :label='cfg.value.title'
  108. v-model='cfg.value.value'
  109. prepend-icon='mdi-settings-box'
  110. :hint='cfg.value.hint ? cfg.value.hint : ""'
  111. persistent-hint
  112. :class='cfg.value.hint ? "mb-2" : ""'
  113. )
  114. v-switch.mb-3(
  115. v-else-if='cfg.value.type === "boolean"'
  116. :key='cfg.key'
  117. :label='cfg.value.title'
  118. v-model='cfg.value.value'
  119. color='primary'
  120. prepend-icon='mdi-settings-box'
  121. :hint='cfg.value.hint ? cfg.value.hint : ""'
  122. persistent-hint
  123. inset
  124. )
  125. v-textarea(
  126. v-else-if='cfg.value.type === "string" && cfg.value.multiline'
  127. outlined
  128. :key='cfg.key'
  129. :label='cfg.value.title'
  130. v-model='cfg.value.value'
  131. prepend-icon='mdi-settings-box'
  132. :hint='cfg.value.hint ? cfg.value.hint : ""'
  133. persistent-hint
  134. :class='cfg.value.hint ? "mb-2" : ""'
  135. )
  136. v-text-field(
  137. v-else
  138. outlined
  139. :key='cfg.key'
  140. :label='cfg.value.title'
  141. v-model='cfg.value.value'
  142. prepend-icon='mdi-settings-box'
  143. :hint='cfg.value.hint ? cfg.value.hint : ""'
  144. persistent-hint
  145. :class='cfg.value.hint ? "mb-2" : ""'
  146. )
  147. v-divider.mt-3
  148. .overline.my-5 {{$t('admin:storage.syncDirection')}}
  149. .body-2.ml-3 {{$t('admin:storage.syncDirectionSubtitle')}}
  150. .pr-3.pt-3
  151. v-radio-group.ml-3.py-0(v-model='target.mode')
  152. v-radio(
  153. :label='$t(`admin:storage.syncDirBi`)'
  154. color='primary'
  155. value='sync'
  156. :disabled='target.supportedModes.indexOf(`sync`) < 0'
  157. )
  158. v-radio(
  159. :label='$t(`admin:storage.syncDirPush`)'
  160. color='primary'
  161. value='push'
  162. :disabled='target.supportedModes.indexOf(`push`) < 0'
  163. )
  164. v-radio(
  165. :label='$t(`admin:storage.syncDirPull`)'
  166. color='primary'
  167. value='pull'
  168. :disabled='target.supportedModes.indexOf(`pull`) < 0'
  169. )
  170. .body-2.ml-3
  171. strong {{$t('admin:storage.syncDirBi')}} #[em.red--text.text--lighten-2(v-if='target.supportedModes.indexOf(`sync`) < 0') {{$t('admin:storage.unsupported')}}]
  172. .pb-3 {{$t('admin:storage.syncDirBiHint')}}
  173. strong {{$t('admin:storage.syncDirPush')}} #[em.red--text.text--lighten-2(v-if='target.supportedModes.indexOf(`push`) < 0') {{$t('admin:storage.unsupported')}}]
  174. .pb-3 {{$t('admin:storage.syncDirPushHint')}}
  175. strong {{$t('admin:storage.syncDirPull')}} #[em.red--text.text--lighten-2(v-if='target.supportedModes.indexOf(`pull`) < 0') {{$t('admin:storage.unsupported')}}]
  176. .pb-3 {{$t('admin:storage.syncDirPullHint')}}
  177. template(v-if='target.hasSchedule')
  178. v-divider.mt-3
  179. .overline.my-5 {{$t('admin:storage.syncSchedule')}}
  180. .body-2.ml-3 {{$t('admin:storage.syncScheduleHint')}}
  181. .pa-3
  182. duration-picker(v-model='target.syncInterval')
  183. i18next.caption.mt-3(path='admin:storage.syncScheduleCurrent', tag='div')
  184. strong(place='schedule') {{getDefaultSchedule(target.syncInterval)}}
  185. i18next.caption(path='admin:storage.syncScheduleDefault', tag='div')
  186. strong(place='schedule') {{getDefaultSchedule(target.syncIntervalDefault)}}
  187. template(v-if='target.actions && target.actions.length > 0')
  188. v-divider.mt-3
  189. .overline.my-5 {{$t('admin:storage.actions')}}
  190. v-alert(outlined, :value='!target.isEnabled', color='red', icon='mdi-alert')
  191. .body-2 {{$t('admin:storage.actionsInactiveWarn')}}
  192. v-container.pt-0(grid-list-xl, fluid)
  193. v-layout(row, wrap, fill-height)
  194. v-flex(xs12, lg6, xl4, v-for='act of target.actions', :key='act.handler')
  195. v-card.radius-7.grey(flat, :class='$vuetify.theme.dark ? `darken-3-d5` : `lighten-3`', height='100%')
  196. v-card-text
  197. .subtitle-1(v-html='act.label')
  198. .body-2.mt-4(v-html='act.hint')
  199. v-btn.mx-0.mt-5(
  200. @click='executeAction(target.key, act.handler)'
  201. outlined
  202. :color='$vuetify.theme.dark ? `blue` : `primary`'
  203. :disabled='runningAction || !target.isEnabled'
  204. :loading='runningActionHandler === act.handler'
  205. ) {{$t('admin:storage.actionRun')}}
  206. </template>
  207. <script>
  208. import _ from 'lodash'
  209. import moment from 'moment'
  210. import momentDurationFormatSetup from 'moment-duration-format'
  211. import DurationPicker from '../common/duration-picker.vue'
  212. import { LoopingRhombusesSpinner } from 'epic-spinners'
  213. import statusQuery from 'gql/admin/storage/storage-query-status.gql'
  214. import targetsQuery from 'gql/admin/storage/storage-query-targets.gql'
  215. import targetExecuteActionMutation from 'gql/admin/storage/storage-mutation-executeaction.gql'
  216. import targetsSaveMutation from 'gql/admin/storage/storage-mutation-save-targets.gql'
  217. momentDurationFormatSetup(moment)
  218. export default {
  219. components: {
  220. DurationPicker,
  221. LoopingRhombusesSpinner
  222. },
  223. filters: {
  224. startCase(val) { return _.startCase(val) }
  225. },
  226. data() {
  227. return {
  228. runningAction: false,
  229. runningActionHandler: '',
  230. selectedTarget: '',
  231. target: {
  232. supportedModes: []
  233. },
  234. targets: [],
  235. status: []
  236. }
  237. },
  238. computed: {
  239. activeTargets() {
  240. return _.filter(this.targets, 'isEnabled')
  241. }
  242. },
  243. watch: {
  244. selectedTarget(newValue, oldValue) {
  245. this.target = _.find(this.targets, ['key', newValue]) || {}
  246. },
  247. targets(newValue, oldValue) {
  248. this.selectedTarget = _.get(_.find(this.targets, ['isEnabled', true]), 'key', 'disk')
  249. }
  250. },
  251. methods: {
  252. async refresh() {
  253. await this.$apollo.queries.targets.refetch()
  254. this.$store.commit('showNotification', {
  255. message: 'List of storage targets has been refreshed.',
  256. style: 'success',
  257. icon: 'cached'
  258. })
  259. },
  260. async save() {
  261. this.$store.commit(`loadingStart`, 'admin-storage-savetargets')
  262. await this.$apollo.mutate({
  263. mutation: targetsSaveMutation,
  264. variables: {
  265. targets: this.targets.map(tgt => _.pick(tgt, [
  266. 'isEnabled',
  267. 'key',
  268. 'config',
  269. 'mode',
  270. 'syncInterval'
  271. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
  272. }
  273. })
  274. this.$store.commit('showNotification', {
  275. message: 'Storage configuration saved successfully.',
  276. style: 'success',
  277. icon: 'check'
  278. })
  279. this.$store.commit(`loadingStop`, 'admin-storage-savetargets')
  280. },
  281. getDefaultSchedule(val) {
  282. if (!val) { return 'N/A' }
  283. return moment.duration(val).format('y [years], M [months], d [days], h [hours], m [minutes]')
  284. },
  285. async executeAction(targetKey, handler) {
  286. this.$store.commit(`loadingStart`, 'admin-storage-executeaction')
  287. this.runningAction = true
  288. this.runningActionHandler = handler
  289. try {
  290. await this.$apollo.mutate({
  291. mutation: targetExecuteActionMutation,
  292. variables: {
  293. targetKey,
  294. handler
  295. }
  296. })
  297. this.$store.commit('showNotification', {
  298. message: 'Action completed.',
  299. style: 'success',
  300. icon: 'check'
  301. })
  302. } catch (err) {
  303. console.warn(err)
  304. }
  305. this.runningAction = false
  306. this.runningActionHandler = ''
  307. this.$store.commit(`loadingStop`, 'admin-storage-executeaction')
  308. }
  309. },
  310. apollo: {
  311. targets: {
  312. query: targetsQuery,
  313. fetchPolicy: 'network-only',
  314. update: (data) => _.cloneDeep(data.storage.targets).map(str => ({
  315. ...str,
  316. config: _.sortBy(str.config.map(cfg => ({
  317. ...cfg,
  318. value: JSON.parse(cfg.value)
  319. })), [t => t.value.order])
  320. })),
  321. watchLoading (isLoading) {
  322. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-storage-targets-refresh')
  323. }
  324. },
  325. status: {
  326. query: statusQuery,
  327. fetchPolicy: 'network-only',
  328. update: (data) => data.storage.status,
  329. watchLoading (isLoading) {
  330. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-storage-status-refresh')
  331. },
  332. pollInterval: 3000
  333. }
  334. }
  335. }
  336. </script>
  337. <style lang='scss' scoped>
  338. .targetlogo {
  339. width: 250px;
  340. height: 85px;
  341. float:right;
  342. display: flex;
  343. justify-content: flex-end;
  344. align-items: center;
  345. img {
  346. max-width: 100%;
  347. max-height: 50px;
  348. }
  349. }
  350. </style>