| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- <template>
- <page-list
- :list="list"
- :columns="columns"
- :group-actions="groupActions"
- :single-actions="singleActions" />
- </template>
- <script>
- import * as R from 'ramda'
- import {
- getStatusTableColumn,
- getTimeTableColumn,
- getBrandTableColumn,
- } from '@/utils/common/tableColumn'
- import { getBrandFilter } from '@/utils/common/tableFilter'
- import expectStatus from '@/constants/expectStatus'
- import WindowsMixin from '@/mixins/windows'
- import ListMixin from '@/mixins/list'
- export default {
- name: 'systemImageCacheList',
- mixins: [WindowsMixin, ListMixin],
- props: {
- resId: String,
- data: {
- type: Object,
- required: true,
- },
- cloudEnv: {
- type: String,
- required: false,
- },
- },
- data () {
- const groupActions = []
- if (this.cloudEnv) {
- groupActions.push({
- label: this.$t('compute.image_cache.perform_precache'),
- permission: 'storagecachedimages_create',
- action: (obj) => {
- this.createCache(this.cloudEnv, obj)
- },
- meta: () => ({
- buttonType: 'primary',
- }),
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_create_cache_list'),
- })
- } else {
- groupActions.push({
- label: this.$t('compute.image_cache.perform_precache'),
- permission: 'storagecachedimages_create',
- actions: (obj) => {
- return [
- {
- label: 'IDC',
- action: () => {
- this.createCache('onpremise', obj)
- },
- },
- {
- label: this.$t('compute.text_400'),
- action: () => {
- this.createCache('private', obj)
- },
- },
- {
- label: this.$t('compute.text_401'),
- action: () => {
- this.createCache('public', obj)
- },
- },
- ]
- },
- meta: () => ({
- buttonType: 'primary',
- }),
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_create_cache_list'),
- })
- }
- groupActions.push({
- label: this.$t('compute.image_cache.perform_batch_precache'),
- permission: 'storagecachedimages_create',
- action: (obj) => {
- this.createDialog('ImageBatchCreateCache', {
- data: [obj],
- columns: this.columns,
- title: this.$t('compute.image_cache.perform_batch_precache'),
- onManager: this.onManager,
- imageId: this.resId,
- refresh: this.refresh,
- })
- },
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_create_cache_list'),
- })
- groupActions.push({
- label: this.$t('compute.perform_delete'),
- permission: 'storagecachedimages_delete',
- action: (obj) => {
- this.createDialog('DeleteCacheDialog', {
- data: this.list.selectedItems,
- columns: this.columns,
- title: this.$t('compute.perform_delete'),
- onManager: this.onManager,
- refresh: this.refresh,
- })
- },
- meta: () => {
- for (let i = 0; i < this.list.selectedItems.length; i++) {
- const result = this.$getDeleteResult(this.list.selectedItems[i])
- if (!result.validate) {
- return result
- }
- }
- if (this.list.selectedItems.length > 0) {
- return {
- validate: true,
- tooltip: '',
- }
- }
- return {
- validate: false,
- tooltip: '',
- }
- },
- })
- return {
- list: this.$list.createList(this, {
- id: 'CacheListForSystemImageSidePage',
- resource: 'storagecachedimages',
- apiVersion: 'v2',
- idKey: 'storagecache_id',
- getParams: {
- cachedimage_id: this.resId,
- details: true,
- },
- filterOptions: {
- brand: getBrandFilter('compute_engine_brands'),
- },
- }),
- columns: [
- {
- field: 'hosts',
- title: this.$t('compute.text_111'),
- minWidth: 240,
- showOverflow: 'title',
- slots: {
- default: ({ row }) => {
- if (!row.hosts) {
- return '-'
- }
- const ret = []
- for (let i = 0; i < row.hosts.length; i++) {
- const host = row.hosts[i]
- const host_id = row.host_info[i].id
- ret.push(
- <list-body-cell-wrap copy hideField={true} field='host' row={row} message={host}>
- <side-page-trigger permission='hosts_get' name='HostSidePage' id={host_id} vm={this}>{host}</side-page-trigger>
- </list-body-cell-wrap>,
- )
- }
- return ret
- },
- },
- },
- {
- field: 'storages',
- title: this.$t('compute.text_99'),
- minWidth: 300,
- showOverflow: 'title',
- slots: {
- default: ({ row }) => {
- if (!row.storages) {
- return '-'
- }
- const ret = []
- for (let i = 0; i < row.storages.length; i++) {
- const storage = row.storages[i]
- const storage_id = row.storage_info[i].id
- ret.push(
- <list-body-cell-wrap copy hideField={true} field='storage' row={row} message={storage}>
- <side-page-trigger permission='storages_get' name='BlockStorageSidePage' id={storage_id} vm={this}>{storage}</side-page-trigger>
- </list-body-cell-wrap>,
- )
- }
- return ret
- },
- },
- },
- /* {
- field: 'path',
- title: this.$t('compute.text_654'),
- minWidth: 150,
- showOverflow: 'title',
- slots: {
- default: ({ row }) => {
- return row.path || '-'
- },
- },
- }, */
- getStatusTableColumn({ statusModule: 'imageCache' }),
- getTimeTableColumn({ title: this.$t('compute.text_691'), field: 'updated_at' }),
- getBrandTableColumn({ field: 'brand' }),
- {
- field: 'account',
- title: this.$t('compute.text_269'),
- width: 100,
- },
- ],
- groupActions: [
- {
- label: this.$t('compute.image_cache.perform_precache'),
- permission: 'storagecachedimages_create',
- actions: (obj) => {
- return [
- {
- label: 'IDC',
- action: () => {
- this.createCache('onpremise', obj)
- },
- },
- {
- label: this.$t('compute.text_400'),
- action: () => {
- this.createCache('private', obj)
- },
- },
- {
- label: this.$t('compute.text_401'),
- action: () => {
- this.createCache('public', obj)
- },
- },
- ]
- },
- meta: () => ({
- buttonType: 'primary',
- }),
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_create_cache_list'),
- },
- {
- label: this.$t('compute.image_cache.perform_batch_precache'),
- permission: 'storagecachedimages_create',
- action: (obj) => {
- this.createDialog('ImageBatchCreateCache', {
- data: [obj],
- columns: this.columns,
- title: this.$t('compute.image_cache.perform_batch_precache'),
- onManager: this.onManager,
- imageId: this.resId,
- refresh: this.refresh,
- })
- },
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_create_cache_list'),
- },
- {
- label: this.$t('compute.perform_delete'),
- permission: 'storagecachedimages_delete',
- action: (obj) => {
- this.createDialog('DeleteCacheDialog', {
- data: this.list.selectedItems,
- columns: this.columns,
- title: this.$t('compute.perform_delete'),
- onManager: this.onManager,
- refresh: this.refresh,
- })
- },
- meta: () => {
- for (let i = 0; i < this.list.selectedItems.length; i++) {
- const result = this.$getDeleteResult(this.list.selectedItems[i])
- if (!result.validate) {
- return result
- }
- }
- if (this.list.selectedItems.length > 0) {
- return {
- validate: true,
- tooltip: '',
- }
- }
- return {
- validate: false,
- tooltip: '',
- }
- },
- },
- ],
- singleActions: [
- {
- label: this.$t('compute.perform_delete'),
- permission: 'storagecachedimages_delete',
- action: (obj) => {
- this.createDialog('DeleteCacheDialog', {
- data: [obj],
- columns: this.columns,
- title: this.$t('compute.perform_delete'),
- onManager: this.onManager,
- imageId: this.resId,
- refresh: this.refresh,
- })
- },
- meta: (obj) => {
- return this.$getDeleteResult(obj)
- },
- },
- ],
- ids: '',
- timer: '',
- }
- },
- created () {
- this.list.fetchData()
- },
- mounted () {
- const steadyStatus = Object.values(expectStatus.imageCache).flat()
- this.timer = setInterval(() => {
- let preStatusNum = 0
- R.forEachObjIndexed((value, key) => {
- if (!steadyStatus.includes(value.data?.status)) {
- preStatusNum++
- }
- }, this.list.data)
- if (preStatusNum !== 0) {
- this.list.refresh()
- }
- }, 10000)
- },
- destroyed () {
- clearInterval(this.timer)
- },
- methods: {
- refresh () {
- this.list.refresh()
- },
- createCache (title, obj) {
- this.createDialog('ImageCreateCache', {
- data: [obj],
- columns: this.columns,
- title,
- onManager: this.onManager,
- imageId: this.resId,
- refresh: this.refresh,
- })
- },
- handleOpenSidepage (row) {
- this.sidePageTriggerHandle(this, 'HostSidePage', {
- id: row.host.id,
- resource: 'hosts',
- getParams: this.getParam,
- }, {
- list: this.list,
- })
- },
- },
- }
- </script>
|