Cache.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions" />
  7. </template>
  8. <script>
  9. import * as R from 'ramda'
  10. import {
  11. getStatusTableColumn,
  12. getTimeTableColumn,
  13. getBrandTableColumn,
  14. } from '@/utils/common/tableColumn'
  15. import { getBrandFilter } from '@/utils/common/tableFilter'
  16. import expectStatus from '@/constants/expectStatus'
  17. import WindowsMixin from '@/mixins/windows'
  18. import ListMixin from '@/mixins/list'
  19. export default {
  20. name: 'systemImageCacheList',
  21. mixins: [WindowsMixin, ListMixin],
  22. props: {
  23. resId: String,
  24. data: {
  25. type: Object,
  26. required: true,
  27. },
  28. cloudEnv: {
  29. type: String,
  30. required: false,
  31. },
  32. },
  33. data () {
  34. const groupActions = []
  35. if (this.cloudEnv) {
  36. groupActions.push({
  37. label: this.$t('compute.image_cache.perform_precache'),
  38. permission: 'storagecachedimages_create',
  39. action: (obj) => {
  40. this.createCache(this.cloudEnv, obj)
  41. },
  42. meta: () => ({
  43. buttonType: 'primary',
  44. }),
  45. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_create_cache_list'),
  46. })
  47. } else {
  48. groupActions.push({
  49. label: this.$t('compute.image_cache.perform_precache'),
  50. permission: 'storagecachedimages_create',
  51. actions: (obj) => {
  52. return [
  53. {
  54. label: 'IDC',
  55. action: () => {
  56. this.createCache('onpremise', obj)
  57. },
  58. },
  59. {
  60. label: this.$t('compute.text_400'),
  61. action: () => {
  62. this.createCache('private', obj)
  63. },
  64. },
  65. {
  66. label: this.$t('compute.text_401'),
  67. action: () => {
  68. this.createCache('public', obj)
  69. },
  70. },
  71. ]
  72. },
  73. meta: () => ({
  74. buttonType: 'primary',
  75. }),
  76. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_create_cache_list'),
  77. })
  78. }
  79. groupActions.push({
  80. label: this.$t('compute.image_cache.perform_batch_precache'),
  81. permission: 'storagecachedimages_create',
  82. action: (obj) => {
  83. this.createDialog('ImageBatchCreateCache', {
  84. data: [obj],
  85. columns: this.columns,
  86. title: this.$t('compute.image_cache.perform_batch_precache'),
  87. onManager: this.onManager,
  88. imageId: this.resId,
  89. refresh: this.refresh,
  90. })
  91. },
  92. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_create_cache_list'),
  93. })
  94. groupActions.push({
  95. label: this.$t('compute.perform_delete'),
  96. permission: 'storagecachedimages_delete',
  97. action: (obj) => {
  98. this.createDialog('DeleteCacheDialog', {
  99. data: this.list.selectedItems,
  100. columns: this.columns,
  101. title: this.$t('compute.perform_delete'),
  102. onManager: this.onManager,
  103. refresh: this.refresh,
  104. })
  105. },
  106. meta: () => {
  107. for (let i = 0; i < this.list.selectedItems.length; i++) {
  108. const result = this.$getDeleteResult(this.list.selectedItems[i])
  109. if (!result.validate) {
  110. return result
  111. }
  112. }
  113. if (this.list.selectedItems.length > 0) {
  114. return {
  115. validate: true,
  116. tooltip: '',
  117. }
  118. }
  119. return {
  120. validate: false,
  121. tooltip: '',
  122. }
  123. },
  124. })
  125. return {
  126. list: this.$list.createList(this, {
  127. id: 'CacheListForSystemImageSidePage',
  128. resource: 'storagecachedimages',
  129. apiVersion: 'v2',
  130. idKey: 'storagecache_id',
  131. getParams: {
  132. cachedimage_id: this.resId,
  133. details: true,
  134. },
  135. filterOptions: {
  136. brand: getBrandFilter('compute_engine_brands'),
  137. },
  138. }),
  139. columns: [
  140. {
  141. field: 'hosts',
  142. title: this.$t('compute.text_111'),
  143. minWidth: 240,
  144. showOverflow: 'title',
  145. slots: {
  146. default: ({ row }) => {
  147. if (!row.hosts) {
  148. return '-'
  149. }
  150. const ret = []
  151. for (let i = 0; i < row.hosts.length; i++) {
  152. const host = row.hosts[i]
  153. const host_id = row.host_info[i].id
  154. ret.push(
  155. <list-body-cell-wrap copy hideField={true} field='host' row={row} message={host}>
  156. <side-page-trigger permission='hosts_get' name='HostSidePage' id={host_id} vm={this}>{host}</side-page-trigger>
  157. </list-body-cell-wrap>,
  158. )
  159. }
  160. return ret
  161. },
  162. },
  163. },
  164. {
  165. field: 'storages',
  166. title: this.$t('compute.text_99'),
  167. minWidth: 300,
  168. showOverflow: 'title',
  169. slots: {
  170. default: ({ row }) => {
  171. if (!row.storages) {
  172. return '-'
  173. }
  174. const ret = []
  175. for (let i = 0; i < row.storages.length; i++) {
  176. const storage = row.storages[i]
  177. const storage_id = row.storage_info[i].id
  178. ret.push(
  179. <list-body-cell-wrap copy hideField={true} field='storage' row={row} message={storage}>
  180. <side-page-trigger permission='storages_get' name='BlockStorageSidePage' id={storage_id} vm={this}>{storage}</side-page-trigger>
  181. </list-body-cell-wrap>,
  182. )
  183. }
  184. return ret
  185. },
  186. },
  187. },
  188. /* {
  189. field: 'path',
  190. title: this.$t('compute.text_654'),
  191. minWidth: 150,
  192. showOverflow: 'title',
  193. slots: {
  194. default: ({ row }) => {
  195. return row.path || '-'
  196. },
  197. },
  198. }, */
  199. getStatusTableColumn({ statusModule: 'imageCache' }),
  200. getTimeTableColumn({ title: this.$t('compute.text_691'), field: 'updated_at' }),
  201. getBrandTableColumn({ field: 'brand' }),
  202. {
  203. field: 'account',
  204. title: this.$t('compute.text_269'),
  205. width: 100,
  206. },
  207. ],
  208. groupActions: [
  209. {
  210. label: this.$t('compute.image_cache.perform_precache'),
  211. permission: 'storagecachedimages_create',
  212. actions: (obj) => {
  213. return [
  214. {
  215. label: 'IDC',
  216. action: () => {
  217. this.createCache('onpremise', obj)
  218. },
  219. },
  220. {
  221. label: this.$t('compute.text_400'),
  222. action: () => {
  223. this.createCache('private', obj)
  224. },
  225. },
  226. {
  227. label: this.$t('compute.text_401'),
  228. action: () => {
  229. this.createCache('public', obj)
  230. },
  231. },
  232. ]
  233. },
  234. meta: () => ({
  235. buttonType: 'primary',
  236. }),
  237. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_create_cache_list'),
  238. },
  239. {
  240. label: this.$t('compute.image_cache.perform_batch_precache'),
  241. permission: 'storagecachedimages_create',
  242. action: (obj) => {
  243. this.createDialog('ImageBatchCreateCache', {
  244. data: [obj],
  245. columns: this.columns,
  246. title: this.$t('compute.image_cache.perform_batch_precache'),
  247. onManager: this.onManager,
  248. imageId: this.resId,
  249. refresh: this.refresh,
  250. })
  251. },
  252. hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_create_cache_list'),
  253. },
  254. {
  255. label: this.$t('compute.perform_delete'),
  256. permission: 'storagecachedimages_delete',
  257. action: (obj) => {
  258. this.createDialog('DeleteCacheDialog', {
  259. data: this.list.selectedItems,
  260. columns: this.columns,
  261. title: this.$t('compute.perform_delete'),
  262. onManager: this.onManager,
  263. refresh: this.refresh,
  264. })
  265. },
  266. meta: () => {
  267. for (let i = 0; i < this.list.selectedItems.length; i++) {
  268. const result = this.$getDeleteResult(this.list.selectedItems[i])
  269. if (!result.validate) {
  270. return result
  271. }
  272. }
  273. if (this.list.selectedItems.length > 0) {
  274. return {
  275. validate: true,
  276. tooltip: '',
  277. }
  278. }
  279. return {
  280. validate: false,
  281. tooltip: '',
  282. }
  283. },
  284. },
  285. ],
  286. singleActions: [
  287. {
  288. label: this.$t('compute.perform_delete'),
  289. permission: 'storagecachedimages_delete',
  290. action: (obj) => {
  291. this.createDialog('DeleteCacheDialog', {
  292. data: [obj],
  293. columns: this.columns,
  294. title: this.$t('compute.perform_delete'),
  295. onManager: this.onManager,
  296. imageId: this.resId,
  297. refresh: this.refresh,
  298. })
  299. },
  300. meta: (obj) => {
  301. return this.$getDeleteResult(obj)
  302. },
  303. },
  304. ],
  305. ids: '',
  306. timer: '',
  307. }
  308. },
  309. created () {
  310. this.list.fetchData()
  311. },
  312. mounted () {
  313. const steadyStatus = Object.values(expectStatus.imageCache).flat()
  314. this.timer = setInterval(() => {
  315. let preStatusNum = 0
  316. R.forEachObjIndexed((value, key) => {
  317. if (!steadyStatus.includes(value.data?.status)) {
  318. preStatusNum++
  319. }
  320. }, this.list.data)
  321. if (preStatusNum !== 0) {
  322. this.list.refresh()
  323. }
  324. }, 10000)
  325. },
  326. destroyed () {
  327. clearInterval(this.timer)
  328. },
  329. methods: {
  330. refresh () {
  331. this.list.refresh()
  332. },
  333. createCache (title, obj) {
  334. this.createDialog('ImageCreateCache', {
  335. data: [obj],
  336. columns: this.columns,
  337. title,
  338. onManager: this.onManager,
  339. imageId: this.resId,
  340. refresh: this.refresh,
  341. })
  342. },
  343. handleOpenSidepage (row) {
  344. this.sidePageTriggerHandle(this, 'HostSidePage', {
  345. id: row.host.id,
  346. resource: 'hosts',
  347. getParams: this.getParam,
  348. }, {
  349. list: this.list,
  350. })
  351. },
  352. },
  353. }
  354. </script>