From b125cab7727de6159cacde6dfadac001bb6133a2 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 10 Sep 2021 17:02:43 +0530 Subject: [PATCH 1/5] ui: add custom form for update template Signed-off-by: Abhishek Kumar --- ui/src/config/section/image.js | 17 +- ui/src/views/image/UpdateTemplate.vue | 383 ++++++++++++++++++++++++++ 2 files changed, 399 insertions(+), 1 deletion(-) create mode 100644 ui/src/views/image/UpdateTemplate.vue diff --git a/ui/src/config/section/image.js b/ui/src/config/section/image.js index 77345372bf49..a1cfb9581db7 100644 --- a/ui/src/config/section/image.js +++ b/ui/src/config/section/image.js @@ -93,7 +93,7 @@ export default { }, { api: 'updateTemplate', - icon: 'edit', + icon: 'settings', label: 'label.edit', dataView: true, show: (record, store) => { @@ -116,6 +116,21 @@ export default { } } }, + { + api: 'updateTemplate', + icon: 'edit', + label: 'label.edit', + dataView: true, + show: (record, store) => { + return (['Admin'].includes(store.userInfo.roletype) || // If admin or owner or belongs to current project + (record.domainid === store.userInfo.domainid && record.account === store.userInfo.account) || + (record.domainid === store.userInfo.domainid && record.projectid && store.project && store.project.id && record.projectid === store.project.id)) && + record.templatetype !== 'SYSTEM' && + record.isready + }, + popup: true, + component: () => import('@/views/image/UpdateTemplate.vue') + }, { api: 'updateTemplatePermissions', icon: 'share-alt', diff --git a/ui/src/views/image/UpdateTemplate.vue b/ui/src/views/image/UpdateTemplate.vue new file mode 100644 index 000000000000..02ba3b297f25 --- /dev/null +++ b/ui/src/views/image/UpdateTemplate.vue @@ -0,0 +1,383 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + + + + + + From b15037c53bda74808bebe5b87c20b3dfb60699e3 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 14 Sep 2021 17:12:02 +0530 Subject: [PATCH 2/5] fix Signed-off-by: Abhishek Kumar --- ui/src/config/section/image.js | 25 ------------------------- ui/src/views/image/UpdateTemplate.vue | 14 ++++++++++---- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/ui/src/config/section/image.js b/ui/src/config/section/image.js index a1cfb9581db7..1aeeb2f4102a 100644 --- a/ui/src/config/section/image.js +++ b/ui/src/config/section/image.js @@ -91,31 +91,6 @@ export default { popup: true, component: () => import('@/views/image/RegisterOrUploadTemplate.vue') }, - { - api: 'updateTemplate', - icon: 'settings', - label: 'label.edit', - dataView: true, - show: (record, store) => { - return (['Admin'].includes(store.userInfo.roletype) || // If admin or owner or belongs to current project - (record.domainid === store.userInfo.domainid && record.account === store.userInfo.account) || - (record.domainid === store.userInfo.domainid && record.projectid && store.project && store.project.id && record.projectid === store.project.id)) && - record.templatetype !== 'SYSTEM' && - record.isready - }, - args: (record, store) => { - var fields = ['name', 'displaytext', 'passwordenabled', 'ostypeid', 'isdynamicallyscalable'] - if (['Admin'].includes(store.userInfo.roletype)) { - fields.push('templatetype') - } - return fields - }, - mapping: { - templatetype: { - options: ['BUILTIN', 'USER', 'SYSTEM', 'ROUTING'] - } - } - }, { api: 'updateTemplate', icon: 'edit', diff --git a/ui/src/views/image/UpdateTemplate.vue b/ui/src/views/image/UpdateTemplate.vue index 02ba3b297f25..f0ff806924f6 100644 --- a/ui/src/views/image/UpdateTemplate.vue +++ b/ui/src/views/image/UpdateTemplate.vue @@ -46,7 +46,7 @@ - + - + Date: Thu, 20 Jan 2022 16:11:23 +0530 Subject: [PATCH 3/5] label fix Signed-off-by: Abhishek Kumar --- ui/public/locales/en.json | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json index 90fcad857c15..984739652767 100644 --- a/ui/public/locales/en.json +++ b/ui/public/locales/en.json @@ -3280,6 +3280,7 @@ "message.success.unmanage.instance": "Successfully unmanaged instance", "message.success.update.ipaddress": "Successfully updated IP Address", "message.success.update.kubeversion": "Successfully updated Kubernetes supported version", +"message.success.update.template": "Successfully updated Template", "message.success.update.user": "Successfully updated user", "message.success.upgrade.kubernetes": "Successfully upgraded Kubernetes cluster", "message.success.upload": "Upload Successfully", From 6b5092adb227d55cc01152b81cf71aa1eb4171b2 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 24 Jan 2022 12:23:29 +0530 Subject: [PATCH 4/5] changes and fix Signed-off-by: Abhishek Kumar --- ui/public/locales/en.json | 1 + ui/src/views/image/UpdateTemplate.vue | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json index bff6fac52b61..9c44d838495c 100644 --- a/ui/public/locales/en.json +++ b/ui/public/locales/en.json @@ -3341,6 +3341,7 @@ "message.template.desc": "OS image that can be used to boot VMs", "message.template.import.vm.temporary": "If a temporary template is used, reset VM operation will not work after import.", "message.template.iso": "Please select a template or ISO to continue", +"message.template.type.change.warning": "WARNING: Changing the template type to SYSTEM will disable further changes to the template.", "message.tier.required": "Tier is required", "message.tooltip.dns.1": "Name of a DNS server for use by VMs in the zone. The public IP addresses for the zone must have a route to this server.", "message.tooltip.dns.2": "A second DNS server name for use by VMs in the zone. The public IP addresses for the zone must have a route to this server.", diff --git a/ui/src/views/image/UpdateTemplate.vue b/ui/src/views/image/UpdateTemplate.vue index f0ff806924f6..fb77e0ee8219 100644 --- a/ui/src/views/image/UpdateTemplate.vue +++ b/ui/src/views/image/UpdateTemplate.vue @@ -125,7 +125,14 @@ - + + + + + + +
+
= 0 }" v-decorator="['templatetype']" - :placeholder="apiParams.templatetype.description"> + :placeholder="apiParams.templatetype.description" + @change="val => { selectedTemplateType = val }"> {{ opt }} @@ -171,7 +179,8 @@ export default { nicAdapterType: {}, keyboardType: {}, osTypes: {}, - loading: false + loading: false, + selectedTemplateType: '' } }, beforeCreate () { @@ -222,7 +231,7 @@ export default { this.fetchKeyboardTypes() }, isValidValueForKey (obj, key) { - return key in obj && obj[key] != null && obj[key] !== undefined + return key in obj && obj[key] != null && obj[key] !== undefined && obj[key] !== '' }, fetchOsTypes () { const params = {} @@ -351,7 +360,7 @@ export default { const params = { id: this.resource.id } - const detailsField = ['rootDiskController', 'nicAdapter', 'keyboardType'] + const detailsField = ['rootDiskController', 'nicAdapter', 'keyboard'] for (const key in values) { if (!this.isValidValueForKey(values, key)) continue if (detailsField.includes(key)) { From 4ca5dc4f88119331f76ffb2e27238d3005ef0a02 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 24 Jan 2022 21:24:23 +0530 Subject: [PATCH 5/5] fix Signed-off-by: Abhishek Kumar --- ui/src/views/image/UpdateTemplate.vue | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ui/src/views/image/UpdateTemplate.vue b/ui/src/views/image/UpdateTemplate.vue index fb77e0ee8219..0d9239cd3216 100644 --- a/ui/src/views/image/UpdateTemplate.vue +++ b/ui/src/views/image/UpdateTemplate.vue @@ -186,6 +186,7 @@ export default { beforeCreate () { this.form = this.$form.createForm(this) this.apiParams = this.$getApiParams('updateTemplate') + this.isAdmin = ['Admin'].includes(this.$store.getters.userInfo.roletype) }, created () { this.$set(this.rootDisk, 'loading', false) @@ -197,7 +198,7 @@ export default { this.$set(this.osTypes, 'loading', false) this.$set(this.osTypes, 'opts', []) const resourceFields = ['name', 'displaytext', 'passwordenabled', 'ostypeid', 'isdynamicallyscalable'] - if (this.isAdmin()) { + if (this.isAdmin) { resourceFields.push('templatetype') } for (var field of resourceFields) { @@ -221,9 +222,6 @@ export default { this.fetchData() }, methods: { - isAdmin () { - return ['Admin'].includes(this.$store.getters.userInfo.roletype) - }, fetchData () { this.fetchOsTypes() this.fetchRootDiskControllerTypes(this.resource.hypervisor)