snapshot.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions"
  7. :showSingleActions="showActions"
  8. :showGroupActions="showActions" />
  9. </template>
  10. <script>
  11. import {
  12. getCopyWithContentTableColumn,
  13. getStatusTableColumn,
  14. getBrandTableColumn,
  15. } from '@/utils/common/tableColumn'
  16. import WindowsMixin from '@/mixins/windows'
  17. import { sizestr } from '@/utils/utils'
  18. import expectStatus from '@/constants/expectStatus'
  19. import i18n from '@/locales'
  20. import SingleActionsMixin from '@Compute/views/snapshot/mixins/singleActions'
  21. import ListMixin from '@/mixins/list'
  22. const DISK_TYPES = {
  23. sys: i18n.t('compute.text_49'),
  24. data: i18n.t('compute.text_50'),
  25. 'swap-swap': i18n.t('compute.text_51'),
  26. }
  27. export default {
  28. name: 'snapshotListSidepage',
  29. mixins: [WindowsMixin, SingleActionsMixin, ListMixin],
  30. props: {
  31. resId: String,
  32. data: {
  33. type: Object,
  34. required: true,
  35. },
  36. },
  37. data () {
  38. return {
  39. list: this.$list.createList(this, {
  40. ctx: this,
  41. id: 'SnapshotListForDiskSidePage',
  42. resource: 'snapshots',
  43. steadyStatus: Object.values(expectStatus.disk).flat(),
  44. getParams: { details: true, disk_id: this.resId },
  45. filterOptions: {
  46. name: {
  47. label: this.$t('compute.text_415'),
  48. filter: true,
  49. formatter: val => {
  50. return `name.contains("${val}")`
  51. },
  52. },
  53. disk_name: {
  54. label: this.$t('compute.text_100'),
  55. filter: true,
  56. formatter: val => {
  57. return `disk_name.contains("${val}")`
  58. },
  59. },
  60. },
  61. autoHiddenFilterKey: 'snapshot_hidden_columns',
  62. }),
  63. columns: [
  64. getCopyWithContentTableColumn({
  65. field: 'name',
  66. title: this.$t('compute.text_415'),
  67. }),
  68. {
  69. field: 'disk_name',
  70. title: this.$t('compute.text_100'),
  71. minWidth: 50,
  72. hidden: () => this.$isScopedPolicyMenuHidden('snapshot_hidden_columns.name'),
  73. },
  74. getBrandTableColumn({ hidden: () => this.$isScopedPolicyMenuHidden('snapshot_hidden_columns.brand') }),
  75. {
  76. field: 'size',
  77. title: this.$t('compute.text_397'),
  78. minWidth: 50,
  79. hidden: () => this.$isScopedPolicyMenuHidden('snapshot_hidden_columns.size'),
  80. formatter: ({ cellValue }) => {
  81. return sizestr(cellValue, 'M', 1024)
  82. },
  83. },
  84. {
  85. field: 'disk_type',
  86. title: this.$t('compute.text_381'),
  87. width: 70,
  88. formatter: ({ cellValue }) => {
  89. return DISK_TYPES[cellValue]
  90. },
  91. hidden: () => this.$isScopedPolicyMenuHidden('snapshot_hidden_columns.disk_type'),
  92. },
  93. getStatusTableColumn({ statusModule: 'snapshot', hidden: () => this.$isScopedPolicyMenuHidden('snapshot_hidden_columns.status') }),
  94. {
  95. field: 'guest',
  96. title: this.$t('compute.text_463'),
  97. minWidth: 100,
  98. showOverflow: 'ellipsis',
  99. slots: {
  100. default: ({ row }, h) => {
  101. return [
  102. <div class='text-truncate'>
  103. {row.guest}
  104. {row.guest_status ? <status status={ row.guest_status } statusModule='server'/> : ''}
  105. </div>,
  106. ]
  107. },
  108. },
  109. hidden: () => this.$isScopedPolicyMenuHidden('snapshot_hidden_columns.guest'),
  110. },
  111. {
  112. field: 'created_at',
  113. title: this.$t('compute.text_243'),
  114. minWidth: 70,
  115. formatter: ({ cellValue }) => {
  116. return this.$moment(cellValue).format()
  117. },
  118. hidden: () => this.$isScopedPolicyMenuHidden('snapshot_hidden_columns.created_at'),
  119. },
  120. ],
  121. groupActions: [
  122. {
  123. label: this.$t('compute.perform_sync_status'),
  124. action: () => {
  125. this.onManager('batchPerformAction', {
  126. steadyStatus: ['running', 'ready'],
  127. managerArgs: {
  128. action: 'syncstatus',
  129. },
  130. })
  131. },
  132. meta: () => ({
  133. validate: this.list.selected.length,
  134. }),
  135. },
  136. {
  137. label: this.$t('compute.perform_delete'),
  138. permission: 'snapshots_delete',
  139. action: () => {
  140. this.createDialog('DeleteResDialog', {
  141. vm: this,
  142. data: this.list.selectedItems,
  143. columns: this.columns,
  144. onManager: this.onManager,
  145. title: this.$t('compute.perform_delete'),
  146. name: this.$t('compute.text_462'),
  147. })
  148. },
  149. meta: () => {
  150. const ret = {
  151. validate: this.list.selected.length,
  152. tooltip: null,
  153. }
  154. if (this.list.selectedItems.some(item => !item.can_delete)) {
  155. ret.validate = false
  156. return ret
  157. }
  158. if (this.list.selectedItems.some(item => item.is_sub_snapshot)) {
  159. ret.validate = false
  160. ret.tooltip = this.$t('compute.text_1062')
  161. return ret
  162. }
  163. return ret
  164. },
  165. },
  166. ],
  167. }
  168. },
  169. computed: {
  170. showActions () {
  171. return !this.$isScopedPolicyMenuHidden('snapshot_hidden_columns.perform_action')
  172. },
  173. },
  174. created () {
  175. this.list.fetchData()
  176. },
  177. }
  178. </script>