admin-storage.vue 15 KB

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