support fractional cpu and memory in calc and set better defaults

This commit is contained in:
Tobias Brunner 2025-07-11 10:13:25 +02:00
parent c0c27cd056
commit 83504f6b7c
No known key found for this signature in database
2 changed files with 38 additions and 34 deletions

View file

@ -474,10 +474,12 @@ Please contact me with next steps for ordering this configuration.`;
// Set slider maximums with some padding
if (maxCpus > 0) {
this.cpuRange.min = "0.25";
this.cpuRange.max = Math.ceil(maxCpus);
}
if (maxMemory > 0) {
this.memoryRange.min = "0.25";
this.memoryRange.max = Math.ceil(maxMemory);
}
@ -511,10 +513,10 @@ Please contact me with next steps for ordering this configuration.`;
// Sort plans by vCPU, then by RAM
availablePlans.sort((a, b) => {
if (parseInt(a.vcpus) !== parseInt(b.vcpus)) {
return parseInt(a.vcpus) - parseInt(b.vcpus);
if (parseFloat(a.vcpus) !== parseFloat(b.vcpus)) {
return parseFloat(a.vcpus) - parseFloat(b.vcpus);
}
return parseInt(a.ram) - parseInt(b.ram);
return parseFloat(a.ram) - parseFloat(b.ram);
});
// Add plans to dropdown
@ -599,8 +601,8 @@ Please contact me with next steps for ordering this configuration.`;
updateAddonPrices() {
if (!this.addonsContainer) return;
const cpus = parseInt(this.cpuRange?.value || 2);
const memory = parseInt(this.memoryRange?.value || 4);
const cpus = parseFloat(this.cpuRange?.value || 0.5);
const memory = parseFloat(this.memoryRange?.value || 1);
const storage = parseInt(this.storageRange?.value || 20);
const instances = parseInt(this.instancesRange?.value || 1);
@ -638,8 +640,8 @@ Please contact me with next steps for ordering this configuration.`;
// Get current plan based on configuration
getCurrentPlan() {
const cpus = parseInt(this.cpuRange?.value || 2);
const memory = parseInt(this.memoryRange?.value || 4);
const cpus = parseFloat(this.cpuRange?.value || 0.5);
const memory = parseFloat(this.memoryRange?.value || 1);
const serviceLevel = document.querySelector('input[name="serviceLevel"]:checked')?.value;
if (this.planSelect?.value) {
@ -662,8 +664,8 @@ Please contact me with next steps for ordering this configuration.`;
if (group[serviceLevel]) {
group[serviceLevel].forEach(plan => {
const planCpus = parseInt(plan.vcpus);
const planMemory = parseInt(plan.ram);
const planCpus = parseFloat(plan.vcpus);
const planMemory = parseFloat(plan.ram);
// Check if plan meets minimum requirements
if (planCpus >= cpus && planMemory >= memory) {
@ -708,8 +710,8 @@ Please contact me with next steps for ordering this configuration.`;
// Reset plan selection if in auto-select mode
if (!this.planSelect?.value) {
const cpus = parseInt(this.cpuRange.value);
const memory = parseInt(this.memoryRange.value);
const cpus = parseFloat(this.cpuRange.value);
const memory = parseFloat(this.memoryRange.value);
const storage = parseInt(this.storageRange.value);
const instances = parseInt(this.instancesRange.value);
const serviceLevel = document.querySelector('input[name="serviceLevel"]:checked')?.value;
@ -958,16 +960,16 @@ Please contact me with next steps for ordering this configuration.`;
// Reset sliders to their default values
resetSlidersToDefaults() {
// Reset CPU slider to default value (2)
// Reset CPU slider to default value (0.5 vCPUs)
if (this.cpuRange) {
this.cpuRange.value = '2';
if (this.cpuValue) this.cpuValue.textContent = '2';
this.cpuRange.value = '0.5';
if (this.cpuValue) this.cpuValue.textContent = '0.5';
}
// Reset Memory slider to default value (4 GB)
// Reset Memory slider to default value (1 GB)
if (this.memoryRange) {
this.memoryRange.value = '4';
if (this.memoryValue) this.memoryValue.textContent = '4';
this.memoryRange.value = '1';
if (this.memoryValue) this.memoryValue.textContent = '1';
}
// Reset Storage slider to default value (20 GB)
@ -1345,10 +1347,12 @@ Please contact me with next steps for ordering this configuration.`;
// Set slider maximums with some padding
if (maxCpus > 0) {
this.cpuRange.min = "0.25";
this.cpuRange.max = Math.ceil(maxCpus);
}
if (maxMemory > 0) {
this.memoryRange.min = "0.25";
this.memoryRange.max = Math.ceil(maxMemory);
}
@ -1382,10 +1386,10 @@ Please contact me with next steps for ordering this configuration.`;
// Sort plans by vCPU, then by RAM
availablePlans.sort((a, b) => {
if (parseInt(a.vcpus) !== parseInt(b.vcpus)) {
return parseInt(a.vcpus) - parseInt(b.vcpus);
if (parseFloat(a.vcpus) !== parseFloat(b.vcpus)) {
return parseFloat(a.vcpus) - parseFloat(b.vcpus);
}
return parseInt(a.ram) - parseInt(b.ram);
return parseFloat(a.ram) - parseFloat(b.ram);
});
// Add plans to dropdown
@ -1470,8 +1474,8 @@ Please contact me with next steps for ordering this configuration.`;
updateAddonPrices() {
if (!this.addonsContainer) return;
const cpus = parseInt(this.cpuRange?.value || 2);
const memory = parseInt(this.memoryRange?.value || 4);
const cpus = parseFloat(this.cpuRange?.value || 0.5);
const memory = parseFloat(this.memoryRange?.value || 1);
const storage = parseInt(this.storageRange?.value || 20);
const instances = parseInt(this.instancesRange?.value || 1);
@ -1509,8 +1513,8 @@ Please contact me with next steps for ordering this configuration.`;
// Get current plan based on configuration
getCurrentPlan() {
const cpus = parseInt(this.cpuRange?.value || 2);
const memory = parseInt(this.memoryRange?.value || 4);
const cpus = parseFloat(this.cpuRange?.value || 0.5);
const memory = parseFloat(this.memoryRange?.value || 1);
const serviceLevel = document.querySelector('input[name="serviceLevel"]:checked')?.value;
if (this.planSelect?.value) {
@ -1533,8 +1537,8 @@ Please contact me with next steps for ordering this configuration.`;
if (group[serviceLevel]) {
group[serviceLevel].forEach(plan => {
const planCpus = parseInt(plan.vcpus);
const planMemory = parseInt(plan.ram);
const planCpus = parseFloat(plan.vcpus);
const planMemory = parseFloat(plan.ram);
// Check if plan meets minimum requirements
if (planCpus >= cpus && planMemory >= memory) {
@ -1579,8 +1583,8 @@ Please contact me with next steps for ordering this configuration.`;
// Reset plan selection if in auto-select mode
if (!this.planSelect?.value) {
const cpus = parseInt(this.cpuRange.value);
const memory = parseInt(this.memoryRange.value);
const cpus = parseFloat(this.cpuRange.value);
const memory = parseFloat(this.memoryRange.value);
const storage = parseInt(this.storageRange.value);
const instances = parseInt(this.instancesRange.value);
const serviceLevel = document.querySelector('input[name="serviceLevel"]:checked')?.value;

View file

@ -219,11 +219,11 @@
<div class="mb-4">
<label for="cpuRange" class="form-label d-flex justify-content-between">
<span>vCPUs</span>
<span class="fw-bold" id="cpuValue">2</span>
<span class="fw-bold" id="cpuValue">0.5</span>
</label>
<input type="range" class="form-range" id="cpuRange" min="1" max="32" value="2" step="1">
<input type="range" class="form-range" id="cpuRange" min="0.25" max="32" value="0.5" step="0.25">
<div class="d-flex justify-content-between text-muted small">
<span id="cpuMinDisplay">1</span>
<span id="cpuMinDisplay">0.25</span>
<span id="cpuMaxDisplay">32</span>
</div>
</div>
@ -232,11 +232,11 @@
<div class="mb-4">
<label for="memoryRange" class="form-label d-flex justify-content-between">
<span>Memory (GB)</span>
<span class="fw-bold" id="memoryValue">4</span>
<span class="fw-bold" id="memoryValue">1</span>
</label>
<input type="range" class="form-range" id="memoryRange" min="1" max="128" value="4" step="1">
<input type="range" class="form-range" id="memoryRange" min="0.25" max="128" value="1" step="0.25">
<div class="d-flex justify-content-between text-muted small">
<span id="memoryMinDisplay">1 GB</span>
<span id="memoryMinDisplay">0.25 GB</span>
<span id="memoryMaxDisplay">128 GB</span>
</div>
</div>