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.

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