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.

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