admin-storage.vue 15 KB

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