Skip to content

Commit 022dbf3

Browse files
committed
ui: show selected template hypervisor in deploy form
1 parent 5328528 commit 022dbf3

4 files changed

Lines changed: 363 additions & 1 deletion

File tree

ui/src/utils/imageSelection.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
export function getEffectiveImageHypervisor (
19+
imageItems,
20+
imageType,
21+
imageId,
22+
fallbackHypervisor = null
23+
) {
24+
if (imageType !== 'templateid' || !imageId) {
25+
return fallbackHypervisor
26+
}
27+
28+
for (const group of Object.values(imageItems || {})) {
29+
const templates = group?.template
30+
if (!Array.isArray(templates)) {
31+
continue
32+
}
33+
34+
const image = templates.find(item => item.id === imageId)
35+
if (image) {
36+
return image.hypervisor || fallbackHypervisor
37+
}
38+
}
39+
40+
return fallbackHypervisor
41+
}

ui/src/views/compute/wizard/OsBasedImageSelection.vue

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import OsLogo from '@/components/widgets/OsLogo'
130130
import OsBasedImageSelectionSearchView from '@views/compute/wizard/OsBasedImageSelectionSearchView'
131131
import OsBasedImageRadioGroup from '@views/compute/wizard/OsBasedImageRadioGroup'
132132
import DiskSizeSelection from '@views/compute/wizard/DiskSizeSelection'
133+
import { getEffectiveImageHypervisor } from '@/utils/imageSelection'
133134
134135
export default {
135136
name: 'OsBasedImageSelection',
@@ -234,6 +235,19 @@ export default {
234235
watch: {
235236
selectedImageType (newValue) {
236237
this.localSelectedImageType = newValue
238+
this.emitEffectiveHypervisor(newValue, this.selectedImageId)
239+
},
240+
imageItems () {
241+
this.emitEffectiveHypervisor(
242+
this.localSelectedImageType,
243+
this.selectedImageId
244+
)
245+
},
246+
'preFillContent.hypervisor' () {
247+
this.emitEffectiveHypervisor(
248+
this.localSelectedImageType,
249+
this.selectedImageId
250+
)
237251
},
238252
guestOsCategories (newValue) {
239253
this.imageSearchFilters = {}
@@ -285,9 +299,26 @@ export default {
285299
this.localSelectedGuestOsCategoryId = value
286300
this.$emit('change-guest-os-category', this.localSelectedGuestOsCategoryId)
287301
},
302+
emitEffectiveHypervisor (imageType, imageId) {
303+
const fallbackHypervisor = this.preFillContent?.hypervisor
304+
if (!fallbackHypervisor) {
305+
return
306+
}
307+
this.$emit(
308+
'update-image',
309+
'hypervisor',
310+
getEffectiveImageHypervisor(
311+
this.imageItems,
312+
imageType,
313+
imageId,
314+
fallbackHypervisor
315+
)
316+
)
317+
},
288318
updateImage (decorator, id) {
289319
this.selectedImageId = id
290320
this.$emit('update-image', decorator, id)
321+
this.emitEffectiveHypervisor(decorator, id)
291322
},
292323
handleImageSearch (searchFilters) {
293324
this.imageSearchFilters = {

ui/src/views/compute/wizard/TemplateIsoSelection.vue

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
<script>
5353
import TemplateIsoRadioGroup from '@views/compute/wizard/TemplateIsoRadioGroup'
54+
import { getEffectiveImageHypervisor } from '@/utils/imageSelection'
5455
5556
export default {
5657
name: 'TemplateIsoSelection',
@@ -110,7 +111,7 @@ export default {
110111
if (this.preFillContent.templateid) {
111112
if (items[filter.id]?.[key]?.some(item => item.id === this.preFillContent.templateid)) {
112113
this.filterType = filter.id
113-
this.checkedValue = items[filter.id][key][0].id
114+
this.checkedValue = this.preFillContent.templateid
114115
break
115116
}
116117
} else if (items[filter.id]?.[key]?.length > 0) {
@@ -119,18 +120,46 @@ export default {
119120
break
120121
}
121122
}
123+
this.emitEffectiveHypervisor(
124+
this.inputDecorator,
125+
this.checkedValue
126+
)
122127
}
123128
},
124129
inputDecorator (newValue, oldValue) {
125130
if (newValue !== oldValue) {
126131
this.filter = ''
127132
}
133+
this.emitEffectiveHypervisor(newValue, this.checkedValue)
134+
},
135+
'preFillContent.hypervisor' () {
136+
this.emitEffectiveHypervisor(
137+
this.inputDecorator,
138+
this.checkedValue
139+
)
128140
}
129141
},
130142
methods: {
143+
emitEffectiveHypervisor (imageType, imageId) {
144+
const fallbackHypervisor = this.preFillContent?.hypervisor
145+
if (!fallbackHypervisor) {
146+
return
147+
}
148+
this.$emit(
149+
'update-template-iso',
150+
'hypervisor',
151+
getEffectiveImageHypervisor(
152+
this.items,
153+
imageType,
154+
imageId,
155+
fallbackHypervisor
156+
)
157+
)
158+
},
131159
updateTemplateIso (name, id) {
132160
this.checkedValue = id
133161
this.$emit('update-template-iso', name, id)
162+
this.emitEffectiveHypervisor(name, id)
134163
},
135164
handleSearch (value) {
136165
if (!this.filter && !value) {

0 commit comments

Comments
 (0)