From f8ea85091feb5881571b29d1d31a8ba950f3a8b0 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Mon, 10 Jul 2023 12:27:09 +0200 Subject: [PATCH 1/2] filters for fields --- ui/src/config/section/compute.js | 5 ++++ ui/src/views/AutogenView.vue | 50 +++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/ui/src/config/section/compute.js b/ui/src/config/section/compute.js index 5393e8bd43ea..68d76574c152 100644 --- a/ui/src/config/section/compute.js +++ b/ui/src/config/section/compute.js @@ -164,6 +164,11 @@ export default { message: 'message.reinstall.vm', dataView: true, args: ['virtualmachineid', 'templateid'], + filters: (record) => { + var filters = [] + filters.push({ key: 'templateid', value: { hypervisortype: record.hypervisor } }) + return filters + }, show: (record) => { return ['Running', 'Stopped'].includes(record.state) }, mapping: { virtualmachineid: { diff --git a/ui/src/views/AutogenView.vue b/ui/src/views/AutogenView.vue index cf552e2ede40..c36ab6710b67 100644 --- a/ui/src/views/AutogenView.vue +++ b/ui/src/views/AutogenView.vue @@ -1030,7 +1030,6 @@ export default { this.setModalWidthByScreen() }, execAction (action, isGroupAction) { - const self = this this.formRef = ref() this.form = reactive({}) this.rules = reactive({}) @@ -1068,6 +1067,7 @@ export default { return 0 }) this.currentAction.paramFields = [] + this.currentAction.paramFilters = [] if ('message' in action) { var message = action.message if (typeof action.message === 'function') { @@ -1075,6 +1075,29 @@ export default { } action.message = message } + + this.getArgs(action, isGroupAction, paramFields) + this.getFilters(action, isGroupAction, paramFields) + this.getFirstIndexFocus() + + this.showAction = true + const listIconForFillValues = ['copy-outlined', 'CopyOutlined', 'edit-outlined', 'EditOutlined', 'share-alt-outlined', 'ShareAltOutlined'] + for (const param of this.currentAction.paramFields) { + if (param.type === 'list' && ['tags', 'hosttags', 'storagetags', 'files'].includes(param.name)) { + param.type = 'string' + } + this.setRules(param) + if (param.type === 'uuid' || param.type === 'list' || param.name === 'account' || (this.currentAction.mapping && param.name in this.currentAction.mapping)) { + this.listUuidOpts(param, this.currentAction.paramFilters[param]) + } + } + this.actionLoading = false + if (action.dataView && listIconForFillValues.includes(action.icon)) { + this.fillEditFormFieldValues() + } + }, + getArgs (action, isGroupAction, paramFields) { + const self = this if ('args' in action) { var args = action.args if (typeof action.args === 'function') { @@ -1096,22 +1119,14 @@ export default { }) } } - this.getFirstIndexFocus() - - this.showAction = true - const listIconForFillValues = ['copy-outlined', 'CopyOutlined', 'edit-outlined', 'EditOutlined', 'share-alt-outlined', 'ShareAltOutlined'] - for (const param of this.currentAction.paramFields) { - if (param.type === 'list' && ['tags', 'hosttags', 'storagetags', 'files'].includes(param.name)) { - param.type = 'string' - } - this.setRules(param) - if (param.type === 'uuid' || param.type === 'list' || param.name === 'account' || (this.currentAction.mapping && param.name in this.currentAction.mapping)) { - this.listUuidOpts(param) + }, + getFilters (action, isGroupAction, paramFields) { + if ('filters' in action) { + var filters = action.filters + if (typeof action.filters === 'function') { + filters = action.filters(action.resource, this.$store.getters, isGroupAction) } - } - this.actionLoading = false - if (action.dataView && listIconForFillValues.includes(action.icon)) { - this.fillEditFormFieldValues() + this.currentAction.paramFilters = filters } }, getFirstIndexFocus () { @@ -1124,13 +1139,14 @@ export default { } } }, - listUuidOpts (param) { + listUuidOpts (param, filters) { if (this.currentAction.mapping && param.name in this.currentAction.mapping && !this.currentAction.mapping[param.name].api) { return } var paramName = param.name var extractedParamName = paramName.replace('ids', '').replace('id', '').toLowerCase() var params = { listall: true } + // add filters const possibleName = 'list' + extractedParamName + 's' var showIcon = false if (this.$showIcon(extractedParamName)) { From 0b368b73515197b72ba384f321f9f01845bf4672 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Tue, 11 Jul 2023 12:58:03 +0200 Subject: [PATCH 2/2] pass the right filters --- ui/src/config/section/compute.js | 7 +++++-- ui/src/views/AutogenView.vue | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ui/src/config/section/compute.js b/ui/src/config/section/compute.js index 68d76574c152..6aa2beff6437 100644 --- a/ui/src/config/section/compute.js +++ b/ui/src/config/section/compute.js @@ -165,8 +165,11 @@ export default { dataView: true, args: ['virtualmachineid', 'templateid'], filters: (record) => { - var filters = [] - filters.push({ key: 'templateid', value: { hypervisortype: record.hypervisor } }) + var filters = {} + var filterParams = {} + filterParams.hypervisortype = record.hypervisor + filterParams.zoneid = record.zoneid + filters.templateid = filterParams return filters }, show: (record) => { return ['Running', 'Stopped'].includes(record.state) }, diff --git a/ui/src/views/AutogenView.vue b/ui/src/views/AutogenView.vue index c36ab6710b67..06157a4dd391 100644 --- a/ui/src/views/AutogenView.vue +++ b/ui/src/views/AutogenView.vue @@ -1088,7 +1088,7 @@ export default { } this.setRules(param) if (param.type === 'uuid' || param.type === 'list' || param.name === 'account' || (this.currentAction.mapping && param.name in this.currentAction.mapping)) { - this.listUuidOpts(param, this.currentAction.paramFilters[param]) + this.listUuidOpts(param, this.currentAction.paramFilters[param.name]) } } this.actionLoading = false @@ -1146,7 +1146,9 @@ export default { var paramName = param.name var extractedParamName = paramName.replace('ids', '').replace('id', '').toLowerCase() var params = { listall: true } - // add filters + for (const filter in filters) { + params[filter] = filters[filter] + } const possibleName = 'list' + extractedParamName + 's' var showIcon = false if (this.$showIcon(extractedParamName)) {