admin-storage.vue 14 KB

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