Skip to content

Commit a2eb103

Browse files
authored
UI: Filter templates by zone and hypervisor type when reinstall a VM (#7739)
1 parent d127d79 commit a2eb103

File tree

2 files changed

+43
-17
lines changed

2 files changed

+43
-17
lines changed

ui/src/config/section/compute.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ export default {
164164
message: 'message.reinstall.vm',
165165
dataView: true,
166166
args: ['virtualmachineid', 'templateid'],
167+
filters: (record) => {
168+
var filters = {}
169+
var filterParams = {}
170+
filterParams.hypervisortype = record.hypervisor
171+
filterParams.zoneid = record.zoneid
172+
filters.templateid = filterParams
173+
return filters
174+
},
167175
show: (record) => { return ['Running', 'Stopped'].includes(record.state) },
168176
mapping: {
169177
virtualmachineid: {

ui/src/views/AutogenView.vue

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,6 @@ export default {
10341034
this.setModalWidthByScreen()
10351035
},
10361036
execAction (action, isGroupAction) {
1037-
const self = this
10381037
this.formRef = ref()
10391038
this.form = reactive({})
10401039
this.rules = reactive({})
@@ -1072,13 +1071,37 @@ export default {
10721071
return 0
10731072
})
10741073
this.currentAction.paramFields = []
1074+
this.currentAction.paramFilters = []
10751075
if ('message' in action) {
10761076
var message = action.message
10771077
if (typeof action.message === 'function') {
10781078
message = action.message(action.resource)
10791079
}
10801080
action.message = message
10811081
}
1082+
1083+
this.getArgs(action, isGroupAction, paramFields)
1084+
this.getFilters(action, isGroupAction, paramFields)
1085+
this.getFirstIndexFocus()
1086+
1087+
this.showAction = true
1088+
const listIconForFillValues = ['copy-outlined', 'CopyOutlined', 'edit-outlined', 'EditOutlined', 'share-alt-outlined', 'ShareAltOutlined']
1089+
for (const param of this.currentAction.paramFields) {
1090+
if (param.type === 'list' && ['tags', 'hosttags', 'storagetags', 'files'].includes(param.name)) {
1091+
param.type = 'string'
1092+
}
1093+
this.setRules(param)
1094+
if (param.type === 'uuid' || param.type === 'list' || param.name === 'account' || (this.currentAction.mapping && param.name in this.currentAction.mapping)) {
1095+
this.listUuidOpts(param, this.currentAction.paramFilters[param.name])
1096+
}
1097+
}
1098+
this.actionLoading = false
1099+
if (action.dataView && listIconForFillValues.includes(action.icon)) {
1100+
this.fillEditFormFieldValues()
1101+
}
1102+
},
1103+
getArgs (action, isGroupAction, paramFields) {
1104+
const self = this
10821105
if ('args' in action) {
10831106
var args = action.args
10841107
if (typeof action.args === 'function') {
@@ -1100,22 +1123,14 @@ export default {
11001123
})
11011124
}
11021125
}
1103-
this.getFirstIndexFocus()
1104-
1105-
this.showAction = true
1106-
const listIconForFillValues = ['copy-outlined', 'CopyOutlined', 'edit-outlined', 'EditOutlined', 'share-alt-outlined', 'ShareAltOutlined']
1107-
for (const param of this.currentAction.paramFields) {
1108-
if (param.type === 'list' && ['tags', 'hosttags', 'storagetags', 'files'].includes(param.name)) {
1109-
param.type = 'string'
1110-
}
1111-
this.setRules(param)
1112-
if (param.type === 'uuid' || param.type === 'list' || param.name === 'account' || (this.currentAction.mapping && param.name in this.currentAction.mapping)) {
1113-
this.listUuidOpts(param)
1126+
},
1127+
getFilters (action, isGroupAction, paramFields) {
1128+
if ('filters' in action) {
1129+
var filters = action.filters
1130+
if (typeof action.filters === 'function') {
1131+
filters = action.filters(action.resource, this.$store.getters, isGroupAction)
11141132
}
1115-
}
1116-
this.actionLoading = false
1117-
if (action.dataView && listIconForFillValues.includes(action.icon)) {
1118-
this.fillEditFormFieldValues()
1133+
this.currentAction.paramFilters = filters
11191134
}
11201135
},
11211136
getFirstIndexFocus () {
@@ -1128,13 +1143,16 @@ export default {
11281143
}
11291144
}
11301145
},
1131-
listUuidOpts (param) {
1146+
listUuidOpts (param, filters) {
11321147
if (this.currentAction.mapping && param.name in this.currentAction.mapping && !this.currentAction.mapping[param.name].api) {
11331148
return
11341149
}
11351150
var paramName = param.name
11361151
var extractedParamName = paramName.replace('ids', '').replace('id', '').toLowerCase()
11371152
var params = { listall: true }
1153+
for (const filter in filters) {
1154+
params[filter] = filters[filter]
1155+
}
11381156
const possibleName = 'list' + extractedParamName + 's'
11391157
var showIcon = false
11401158
if (this.$showIcon(extractedParamName)) {

0 commit comments

Comments
 (0)