| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489 |
- import { mapGetters } from 'vuex'
- import * as R from 'ramda'
- import _ from 'lodash'
- import { getSetPublicAction } from '@/utils/common/tableActions'
- import i18n from '@/locales'
- export default {
- computed: {
- ...mapGetters(['isAdminMode', 'isDomainMode', 'userInfo']),
- },
- created () {
- const validateAction = function (obj) {
- if (obj.is_guest_image === true || obj.is_guest_image === 'true') {
- return false
- }
- return true
- }
- const validateActionTooltip = function (obj) {
- if (obj.is_guest_image === true || obj.is_guest_image === 'true') {
- return i18n.t('compute.text_622')
- }
- return ''
- }
- const ownerDomain = obj => this.$store.getters.isAdminMode || obj.domain_id === this.$store.getters.userInfo.projectDomainId
- const isOwnerProject = project => project === this.$store.getters.userInfo.projectId || project === this.$store.getters.userInfo.projectName
- this.singleActions = [
- {
- label: i18n.t('compute.text_663'),
- permission: 'server_create',
- action: obj => {
- this.createDialog('ImageCreateServerDialog', {
- data: [obj],
- columns: this.columns,
- })
- },
- meta: obj => {
- const ret = {
- validate: true,
- tooltip: '',
- }
- if (obj.status !== 'active') {
- ret.validate = false
- ret.tooltip = i18n.t('compute.text_681')
- }
- if (!_.get(obj, 'properties.os_type')) {
- ret.validate = false
- ret.tooltip = i18n.t('compute.image_create_server')
- }
- return ret
- },
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_create_server') || this.$route.path.includes('app-package'),
- },
- {
- label: i18n.t('compute.text_247'),
- permission: 'images_update',
- action: obj => {
- this.createDialog('ImageEditAttributesDialog', {
- data: [obj],
- columns: this.columns,
- refresh: this.refresh,
- onManager: this.onManager,
- })
- },
- meta: obj => {
- if (!validateAction(obj)) {
- return {
- validate: false,
- tooltip: validateActionTooltip(obj),
- }
- }
- if (this.isAdminMode) {
- return {
- validate: true,
- }
- } else if (this.isDomainMode) {
- return {
- validate: ownerDomain(obj),
- tooltip: i18n.t('compute.text_682'),
- }
- }
- return {
- validate: isOwnerProject(obj.tenant_id),
- tooltip: !isOwnerProject(obj.tenant_id) ? i18n.t('compute.text_623', [i18n.t('dictionary.domain')]) : '',
- }
- },
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_edit_attribute'),
- },
- {
- label: i18n.t('compute.text_352'),
- actions: obj => {
- return [
- {
- label: i18n.t('compute.text_683'),
- permission: 'images_update',
- action: () => {
- this.updateStandard(true, [obj])
- },
- meta: () => {
- let ret = {
- validate: false,
- tooltip: '',
- }
- const actions = new Map([
- ['admin', () => {
- if (this.booleanTransfer(obj.is_standard)) {
- ret.tooltip = i18n.t('compute.text_644')
- }
- return ret
- }],
- ['domain', () => {
- ret.tooltip = i18n.t('compute.text_646')
- return ret
- }],
- ['user', () => {
- ret.tooltip = i18n.t('compute.text_646')
- return ret
- }],
- ])
- const action = actions.get(this.isAdminMode ? 'admin' : '') || actions.get(this.isDomainMode ? 'domain' : 'user')
- ret = action.call(this)
- if (ret.tooltip) return ret
- return { validate: true, tooltip: '' }
- },
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.iamge_set_public_image'),
- },
- {
- label: i18n.t('compute.text_684'),
- permission: 'images_update',
- action: () => {
- this.updateStandard(false, [obj])
- },
- meta: () => {
- let ret = {
- validate: false,
- tooltip: '',
- }
- const actions = new Map([
- ['admin', () => {
- if (!this.booleanTransfer(obj.is_standard)) {
- ret.tooltip = i18n.t('compute.text_685')
- }
- return ret
- }],
- ['domain', () => {
- ret.tooltip = i18n.t('compute.text_646')
- return ret
- }],
- ['user', () => {
- ret.tooltip = i18n.t('compute.text_646')
- return ret
- }],
- ])
- const action = actions.get(this.isAdminMode ? 'admin' : '') || actions.get(this.isDomainMode ? 'domain' : 'user')
- ret = action.call(this)
- if (ret.tooltip) return ret
- return { validate: true, tooltip: '' }
- },
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_set_customize_image'),
- },
- getSetPublicAction(this, {
- name: this.$route.path.includes('app-package') ? this.$t('dictionary.app_package') : this.$t('dictionary.image'),
- scope: 'project',
- resource: 'images',
- apiVersion: 'v1',
- }, {
- permission: 'images_perform_public,images_perform_private',
- meta: () => {
- let ret = {
- validate: false,
- tooltip: '',
- }
- const actions = new Map([
- ['admin', () => {
- if (this.booleanTransfer(obj.is_standard)) {
- ret.tooltip = i18n.t('compute.text_644')
- }
- return ret
- }],
- ['domain', () => {
- if ((obj.shared_domains && obj.shared_domains.length > 0) || obj.public_scope === 'system') {
- ret.tooltip = i18n.t('compute.text_686')
- return ret
- }
- if (this.booleanTransfer(obj.is_standard)) {
- ret.tooltip = i18n.t('compute.text_644')
- return ret
- }
- return ret
- }],
- ['user', () => {
- ret.tooltip = i18n.t('compute.text_613')
- if (!this.booleanTransfer(obj.is_standard) && obj.public_scope === 'system') {
- ret.tooltip = i18n.t('compute.text_646')
- return ret
- }
- return ret
- }],
- ])
- const action = actions.get(this.isAdminMode ? 'admin' : '') || actions.get(this.isDomainMode ? 'domain' : 'user')
- ret = action.call(this)
- if (ret.tooltip) return ret
- return { validate: true, tooltip: '' }
- },
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_set_public'),
- }),
- {
- label: i18n.t('compute.perform_image_probe'),
- permission: 'images_perform_probe',
- action: () => {
- this.onManager('performAction', {
- steadyStatus: ['active'],
- id: obj.id,
- managerArgs: {
- action: 'probe',
- },
- })
- },
- meta: () => {
- const ret = {
- validate: true,
- tooltip: null,
- }
- if (obj.status !== 'active' && obj.status !== 'saved') {
- ret.validate = false
- ret.tooltip = i18n.t('compute.image_probe_prompt')
- }
- return ret
- },
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_perform_probe'),
- },
- // {
- // label: '设置共享',
- // permission: 'images_perform_public',
- // action: () => {
- // this.createDialog('SetPublicDialog', {
- // data: [obj],
- // columns: this.columns,
- // onManager: this.onManager,
- // })
- // },
- // meta: () => {
- // let ret = {
- // validate: false,
- // tooltip: '',
- // }
- // const actions = new Map([
- // ['admin', () => {
- // if (this.booleanTransfer(obj.is_standard)) {
- // ret.tooltip = '公共镜像不支持该操作'
- // }
- // return ret
- // }],
- // ['domain', () => {
- // if (this.booleanTransfer(obj.is_standard)) {
- // ret.tooltip = '公共镜像不支持该操作'
- // return ret
- // }
- // if (obj.public_scope === 'system') {
- // ret.tooltip = '系统共享镜像不支持该操作'
- // return ret
- // }
- // return ret
- // }],
- // ['user', () => {
- // ret.tooltip = '只有管理员支持该操作'
- // if (!this.booleanTransfer(obj.is_standard) && obj.public_scope === 'system') {
- // ret.tooltip = '只有系统管理员支持该操作'
- // return ret
- // }
- // return ret
- // }],
- // ])
- // let action = actions.get(this.isAdminMode ? 'admin' : '') || actions.get(this.isDomainMode ? 'domain' : 'user')
- // ret = action.call(this)
- // if (ret.tooltip) return ret
- // return { validate: true, tooltip: '' }
- // },
- // },
- {
- label: this.$t('compute.perform_change_owner', [this.$t('dictionary.project')]),
- permission: 'images_perform_change_owner',
- action: () => {
- this.createDialog('ChangeOwenrDialog', {
- data: [obj],
- columns: this.columns,
- onManager: this.onManager,
- name: this.$route.path.includes('app-package') ? this.$t('dictionary.app_package') : this.$t('dictionary.image'),
- resource: 'images',
- apiVersion: 'v1',
- })
- },
- meta: () => {
- const ret = {
- validate: true,
- tooltip: null,
- }
- if (!this.isAdminMode && !this.isDomainMode) {
- ret.validate = false
- ret.tooltip = i18n.t('compute.text_613')
- return ret
- }
- if (this.booleanTransfer(obj.is_public)) {
- ret.validate = false
- ret.tooltip = i18n.t('compute.text_614')
- return ret
- }
- return ret
- },
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_change_project'),
- },
- {
- label: this.$t('dashboard.text_105'),
- permission: 'images_get',
- action: () => {
- this.createDialog('ImageExportDialog', {
- data: [obj],
- columns: this.columns,
- onManager: this.onManager,
- })
- },
- meta: () => {
- const ret = {
- validate: false,
- tooltip: '',
- }
- if (obj.status !== 'active') {
- ret.tooltip = this.$t('cloudenv.text_368', [this.$t('status.image')[obj.status]])
- return ret
- }
- if (obj.is_standard === true || obj.is_standard === 'true') {
- ret.tooltip = this.$t('compute.standard_not_export')
- return ret
- }
- return { validate: true, tooltip: '' }
- },
- },
- {
- label: i18n.t('common_277'),
- permission: 'images_delete',
- action: (row) => {
- this.createDialog('ChangeDisableDelete', {
- name: this.$route.path.includes('app-package') ? this.$t('dictionary.app_package') : i18n.t('compute.text_97'),
- columns: this.columns,
- onManager: this.onManager,
- data: [row],
- })
- },
- meta: () => {
- let ret = {
- validate: false,
- tooltip: '',
- }
- const actions = new Map([
- ['admin', () => {
- if (this.booleanTransfer(obj.is_standard)) {
- ret.tooltip = i18n.t('compute.text_687')
- return ret
- }
- return ret
- }],
- ['domain', () => {
- if (this.booleanTransfer(obj.is_standard)) {
- ret.tooltip = i18n.t('compute.text_688')
- return ret
- }
- if (!ownerDomain(obj)) {
- ret.tooltip = i18n.t('compute.text_689')
- return ret
- }
- return ret
- }],
- ['user', () => {
- if (this.booleanTransfer(obj.is_standard)) {
- ret.tooltip = i18n.t('compute.text_688')
- return ret
- }
- if (!isOwnerProject(obj.tenant_id)) {
- ret.tooltip = i18n.t('compute.text_690')
- return ret
- }
- return ret
- }],
- ])
- const action = actions.get(this.isAdminMode ? 'admin' : '') || actions.get(this.isDomainMode ? 'domain' : 'user')
- ret = action.call(this)
- if (ret.tooltip) return ret
- return { validate: true, tooltip: '' }
- },
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_set_delete_protection'),
- },
- {
- label: i18n.t('compute.perform_delete'),
- permission: 'images_delete',
- action: () => {
- this.createDialog('DeleteResDialog', {
- vm: this,
- data: [obj],
- alert: this.$t('compute.text_1393'),
- columns: this.columns,
- title: i18n.t('compute.perform_delete'),
- name: this.$route.path.includes('app-package') ? this.$t('dictionary.app_package') : this.$t('dictionary.image'),
- onManager: this.onManager,
- })
- },
- meta: () => {
- let ret = {
- validate: false,
- tooltip: '',
- }
- const actions = new Map([
- ['admin', () => {
- if (this.booleanTransfer(obj.is_standard)) {
- ret.tooltip = i18n.t('compute.text_648')
- return ret
- }
- if (this.booleanTransfer(obj.disable_delete) && this.booleanTransfer(obj.protected)) {
- ret.tooltip = i18n.t('common.text00008')
- return ret
- }
- return ret
- }],
- ['domain', () => {
- if (this.booleanTransfer(obj.is_standard)) {
- ret.tooltip = i18n.t('compute.text_649')
- return ret
- }
- if (!ownerDomain(obj)) {
- ret.tooltip = i18n.t('compute.text_650')
- return ret
- }
- if (this.booleanTransfer(obj.disable_delete) && this.booleanTransfer(obj.protected)) {
- ret.tooltip = i18n.t('common.text00008')
- return ret
- }
- return ret
- }],
- ['user', () => {
- if (this.booleanTransfer(obj.is_standard)) {
- ret.tooltip = i18n.t('compute.text_649')
- return ret
- }
- if (!isOwnerProject(obj.tenant_id)) {
- ret.tooltip = i18n.t('compute.text_651')
- return ret
- }
- if (this.booleanTransfer(obj.disable_delete) && this.booleanTransfer(obj.protected)) {
- ret.tooltip = i18n.t('common.text00008')
- return ret
- }
- return ret
- }],
- ])
- const action = actions.get(this.isAdminMode ? 'admin' : '') || actions.get(this.isDomainMode ? 'domain' : 'user')
- ret = action.call(this)
- if (ret.tooltip) return ret
- return this.$getDeleteResult(obj)
- },
- hidden: () => this.$isScopedPolicyMenuHidden('image_hidden_menus.image_delete'),
- },
- ]
- },
- },
- ]
- },
- methods: {
- updateStandard (isStandard, selectedItems) {
- const params = {
- is_standard: isStandard,
- }
- this.onManager('batchPerformAction', {
- id: selectedItems.map(item => item.id),
- managerArgs: {
- action: 'mark-standard',
- data: params,
- },
- })
- },
- booleanTransfer (val) {
- if (R.is(String, val)) {
- return val === 'true'
- }
- return val
- },
- },
- }
|