|
279 | 279 | @select-compute-item="($event) => updateComputeOffering($event)" |
280 | 280 | @handle-search-filter="($event) => fetchComputeOfferings($event)" /> |
281 | 281 | <compute-selection |
| 282 | + :key="computeSelectionKey" |
282 | 283 | class="row-element" |
283 | 284 | v-if="computeOffering && (computeOffering.iscustomized || computeOffering.iscustomizediops)" |
284 | 285 | :isCustomized="computeOffering.iscustomized" |
|
287 | 288 | :cpuSpeedInputDecorator="cpuSpeedKey" |
288 | 289 | :memoryInputDecorator="memoryKey" |
289 | 290 | :computeOfferingId="computeOffering.id" |
290 | | - :preFillContent="resource" |
| 291 | + :preFillContent="computeOfferingPreFillContent" |
291 | 292 | :isConstrained="'serviceofferingdetails' in computeOffering" |
292 | 293 | :minCpu="getMinCpu()" |
293 | 294 | :maxCpu="getMaxCpu()" |
@@ -765,6 +766,23 @@ export default { |
765 | 766 | } |
766 | 767 | } |
767 | 768 | return nics |
| 769 | + }, |
| 770 | + computeOfferingPreFillContent () { |
| 771 | + return { |
| 772 | + ...this.resource, |
| 773 | + cpunumber: this.getCustomCpuNumberDefault(), |
| 774 | + cpuspeed: this.getCPUSpeed(), |
| 775 | + memory: this.getCustomMemoryDefault() |
| 776 | + } |
| 777 | + }, |
| 778 | + computeSelectionKey () { |
| 779 | + const preFill = this.computeOfferingPreFillContent |
| 780 | + return [ |
| 781 | + this.computeOffering?.id || 'offering', |
| 782 | + preFill.cpunumber || 'cpu', |
| 783 | + preFill.cpuspeed || 'speed', |
| 784 | + preFill.memory || 'memory' |
| 785 | + ].join('-') |
768 | 786 | } |
769 | 787 | }, |
770 | 788 | watch: { |
@@ -865,14 +883,26 @@ export default { |
865 | 883 | } |
866 | 884 | return 'serviceofferingdetails' in this.computeOffering ? this.computeOffering.serviceofferingdetails.maxmemory * 1 : Number.MAX_SAFE_INTEGER |
867 | 885 | }, |
| 886 | + clampCustomValue (value, min, max) { |
| 887 | + if (value === undefined || value === null || isNaN(value)) { |
| 888 | + return min |
| 889 | + } |
| 890 | + return Math.min(Math.max(value * 1, min), max) |
| 891 | + }, |
| 892 | + getCustomCpuNumberDefault () { |
| 893 | + return this.clampCustomValue(this.resource?.cpunumber, this.getMinCpu(), this.getMaxCpu()) |
| 894 | + }, |
| 895 | + getCustomMemoryDefault () { |
| 896 | + return this.clampCustomValue(this.resource?.memory, this.getMinMemory(), this.getMaxMemory()) |
| 897 | + }, |
868 | 898 | getCPUSpeed () { |
869 | 899 | if (!this.computeOffering) { |
870 | | - return 0 |
| 900 | + return 2000 |
871 | 901 | } |
872 | 902 | if (this.computeOffering.cpuspeed) { |
873 | 903 | return this.computeOffering.cpuspeed * 1 |
874 | 904 | } |
875 | | - return this.resource.cpuspeed * 1 || 0 |
| 905 | + return this.resource.cpuspeed * 1 || 2000 |
876 | 906 | }, |
877 | 907 | fetchOptions (param, name, exclude) { |
878 | 908 | if (exclude && exclude.length > 0) { |
|
0 commit comments