storageResourceProps.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import _ from 'lodash'
  2. import {
  3. getNameDescriptionTableColumn,
  4. getEnabledTableColumn,
  5. getStatusTableColumn,
  6. getBrandTableColumn,
  7. getPublicScopeTableColumn,
  8. getProjectDomainTableColumn,
  9. getRegionTableColumn,
  10. getTimeTableColumn,
  11. } from '@/utils/common/tableColumn'
  12. import {
  13. getNameFilter,
  14. } from '@/utils/common/tableFilter'
  15. import { sizestr } from '@/utils/utils'
  16. import { STORAGE_TYPES, MEDIUM_TYPES } from '@Storage/constants'
  17. export default {
  18. computed: {
  19. resourceProps () {
  20. return {
  21. list: this.$list.createList(this, {
  22. id: 'DiskStoragesListForChangeBlockStorageDialog',
  23. resource: 'storages',
  24. getParams: {
  25. server_id: this.selectedItemsGuestIds[0],
  26. enabled: true,
  27. filter: `id.notin(${this.selectedItemsStorageIds.join(',')})`,
  28. },
  29. filterOptions: {
  30. id: {
  31. label: this.$t('table.title.id'),
  32. },
  33. name: getNameFilter(),
  34. },
  35. }),
  36. columns: [
  37. getNameDescriptionTableColumn({
  38. hideField: true,
  39. addLock: true,
  40. addBackup: true,
  41. edit: false,
  42. editDesc: false,
  43. minWidth: 120,
  44. slotCallback: row => {
  45. return [
  46. <list-body-cell-wrap field='name' row={row} />,
  47. ]
  48. },
  49. }),
  50. getStatusTableColumn({
  51. statusModule: 'blockstorage',
  52. minWidth: 100,
  53. }),
  54. getEnabledTableColumn(),
  55. {
  56. field: 'capacity',
  57. title: this.$t('storage.text_177'),
  58. width: 180,
  59. slots: {
  60. default: ({ row }, h) => {
  61. const capacity = sizestr(row.capacity, 'M', 1024)
  62. const allowedBrands = ['VMware', 'OneCloud']
  63. const actual_capacity_used = allowedBrands.includes(row.brand) ? sizestr(row.actual_capacity_used, 'M', 1024) : '-'
  64. return [<div>
  65. <div>{this.$t('storage.text_178', [actual_capacity_used])}</div>
  66. <div>{this.$t('storage.text_180', [capacity])}</div>
  67. </div>]
  68. },
  69. },
  70. },
  71. {
  72. field: 'virtual_capacity',
  73. title: this.$t('storage.text_43'),
  74. width: 180,
  75. slots: {
  76. default: ({ row }, h) => {
  77. const virtual_capacity = sizestr(row.virtual_capacity, 'M', 1024)
  78. const used_capacity = sizestr(row.used_capacity, 'M', 1024)
  79. return [<div>
  80. <div>{this.$t('storage.text_181', [used_capacity])}</div>
  81. <div>{this.$t('storage.text_180', [virtual_capacity])}</div>
  82. </div>]
  83. },
  84. },
  85. },
  86. {
  87. field: 'storage_type',
  88. title: this.$t('storage.text_38'),
  89. width: 100,
  90. formatter: ({ row }) => {
  91. return STORAGE_TYPES[row.storage_type] || row.storage_type
  92. },
  93. },
  94. {
  95. field: 'medium_type',
  96. title: this.$t('storage.text_39'),
  97. width: 120,
  98. formatter: ({ row }) => {
  99. return MEDIUM_TYPES[row.medium_type] || row.medium_type
  100. },
  101. },
  102. getBrandTableColumn(),
  103. {
  104. field: 'schedtag',
  105. title: this.$t('storage.text_45'),
  106. width: 120,
  107. slots: {
  108. default: ({ row }) => {
  109. const tags = _.sortBy(row.schedtags, ['default', 'name'])
  110. if (!tags.length) {
  111. return [
  112. <div class='text-color-help'>{ this.$t('storage.text_171') }</div>,
  113. ]
  114. }
  115. const list = tags.map(tag => <a-tag class='mb-2 mr-1' color='blue'>{tag.name}</a-tag>)
  116. return [<list-body-cell-popover text={this.$t('compute.text_619', [tags.length])} max-width="400px">
  117. <div style="display: inline-flex; flex-wrap: wrap; max-width: 40vw;">
  118. {...list}
  119. </div>
  120. </list-body-cell-popover>]
  121. },
  122. },
  123. },
  124. getPublicScopeTableColumn({ vm: this, resource: 'storages' }),
  125. getProjectDomainTableColumn(),
  126. getRegionTableColumn(),
  127. getTimeTableColumn(),
  128. ],
  129. }
  130. },
  131. },
  132. methods: {},
  133. }